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