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