Home | History | Annotate | Line # | Download | only in rasops
rasops1.c revision 1.5
      1  1.5  ad /* 	$NetBSD: rasops1.c,v 1.5 1999/05/18 21:51:59 ad Exp $ */
      2  1.1  ad 
      3  1.5  ad /*-
      4  1.5  ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.5  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.5  ad  * by Andy Doran.
      9  1.5  ad  *
     10  1.1  ad  * Redistribution and use in source and binary forms, with or without
     11  1.1  ad  * modification, are permitted provided that the following conditions
     12  1.1  ad  * are met:
     13  1.1  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  ad  *    documentation and/or other materials provided with the distribution.
     18  1.5  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.5  ad  *    must display the following acknowledgement:
     20  1.5  ad  *	This product includes software developed by the NetBSD
     21  1.5  ad  *	Foundation, Inc. and its contributors.
     22  1.5  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.5  ad  *    contributors may be used to endorse or promote products derived
     24  1.5  ad  *    from this software without specific prior written permission.
     25  1.1  ad  *
     26  1.5  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.5  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.5  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.5  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.5  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.5  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.5  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.5  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.5  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.5  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.5  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ad  */
     38  1.2  ad 
     39  1.1  ad #include "opt_rasops.h"
     40  1.1  ad #include <sys/cdefs.h>
     41  1.5  ad __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.5 1999/05/18 21:51:59 ad Exp $");
     42  1.1  ad 
     43  1.1  ad #include <sys/types.h>
     44  1.1  ad #include <sys/param.h>
     45  1.1  ad #include <sys/systm.h>
     46  1.1  ad #include <sys/time.h>
     47  1.1  ad #include <machine/endian.h>
     48  1.1  ad 
     49  1.1  ad #include <dev/wscons/wsdisplayvar.h>
     50  1.3  ad #include <dev/wscons/wsconsio.h>
     51  1.1  ad #include <dev/rasops/rasops.h>
     52  1.4  ad #include <dev/rasops/rasops_masks.h>
     53  1.1  ad 
     54  1.1  ad static void	rasops1_putchar __P((void *, int, int col, u_int, long));
     55  1.1  ad static void	rasops1_putchar8 __P((void *, int, int col, u_int, long));
     56  1.1  ad static void	rasops1_putchar16 __P((void *, int, int col, u_int, long));
     57  1.1  ad static void	rasops1_copycols __P((void *, int, int, int, int));
     58  1.3  ad static void	rasops1_erasecols __P((void *, int, int, int, long));
     59  1.1  ad static void	rasops1_do_cursor __P((struct rasops_info *));
     60  1.1  ad 
     61  1.1  ad void	rasops1_init __P((struct rasops_info *ri));
     62  1.1  ad 
     63  1.1  ad /*
     64  1.1  ad  * Initalize rasops_info struct for this colordepth.
     65  1.1  ad  */
     66  1.1  ad void
     67  1.1  ad rasops1_init(ri)
     68  1.1  ad 	struct rasops_info *ri;
     69  1.1  ad {
     70  1.1  ad 
     71  1.1  ad 	switch (ri->ri_font->fontwidth) {
     72  1.1  ad 	case 8:
     73  1.1  ad 		ri->ri_ops.putchar = rasops1_putchar8;
     74  1.1  ad 		break;
     75  1.1  ad 	case 16:
     76  1.1  ad 		ri->ri_ops.putchar = rasops1_putchar16;
     77  1.1  ad 		break;
     78  1.1  ad 	default:
     79  1.1  ad 		ri->ri_ops.putchar = rasops1_putchar;
     80  1.1  ad 		break;
     81  1.1  ad 	}
     82  1.1  ad 
     83  1.1  ad 	if (ri->ri_font->fontwidth & 7) {
     84  1.1  ad 		ri->ri_ops.erasecols = rasops1_erasecols;
     85  1.1  ad 		ri->ri_ops.copycols = rasops1_copycols;
     86  1.1  ad 		ri->ri_do_cursor = rasops1_do_cursor;
     87  1.1  ad 	}
     88  1.1  ad }
     89  1.1  ad 
     90  1.1  ad 
     91  1.1  ad /*
     92  1.4  ad  * Paint a single character. This is the generic version, this is ugly.
     93  1.1  ad  */
     94  1.1  ad static void
     95  1.1  ad rasops1_putchar(cookie, row, col, uc, attr)
     96  1.1  ad 	void *cookie;
     97  1.1  ad 	int row, col;
     98  1.1  ad 	u_int uc;
     99  1.1  ad 	long attr;
    100  1.1  ad {
    101  1.4  ad 	int height, width, fs, rs, fb, bg, fg, lmask, rmask;
    102  1.4  ad 	struct rasops_info *ri;
    103  1.4  ad 	int32_t *rp;
    104  1.4  ad 	u_char *fr;
    105  1.4  ad 
    106  1.4  ad 	ri = (struct rasops_info *)cookie;
    107  1.4  ad 
    108  1.4  ad #ifdef RASOPS_CLIPPING
    109  1.4  ad 	/* Catches 'row < 0' case too */
    110  1.4  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    111  1.4  ad 		return;
    112  1.4  ad 
    113  1.4  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    114  1.4  ad 		return;
    115  1.4  ad #endif
    116  1.4  ad 
    117  1.4  ad 	col *= ri->ri_font->fontwidth;
    118  1.4  ad 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    119  1.4  ad 	height = ri->ri_font->fontheight;
    120  1.4  ad 	width = ri->ri_font->fontwidth;
    121  1.4  ad 	col = col & 31;
    122  1.4  ad 	rs = ri->ri_stride;
    123  1.4  ad 
    124  1.4  ad 	bg = (attr & 0x000f0000) ? 0xffffffff : 0;
    125  1.4  ad 	fg = (attr & 0x0f000000) ? 0xffffffff : 0;
    126  1.4  ad 
    127  1.4  ad 	/* If fg and bg match this becomes a space character */
    128  1.4  ad 	if (fg == bg || uc == ' ') {
    129  1.4  ad 		uc = (u_int)-1;
    130  1.4  ad 		fr = 0;		/* shutup gcc */
    131  1.4  ad 		fs = 0;		/* shutup gcc */
    132  1.4  ad 	} else {
    133  1.4  ad 		uc -= ri->ri_font->firstchar;
    134  1.4  ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    135  1.4  ad 		fs = ri->ri_font->stride;
    136  1.4  ad 	}
    137  1.4  ad 
    138  1.4  ad 	/* Single word, one mask */
    139  1.4  ad 	if ((col + width) <= 32) {
    140  1.4  ad 		rmask = rasops_pmask[col][width];
    141  1.4  ad 		lmask = ~rmask;
    142  1.4  ad 
    143  1.4  ad 		if (uc == (u_int)-1) {
    144  1.4  ad 			bg &= rmask;
    145  1.4  ad 
    146  1.4  ad 			while (height--) {
    147  1.4  ad 				*rp = (*rp & lmask) | bg;
    148  1.4  ad 				DELTA(rp, rs, int32_t *);
    149  1.4  ad 			}
    150  1.4  ad 		} else {
    151  1.4  ad 			/* NOT fontbits if bg is white */
    152  1.4  ad 			if (bg) {
    153  1.4  ad 				while (height--) {
    154  1.4  ad 					fb = ~(fr[3] | (fr[2] << 8) |
    155  1.4  ad 					    (fr[1] << 16) | (fr[0] << 24));
    156  1.4  ad 					*rp = (*rp & lmask)
    157  1.4  ad 					    | (MBE(fb >> col) & rmask);
    158  1.4  ad 
    159  1.4  ad 					fr += fs;
    160  1.4  ad 					DELTA(rp, rs, int32_t *);
    161  1.4  ad 				}
    162  1.4  ad 			} else {
    163  1.4  ad 				while (height--) {
    164  1.4  ad 					fb = (fr[3] | (fr[2] << 8) |
    165  1.4  ad 					    (fr[1] << 16) | (fr[0] << 24));
    166  1.4  ad 					*rp = (*rp & lmask)
    167  1.4  ad 					    | (MBE(fb >> col) & rmask);
    168  1.4  ad 
    169  1.4  ad 					fr += fs;
    170  1.4  ad 					DELTA(rp, rs, int32_t *);
    171  1.4  ad 				}
    172  1.4  ad 			}
    173  1.4  ad 		}
    174  1.4  ad 
    175  1.4  ad 		/* Do underline */
    176  1.4  ad 		if (attr & 1) {
    177  1.4  ad 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    178  1.4  ad 			*rp = (*rp & lmask) | (fg & rmask);
    179  1.4  ad 		}
    180  1.4  ad 	} else {
    181  1.4  ad 		lmask = ~rasops_lmask[col];
    182  1.4  ad 		rmask = ~rasops_rmask[(col + width) & 31];
    183  1.4  ad 
    184  1.4  ad 		if (uc == (u_int)-1) {
    185  1.4  ad 			bg = bg & ~lmask;
    186  1.4  ad 			width = bg & ~rmask;
    187  1.4  ad 
    188  1.4  ad 			while (height--) {
    189  1.4  ad 				rp[0] = (rp[0] & lmask) | bg;
    190  1.4  ad 				rp[1] = (rp[1] & rmask) | width;
    191  1.4  ad 				DELTA(rp, rs, int32_t *);
    192  1.4  ad 			}
    193  1.4  ad 		} else {
    194  1.4  ad 			width = 32 - col;
    195  1.4  ad 
    196  1.4  ad 			/* NOT fontbits if bg is white */
    197  1.4  ad 			if (bg) {
    198  1.4  ad 				while (height--) {
    199  1.4  ad 					fb = ~(fr[3] | (fr[2] << 8) |
    200  1.4  ad 					    (fr[1] << 16) | (fr[0] << 24));
    201  1.4  ad 
    202  1.4  ad 					rp[0] = (rp[0] & lmask)
    203  1.4  ad 					    | MBE((u_int)fb >> col);
    204  1.4  ad 
    205  1.4  ad 					rp[1] = (rp[1] & rmask)
    206  1.4  ad 					    | (MBE((u_int)fb << width) & ~rmask);
    207  1.4  ad 
    208  1.4  ad 					fr += fs;
    209  1.4  ad 					DELTA(rp, rs, int32_t *);
    210  1.4  ad 				}
    211  1.4  ad 			} else {
    212  1.4  ad 				while (height--) {
    213  1.4  ad 					fb = (fr[3] | (fr[2] << 8) |
    214  1.4  ad 					    (fr[1] << 16) | (fr[0] << 24));
    215  1.4  ad 
    216  1.4  ad 					rp[0] = (rp[0] & lmask)
    217  1.4  ad 					    | MBE(fb >> col);
    218  1.4  ad 
    219  1.4  ad 					rp[1] = (rp[1] & rmask)
    220  1.4  ad 					    | (MBE(fb << width) & ~rmask);
    221  1.4  ad 
    222  1.4  ad 					fr += fs;
    223  1.4  ad 					DELTA(rp, rs, int32_t *);
    224  1.4  ad 				}
    225  1.4  ad 			}
    226  1.4  ad 		}
    227  1.1  ad 
    228  1.4  ad 		/* Do underline */
    229  1.4  ad 		if (attr & 1) {
    230  1.4  ad 			DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    231  1.4  ad 			rp[0] = (rp[0] & lmask) | (fg & ~lmask);
    232  1.4  ad 			rp[1] = (rp[1] & rmask) | (fg & ~rmask);
    233  1.4  ad 		}
    234  1.4  ad 	}
    235  1.1  ad }
    236  1.1  ad 
    237  1.1  ad 
    238  1.1  ad /*
    239  1.1  ad  * Paint a single character. This is for 8-pixel wide fonts.
    240  1.1  ad  */
    241  1.1  ad static void
    242  1.1  ad rasops1_putchar8(cookie, row, col, uc, attr)
    243  1.1  ad 	void *cookie;
    244  1.1  ad 	int row, col;
    245  1.1  ad 	u_int uc;
    246  1.1  ad 	long attr;
    247  1.1  ad {
    248  1.1  ad 	int height, fs, rs, bg, fg;
    249  1.1  ad 	struct rasops_info *ri;
    250  1.1  ad 	u_char *fr, *rp;
    251  1.1  ad 
    252  1.1  ad 	ri = (struct rasops_info *)cookie;
    253  1.1  ad 
    254  1.1  ad #ifdef RASOPS_CLIPPING
    255  1.3  ad 	/* Catches 'row < 0' case too */
    256  1.3  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    257  1.1  ad 		return;
    258  1.1  ad 
    259  1.3  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    260  1.1  ad 		return;
    261  1.1  ad #endif
    262  1.1  ad 
    263  1.3  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    264  1.1  ad 	height = ri->ri_font->fontheight;
    265  1.1  ad 	rs = ri->ri_stride;
    266  1.1  ad 
    267  1.1  ad 	bg = (attr & 0x000f0000) ? 0xff : 0;
    268  1.1  ad 	fg = (attr & 0x0f000000) ? 0xff : 0;
    269  1.1  ad 
    270  1.1  ad 	/* If fg and bg match this becomes a space character */
    271  1.1  ad 	if (fg == bg || uc == ' ') {
    272  1.1  ad 		while (height--) {
    273  1.1  ad 			*rp = bg;
    274  1.1  ad 			rp += rs;
    275  1.1  ad 		}
    276  1.1  ad 	} else {
    277  1.1  ad 		uc -= ri->ri_font->firstchar;
    278  1.1  ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    279  1.1  ad 		fs = ri->ri_font->stride;
    280  1.1  ad 
    281  1.1  ad 		/* NOT fontbits if bg is white */
    282  1.1  ad 		if (bg) {
    283  1.1  ad 			while (height--) {
    284  1.1  ad 				*rp = ~*fr;
    285  1.1  ad 				fr += fs;
    286  1.1  ad 				rp += rs;
    287  1.1  ad 			}
    288  1.1  ad 		} else {
    289  1.1  ad 			while (height--) {
    290  1.1  ad 				*rp = *fr;
    291  1.1  ad 				fr += fs;
    292  1.1  ad 				rp += rs;
    293  1.1  ad 			}
    294  1.1  ad 		}
    295  1.4  ad 
    296  1.1  ad 	}
    297  1.1  ad 
    298  1.1  ad 	/* Do underline */
    299  1.1  ad 	if (attr & 1)
    300  1.1  ad 		rp[-(ri->ri_stride << 1)] = fg;
    301  1.1  ad }
    302  1.1  ad 
    303  1.1  ad 
    304  1.1  ad /*
    305  1.1  ad  * Paint a single character. This is for 16-pixel wide fonts.
    306  1.1  ad  */
    307  1.1  ad static void
    308  1.1  ad rasops1_putchar16(cookie, row, col, uc, attr)
    309  1.1  ad 	void *cookie;
    310  1.1  ad 	int row, col;
    311  1.1  ad 	u_int uc;
    312  1.1  ad 	long attr;
    313  1.1  ad {
    314  1.1  ad 	int height, fs, rs, bg, fg;
    315  1.1  ad 	struct rasops_info *ri;
    316  1.1  ad 	u_char *fr, *rp;
    317  1.1  ad 
    318  1.1  ad 	ri = (struct rasops_info *)cookie;
    319  1.1  ad 
    320  1.1  ad #ifdef RASOPS_CLIPPING
    321  1.3  ad 	/* Catches 'row < 0' case too */
    322  1.3  ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    323  1.1  ad 		return;
    324  1.1  ad 
    325  1.3  ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    326  1.1  ad 		return;
    327  1.1  ad #endif
    328  1.1  ad 
    329  1.3  ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    330  1.1  ad 	height = ri->ri_font->fontheight;
    331  1.1  ad 	rs = ri->ri_stride;
    332  1.1  ad 
    333  1.1  ad 	bg = (attr & 0x000f0000) ? 0xffff : 0;
    334  1.1  ad 	fg = (attr & 0x0f000000) ? 0xffff : 0;
    335  1.1  ad 
    336  1.1  ad 	/* If fg and bg match this becomes a space character */
    337  1.1  ad 	if (fg == bg || uc == ' ') {
    338  1.1  ad 		while (height--) {
    339  1.1  ad 			*(int16_t *)rp = bg;
    340  1.1  ad 			rp += rs;
    341  1.1  ad 		}
    342  1.1  ad 	} else {
    343  1.1  ad 		uc -= ri->ri_font->firstchar;
    344  1.1  ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    345  1.1  ad 		fs = ri->ri_font->stride;
    346  1.1  ad 
    347  1.1  ad 		/* NOT fontbits if bg is white */
    348  1.1  ad 		if (bg) {
    349  1.1  ad 			while (height--) {
    350  1.1  ad 				rp[0] = ~fr[0];
    351  1.1  ad 				rp[1] = ~fr[1];
    352  1.1  ad 				fr += fs;
    353  1.1  ad 				rp += rs;
    354  1.1  ad 			}
    355  1.1  ad 		} else {
    356  1.1  ad 			while (height--) {
    357  1.1  ad 				rp[0] = fr[0];
    358  1.1  ad 				rp[1] = fr[1];
    359  1.1  ad 				fr += fs;
    360  1.1  ad 				rp += rs;
    361  1.1  ad 			}
    362  1.1  ad 		}
    363  1.1  ad 	}
    364  1.1  ad 
    365  1.1  ad 	/* Do underline */
    366  1.1  ad 	if (attr & 1)
    367  1.1  ad 		*(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
    368  1.1  ad }
    369  1.1  ad 
    370  1.1  ad /*
    371  1.4  ad  * Grab routines common to depths where (bpp < 8)
    372  1.1  ad  */
    373  1.4  ad #define NAME(ident)	rasops1_##ident
    374  1.4  ad #define PIXEL_SHIFT	0
    375  1.1  ad 
    376  1.4  ad #include <dev/rasops/rasops_bitops.h>
    377