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