wscons_rinit.c revision 1.5 1 1.5 agc /* $NetBSD: wscons_rinit.c,v 1.5 2003/08/07 16:31:29 agc 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.5 agc * 3. Neither the name of the University nor the names of its contributors
25 1.1 drochner * may be used to endorse or promote products derived from this software
26 1.1 drochner * without specific prior written permission.
27 1.1 drochner *
28 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 drochner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 drochner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 drochner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 drochner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 drochner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 drochner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 drochner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 drochner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 drochner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 drochner * SUCH DAMAGE.
39 1.1 drochner *
40 1.1 drochner * @(#)rcons_font.c 8.1 (Berkeley) 6/11/93
41 1.1 drochner */
42 1.4 lukem
43 1.4 lukem #include <sys/cdefs.h>
44 1.5 agc __KERNEL_RCSID(0, "$NetBSD: wscons_rinit.c,v 1.5 2003/08/07 16:31:29 agc Exp $");
45 1.1 drochner
46 1.1 drochner #include <sys/param.h>
47 1.1 drochner #include <sys/systm.h>
48 1.1 drochner #include <sys/device.h>
49 1.1 drochner
50 1.1 drochner #include <dev/rcons/raster.h>
51 1.1 drochner #include <dev/wscons/wscons_raster.h>
52 1.1 drochner
53 1.1 drochner #include <dev/wscons/wscons_rfont.h>
54 1.1 drochner
55 1.3 augustss void rcons_initfont(struct rcons *, struct raster_font *);
56 1.1 drochner
57 1.1 drochner void
58 1.3 augustss rcons_initfont(struct rcons *rc, struct raster_font *fp)
59 1.1 drochner {
60 1.1 drochner static int initfontdone;
61 1.1 drochner
62 1.1 drochner rc->rc_font = fp;
63 1.1 drochner
64 1.1 drochner /* Get distance to top and bottom of font from font origin */
65 1.1 drochner rc->rc_font_ascent = -(rc->rc_font->chars)['a'].homey;
66 1.1 drochner
67 1.1 drochner #if !defined(MSBYTE_FIRST) && !defined(MSBIT_FIRST) /* XXX other cases */
68 1.1 drochner /* swap byte order on font data. ick. */
69 1.1 drochner if (!initfontdone) {
70 1.1 drochner int ch, i, n, bit;
71 1.1 drochner u_int32_t *pix, npix;
72 1.1 drochner
73 1.1 drochner for (ch = 0; ch < 256; ch++) {
74 1.1 drochner if (rc->rc_font->chars[ch].r == 0)
75 1.1 drochner continue;
76 1.1 drochner
77 1.1 drochner n = rc->rc_font->chars[ch].r->linelongs *
78 1.1 drochner rc->rc_font->chars[ch].r->height;
79 1.1 drochner pix = rc->rc_font->chars[ch].r->pixels;
80 1.1 drochner
81 1.1 drochner for (i = 0; i < n; i++) {
82 1.1 drochner npix = 0;
83 1.1 drochner for (bit = 0; bit < 32; bit++)
84 1.1 drochner if (pix[i] & (1 << bit))
85 1.1 drochner npix |= (1 << (31 - bit));
86 1.1 drochner pix[i] = npix;
87 1.1 drochner }
88 1.1 drochner }
89 1.1 drochner }
90 1.1 drochner #endif
91 1.1 drochner
92 1.1 drochner initfontdone = 1;
93 1.1 drochner }
94 1.1 drochner
95 1.1 drochner void
96 1.3 augustss rcons_init(struct rcons *rc, int mrow, int mcol)
97 1.1 drochner {
98 1.1 drochner struct raster *rp = rc->rc_sp;
99 1.1 drochner int i;
100 1.1 drochner
101 1.1 drochner rcons_initfont(rc, &gallant19);
102 1.1 drochner
103 1.1 drochner i = rp->height / rc->rc_font->height;
104 1.1 drochner rc->rc_maxrow = min(i, mrow);
105 1.1 drochner
106 1.1 drochner i = rp->width / rc->rc_font->width;
107 1.1 drochner rc->rc_maxcol = min(i, mcol);
108 1.1 drochner
109 1.1 drochner /* Center emulator screen (but align x origin to 32 bits) */
110 1.1 drochner rc->rc_xorigin =
111 1.1 drochner ((rp->width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
112 1.1 drochner rc->rc_yorigin =
113 1.1 drochner (rp->height - rc->rc_maxrow * rc->rc_font->height) / 2;
114 1.1 drochner
115 1.1 drochner /* Raster width used for row copies */
116 1.1 drochner rc->rc_raswidth = rc->rc_maxcol * rc->rc_font->width;
117 1.1 drochner if (rc->rc_raswidth & 0x1f) {
118 1.1 drochner /* Pad to 32 bits */
119 1.1 drochner i = (rc->rc_raswidth + 0x1f) & ~0x1f;
120 1.1 drochner /* Make sure width isn't too wide */
121 1.1 drochner if (rc->rc_xorigin + i <= rp->width)
122 1.1 drochner rc->rc_raswidth = i;
123 1.1 drochner }
124 1.1 drochner
125 1.1 drochner rc->rc_bits = 0;
126 1.1 drochner
127 1.1 drochner /* If cursor position given, assume it's there and drawn. */
128 1.1 drochner if (*rc->rc_crowp != -1 && *rc->rc_ccolp != -1)
129 1.1 drochner rc->rc_bits |= RC_CURSOR;
130 1.1 drochner }
131