Home | History | Annotate | Line # | Download | only in rasops
rasops24.c revision 1.8.2.1
      1  1.8.2.1  bouyer /* 	$NetBSD: rasops24.c,v 1.8.2.1 2000/11/20 11:43:02 bouyer Exp $	*/
      2      1.1      ad 
      3      1.6      ad /*-
      4      1.6      ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5      1.1      ad  * All rights reserved.
      6      1.1      ad  *
      7      1.6      ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.8.2.1  bouyer  * by Andrew Doran.
      9      1.6      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.6      ad  * 3. All advertising materials mentioning features or use of this software
     19      1.6      ad  *    must display the following acknowledgement:
     20      1.6      ad  *	This product includes software developed by the NetBSD
     21      1.6      ad  *	Foundation, Inc. and its contributors.
     22      1.6      ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.6      ad  *    contributors may be used to endorse or promote products derived
     24      1.6      ad  *    from this software without specific prior written permission.
     25      1.1      ad  *
     26      1.6      ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.6      ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.6      ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.6      ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.6      ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.6      ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.6      ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.6      ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.6      ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.6      ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.6      ad  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1      ad  */
     38      1.2      ad 
     39      1.1      ad #include "opt_rasops.h"
     40      1.3      ad #include <sys/cdefs.h>
     41  1.8.2.1  bouyer __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.8.2.1 2000/11/20 11:43:02 bouyer 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 
     48      1.4      ad #include <machine/endian.h>
     49      1.4      ad #include <machine/bswap.h>
     50      1.4      ad 
     51      1.1      ad #include <dev/wscons/wsdisplayvar.h>
     52      1.1      ad #include <dev/wscons/wsconsio.h>
     53      1.1      ad #include <dev/rasops/rasops.h>
     54      1.1      ad 
     55  1.8.2.1  bouyer static void 	rasops24_erasecols __P((void *, int, int, int, long));
     56  1.8.2.1  bouyer static void 	rasops24_eraserows __P((void *, int, int, long));
     57      1.1      ad static void 	rasops24_putchar __P((void *, int, int, u_int, long attr));
     58  1.8.2.1  bouyer #ifndef RASOPS_SMALL
     59      1.4      ad static void 	rasops24_putchar8 __P((void *, int, int, u_int, long attr));
     60      1.4      ad static void 	rasops24_putchar12 __P((void *, int, int, u_int, long attr));
     61      1.4      ad static void 	rasops24_putchar16 __P((void *, int, int, u_int, long attr));
     62      1.4      ad static void	rasops24_makestamp __P((struct rasops_info *, long));
     63  1.8.2.1  bouyer #endif
     64      1.1      ad 
     65  1.8.2.1  bouyer /*
     66  1.8.2.1  bouyer  * 4x1 stamp for optimized character blitting
     67      1.4      ad  */
     68      1.4      ad static int32_t	stamp[64];
     69      1.4      ad static long	stamp_attr;
     70      1.4      ad static int	stamp_mutex;	/* XXX see note in readme */
     71      1.4      ad 
     72      1.4      ad /*
     73      1.4      ad  * XXX this confuses the hell out of gcc2 (not egcs) which always insists
     74      1.4      ad  * that the shift count is negative.
     75      1.4      ad  *
     76      1.4      ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     77      1.4      ad  * destination int32_t[0] = STAMP_READ(offset)
     78      1.4      ad  * destination int32_t[1] = STAMP_READ(offset + 4)
     79      1.4      ad  * destination int32_t[2] = STAMP_READ(offset + 8)
     80      1.4      ad  */
     81      1.4      ad #define STAMP_SHIFT(fb,n)	((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
     82  1.8.2.1  bouyer #define STAMP_MASK		(0xf << 4)
     83      1.4      ad #define STAMP_READ(o)		(*(int32_t *)((caddr_t)stamp + (o)))
     84      1.4      ad 
     85      1.1      ad /*
     86      1.1      ad  * Initalize rasops_info struct for this colordepth.
     87      1.1      ad  */
     88      1.1      ad void
     89      1.1      ad rasops24_init(ri)
     90      1.1      ad 	struct rasops_info *ri;
     91      1.1      ad {
     92      1.1      ad 
     93      1.1      ad 	switch (ri->ri_font->fontwidth) {
     94  1.8.2.1  bouyer #ifndef RASOPS_SMALL
     95      1.1      ad 	case 8:
     96      1.4      ad 		ri->ri_ops.putchar = rasops24_putchar8;
     97      1.1      ad 		break;
     98      1.1      ad 	case 12:
     99      1.4      ad 		ri->ri_ops.putchar = rasops24_putchar12;
    100      1.1      ad 		break;
    101      1.1      ad 	case 16:
    102      1.4      ad 		ri->ri_ops.putchar = rasops24_putchar16;
    103      1.1      ad 		break;
    104  1.8.2.1  bouyer #endif
    105      1.1      ad 	default:
    106      1.4      ad 		ri->ri_ops.putchar = rasops24_putchar;
    107      1.1      ad 		break;
    108      1.1      ad 	}
    109      1.4      ad 
    110      1.1      ad 	if (ri->ri_rnum == 0) {
    111      1.1      ad 		ri->ri_rnum = 8;
    112      1.4      ad 		ri->ri_rpos = 0;
    113      1.1      ad 		ri->ri_gnum = 8;
    114      1.4      ad 		ri->ri_gpos = 8;
    115      1.1      ad 		ri->ri_bnum = 8;
    116      1.1      ad 		ri->ri_bpos = 16;
    117      1.1      ad 	}
    118      1.4      ad 
    119      1.4      ad 	ri->ri_ops.erasecols = rasops24_erasecols;
    120      1.4      ad 	ri->ri_ops.eraserows = rasops24_eraserows;
    121      1.1      ad }
    122      1.1      ad 
    123      1.1      ad /*
    124      1.4      ad  * Put a single character. This is the generic version.
    125  1.8.2.1  bouyer  * XXX this bites - we should use masks.
    126      1.1      ad  */
    127      1.4      ad static void
    128      1.4      ad rasops24_putchar(cookie, row, col, uc, attr)
    129      1.4      ad 	void *cookie;
    130      1.4      ad 	int row, col;
    131      1.4      ad 	u_int uc;
    132      1.1      ad 	long attr;
    133      1.1      ad {
    134      1.4      ad 	int fb, width, height, cnt, clr[2];
    135  1.8.2.1  bouyer 	struct rasops_info *ri;
    136      1.4      ad 	u_char *dp, *rp, *fr;
    137  1.8.2.1  bouyer 
    138      1.4      ad 	ri = (struct rasops_info *)cookie;
    139      1.1      ad 
    140  1.8.2.1  bouyer #ifdef RASOPS_CLIPPING
    141  1.8.2.1  bouyer 	/* Catches 'row < 0' case too */
    142      1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    143      1.4      ad 		return;
    144      1.1      ad 
    145      1.4      ad 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    146      1.4      ad 		return;
    147      1.4      ad #endif
    148  1.8.2.1  bouyer 
    149      1.1      ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    150      1.1      ad 	height = ri->ri_font->fontheight;
    151      1.4      ad 	width = ri->ri_font->fontwidth;
    152  1.8.2.1  bouyer 
    153  1.8.2.1  bouyer 	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
    154  1.8.2.1  bouyer 	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
    155      1.4      ad 
    156      1.4      ad 	if (uc == ' ') {
    157  1.8.2.1  bouyer 		u_char c = clr[0];
    158      1.4      ad 		while (height--) {
    159      1.4      ad 			dp = rp;
    160      1.4      ad 			rp += ri->ri_stride;
    161  1.8.2.1  bouyer 
    162      1.4      ad 			for (cnt = width; cnt; cnt--) {
    163  1.8.2.1  bouyer 				*dp++ = c >> 16;
    164  1.8.2.1  bouyer 				*dp++ = c >> 8;
    165  1.8.2.1  bouyer 				*dp++ = c;
    166      1.4      ad 			}
    167  1.8.2.1  bouyer 		}
    168      1.4      ad 	} else {
    169      1.4      ad 		uc -= ri->ri_font->firstchar;
    170      1.4      ad 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
    171      1.1      ad 
    172      1.4      ad 		while (height--) {
    173      1.4      ad 			dp = rp;
    174  1.8.2.1  bouyer 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
    175  1.8.2.1  bouyer 			    (fr[0] << 24);
    176      1.4      ad 			fr += ri->ri_font->stride;
    177      1.4      ad 			rp += ri->ri_stride;
    178  1.8.2.1  bouyer 
    179      1.4      ad 			for (cnt = width; cnt; cnt--, fb <<= 1) {
    180      1.4      ad 				if ((fb >> 31) & 1) {
    181      1.4      ad 					*dp++ = clr[1] >> 16;
    182      1.4      ad 					*dp++ = clr[1] >> 8;
    183      1.4      ad 					*dp++ = clr[1];
    184      1.4      ad 				} else {
    185      1.4      ad 					*dp++ = clr[0] >> 16;
    186      1.4      ad 					*dp++ = clr[0] >> 8;
    187      1.4      ad 					*dp++ = clr[0];
    188      1.4      ad 				}
    189      1.4      ad 			}
    190  1.8.2.1  bouyer 		}
    191      1.4      ad 	}
    192  1.8.2.1  bouyer 
    193      1.4      ad 	/* Do underline */
    194  1.8.2.1  bouyer 	if ((attr & 1) != 0) {
    195  1.8.2.1  bouyer 		u_char c = clr[1];
    196  1.8.2.1  bouyer 
    197      1.4      ad 		rp -= ri->ri_stride << 1;
    198      1.4      ad 
    199      1.4      ad 		while (width--) {
    200  1.8.2.1  bouyer 			*rp++ = c >> 16;
    201  1.8.2.1  bouyer 			*rp++ = c >> 8;
    202  1.8.2.1  bouyer 			*rp++ = c;
    203      1.1      ad 		}
    204  1.8.2.1  bouyer 	}
    205      1.1      ad }
    206      1.1      ad 
    207  1.8.2.1  bouyer #ifndef RASOPS_SMALL
    208  1.8.2.1  bouyer /*
    209  1.8.2.1  bouyer  * Recompute the blitting stamp.
    210  1.8.2.1  bouyer  */
    211  1.8.2.1  bouyer static void
    212  1.8.2.1  bouyer rasops24_makestamp(ri, attr)
    213  1.8.2.1  bouyer 	struct rasops_info *ri;
    214  1.8.2.1  bouyer 	long attr;
    215  1.8.2.1  bouyer {
    216  1.8.2.1  bouyer 	u_int fg, bg, c1, c2, c3, c4;
    217  1.8.2.1  bouyer 	int i;
    218  1.8.2.1  bouyer 
    219  1.8.2.1  bouyer 	fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffffff;
    220  1.8.2.1  bouyer 	bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffffff;
    221  1.8.2.1  bouyer 	stamp_attr = attr;
    222  1.8.2.1  bouyer 
    223  1.8.2.1  bouyer 	for (i = 0; i < 64; i += 4) {
    224  1.8.2.1  bouyer #if BYTE_ORDER == LITTLE_ENDIAN
    225  1.8.2.1  bouyer 		c1 = (i & 32 ? fg : bg);
    226  1.8.2.1  bouyer 		c2 = (i & 16 ? fg : bg);
    227  1.8.2.1  bouyer 		c3 = (i & 8 ? fg : bg);
    228  1.8.2.1  bouyer 		c4 = (i & 4 ? fg : bg);
    229  1.8.2.1  bouyer #else
    230  1.8.2.1  bouyer 		c1 = (i & 8 ? fg : bg);
    231  1.8.2.1  bouyer 		c2 = (i & 4 ? fg : bg);
    232  1.8.2.1  bouyer 		c3 = (i & 16 ? fg : bg);
    233  1.8.2.1  bouyer 		c4 = (i & 32 ? fg : bg);
    234  1.8.2.1  bouyer #endif
    235  1.8.2.1  bouyer 		stamp[i+0] = (c1 <<  8) | (c2 >> 16);
    236  1.8.2.1  bouyer 		stamp[i+1] = (c2 << 16) | (c3 >>  8);
    237  1.8.2.1  bouyer 		stamp[i+2] = (c3 << 24) | c4;
    238  1.8.2.1  bouyer 
    239  1.8.2.1  bouyer #if BYTE_ORDER == LITTLE_ENDIAN
    240  1.8.2.1  bouyer 		if ((ri->ri_flg & RI_BSWAP) == 0) {
    241  1.8.2.1  bouyer #else
    242  1.8.2.1  bouyer 		if ((ri->ri_flg & RI_BSWAP) != 0) {
    243  1.8.2.1  bouyer #endif
    244  1.8.2.1  bouyer 			stamp[i+0] = bswap32(stamp[i+0]);
    245  1.8.2.1  bouyer 			stamp[i+1] = bswap32(stamp[i+1]);
    246  1.8.2.1  bouyer 			stamp[i+2] = bswap32(stamp[i+2]);
    247  1.8.2.1  bouyer 		}
    248  1.8.2.1  bouyer 	}
    249  1.8.2.1  bouyer }
    250      1.1      ad 
    251      1.1      ad /*
    252      1.4      ad  * Put a single character. This is for 8-pixel wide fonts.
    253      1.1      ad  */
    254      1.1      ad static void
    255      1.4      ad rasops24_putchar8(cookie, row, col, uc, attr)
    256      1.1      ad 	void *cookie;
    257      1.4      ad 	int row, col;
    258      1.4      ad 	u_int uc;
    259      1.1      ad 	long attr;
    260      1.1      ad {
    261      1.1      ad 	struct rasops_info *ri;
    262      1.4      ad 	int height, so, fs;
    263      1.4      ad 	int32_t *rp;
    264      1.4      ad 	u_char *fr;
    265  1.8.2.1  bouyer 
    266      1.4      ad 	/* Can't risk remaking the stamp if it's already in use */
    267      1.4      ad 	if (stamp_mutex++) {
    268      1.4      ad 		stamp_mutex--;
    269      1.4      ad 		rasops24_putchar(cookie, row, col, uc, attr);
    270      1.4      ad 		return;
    271      1.4      ad 	}
    272      1.4      ad 
    273      1.1      ad 	ri = (struct rasops_info *)cookie;
    274      1.1      ad 
    275  1.8.2.1  bouyer #ifdef RASOPS_CLIPPING
    276      1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    277      1.4      ad 		stamp_mutex--;
    278      1.1      ad 		return;
    279      1.4      ad 	}
    280      1.1      ad 
    281      1.4      ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    282      1.4      ad 		stamp_mutex--;
    283      1.4      ad 		return;
    284      1.1      ad 	}
    285      1.4      ad #endif
    286      1.1      ad 
    287      1.4      ad 	/* Recompute stamp? */
    288      1.4      ad 	if (attr != stamp_attr)
    289      1.4      ad 		rasops24_makestamp(ri, attr);
    290  1.8.2.1  bouyer 
    291      1.4      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    292      1.1      ad 	height = ri->ri_font->fontheight;
    293  1.8.2.1  bouyer 
    294      1.4      ad 	if (uc == (u_int)-1) {
    295  1.8.2.1  bouyer 		int32_t c = stamp[0];
    296      1.4      ad 		while (height--) {
    297  1.8.2.1  bouyer 			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    298      1.4      ad 			DELTA(rp, ri->ri_stride, int32_t *);
    299  1.8.2.1  bouyer 		}
    300      1.4      ad 	} else {
    301      1.4      ad 		uc -= ri->ri_font->firstchar;
    302      1.4      ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    303      1.4      ad 		fs = ri->ri_font->stride;
    304  1.8.2.1  bouyer 
    305      1.4      ad 		while (height--) {
    306      1.4      ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    307      1.4      ad 			rp[0] = STAMP_READ(so);
    308      1.4      ad 			rp[1] = STAMP_READ(so + 4);
    309      1.4      ad 			rp[2] = STAMP_READ(so + 8);
    310  1.8.2.1  bouyer 
    311      1.4      ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    312      1.4      ad 			rp[3] = STAMP_READ(so);
    313      1.4      ad 			rp[4] = STAMP_READ(so + 4);
    314      1.4      ad 			rp[5] = STAMP_READ(so + 8);
    315      1.1      ad 
    316      1.4      ad 			fr += fs;
    317  1.8.2.1  bouyer 			DELTA(rp, ri->ri_stride, int32_t *);
    318      1.1      ad 		}
    319  1.8.2.1  bouyer 	}
    320      1.4      ad 
    321      1.4      ad 	/* Do underline */
    322  1.8.2.1  bouyer 	if ((attr & 1) != 0) {
    323  1.8.2.1  bouyer 		int32_t c = STAMP_READ(52);
    324  1.8.2.1  bouyer 
    325      1.4      ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    326  1.8.2.1  bouyer 		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
    327  1.8.2.1  bouyer 	}
    328  1.8.2.1  bouyer 
    329      1.4      ad 	stamp_mutex--;
    330      1.1      ad }
    331      1.1      ad 
    332      1.1      ad /*
    333      1.4      ad  * Put a single character. This is for 12-pixel wide fonts.
    334      1.1      ad  */
    335      1.1      ad static void
    336      1.4      ad rasops24_putchar12(cookie, row, col, uc, attr)
    337      1.1      ad 	void *cookie;
    338      1.1      ad 	int row, col;
    339      1.1      ad 	u_int uc;
    340      1.1      ad 	long attr;
    341      1.1      ad {
    342      1.1      ad 	struct rasops_info *ri;
    343      1.4      ad 	int height, so, fs;
    344      1.4      ad 	int32_t *rp;
    345      1.4      ad 	u_char *fr;
    346  1.8.2.1  bouyer 
    347      1.4      ad 	/* Can't risk remaking the stamp if it's already in use */
    348      1.4      ad 	if (stamp_mutex++) {
    349      1.4      ad 		stamp_mutex--;
    350      1.4      ad 		rasops24_putchar(cookie, row, col, uc, attr);
    351      1.1      ad 		return;
    352      1.1      ad 	}
    353      1.4      ad 
    354      1.1      ad 	ri = (struct rasops_info *)cookie;
    355      1.1      ad 
    356  1.8.2.1  bouyer #ifdef RASOPS_CLIPPING
    357      1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    358      1.4      ad 		stamp_mutex--;
    359      1.1      ad 		return;
    360      1.4      ad 	}
    361      1.1      ad 
    362      1.4      ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    363      1.4      ad 		stamp_mutex--;
    364      1.1      ad 		return;
    365      1.4      ad 	}
    366      1.1      ad #endif
    367      1.4      ad 
    368      1.4      ad 	/* Recompute stamp? */
    369      1.4      ad 	if (attr != stamp_attr)
    370      1.4      ad 		rasops24_makestamp(ri, attr);
    371  1.8.2.1  bouyer 
    372      1.4      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    373      1.4      ad 	height = ri->ri_font->fontheight;
    374      1.1      ad 
    375      1.4      ad 	if (uc == (u_int)-1) {
    376  1.8.2.1  bouyer 		int32_t c = stamp[0];
    377      1.4      ad 		while (height--) {
    378  1.8.2.1  bouyer 			rp[0] = rp[1] = rp[2] = rp[3] =
    379  1.8.2.1  bouyer 			rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    380  1.8.2.1  bouyer 			DELTA(rp, ri->ri_stride, int32_t *);
    381  1.8.2.1  bouyer 		}
    382      1.4      ad 	} else {
    383      1.4      ad 		uc -= ri->ri_font->firstchar;
    384      1.4      ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    385      1.4      ad 		fs = ri->ri_font->stride;
    386  1.8.2.1  bouyer 
    387      1.4      ad 		while (height--) {
    388      1.4      ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    389      1.4      ad 			rp[0] = STAMP_READ(so);
    390      1.4      ad 			rp[1] = STAMP_READ(so + 4);
    391      1.4      ad 			rp[2] = STAMP_READ(so + 8);
    392  1.8.2.1  bouyer 
    393      1.4      ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    394      1.4      ad 			rp[3] = STAMP_READ(so);
    395      1.4      ad 			rp[4] = STAMP_READ(so + 4);
    396      1.4      ad 			rp[5] = STAMP_READ(so + 8);
    397      1.4      ad 
    398      1.4      ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    399      1.4      ad 			rp[6] = STAMP_READ(so);
    400      1.4      ad 			rp[7] = STAMP_READ(so + 4);
    401      1.4      ad 			rp[8] = STAMP_READ(so + 8);
    402      1.1      ad 
    403      1.4      ad 			fr += fs;
    404  1.8.2.1  bouyer 			DELTA(rp, ri->ri_stride, int32_t *);
    405      1.1      ad 		}
    406  1.8.2.1  bouyer 	}
    407      1.4      ad 
    408      1.4      ad 	/* Do underline */
    409  1.8.2.1  bouyer 	if ((attr & 1) != 0) {
    410  1.8.2.1  bouyer 		int32_t c = STAMP_READ(52);
    411  1.8.2.1  bouyer 
    412      1.4      ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    413  1.8.2.1  bouyer 		rp[0] = rp[1] = rp[2] = rp[3] =
    414  1.8.2.1  bouyer 		rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = c;
    415  1.8.2.1  bouyer 	}
    416  1.8.2.1  bouyer 
    417      1.4      ad 	stamp_mutex--;
    418      1.1      ad }
    419      1.1      ad 
    420      1.1      ad /*
    421      1.4      ad  * Put a single character. This is for 16-pixel wide fonts.
    422      1.1      ad  */
    423      1.1      ad static void
    424      1.4      ad rasops24_putchar16(cookie, row, col, uc, attr)
    425      1.4      ad 	void *cookie;
    426      1.4      ad 	int row, col;
    427      1.4      ad 	u_int uc;
    428      1.4      ad 	long attr;
    429      1.1      ad {
    430      1.4      ad 	struct rasops_info *ri;
    431      1.4      ad 	int height, so, fs;
    432      1.4      ad 	int32_t *rp;
    433      1.4      ad 	u_char *fr;
    434  1.8.2.1  bouyer 
    435      1.4      ad 	/* Can't risk remaking the stamp if it's already in use */
    436      1.4      ad 	if (stamp_mutex++) {
    437      1.4      ad 		stamp_mutex--;
    438      1.4      ad 		rasops24_putchar(cookie, row, col, uc, attr);
    439      1.4      ad 		return;
    440      1.4      ad 	}
    441      1.4      ad 
    442      1.4      ad 	ri = (struct rasops_info *)cookie;
    443      1.4      ad 
    444  1.8.2.1  bouyer #ifdef RASOPS_CLIPPING
    445      1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows) {
    446      1.4      ad 		stamp_mutex--;
    447      1.4      ad 		return;
    448      1.4      ad 	}
    449      1.4      ad 
    450      1.4      ad 	if ((unsigned)col >= (unsigned)ri->ri_cols) {
    451      1.4      ad 		stamp_mutex--;
    452      1.4      ad 		return;
    453      1.4      ad 	}
    454      1.4      ad #endif
    455      1.4      ad 
    456      1.4      ad 	/* Recompute stamp? */
    457      1.5      ad 	if (attr != stamp_attr)
    458      1.4      ad 		rasops24_makestamp(ri, attr);
    459      1.5      ad 
    460      1.4      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    461      1.4      ad 	height = ri->ri_font->fontheight;
    462  1.8.2.1  bouyer 
    463      1.4      ad 	if (uc == (u_int)-1) {
    464  1.8.2.1  bouyer 		int32_t c = stamp[0];
    465      1.4      ad 		while (height--) {
    466  1.8.2.1  bouyer 			rp[0] = rp[1] = rp[2] = rp[3] =
    467  1.8.2.1  bouyer 			rp[4] = rp[5] = rp[6] = rp[7] =
    468  1.8.2.1  bouyer 			rp[8] = rp[9] = rp[10] = rp[11] = c;
    469  1.8.2.1  bouyer 			DELTA(rp, ri->ri_stride, int32_t *);
    470  1.8.2.1  bouyer 		}
    471      1.4      ad 	} else {
    472      1.4      ad 		uc -= ri->ri_font->firstchar;
    473      1.4      ad 		fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
    474      1.4      ad 		fs = ri->ri_font->stride;
    475  1.8.2.1  bouyer 
    476      1.4      ad 		while (height--) {
    477      1.4      ad 			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
    478      1.4      ad 			rp[0] = STAMP_READ(so);
    479      1.4      ad 			rp[1] = STAMP_READ(so + 4);
    480      1.4      ad 			rp[2] = STAMP_READ(so + 8);
    481  1.8.2.1  bouyer 
    482      1.4      ad 			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
    483      1.4      ad 			rp[3] = STAMP_READ(so);
    484      1.4      ad 			rp[4] = STAMP_READ(so + 4);
    485      1.4      ad 			rp[5] = STAMP_READ(so + 8);
    486      1.4      ad 
    487      1.4      ad 			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
    488      1.4      ad 			rp[6] = STAMP_READ(so);
    489      1.4      ad 			rp[7] = STAMP_READ(so + 4);
    490      1.4      ad 			rp[8] = STAMP_READ(so + 8);
    491  1.8.2.1  bouyer 
    492      1.4      ad 			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
    493      1.4      ad 			rp[9] = STAMP_READ(so);
    494      1.4      ad 			rp[10] = STAMP_READ(so + 4);
    495      1.4      ad 			rp[11] = STAMP_READ(so + 8);
    496      1.4      ad 
    497  1.8.2.1  bouyer 			DELTA(rp, ri->ri_stride, int32_t *);
    498      1.4      ad 			fr += fs;
    499      1.4      ad 		}
    500  1.8.2.1  bouyer 	}
    501      1.1      ad 
    502      1.4      ad 	/* Do underline */
    503  1.8.2.1  bouyer 	if ((attr & 1) != 0) {
    504  1.8.2.1  bouyer 		int32_t c = STAMP_READ(52);
    505  1.8.2.1  bouyer 
    506      1.4      ad 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
    507  1.8.2.1  bouyer 		rp[0] = rp[1] = rp[2] = rp[3] =
    508  1.8.2.1  bouyer 		rp[4] = rp[5] = rp[6] = rp[7] =
    509  1.8.2.1  bouyer 		rp[8] = rp[9] = rp[10] = rp[11] = c;
    510  1.8.2.1  bouyer 	}
    511  1.8.2.1  bouyer 
    512      1.4      ad 	stamp_mutex--;
    513      1.1      ad }
    514  1.8.2.1  bouyer #endif	/* !RASOPS_SMALL */
    515      1.1      ad 
    516      1.1      ad /*
    517      1.4      ad  * Erase rows. This is nice and easy due to alignment.
    518      1.1      ad  */
    519      1.1      ad static void
    520      1.1      ad rasops24_eraserows(cookie, row, num, attr)
    521      1.1      ad 	void *cookie;
    522      1.1      ad 	int row, num;
    523      1.1      ad 	long attr;
    524      1.1      ad {
    525      1.8      ad 	int n9, n3, n1, cnt, stride, delta;
    526      1.8      ad 	u_int32_t *dp, clr, stamp[3];
    527      1.1      ad 	struct rasops_info *ri;
    528  1.8.2.1  bouyer 
    529  1.8.2.1  bouyer 	/*
    530      1.4      ad 	 * If the color is gray, we can cheat and use the generic routines
    531      1.4      ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    532      1.4      ad 	 */
    533  1.8.2.1  bouyer 	if ((attr & 4) != 0) {
    534      1.4      ad 		rasops_eraserows(cookie, row, num, attr);
    535      1.4      ad 		return;
    536      1.4      ad 	}
    537      1.4      ad 
    538      1.1      ad 	ri = (struct rasops_info *)cookie;
    539      1.1      ad 
    540      1.1      ad #ifdef RASOPS_CLIPPING
    541      1.1      ad 	if (row < 0) {
    542      1.1      ad 		num += row;
    543      1.1      ad 		row = 0;
    544      1.1      ad 	}
    545      1.1      ad 
    546      1.1      ad 	if ((row + num) > ri->ri_rows)
    547      1.1      ad 		num = ri->ri_rows - row;
    548  1.8.2.1  bouyer 
    549      1.1      ad 	if (num <= 0)
    550      1.1      ad 		return;
    551      1.1      ad #endif
    552  1.8.2.1  bouyer 
    553  1.8.2.1  bouyer 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    554      1.4      ad 	stamp[0] = (clr <<  8) | (clr >> 16);
    555      1.4      ad 	stamp[1] = (clr << 16) | (clr >>  8);
    556      1.4      ad 	stamp[2] = (clr << 24) | clr;
    557      1.4      ad 
    558      1.4      ad #if BYTE_ORDER == LITTLE_ENDIAN
    559      1.7      ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    560      1.4      ad #else
    561      1.7      ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    562      1.4      ad #endif
    563      1.4      ad 		stamp[0] = bswap32(stamp[0]);
    564      1.4      ad 		stamp[1] = bswap32(stamp[1]);
    565      1.4      ad 		stamp[2] = bswap32(stamp[2]);
    566      1.4      ad 	}
    567      1.4      ad 
    568  1.8.2.1  bouyer 	/*
    569      1.7      ad 	 * XXX the wsdisplay_emulops interface seems a little deficient in
    570  1.8.2.1  bouyer 	 * that there is no way to clear the *entire* screen. We provide a
    571  1.8.2.1  bouyer 	 * workaround here: if the entire console area is being cleared, and
    572      1.7      ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    573  1.8.2.1  bouyer 	 */
    574      1.7      ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    575      1.7      ad 		stride = ri->ri_stride;
    576      1.7      ad 		num = ri->ri_height;
    577      1.8      ad 		dp = (int32_t *)ri->ri_origbits;
    578      1.8      ad 		delta = 0;
    579      1.7      ad 	} else {
    580      1.7      ad 		stride = ri->ri_emustride;
    581      1.7      ad 		num *= ri->ri_font->fontheight;
    582      1.8      ad 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    583      1.8      ad 		delta = ri->ri_delta;
    584      1.7      ad 	}
    585      1.7      ad 
    586      1.7      ad 	n9 = stride / 36;
    587      1.1      ad 	cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
    588      1.7      ad 	n3 = (stride - cnt) / 12;
    589      1.1      ad 	cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
    590      1.7      ad 	n1 = (stride - cnt) >> 2;
    591  1.8.2.1  bouyer 
    592      1.4      ad 	while (num--) {
    593      1.4      ad 		for (cnt = n9; cnt; cnt--) {
    594      1.4      ad 			dp[0] = stamp[0];
    595      1.4      ad 			dp[1] = stamp[1];
    596      1.4      ad 			dp[2] = stamp[2];
    597      1.4      ad 			dp[3] = stamp[0];
    598      1.4      ad 			dp[4] = stamp[1];
    599      1.4      ad 			dp[5] = stamp[2];
    600      1.4      ad 			dp[6] = stamp[0];
    601      1.4      ad 			dp[7] = stamp[1];
    602      1.4      ad 			dp[8] = stamp[2];
    603      1.4      ad 			dp += 9;
    604      1.4      ad 		}
    605      1.1      ad 
    606      1.4      ad 		for (cnt = n3; cnt; cnt--) {
    607      1.4      ad 			dp[0] = stamp[0];
    608      1.4      ad 			dp[1] = stamp[1];
    609      1.4      ad 			dp[2] = stamp[2];
    610      1.4      ad 			dp += 3;
    611      1.4      ad 		}
    612  1.8.2.1  bouyer 
    613      1.4      ad 		for (cnt = 0; cnt < n1; cnt++)
    614      1.4      ad 			*dp++ = stamp[cnt];
    615  1.8.2.1  bouyer 
    616      1.8      ad 		DELTA(dp, delta, int32_t *);
    617      1.4      ad 	}
    618      1.4      ad }
    619      1.4      ad 
    620      1.4      ad /*
    621      1.4      ad  * Erase columns.
    622      1.4      ad  */
    623      1.4      ad static void
    624      1.4      ad rasops24_erasecols(cookie, row, col, num, attr)
    625      1.4      ad 	void *cookie;
    626      1.4      ad 	int row, col, num;
    627      1.4      ad 	long attr;
    628      1.4      ad {
    629      1.4      ad 	int n12, n4, height, cnt, slop, clr, stamp[3];
    630      1.4      ad 	struct rasops_info *ri;
    631      1.4      ad 	int32_t *dp, *rp;
    632      1.4      ad 	u_char *dbp;
    633      1.4      ad 
    634  1.8.2.1  bouyer 	/*
    635      1.4      ad 	 * If the color is gray, we can cheat and use the generic routines
    636      1.4      ad 	 * (which are faster, hopefully) since the r,g,b values are the same.
    637      1.4      ad 	 */
    638  1.8.2.1  bouyer 	if ((attr & 4) != 0) {
    639      1.4      ad 		rasops_erasecols(cookie, row, col, num, attr);
    640      1.4      ad 		return;
    641      1.4      ad 	}
    642  1.8.2.1  bouyer 
    643      1.4      ad 	ri = (struct rasops_info *)cookie;
    644      1.4      ad 
    645  1.8.2.1  bouyer #ifdef RASOPS_CLIPPING
    646  1.8.2.1  bouyer 	/* Catches 'row < 0' case too */
    647      1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    648      1.4      ad 		return;
    649      1.4      ad 
    650      1.4      ad 	if (col < 0) {
    651      1.4      ad 		num += col;
    652      1.4      ad 		col = 0;
    653      1.4      ad 	}
    654      1.4      ad 
    655      1.4      ad 	if ((col + num) > ri->ri_cols)
    656      1.4      ad 		num = ri->ri_cols - col;
    657  1.8.2.1  bouyer 
    658      1.4      ad 	if (num <= 0)
    659      1.4      ad 		return;
    660      1.4      ad #endif
    661  1.8.2.1  bouyer 
    662      1.4      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    663      1.4      ad 	num *= ri->ri_font->fontwidth;
    664      1.4      ad 	height = ri->ri_font->fontheight;
    665      1.4      ad 
    666  1.8.2.1  bouyer 	clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff;
    667      1.4      ad 	stamp[0] = (clr <<  8) | (clr >> 16);
    668      1.4      ad 	stamp[1] = (clr << 16) | (clr >>  8);
    669      1.4      ad 	stamp[2] = (clr << 24) | clr;
    670      1.4      ad 
    671      1.4      ad #if BYTE_ORDER == LITTLE_ENDIAN
    672      1.7      ad 	if ((ri->ri_flg & RI_BSWAP) == 0) {
    673      1.4      ad #else
    674      1.7      ad 	if ((ri->ri_flg & RI_BSWAP) != 0) {
    675      1.4      ad #endif
    676      1.4      ad 		stamp[0] = bswap32(stamp[0]);
    677      1.4      ad 		stamp[1] = bswap32(stamp[1]);
    678      1.4      ad 		stamp[2] = bswap32(stamp[2]);
    679      1.4      ad 	}
    680  1.8.2.1  bouyer 
    681  1.8.2.1  bouyer 	/*
    682      1.4      ad 	 * The current byte offset mod 4 tells us the number of 24-bit pels
    683      1.4      ad 	 * we need to write for alignment to 32-bits. Once we're aligned on
    684      1.4      ad 	 * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
    685      1.4      ad 	 * the stamp does not need to be rotated. The following shows the
    686  1.8.2.1  bouyer 	 * layout of 4 pels in a 3 word region and illustrates this:
    687      1.4      ad 	 *
    688      1.4      ad 	 *	aaab bbcc cddd
    689      1.4      ad 	 */
    690      1.4      ad 	slop = (int)rp & 3;	num -= slop;
    691      1.4      ad 	n12 = num / 12;		num -= (n12 << 3) + (n12 << 2);
    692      1.4      ad 	n4 = num >> 2;		num &= 3;
    693  1.8.2.1  bouyer 
    694      1.4      ad 	while (height--) {
    695      1.4      ad 		dbp = (u_char *)rp;
    696      1.4      ad 		DELTA(rp, ri->ri_stride, int32_t *);
    697      1.4      ad 
    698      1.4      ad 		/* Align to 4 bytes */
    699      1.7      ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    700      1.4      ad 		for (cnt = slop; cnt; cnt--) {
    701      1.4      ad 			*dbp++ = (clr >> 16);
    702      1.4      ad 			*dbp++ = (clr >> 8);
    703  1.8.2.1  bouyer 			*dbp++ = clr;
    704  1.8.2.1  bouyer 		}
    705      1.4      ad 
    706      1.4      ad 		dp = (int32_t *)dbp;
    707  1.8.2.1  bouyer 
    708      1.4      ad 		/* 12 pels per loop */
    709      1.4      ad 		for (cnt = n12; cnt; cnt--) {
    710      1.4      ad 			dp[0] = stamp[0];
    711      1.4      ad 			dp[1] = stamp[1];
    712      1.4      ad 			dp[2] = stamp[2];
    713      1.4      ad 			dp[3] = stamp[0];
    714      1.4      ad 			dp[4] = stamp[1];
    715      1.4      ad 			dp[5] = stamp[2];
    716      1.4      ad 			dp[6] = stamp[0];
    717      1.4      ad 			dp[7] = stamp[1];
    718      1.4      ad 			dp[8] = stamp[2];
    719      1.4      ad 			dp += 9;
    720      1.1      ad 		}
    721      1.1      ad 
    722      1.4      ad 		/* 4 pels per loop */
    723      1.4      ad 		for (cnt = n4; cnt; cnt--) {
    724      1.4      ad 			dp[0] = stamp[0];
    725      1.4      ad 			dp[1] = stamp[1];
    726      1.4      ad 			dp[2] = stamp[2];
    727      1.4      ad 			dp += 3;
    728      1.4      ad 		}
    729  1.8.2.1  bouyer 
    730      1.4      ad 		/* Trailing slop */
    731      1.7      ad 		/* XXX handle with masks, bring under control of RI_BSWAP */
    732      1.4      ad 		dbp = (u_char *)dp;
    733      1.4      ad 		for (cnt = num; cnt; cnt--) {
    734      1.4      ad 			*dbp++ = (clr >> 16);
    735      1.4      ad 			*dbp++ = (clr >> 8);
    736  1.8.2.1  bouyer 			*dbp++ = clr;
    737  1.8.2.1  bouyer 		}
    738      1.1      ad 	}
    739      1.1      ad }
    740