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