Home | History | Annotate | Line # | Download | only in rasops
rasops32.c revision 1.1
      1 /* $NetBSD: rasops32.c,v 1.1 1999/04/13 00:18:01 ad 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 Andy Doran <ad (at) NetBSD.org>.
      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 #include "opt_rasops.h"
     39 #ifdef RASOPS32
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.1 1999/04/13 00:18:01 ad Exp $");
     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 static void 	rasops32_erasecols __P((void *, int, int, int, long));
     55 static void 	rasops32_eraserows __P((void *, int, int, long));
     56 static int32_t	rasops32_fg_color __P((struct rasops_info *, long));
     57 static int32_t	rasops32_bg_color __P((struct rasops_info *, long));
     58 static void	rasops32_do_cursor __P((struct rasops_info *));
     59 void		rasops32_init __P((struct rasops_info *ri));
     60 
     61 /*
     62  * Initalize a 'rasops_info' descriptor for this depth.
     63  */
     64 void
     65 rasops32_init(ri)
     66 	struct rasops_info *ri;
     67 {
     68 
     69 	/*
     70 	 * This sucks. There is little optimization you can do with this
     71 	 * colordepth on 32-bit machines.
     72   	 *
     73 	 * XXX c'mon sparc, alpha ppl?
     74 	 */
     75 	ri->ri_ops.putchar = rasops32_putchar;
     76 	ri->ri_ops.erasecols = rasops32_erasecols;
     77 	ri->ri_ops.eraserows = rasops32_eraserows;
     78 	ri->ri_do_cursor = rasops32_do_cursor;
     79 	rasops_init_devcmap(ri);
     80 }
     81 
     82 
     83 /*
     84  * Get background color from attribute.
     85  */
     86 static __inline__ int32_t
     87 rasops32_bg_color(ri, attr)
     88 	struct rasops_info *ri;
     89 	long attr;
     90 {
     91 
     92 	return ri->ri_devcmap[((int32_t)attr >> 24) & 15];
     93 }
     94 
     95 
     96 /*
     97  * Get foreground color from attribute.
     98  */
     99 static __inline__ int32_t
    100 rasops32_fg_color(ri, attr)
    101 	struct rasops_info *ri;
    102 	long attr;
    103 {
    104 
    105 	return ri->ri_devcmap[((int32_t)attr >> 16) & 15];
    106 }
    107 
    108 
    109 /*
    110  * Actually turn the cursor on or off. This does the dirty work for
    111  * rasops_cursor().
    112  */
    113 static void
    114 rasops32_do_cursor(ri)
    115 	struct rasops_info *ri;
    116 {
    117 	u_char *rp;
    118 	int32_t *dp, planemask;
    119 	int num, height, cnt, row, col;
    120 
    121 	row = ri->ri_crow;
    122 	col = ri->ri_ccol;
    123 
    124 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    125 	height = ri->ri_font->fontheight;
    126 	num = ri->ri_xscale >> 2;
    127 	planemask = ri->ri_devcmap[15];
    128 
    129 	while (height--) {
    130 		dp = (int32_t *)rp;
    131 		rp += ri->ri_stride;
    132 
    133 		for (cnt = num; cnt; cnt--)
    134 			*dp++ ^= planemask;
    135 	}
    136 }
    137 
    138 
    139 /*
    140  * Paint a single character.
    141  */
    142 static void
    143 rasops32_putchar(cookie, row, col, uc, attr)
    144 	void *cookie;
    145 	int row, col;
    146 	u_int uc;
    147 	long attr;
    148 {
    149 	struct rasops_info *ri;
    150 	int32_t *dp, *rp, clr[2];
    151 	u_char *fr;
    152 	int width, height, cnt, fs, fb;
    153 
    154 	ri = (struct rasops_info *)cookie;
    155 
    156 #ifdef RASOPS_CLIPPING
    157 	/* Catches 'row < 0' case too */
    158 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    159 		return;
    160 
    161 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    162 		return;
    163 #endif
    164 
    165 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    166 
    167 	height = ri->ri_font->fontheight;
    168 	width = ri->ri_font->fontwidth;
    169 	clr[0] = rasops32_bg_color(ri, attr);
    170 	clr[1] = rasops32_fg_color(ri, attr);
    171 
    172 	if (uc == ' ') {
    173 		while (height--) {
    174 			dp = rp;
    175 			DELTA(rp, ri->ri_stride, int32_t *);
    176 
    177 			for (cnt = width; cnt; cnt--)
    178 				*dp++ = clr[0];
    179 		}
    180 	} else {
    181 		uc -= ri->ri_font->firstchar;
    182 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    183 		fs = ri->ri_font->stride;
    184 
    185 		while (height--) {
    186 			dp = rp;
    187 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
    188 			fr += fs;
    189 			DELTA(rp, ri->ri_stride, int32_t *);
    190 
    191 			for (cnt = width; cnt; cnt--) {
    192 				*dp++ = clr[(fb >> 31) & 1];
    193 				fb <<= 1;
    194 			}
    195 		}
    196 	}
    197 
    198 	/* Do underline */
    199 	if (attr & 1) {
    200 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    201 
    202 		while (width--)
    203 			*rp++ = clr[1];
    204 	}
    205 }
    206 
    207 
    208 /*
    209  * Erase rows.
    210  */
    211 static void
    212 rasops32_eraserows(cookie, row, num, attr)
    213 	void *cookie;
    214 	int row, num;
    215 	long attr;
    216 {
    217 	struct rasops_info *ri;
    218 	int32_t *dp, clr;
    219 	int n8, n1, cnt;
    220 
    221 	ri = (struct rasops_info *)cookie;
    222 
    223 #ifdef RASOPS_CLIPPING
    224 	if (row < 0) {
    225 		num += row;
    226 		row = 0;
    227 	}
    228 
    229 	if ((row + num) > ri->ri_rows)
    230 		num = ri->ri_rows - row;
    231 
    232 	if (num <= 0)
    233 		return;
    234 #endif
    235 
    236 	num *= ri->ri_font->fontheight;
    237 	dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    238 	clr = rasops32_bg_color(ri, attr);
    239 
    240 	n8 = ri->ri_emustride >> 5;
    241 	n1 = (ri->ri_emustride >> 2) & 7;
    242 
    243 	while (num--) {
    244 		for (cnt = n8; cnt; cnt--) {
    245 			dp[0] = clr;
    246 			dp[1] = clr;
    247 			dp[2] = clr;
    248 			dp[3] = clr;
    249 			dp[4] = clr;
    250 			dp[5] = clr;
    251 			dp[6] = clr;
    252 			dp[7] = clr;
    253 			dp += 8;
    254 		}
    255 
    256 		for (cnt = n1; cnt; cnt--)
    257 			*dp++ = clr;
    258 
    259 		DELTA(dp, ri->ri_delta, int32_t *);
    260 	}
    261 }
    262 
    263 
    264 /*
    265  * Erase columns.
    266  */
    267 static void
    268 rasops32_erasecols(cookie, row, col, num, attr)
    269 	void *cookie;
    270 	int row, col, num;
    271 	long attr;
    272 {
    273 	int n8, clr, height, cnt;
    274 	struct rasops_info *ri;
    275 	int32_t *dst;
    276 	u_char *rp;
    277 
    278 	ri = (struct rasops_info *)cookie;
    279 
    280 #ifdef RASOPS_CLIPPING
    281 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    282 		return;
    283 
    284 	if (col < 0) {
    285 		num += col;
    286 		col = 0;
    287 	}
    288 
    289 	if ((col + num) > ri->ri_cols)
    290 		num = ri->ri_cols - col;
    291 
    292 	if (num <= 0)
    293 		return;
    294 #endif
    295 
    296 	num = num * ri->ri_xscale;
    297 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    298 	clr = rasops32_bg_color(ri, attr);
    299 	height = ri->ri_font->fontheight;
    300 	n8 = num >> 5;
    301 	num = (num >> 2) & 7;
    302 
    303 	while (height--) {
    304 		dst = (int32_t *)rp;
    305 		rp += ri->ri_stride;
    306 
    307 		for (cnt = n8; cnt; cnt--) {
    308 			dst[0] = clr;
    309 			dst[1] = clr;
    310 			dst[2] = clr;
    311 			dst[3] = clr;
    312 			dst[4] = clr;
    313 			dst[5] = clr;
    314 			dst[6] = clr;
    315 			dst[7] = clr;
    316 			dst += 8;
    317 		}
    318 
    319 		for (cnt = num; cnt; cnt--)
    320 			*dst++ = clr;
    321 	}
    322 }
    323 
    324 #endif /* RASOPS32 */
    325