Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.6
      1 /* 	$NetBSD: rasops1.c,v 1.6 1999/07/21 19:19:04 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.
      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 "opt_rasops.h"
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.6 1999/07/21 19:19:04 ad Exp $");
     42 
     43 #include <sys/types.h>
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/time.h>
     47 #include <machine/endian.h>
     48 
     49 #include <dev/wscons/wsdisplayvar.h>
     50 #include <dev/wscons/wsconsio.h>
     51 #include <dev/rasops/rasops.h>
     52 #include <dev/rasops/rasops_masks.h>
     53 
     54 static void	rasops1_putchar __P((void *, int, int col, u_int, long));
     55 static void	rasops1_putchar8 __P((void *, int, int col, u_int, long));
     56 static void	rasops1_putchar16 __P((void *, int, int col, u_int, long));
     57 static void	rasops1_copycols __P((void *, int, int, int, int));
     58 static void	rasops1_erasecols __P((void *, int, int, int, long));
     59 static void	rasops1_do_cursor __P((struct rasops_info *));
     60 
     61 void	rasops1_init __P((struct rasops_info *ri));
     62 
     63 /*
     64  * Initalize rasops_info struct for this colordepth.
     65  */
     66 void
     67 rasops1_init(ri)
     68 	struct rasops_info *ri;
     69 {
     70 
     71 	switch (ri->ri_font->fontwidth) {
     72 	case 8:
     73 		ri->ri_ops.putchar = rasops1_putchar8;
     74 		break;
     75 	case 16:
     76 		ri->ri_ops.putchar = rasops1_putchar16;
     77 		break;
     78 	default:
     79 		ri->ri_ops.putchar = rasops1_putchar;
     80 		break;
     81 	}
     82 
     83 	if ((ri->ri_font->fontwidth & 7) != 0) {
     84 		ri->ri_ops.erasecols = rasops1_erasecols;
     85 		ri->ri_ops.copycols = rasops1_copycols;
     86 		ri->ri_do_cursor = rasops1_do_cursor;
     87 	}
     88 }
     89 
     90 
     91 /*
     92  * Paint a single character. This is the generic version, this is ugly.
     93  */
     94 static void
     95 rasops1_putchar(cookie, row, col, uc, attr)
     96 	void *cookie;
     97 	int row, col;
     98 	u_int uc;
     99 	long attr;
    100 {
    101 	int height, width, fs, rs, fb, bg, fg, lmask, rmask;
    102 	struct rasops_info *ri;
    103 	int32_t *rp;
    104 	u_char *fr;
    105 
    106 	ri = (struct rasops_info *)cookie;
    107 
    108 #ifdef RASOPS_CLIPPING
    109 	/* Catches 'row < 0' case too */
    110 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    111 		return;
    112 
    113 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    114 		return;
    115 #endif
    116 
    117 	col *= ri->ri_font->fontwidth;
    118 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    119 	height = ri->ri_font->fontheight;
    120 	width = ri->ri_font->fontwidth;
    121 	col = col & 31;
    122 	rs = ri->ri_stride;
    123 
    124 	bg = (attr & 0x000f0000) ? 0xffffffff : 0;
    125 	fg = (attr & 0x0f000000) ? 0xffffffff : 0;
    126 
    127 	/* If fg and bg match this becomes a space character */
    128 	if (fg == bg || uc == ' ') {
    129 		uc = (u_int)-1;
    130 		fr = 0;		/* shutup gcc */
    131 		fs = 0;		/* shutup gcc */
    132 	} else {
    133 		uc -= ri->ri_font->firstchar;
    134 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    135 		fs = ri->ri_font->stride;
    136 	}
    137 
    138 	/* Single word, one mask */
    139 	if ((col + width) <= 32) {
    140 		rmask = rasops_pmask[col][width];
    141 		lmask = ~rmask;
    142 
    143 		if (uc == (u_int)-1) {
    144 			bg &= rmask;
    145 
    146 			while (height--) {
    147 				*rp = (*rp & lmask) | bg;
    148 				DELTA(rp, rs, int32_t *);
    149 			}
    150 		} else {
    151 			/* NOT fontbits if bg is white */
    152 			if (bg) {
    153 				while (height--) {
    154 					fb = ~(fr[3] | (fr[2] << 8) |
    155 					    (fr[1] << 16) | (fr[0] << 24));
    156 					*rp = (*rp & lmask)
    157 					    | (MBE(fb >> col) & rmask);
    158 
    159 					fr += fs;
    160 					DELTA(rp, rs, int32_t *);
    161 				}
    162 			} else {
    163 				while (height--) {
    164 					fb = (fr[3] | (fr[2] << 8) |
    165 					    (fr[1] << 16) | (fr[0] << 24));
    166 					*rp = (*rp & lmask)
    167 					    | (MBE(fb >> col) & rmask);
    168 
    169 					fr += fs;
    170 					DELTA(rp, rs, int32_t *);
    171 				}
    172 			}
    173 		}
    174 
    175 		/* Do underline */
    176 		if (attr & 1) {
    177 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    178 			*rp = (*rp & lmask) | (fg & rmask);
    179 		}
    180 	} else {
    181 		lmask = ~rasops_lmask[col];
    182 		rmask = ~rasops_rmask[(col + width) & 31];
    183 
    184 		if (uc == (u_int)-1) {
    185 			bg = bg & ~lmask;
    186 			width = bg & ~rmask;
    187 
    188 			while (height--) {
    189 				rp[0] = (rp[0] & lmask) | bg;
    190 				rp[1] = (rp[1] & rmask) | width;
    191 				DELTA(rp, rs, int32_t *);
    192 			}
    193 		} else {
    194 			width = 32 - col;
    195 
    196 			/* NOT fontbits if bg is white */
    197 			if (bg) {
    198 				while (height--) {
    199 					fb = ~(fr[3] | (fr[2] << 8) |
    200 					    (fr[1] << 16) | (fr[0] << 24));
    201 
    202 					rp[0] = (rp[0] & lmask)
    203 					    | MBE((u_int)fb >> col);
    204 
    205 					rp[1] = (rp[1] & rmask)
    206 					    | (MBE((u_int)fb << width) & ~rmask);
    207 
    208 					fr += fs;
    209 					DELTA(rp, rs, int32_t *);
    210 				}
    211 			} else {
    212 				while (height--) {
    213 					fb = (fr[3] | (fr[2] << 8) |
    214 					    (fr[1] << 16) | (fr[0] << 24));
    215 
    216 					rp[0] = (rp[0] & lmask)
    217 					    | MBE(fb >> col);
    218 
    219 					rp[1] = (rp[1] & rmask)
    220 					    | (MBE(fb << width) & ~rmask);
    221 
    222 					fr += fs;
    223 					DELTA(rp, rs, int32_t *);
    224 				}
    225 			}
    226 		}
    227 
    228 		/* Do underline */
    229 		if (attr & 1) {
    230 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    231 			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
    232 			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
    233 		}
    234 	}
    235 }
    236 
    237 
    238 /*
    239  * Paint a single character. This is for 8-pixel wide fonts.
    240  */
    241 static void
    242 rasops1_putchar8(cookie, row, col, uc, attr)
    243 	void *cookie;
    244 	int row, col;
    245 	u_int uc;
    246 	long attr;
    247 {
    248 	int height, fs, rs, bg, fg;
    249 	struct rasops_info *ri;
    250 	u_char *fr, *rp;
    251 
    252 	ri = (struct rasops_info *)cookie;
    253 
    254 #ifdef RASOPS_CLIPPING
    255 	/* Catches 'row < 0' case too */
    256 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    257 		return;
    258 
    259 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    260 		return;
    261 #endif
    262 
    263 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    264 	height = ri->ri_font->fontheight;
    265 	rs = ri->ri_stride;
    266 
    267 	bg = (attr & 0x000f0000) ? 0xff : 0;
    268 	fg = (attr & 0x0f000000) ? 0xff : 0;
    269 
    270 	/* If fg and bg match this becomes a space character */
    271 	if (fg == bg || uc == ' ') {
    272 		while (height--) {
    273 			*rp = bg;
    274 			rp += rs;
    275 		}
    276 	} else {
    277 		uc -= ri->ri_font->firstchar;
    278 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    279 		fs = ri->ri_font->stride;
    280 
    281 		/* NOT fontbits if bg is white */
    282 		if (bg) {
    283 			while (height--) {
    284 				*rp = ~*fr;
    285 				fr += fs;
    286 				rp += rs;
    287 			}
    288 		} else {
    289 			while (height--) {
    290 				*rp = *fr;
    291 				fr += fs;
    292 				rp += rs;
    293 			}
    294 		}
    295 
    296 	}
    297 
    298 	/* Do underline */
    299 	if (attr & 1)
    300 		rp[-(ri->ri_stride << 1)] = fg;
    301 }
    302 
    303 
    304 /*
    305  * Paint a single character. This is for 16-pixel wide fonts.
    306  */
    307 static void
    308 rasops1_putchar16(cookie, row, col, uc, attr)
    309 	void *cookie;
    310 	int row, col;
    311 	u_int uc;
    312 	long attr;
    313 {
    314 	int height, fs, rs, bg, fg;
    315 	struct rasops_info *ri;
    316 	u_char *fr, *rp;
    317 
    318 	ri = (struct rasops_info *)cookie;
    319 
    320 #ifdef RASOPS_CLIPPING
    321 	/* Catches 'row < 0' case too */
    322 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    323 		return;
    324 
    325 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    326 		return;
    327 #endif
    328 
    329 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    330 	height = ri->ri_font->fontheight;
    331 	rs = ri->ri_stride;
    332 
    333 	bg = (attr & 0x000f0000) ? 0xffff : 0;
    334 	fg = (attr & 0x0f000000) ? 0xffff : 0;
    335 
    336 	/* If fg and bg match this becomes a space character */
    337 	if (fg == bg || uc == ' ') {
    338 		while (height--) {
    339 			*(int16_t *)rp = bg;
    340 			rp += rs;
    341 		}
    342 	} else {
    343 		uc -= ri->ri_font->firstchar;
    344 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    345 		fs = ri->ri_font->stride;
    346 
    347 		/* NOT fontbits if bg is white */
    348 		if (bg) {
    349 			while (height--) {
    350 				rp[0] = ~fr[0];
    351 				rp[1] = ~fr[1];
    352 				fr += fs;
    353 				rp += rs;
    354 			}
    355 		} else {
    356 			while (height--) {
    357 				rp[0] = fr[0];
    358 				rp[1] = fr[1];
    359 				fr += fs;
    360 				rp += rs;
    361 			}
    362 		}
    363 	}
    364 
    365 	/* Do underline */
    366 	if (attr & 1)
    367 		*(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
    368 }
    369 
    370 /*
    371  * Grab routines common to depths where (bpp < 8)
    372  */
    373 #define NAME(ident)	rasops1_##ident
    374 #define PIXEL_SHIFT	0
    375 
    376 #include <dev/rasops/rasops_bitops.h>
    377