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