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