wscons_rinit.c revision 1.3 1 /* $NetBSD: wscons_rinit.c,v 1.3 2001/10/13 15:56:15 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)rcons_font.c 8.1 (Berkeley) 6/11/93
45 */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50
51 #include <dev/rcons/raster.h>
52 #include <dev/wscons/wscons_raster.h>
53
54 #include <dev/wscons/wscons_rfont.h>
55
56 void rcons_initfont(struct rcons *, struct raster_font *);
57
58 void
59 rcons_initfont(struct rcons *rc, struct raster_font *fp)
60 {
61 static int initfontdone;
62
63 rc->rc_font = fp;
64
65 /* Get distance to top and bottom of font from font origin */
66 rc->rc_font_ascent = -(rc->rc_font->chars)['a'].homey;
67
68 #if !defined(MSBYTE_FIRST) && !defined(MSBIT_FIRST) /* XXX other cases */
69 /* swap byte order on font data. ick. */
70 if (!initfontdone) {
71 int ch, i, n, bit;
72 u_int32_t *pix, npix;
73
74 for (ch = 0; ch < 256; ch++) {
75 if (rc->rc_font->chars[ch].r == 0)
76 continue;
77
78 n = rc->rc_font->chars[ch].r->linelongs *
79 rc->rc_font->chars[ch].r->height;
80 pix = rc->rc_font->chars[ch].r->pixels;
81
82 for (i = 0; i < n; i++) {
83 npix = 0;
84 for (bit = 0; bit < 32; bit++)
85 if (pix[i] & (1 << bit))
86 npix |= (1 << (31 - bit));
87 pix[i] = npix;
88 }
89 }
90 }
91 #endif
92
93 initfontdone = 1;
94 }
95
96 void
97 rcons_init(struct rcons *rc, int mrow, int mcol)
98 {
99 struct raster *rp = rc->rc_sp;
100 int i;
101
102 rcons_initfont(rc, &gallant19);
103
104 i = rp->height / rc->rc_font->height;
105 rc->rc_maxrow = min(i, mrow);
106
107 i = rp->width / rc->rc_font->width;
108 rc->rc_maxcol = min(i, mcol);
109
110 /* Center emulator screen (but align x origin to 32 bits) */
111 rc->rc_xorigin =
112 ((rp->width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
113 rc->rc_yorigin =
114 (rp->height - rc->rc_maxrow * rc->rc_font->height) / 2;
115
116 /* Raster width used for row copies */
117 rc->rc_raswidth = rc->rc_maxcol * rc->rc_font->width;
118 if (rc->rc_raswidth & 0x1f) {
119 /* Pad to 32 bits */
120 i = (rc->rc_raswidth + 0x1f) & ~0x1f;
121 /* Make sure width isn't too wide */
122 if (rc->rc_xorigin + i <= rp->width)
123 rc->rc_raswidth = i;
124 }
125
126 rc->rc_bits = 0;
127
128 /* If cursor position given, assume it's there and drawn. */
129 if (*rc->rc_crowp != -1 && *rc->rc_ccolp != -1)
130 rc->rc_bits |= RC_CURSOR;
131 }
132