Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.10
      1 /*	 $NetBSD: rasops32.c,v 1.10 2001/11/13 07:00:23 lukem Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.10 2001/11/13 07:00:23 lukem Exp $");
     41 
     42 #include "opt_rasops.h"
     43 
     44 #include <sys/types.h>
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/time.h>
     48 
     49 #include <dev/wscons/wsdisplayvar.h>
     50 #include <dev/wscons/wsconsio.h>
     51 #include <dev/rasops/rasops.h>
     52 
     53 static void 	rasops32_putchar __P((void *, int, int, u_int, long attr));
     54 
     55 /*
     56  * Initialize a 'rasops_info' descriptor for this depth.
     57  */
     58 void
     59 rasops32_init(ri)
     60 	struct rasops_info *ri;
     61 {
     62 
     63 	if (ri->ri_rnum == 0) {
     64 		ri->ri_rnum = 8;
     65 		ri->ri_rpos = 0;
     66 		ri->ri_gnum = 8;
     67 		ri->ri_gpos = 8;
     68 		ri->ri_bnum = 8;
     69 		ri->ri_bpos = 16;
     70 	}
     71 
     72 	ri->ri_ops.putchar = rasops32_putchar;
     73 }
     74 
     75 /*
     76  * Paint a single character.
     77  */
     78 static void
     79 rasops32_putchar(cookie, row, col, uc, attr)
     80 	void *cookie;
     81 	int row, col;
     82 	u_int uc;
     83 	long attr;
     84 {
     85 	int width, height, cnt, fs, fb, clr[2];
     86 	struct rasops_info *ri;
     87 	int32_t *dp, *rp;
     88 	u_char *fr;
     89 
     90 	ri = (struct rasops_info *)cookie;
     91 
     92 #ifdef RASOPS_CLIPPING
     93 	/* Catches 'row < 0' case too */
     94 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     95 		return;
     96 
     97 	if ((unsigned)col >= (unsigned)ri->ri_cols)
     98 		return;
     99 #endif
    100 
    101 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    102 
    103 	height = ri->ri_font->fontheight;
    104 	width = ri->ri_font->fontwidth;
    105 
    106 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
    107 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
    108 
    109 	if (uc == ' ') {
    110 		while (height--) {
    111 			dp = rp;
    112 			DELTA(rp, ri->ri_stride, int32_t *);
    113 
    114 			for (cnt = width; cnt; cnt--)
    115 				*dp++ = clr[0];
    116 		}
    117 	} else {
    118 		uc -= ri->ri_font->firstchar;
    119 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    120 		fs = ri->ri_font->stride;
    121 
    122 		while (height--) {
    123 			dp = rp;
    124 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    125 			    (fr[0] << 24);
    126 			fr += fs;
    127 			DELTA(rp, ri->ri_stride, int32_t *);
    128 
    129 			for (cnt = width; cnt; cnt--) {
    130 				*dp++ = clr[(fb >> 31) & 1];
    131 				fb <<= 1;
    132 			}
    133 		}
    134 	}
    135 
    136 	/* Do underline */
    137 	if ((attr & 1) != 0) {
    138 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    139 
    140 		while (width--)
    141 			*rp++ = clr[1];
    142 	}
    143 }
    144