wscons_rinit.c revision 1.3 1 1.3 augustss /* $NetBSD: wscons_rinit.c,v 1.3 2001/10/13 15:56:15 augustss 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.1 drochner
47 1.1 drochner #include <sys/param.h>
48 1.1 drochner #include <sys/systm.h>
49 1.1 drochner #include <sys/device.h>
50 1.1 drochner
51 1.1 drochner #include <dev/rcons/raster.h>
52 1.1 drochner #include <dev/wscons/wscons_raster.h>
53 1.1 drochner
54 1.1 drochner #include <dev/wscons/wscons_rfont.h>
55 1.1 drochner
56 1.3 augustss void rcons_initfont(struct rcons *, struct raster_font *);
57 1.1 drochner
58 1.1 drochner void
59 1.3 augustss rcons_initfont(struct rcons *rc, struct raster_font *fp)
60 1.1 drochner {
61 1.1 drochner static int initfontdone;
62 1.1 drochner
63 1.1 drochner rc->rc_font = fp;
64 1.1 drochner
65 1.1 drochner /* Get distance to top and bottom of font from font origin */
66 1.1 drochner rc->rc_font_ascent = -(rc->rc_font->chars)['a'].homey;
67 1.1 drochner
68 1.1 drochner #if !defined(MSBYTE_FIRST) && !defined(MSBIT_FIRST) /* XXX other cases */
69 1.1 drochner /* swap byte order on font data. ick. */
70 1.1 drochner if (!initfontdone) {
71 1.1 drochner int ch, i, n, bit;
72 1.1 drochner u_int32_t *pix, npix;
73 1.1 drochner
74 1.1 drochner for (ch = 0; ch < 256; ch++) {
75 1.1 drochner if (rc->rc_font->chars[ch].r == 0)
76 1.1 drochner continue;
77 1.1 drochner
78 1.1 drochner n = rc->rc_font->chars[ch].r->linelongs *
79 1.1 drochner rc->rc_font->chars[ch].r->height;
80 1.1 drochner pix = rc->rc_font->chars[ch].r->pixels;
81 1.1 drochner
82 1.1 drochner for (i = 0; i < n; i++) {
83 1.1 drochner npix = 0;
84 1.1 drochner for (bit = 0; bit < 32; bit++)
85 1.1 drochner if (pix[i] & (1 << bit))
86 1.1 drochner npix |= (1 << (31 - bit));
87 1.1 drochner pix[i] = npix;
88 1.1 drochner }
89 1.1 drochner }
90 1.1 drochner }
91 1.1 drochner #endif
92 1.1 drochner
93 1.1 drochner initfontdone = 1;
94 1.1 drochner }
95 1.1 drochner
96 1.1 drochner void
97 1.3 augustss rcons_init(struct rcons *rc, int mrow, int mcol)
98 1.1 drochner {
99 1.1 drochner struct raster *rp = rc->rc_sp;
100 1.1 drochner int i;
101 1.1 drochner
102 1.1 drochner rcons_initfont(rc, &gallant19);
103 1.1 drochner
104 1.1 drochner i = rp->height / rc->rc_font->height;
105 1.1 drochner rc->rc_maxrow = min(i, mrow);
106 1.1 drochner
107 1.1 drochner i = rp->width / rc->rc_font->width;
108 1.1 drochner rc->rc_maxcol = min(i, mcol);
109 1.1 drochner
110 1.1 drochner /* Center emulator screen (but align x origin to 32 bits) */
111 1.1 drochner rc->rc_xorigin =
112 1.1 drochner ((rp->width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
113 1.1 drochner rc->rc_yorigin =
114 1.1 drochner (rp->height - rc->rc_maxrow * rc->rc_font->height) / 2;
115 1.1 drochner
116 1.1 drochner /* Raster width used for row copies */
117 1.1 drochner rc->rc_raswidth = rc->rc_maxcol * rc->rc_font->width;
118 1.1 drochner if (rc->rc_raswidth & 0x1f) {
119 1.1 drochner /* Pad to 32 bits */
120 1.1 drochner i = (rc->rc_raswidth + 0x1f) & ~0x1f;
121 1.1 drochner /* Make sure width isn't too wide */
122 1.1 drochner if (rc->rc_xorigin + i <= rp->width)
123 1.1 drochner rc->rc_raswidth = i;
124 1.1 drochner }
125 1.1 drochner
126 1.1 drochner rc->rc_bits = 0;
127 1.1 drochner
128 1.1 drochner /* If cursor position given, assume it's there and drawn. */
129 1.1 drochner if (*rc->rc_crowp != -1 && *rc->rc_ccolp != -1)
130 1.1 drochner rc->rc_bits |= RC_CURSOR;
131 1.1 drochner }
132