Home | History | Annotate | Line # | Download | only in rasops
rasops.c revision 1.19.2.4
      1  1.19.2.4  bouyer /*	 $NetBSD: rasops.c,v 1.19.2.4 2001/03/12 13:31:23 bouyer Exp $	*/
      2       1.1      ad 
      3       1.9      ad /*-
      4       1.9      ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5       1.1      ad  * All rights reserved.
      6       1.1      ad  *
      7       1.9      ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.19.2.1  bouyer  * by Andrew Doran.
      9       1.9      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.9      ad  * 3. All advertising materials mentioning features or use of this software
     19       1.9      ad  *    must display the following acknowledgement:
     20       1.9      ad  *	This product includes software developed by the NetBSD
     21       1.9      ad  *	Foundation, Inc. and its contributors.
     22       1.9      ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.9      ad  *    contributors may be used to endorse or promote products derived
     24       1.9      ad  *    from this software without specific prior written permission.
     25       1.1      ad  *
     26       1.9      ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.9      ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.9      ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.9      ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.9      ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.9      ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.9      ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.9      ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.9      ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.9      ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.9      ad  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      ad  */
     38       1.2      ad 
     39       1.1      ad #include <sys/cdefs.h>
     40  1.19.2.4  bouyer __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.19.2.4 2001/03/12 13:31:23 bouyer Exp $");
     41       1.1      ad 
     42      1.18      ad #include "opt_rasops.h"
     43       1.4      ad #include "rasops_glue.h"
     44       1.1      ad 
     45       1.1      ad #include <sys/types.h>
     46       1.1      ad #include <sys/param.h>
     47       1.1      ad #include <sys/systm.h>
     48       1.1      ad #include <sys/time.h>
     49       1.1      ad 
     50       1.3      ad #include <machine/bswap.h>
     51       1.4      ad #include <machine/endian.h>
     52       1.3      ad 
     53       1.1      ad #include <dev/wscons/wsdisplayvar.h>
     54       1.1      ad #include <dev/wscons/wsconsio.h>
     55       1.1      ad #include <dev/wsfont/wsfont.h>
     56       1.1      ad #include <dev/rasops/rasops.h>
     57       1.1      ad 
     58      1.11      ad #ifndef _KERNEL
     59      1.11      ad #include <errno.h>
     60      1.11      ad #endif
     61      1.11      ad 
     62       1.1      ad /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
     63  1.19.2.1  bouyer const u_char rasops_cmap[256*3] = {
     64       1.1      ad 	0x00, 0x00, 0x00, /* black */
     65       1.1      ad 	0x7f, 0x00, 0x00, /* red */
     66       1.1      ad 	0x00, 0x7f, 0x00, /* green */
     67       1.1      ad 	0x7f, 0x7f, 0x00, /* brown */
     68       1.1      ad 	0x00, 0x00, 0x7f, /* blue */
     69       1.1      ad 	0x7f, 0x00, 0x7f, /* magenta */
     70       1.1      ad 	0x00, 0x7f, 0x7f, /* cyan */
     71       1.1      ad 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
     72       1.1      ad 
     73       1.1      ad 	0x7f, 0x7f, 0x7f, /* black */
     74       1.1      ad 	0xff, 0x00, 0x00, /* red */
     75       1.1      ad 	0x00, 0xff, 0x00, /* green */
     76       1.1      ad 	0xff, 0xff, 0x00, /* brown */
     77       1.1      ad 	0x00, 0x00, 0xff, /* blue */
     78       1.1      ad 	0xff, 0x00, 0xff, /* magenta */
     79       1.1      ad 	0x00, 0xff, 0xff, /* cyan */
     80       1.1      ad 	0xff, 0xff, 0xff, /* white */
     81  1.19.2.1  bouyer 
     82  1.19.2.1  bouyer 	/*
     83  1.19.2.1  bouyer 	 * For the cursor, we need at least the last (255th)
     84  1.19.2.1  bouyer 	 * color to be white. Fill up white completely for
     85  1.19.2.1  bouyer 	 * simplicity.
     86  1.19.2.1  bouyer 	 */
     87  1.19.2.1  bouyer #define _CMWHITE 0xff, 0xff, 0xff,
     88  1.19.2.1  bouyer #define _CMWHITE16	_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     89  1.19.2.1  bouyer 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     90  1.19.2.1  bouyer 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     91  1.19.2.1  bouyer 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE
     92  1.19.2.1  bouyer 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     93  1.19.2.1  bouyer 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     94  1.19.2.1  bouyer 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     95  1.19.2.1  bouyer #undef _CMWHITE16
     96  1.19.2.1  bouyer #undef _CMWHITE
     97       1.1      ad };
     98       1.1      ad 
     99       1.1      ad /* True if color is gray */
    100  1.19.2.1  bouyer const u_char rasops_isgray[16] = {
    101  1.19.2.1  bouyer 	1, 0, 0, 0,
    102       1.1      ad 	0, 0, 0, 1,
    103       1.1      ad 	1, 0, 0, 0,
    104       1.1      ad 	0, 0, 0, 1
    105       1.1      ad };
    106       1.1      ad 
    107       1.4      ad /* Generic functions */
    108       1.1      ad static void	rasops_copyrows __P((void *, int, int, int));
    109       1.1      ad static int	rasops_mapchar __P((void *, int, u_int *));
    110       1.1      ad static void	rasops_cursor __P((void *, int, int, int));
    111       1.1      ad static int	rasops_alloc_cattr __P((void *, int, int, int, long *));
    112       1.1      ad static int	rasops_alloc_mattr __P((void *, int, int, int, long *));
    113       1.4      ad static void	rasops_do_cursor __P((struct rasops_info *));
    114       1.4      ad static void	rasops_init_devcmap __P((struct rasops_info *));
    115       1.1      ad 
    116       1.1      ad /*
    117       1.1      ad  * Initalize a 'rasops_info' descriptor.
    118       1.1      ad  */
    119       1.1      ad int
    120      1.13      ad rasops_init(ri, wantrows, wantcols)
    121       1.1      ad 	struct rasops_info *ri;
    122      1.13      ad 	int wantrows, wantcols;
    123       1.1      ad {
    124  1.19.2.1  bouyer 
    125  1.19.2.1  bouyer #ifdef _KERNEL
    126       1.1      ad 	/* Select a font if the caller doesn't care */
    127       1.1      ad 	if (ri->ri_font == NULL) {
    128       1.1      ad 		int cookie;
    129  1.19.2.1  bouyer 
    130       1.1      ad 		wsfont_init();
    131       1.1      ad 
    132       1.1      ad 		/* Want 8 pixel wide, don't care about aestethics */
    133       1.7      ad 		if ((cookie = wsfont_find(NULL, 8, 0, 0)) <= 0)
    134       1.1      ad 			cookie = wsfont_find(NULL, 0, 0, 0);
    135       1.1      ad 
    136       1.7      ad 		if (cookie <= 0) {
    137       1.1      ad 			printf("rasops_init: font table is empty\n");
    138       1.1      ad 			return (-1);
    139       1.1      ad 		}
    140  1.19.2.1  bouyer 
    141  1.19.2.1  bouyer 		if (wsfont_lock(cookie, &ri->ri_font,
    142  1.19.2.1  bouyer 		    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R) <= 0) {
    143       1.1      ad 			printf("rasops_init: couldn't lock font\n");
    144       1.1      ad 			return (-1);
    145       1.1      ad 		}
    146       1.8      ad 
    147       1.5      ad 		ri->ri_wsfcookie = cookie;
    148       1.1      ad 	}
    149       1.4      ad #endif
    150  1.19.2.1  bouyer 
    151       1.1      ad 	/* This should never happen in reality... */
    152       1.1      ad #ifdef DEBUG
    153  1.19.2.1  bouyer 	if ((long)ri->ri_bits & 3) {
    154       1.1      ad 		printf("rasops_init: bits not aligned on 32-bit boundary\n");
    155       1.1      ad 		return (-1);
    156       1.1      ad 	}
    157       1.1      ad 
    158       1.1      ad 	if ((int)ri->ri_stride & 3) {
    159       1.1      ad 		printf("rasops_init: stride not aligned on 32-bit boundary\n");
    160       1.1      ad 		return (-1);
    161       1.1      ad 	}
    162       1.1      ad #endif
    163       1.4      ad 
    164      1.13      ad 	if (rasops_reconfig(ri, wantrows, wantcols))
    165       1.4      ad 		return (-1);
    166  1.19.2.1  bouyer 
    167       1.4      ad 	rasops_init_devcmap(ri);
    168       1.4      ad 	return (0);
    169       1.4      ad }
    170       1.4      ad 
    171       1.4      ad /*
    172      1.13      ad  * Reconfigure (because parameters have changed in some way).
    173       1.4      ad  */
    174       1.4      ad int
    175      1.13      ad rasops_reconfig(ri, wantrows, wantcols)
    176       1.4      ad 	struct rasops_info *ri;
    177      1.13      ad 	int wantrows, wantcols;
    178       1.4      ad {
    179  1.19.2.1  bouyer 	int bpp, s;
    180  1.19.2.1  bouyer 
    181      1.13      ad 	s = splhigh();
    182  1.19.2.1  bouyer 
    183       1.4      ad 	if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
    184       1.4      ad 		panic("rasops_init: fontwidth assumptions botched!\n");
    185  1.19.2.1  bouyer 
    186       1.4      ad 	/* Need this to frob the setup below */
    187       1.4      ad 	bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
    188       1.4      ad 
    189      1.13      ad 	if ((ri->ri_flg & RI_CFGDONE) != 0)
    190       1.4      ad 		ri->ri_bits = ri->ri_origbits;
    191  1.19.2.1  bouyer 
    192       1.1      ad 	/* Don't care if the caller wants a hideously small console */
    193       1.1      ad 	if (wantrows < 10)
    194      1.13      ad 		wantrows = 10;
    195  1.19.2.1  bouyer 
    196       1.1      ad 	if (wantcols < 20)
    197      1.13      ad 		wantcols = 20;
    198  1.19.2.1  bouyer 
    199       1.1      ad 	/* Now constrain what they get */
    200       1.1      ad 	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
    201       1.1      ad 	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
    202  1.19.2.1  bouyer 
    203       1.1      ad 	if (ri->ri_emuwidth > ri->ri_width)
    204       1.1      ad 		ri->ri_emuwidth = ri->ri_width;
    205  1.19.2.1  bouyer 
    206       1.1      ad 	if (ri->ri_emuheight > ri->ri_height)
    207       1.1      ad 		ri->ri_emuheight = ri->ri_height;
    208  1.19.2.1  bouyer 
    209       1.1      ad 	/* Reduce width until aligned on a 32-bit boundary */
    210  1.19.2.1  bouyer 	while ((ri->ri_emuwidth * bpp & 31) != 0)
    211       1.1      ad 		ri->ri_emuwidth--;
    212  1.19.2.1  bouyer 
    213       1.1      ad 	ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
    214       1.1      ad 	ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
    215       1.4      ad 	ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
    216       1.1      ad 	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
    217       1.1      ad 	ri->ri_ccol = 0;
    218       1.1      ad 	ri->ri_crow = 0;
    219       1.4      ad 	ri->ri_pelbytes = bpp >> 3;
    220  1.19.2.1  bouyer 
    221       1.4      ad 	ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
    222       1.1      ad 	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
    223       1.1      ad 	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
    224       1.1      ad 
    225  1.19.2.1  bouyer #ifdef DEBUG
    226      1.18      ad 	if ((ri->ri_delta & 3) != 0)
    227      1.13      ad 		panic("rasops_init: ri_delta not aligned on 32-bit boundary");
    228  1.19.2.1  bouyer #endif
    229       1.1      ad 	/* Clear the entire display */
    230      1.13      ad 	if ((ri->ri_flg & RI_CLEAR) != 0)
    231      1.13      ad 		memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    232  1.19.2.1  bouyer 
    233  1.19.2.1  bouyer 	/* Now centre our window if needs be */
    234       1.1      ad 	ri->ri_origbits = ri->ri_bits;
    235  1.19.2.1  bouyer 
    236      1.13      ad 	if ((ri->ri_flg & RI_CENTER) != 0) {
    237  1.19.2.4  bouyer 		ri->ri_bits += (((ri->ri_width * bpp >> 3) -
    238  1.19.2.4  bouyer 		    ri->ri_emustride) >> 1) & ~3;
    239  1.19.2.1  bouyer 		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    240       1.1      ad 		    ri->ri_stride;
    241  1.19.2.1  bouyer 
    242  1.19.2.1  bouyer 		ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
    243       1.5      ad 		   / ri->ri_stride;
    244  1.19.2.1  bouyer 		ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
    245  1.19.2.1  bouyer 		   % ri->ri_stride) * 8 / bpp);
    246       1.5      ad 	} else
    247       1.5      ad 		ri->ri_xorigin = ri->ri_yorigin = 0;
    248       1.4      ad 
    249  1.19.2.1  bouyer 	/*
    250       1.4      ad 	 * Fill in defaults for operations set.  XXX this nukes private
    251       1.4      ad 	 * routines used by accelerated fb drivers.
    252       1.4      ad 	 */
    253       1.1      ad 	ri->ri_ops.mapchar = rasops_mapchar;
    254       1.1      ad 	ri->ri_ops.copyrows = rasops_copyrows;
    255       1.1      ad 	ri->ri_ops.copycols = rasops_copycols;
    256       1.4      ad 	ri->ri_ops.erasecols = rasops_erasecols;
    257       1.4      ad 	ri->ri_ops.eraserows = rasops_eraserows;
    258       1.1      ad 	ri->ri_ops.cursor = rasops_cursor;
    259       1.4      ad 	ri->ri_do_cursor = rasops_do_cursor;
    260  1.19.2.1  bouyer 
    261      1.13      ad 	if (ri->ri_depth < 8 || (ri->ri_flg & RI_FORCEMONO) != 0) {
    262       1.1      ad 		ri->ri_ops.alloc_attr = rasops_alloc_mattr;
    263  1.19.2.1  bouyer 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
    264       1.4      ad 	} else {
    265       1.1      ad 		ri->ri_ops.alloc_attr = rasops_alloc_cattr;
    266  1.19.2.1  bouyer 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
    267  1.19.2.1  bouyer 		    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    268       1.4      ad 	}
    269       1.4      ad 
    270       1.1      ad 	switch (ri->ri_depth) {
    271  1.19.2.1  bouyer #if NRASOPS1 > 0
    272       1.1      ad 	case 1:
    273       1.1      ad 		rasops1_init(ri);
    274       1.1      ad 		break;
    275       1.1      ad #endif
    276  1.19.2.1  bouyer #if NRASOPS2 > 0
    277       1.4      ad 	case 2:
    278       1.4      ad 		rasops2_init(ri);
    279       1.4      ad 		break;
    280       1.4      ad #endif
    281  1.19.2.3  bouyer #if NRASOPS4 > 0
    282  1.19.2.3  bouyer 	case 4:
    283  1.19.2.3  bouyer 		rasops4_init(ri);
    284  1.19.2.3  bouyer 		break;
    285  1.19.2.3  bouyer #endif
    286  1.19.2.1  bouyer #if NRASOPS8 > 0
    287       1.1      ad 	case 8:
    288       1.1      ad 		rasops8_init(ri);
    289       1.1      ad 		break;
    290       1.1      ad #endif
    291  1.19.2.1  bouyer #if NRASOPS15 > 0 || NRASOPS16 > 0
    292       1.1      ad 	case 15:
    293       1.1      ad 	case 16:
    294       1.1      ad 		rasops15_init(ri);
    295       1.1      ad 		break;
    296       1.1      ad #endif
    297  1.19.2.1  bouyer #if NRASOPS24 > 0
    298       1.1      ad 	case 24:
    299       1.1      ad 		rasops24_init(ri);
    300       1.1      ad 		break;
    301       1.1      ad #endif
    302  1.19.2.1  bouyer #if NRASOPS32 > 0
    303       1.1      ad 	case 32:
    304       1.1      ad 		rasops32_init(ri);
    305       1.1      ad 		break;
    306       1.1      ad #endif
    307       1.1      ad 	default:
    308      1.13      ad 		ri->ri_flg &= ~RI_CFGDONE;
    309      1.13      ad 		splx(s);
    310       1.1      ad 		return (-1);
    311       1.1      ad 	}
    312  1.19.2.1  bouyer 
    313      1.13      ad 	ri->ri_flg |= RI_CFGDONE;
    314      1.13      ad 	splx(s);
    315       1.1      ad 	return (0);
    316       1.1      ad }
    317       1.1      ad 
    318       1.1      ad /*
    319       1.1      ad  * Map a character.
    320       1.1      ad  */
    321       1.1      ad static int
    322       1.1      ad rasops_mapchar(cookie, c, cp)
    323       1.1      ad 	void *cookie;
    324       1.1      ad 	int c;
    325       1.1      ad 	u_int *cp;
    326       1.1      ad {
    327       1.1      ad 	struct rasops_info *ri;
    328  1.19.2.1  bouyer 
    329       1.1      ad 	ri = (struct rasops_info *)cookie;
    330       1.8      ad 
    331  1.19.2.1  bouyer #ifdef DIAGNOSTIC
    332       1.8      ad 	if (ri->ri_font == NULL)
    333       1.8      ad 		panic("rasops_mapchar: no font selected\n");
    334  1.19.2.1  bouyer #endif
    335  1.19.2.3  bouyer 	if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) {
    336  1.19.2.3  bouyer 
    337  1.19.2.3  bouyer 		if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
    338  1.19.2.3  bouyer 
    339  1.19.2.3  bouyer 			*cp = ' ';
    340  1.19.2.3  bouyer 			return (0);
    341  1.19.2.3  bouyer 
    342  1.19.2.3  bouyer 		}
    343  1.19.2.3  bouyer 	}
    344  1.19.2.3  bouyer 
    345  1.19.2.1  bouyer 
    346       1.1      ad 	if (c < ri->ri_font->firstchar) {
    347       1.1      ad 		*cp = ' ';
    348       1.1      ad 		return (0);
    349       1.1      ad 	}
    350  1.19.2.1  bouyer 
    351       1.1      ad 	if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
    352       1.1      ad 		*cp = ' ';
    353       1.1      ad 		return (0);
    354       1.1      ad 	}
    355  1.19.2.1  bouyer 
    356       1.1      ad 	*cp = c;
    357       1.1      ad 	return (5);
    358       1.1      ad }
    359       1.1      ad 
    360       1.1      ad /*
    361       1.1      ad  * Allocate a color attribute.
    362       1.1      ad  */
    363       1.1      ad static int
    364       1.1      ad rasops_alloc_cattr(cookie, fg, bg, flg, attr)
    365       1.1      ad 	void *cookie;
    366       1.1      ad 	int fg, bg, flg;
    367       1.1      ad 	long *attr;
    368       1.1      ad {
    369       1.1      ad 	int swap;
    370       1.1      ad 
    371       1.1      ad #ifdef RASOPS_CLIPPING
    372       1.1      ad 	fg &= 7;
    373       1.1      ad 	bg &= 7;
    374       1.1      ad #endif
    375      1.17      ad 	if ((flg & WSATTR_BLINK) != 0)
    376       1.1      ad 		return (EINVAL);
    377  1.19.2.1  bouyer 
    378  1.19.2.1  bouyer 	if ((flg & WSATTR_WSCOLORS) == 0) {
    379  1.19.2.1  bouyer 		fg = WSCOL_WHITE;
    380  1.19.2.1  bouyer 		bg = WSCOL_BLACK;
    381  1.19.2.1  bouyer 	}
    382  1.19.2.1  bouyer 
    383      1.17      ad 	if ((flg & WSATTR_REVERSE) != 0) {
    384       1.1      ad 		swap = fg;
    385       1.1      ad 		fg = bg;
    386       1.1      ad 		bg = swap;
    387       1.1      ad 	}
    388       1.1      ad 
    389      1.17      ad 	if ((flg & WSATTR_HILIT) != 0)
    390       1.1      ad 		fg += 8;
    391  1.19.2.1  bouyer 
    392       1.1      ad 	flg = ((flg & WSATTR_UNDERLINE) ? 1 : 0);
    393  1.19.2.1  bouyer 
    394       1.1      ad 	if (rasops_isgray[fg])
    395       1.1      ad 		flg |= 2;
    396       1.1      ad 
    397       1.1      ad 	if (rasops_isgray[bg])
    398       1.1      ad 		flg |= 4;
    399       1.1      ad 
    400       1.1      ad 	*attr = (bg << 16) | (fg << 24) | flg;
    401      1.17      ad 	return (0);
    402       1.1      ad }
    403       1.1      ad 
    404       1.1      ad /*
    405       1.1      ad  * Allocate a mono attribute.
    406       1.1      ad  */
    407       1.1      ad static int
    408       1.1      ad rasops_alloc_mattr(cookie, fg, bg, flg, attr)
    409       1.1      ad 	void *cookie;
    410       1.1      ad 	int fg, bg, flg;
    411       1.1      ad 	long *attr;
    412       1.1      ad {
    413       1.1      ad 	int swap;
    414       1.1      ad 
    415  1.19.2.1  bouyer 	if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
    416       1.1      ad 		return (EINVAL);
    417  1.19.2.1  bouyer 
    418  1.19.2.1  bouyer 	fg = 1;
    419  1.19.2.1  bouyer 	bg = 0;
    420  1.19.2.1  bouyer 
    421      1.17      ad 	if ((flg & WSATTR_REVERSE) != 0) {
    422       1.1      ad 		swap = fg;
    423       1.1      ad 		fg = bg;
    424       1.1      ad 		bg = swap;
    425       1.1      ad 	}
    426       1.1      ad 
    427       1.1      ad 	*attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
    428      1.17      ad 	return (0);
    429       1.1      ad }
    430       1.1      ad 
    431       1.1      ad /*
    432       1.1      ad  * Copy rows.
    433       1.1      ad  */
    434       1.1      ad static void
    435       1.1      ad rasops_copyrows(cookie, src, dst, num)
    436       1.1      ad 	void *cookie;
    437       1.1      ad 	int src, dst, num;
    438       1.1      ad {
    439      1.18      ad 	int32_t *sp, *dp, *srp, *drp;
    440       1.1      ad 	struct rasops_info *ri;
    441      1.18      ad 	int n8, n1, cnt, delta;
    442  1.19.2.1  bouyer 
    443       1.1      ad 	ri = (struct rasops_info *)cookie;
    444       1.1      ad 
    445       1.1      ad #ifdef RASOPS_CLIPPING
    446       1.1      ad 	if (dst == src)
    447       1.1      ad 		return;
    448  1.19.2.1  bouyer 
    449       1.1      ad 	if (src < 0) {
    450       1.1      ad 		num += src;
    451       1.1      ad 		src = 0;
    452       1.1      ad 	}
    453       1.1      ad 
    454       1.1      ad 	if ((src + num) > ri->ri_rows)
    455       1.1      ad 		num = ri->ri_rows - src;
    456       1.1      ad 
    457       1.1      ad 	if (dst < 0) {
    458       1.1      ad 		num += dst;
    459       1.1      ad 		dst = 0;
    460       1.1      ad 	}
    461       1.1      ad 
    462       1.1      ad 	if ((dst + num) > ri->ri_rows)
    463       1.1      ad 		num = ri->ri_rows - dst;
    464  1.19.2.1  bouyer 
    465       1.1      ad 	if (num <= 0)
    466       1.1      ad 		return;
    467       1.1      ad #endif
    468       1.1      ad 
    469       1.1      ad 	num *= ri->ri_font->fontheight;
    470       1.1      ad 	n8 = ri->ri_emustride >> 5;
    471       1.1      ad 	n1 = (ri->ri_emustride >> 2) & 7;
    472  1.19.2.1  bouyer 
    473       1.1      ad 	if (dst < src) {
    474      1.18      ad 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_yscale);
    475      1.18      ad 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_yscale);
    476      1.18      ad 		delta = ri->ri_stride;
    477       1.1      ad 	} else {
    478       1.1      ad 		src = ri->ri_font->fontheight * src + num - 1;
    479       1.1      ad 		dst = ri->ri_font->fontheight * dst + num - 1;
    480       1.1      ad 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_stride);
    481       1.1      ad 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_stride);
    482      1.18      ad 		delta = -ri->ri_stride;
    483      1.18      ad 	}
    484  1.19.2.1  bouyer 
    485      1.18      ad 	while (num--) {
    486      1.18      ad 		dp = drp;
    487      1.18      ad 		sp = srp;
    488      1.18      ad 		DELTA(drp, delta, int32_t *);
    489      1.18      ad 		DELTA(srp, delta, int32_t *);
    490      1.18      ad 
    491      1.18      ad 		for (cnt = n8; cnt; cnt--) {
    492      1.18      ad 			dp[0] = sp[0];
    493      1.18      ad 			dp[1] = sp[1];
    494      1.18      ad 			dp[2] = sp[2];
    495      1.18      ad 			dp[3] = sp[3];
    496      1.18      ad 			dp[4] = sp[4];
    497      1.18      ad 			dp[5] = sp[5];
    498      1.18      ad 			dp[6] = sp[6];
    499      1.18      ad 			dp[7] = sp[7];
    500      1.18      ad 			dp += 8;
    501      1.18      ad 			sp += 8;
    502      1.18      ad 		}
    503  1.19.2.1  bouyer 
    504      1.18      ad 		for (cnt = n1; cnt; cnt--)
    505      1.18      ad 			*dp++ = *sp++;
    506       1.1      ad 	}
    507       1.1      ad }
    508       1.1      ad 
    509       1.1      ad /*
    510       1.1      ad  * Copy columns. This is slow, and hard to optimize due to alignment,
    511       1.1      ad  * and the fact that we have to copy both left->right and right->left.
    512       1.1      ad  * We simply cop-out here and use bcopy(), since it handles all of
    513       1.1      ad  * these cases anyway.
    514       1.1      ad  */
    515       1.4      ad void
    516       1.1      ad rasops_copycols(cookie, row, src, dst, num)
    517       1.1      ad 	void *cookie;
    518       1.1      ad 	int row, src, dst, num;
    519       1.1      ad {
    520       1.1      ad 	struct rasops_info *ri;
    521       1.1      ad 	u_char *sp, *dp;
    522       1.1      ad 	int height;
    523  1.19.2.1  bouyer 
    524       1.1      ad 	ri = (struct rasops_info *)cookie;
    525       1.1      ad 
    526       1.1      ad #ifdef RASOPS_CLIPPING
    527       1.1      ad 	if (dst == src)
    528       1.1      ad 		return;
    529  1.19.2.1  bouyer 
    530       1.3      ad 	/* Catches < 0 case too */
    531       1.3      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    532       1.1      ad 		return;
    533  1.19.2.1  bouyer 
    534       1.1      ad 	if (src < 0) {
    535       1.1      ad 		num += src;
    536       1.1      ad 		src = 0;
    537       1.1      ad 	}
    538       1.1      ad 
    539       1.1      ad 	if ((src + num) > ri->ri_cols)
    540       1.1      ad 		num = ri->ri_cols - src;
    541       1.1      ad 
    542       1.1      ad 	if (dst < 0) {
    543       1.1      ad 		num += dst;
    544       1.1      ad 		dst = 0;
    545       1.1      ad 	}
    546       1.1      ad 
    547       1.1      ad 	if ((dst + num) > ri->ri_cols)
    548       1.1      ad 		num = ri->ri_cols - dst;
    549  1.19.2.1  bouyer 
    550       1.1      ad 	if (num <= 0)
    551       1.1      ad 		return;
    552       1.1      ad #endif
    553  1.19.2.1  bouyer 
    554       1.1      ad 	num *= ri->ri_xscale;
    555       1.1      ad 	row *= ri->ri_yscale;
    556       1.1      ad 	height = ri->ri_font->fontheight;
    557  1.19.2.1  bouyer 
    558       1.1      ad 	sp = ri->ri_bits + row + src * ri->ri_xscale;
    559       1.1      ad 	dp = ri->ri_bits + row + dst * ri->ri_xscale;
    560  1.19.2.1  bouyer 
    561       1.1      ad 	while (height--) {
    562       1.1      ad 		bcopy(sp, dp, num);
    563       1.1      ad 		dp += ri->ri_stride;
    564       1.1      ad 		sp += ri->ri_stride;
    565       1.1      ad 	}
    566       1.1      ad }
    567       1.1      ad 
    568       1.1      ad /*
    569       1.1      ad  * Turn cursor off/on.
    570       1.1      ad  */
    571       1.1      ad static void
    572       1.1      ad rasops_cursor(cookie, on, row, col)
    573       1.1      ad 	void *cookie;
    574       1.1      ad 	int on, row, col;
    575       1.1      ad {
    576       1.1      ad 	struct rasops_info *ri;
    577  1.19.2.1  bouyer 
    578       1.1      ad 	ri = (struct rasops_info *)cookie;
    579  1.19.2.1  bouyer 
    580       1.1      ad 	/* Turn old cursor off */
    581      1.13      ad 	if ((ri->ri_flg & RI_CURSOR) != 0)
    582  1.19.2.1  bouyer #ifdef RASOPS_CLIPPING
    583      1.13      ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    584       1.1      ad #endif
    585       1.1      ad 			ri->ri_do_cursor(ri);
    586       1.1      ad 
    587       1.1      ad 	/* Select new cursor */
    588       1.1      ad #ifdef RASOPS_CLIPPING
    589      1.13      ad 	ri->ri_flg &= ~RI_CURSORCLIP;
    590  1.19.2.1  bouyer 
    591       1.1      ad 	if (row < 0 || row >= ri->ri_rows)
    592      1.13      ad 		ri->ri_flg |= RI_CURSORCLIP;
    593       1.1      ad 	else if (col < 0 || col >= ri->ri_cols)
    594      1.13      ad 		ri->ri_flg |= RI_CURSORCLIP;
    595       1.1      ad #endif
    596       1.1      ad 	ri->ri_crow = row;
    597       1.1      ad 	ri->ri_ccol = col;
    598       1.1      ad 
    599       1.1      ad 	if (on) {
    600      1.13      ad 		ri->ri_flg |= RI_CURSOR;
    601  1.19.2.1  bouyer #ifdef RASOPS_CLIPPING
    602      1.13      ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    603       1.1      ad #endif
    604       1.1      ad 			ri->ri_do_cursor(ri);
    605  1.19.2.1  bouyer 	} else
    606      1.13      ad 		ri->ri_flg &= ~RI_CURSOR;
    607       1.1      ad }
    608       1.1      ad 
    609       1.1      ad /*
    610       1.1      ad  * Make the device colormap
    611       1.1      ad  */
    612       1.4      ad static void
    613       1.1      ad rasops_init_devcmap(ri)
    614       1.1      ad 	struct rasops_info *ri;
    615       1.1      ad {
    616  1.19.2.1  bouyer 	const u_char *p;
    617       1.1      ad 	int i, c;
    618  1.19.2.1  bouyer 
    619       1.4      ad 	switch (ri->ri_depth) {
    620       1.4      ad 	case 1:
    621       1.4      ad 		ri->ri_devcmap[0] = 0;
    622       1.4      ad 		for (i = 1; i < 16; i++)
    623       1.4      ad 			ri->ri_devcmap[i] = -1;
    624       1.4      ad 		return;
    625       1.4      ad 
    626       1.4      ad 	case 2:
    627       1.4      ad 		for (i = 1; i < 15; i++)
    628       1.4      ad 			ri->ri_devcmap[i] = 0xaaaaaaaa;
    629  1.19.2.1  bouyer 
    630       1.4      ad 		ri->ri_devcmap[0] = 0;
    631       1.4      ad 		ri->ri_devcmap[8] = 0x55555555;
    632       1.4      ad 		ri->ri_devcmap[15] = -1;
    633       1.4      ad 		return;
    634       1.4      ad 
    635       1.4      ad 	case 8:
    636       1.4      ad 		for (i = 0; i < 16; i++)
    637       1.4      ad 			ri->ri_devcmap[i] = i | (i<<8) | (i<<16) | (i<<24);
    638       1.4      ad 		return;
    639       1.4      ad 	}
    640  1.19.2.1  bouyer 
    641       1.1      ad 	p = rasops_cmap;
    642  1.19.2.1  bouyer 
    643  1.19.2.1  bouyer 	for (i = 0; i < 16; i++) {
    644       1.1      ad 		if (ri->ri_rnum <= 8)
    645      1.12      ad 			c = (*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
    646  1.19.2.1  bouyer 		else
    647      1.12      ad 			c = (*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
    648  1.19.2.1  bouyer 		p++;
    649       1.1      ad 
    650       1.1      ad 		if (ri->ri_gnum <= 8)
    651      1.12      ad 			c |= (*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
    652  1.19.2.1  bouyer 		else
    653      1.12      ad 			c |= (*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
    654  1.19.2.1  bouyer 		p++;
    655       1.1      ad 
    656       1.1      ad 		if (ri->ri_bnum <= 8)
    657      1.12      ad 			c |= (*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
    658  1.19.2.1  bouyer 		else
    659      1.12      ad 			c |= (*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
    660  1.19.2.1  bouyer 		p++;
    661       1.4      ad 
    662       1.4      ad 		/* Fill the word for generic routines, which want this */
    663       1.4      ad 		if (ri->ri_depth == 24)
    664       1.4      ad 			c = c | ((c & 0xff) << 24);
    665       1.4      ad 		else if (ri->ri_depth <= 16)
    666       1.4      ad 			c = c | (c << 16);
    667       1.1      ad 
    668       1.4      ad 		/* 24bpp does bswap on the fly. {32,16,15}bpp do it here. */
    669      1.13      ad 		if ((ri->ri_flg & RI_BSWAP) == 0)
    670       1.3      ad 			ri->ri_devcmap[i] = c;
    671       1.4      ad 		else if (ri->ri_depth == 32)
    672       1.3      ad 			ri->ri_devcmap[i] = bswap32(c);
    673       1.4      ad 		else if (ri->ri_depth == 16 || ri->ri_depth == 15)
    674       1.3      ad 			ri->ri_devcmap[i] = bswap16(c);
    675       1.4      ad 		else
    676       1.4      ad 			ri->ri_devcmap[i] = c;
    677       1.1      ad 	}
    678       1.1      ad }
    679       1.1      ad 
    680       1.1      ad /*
    681       1.1      ad  * Unpack a rasops attribute
    682       1.1      ad  */
    683       1.1      ad void
    684       1.1      ad rasops_unpack_attr(attr, fg, bg, underline)
    685       1.1      ad 	long attr;
    686       1.1      ad 	int *fg, *bg, *underline;
    687       1.1      ad {
    688       1.4      ad 
    689  1.19.2.1  bouyer 	*fg = ((u_int)attr >> 24) & 0xf;
    690  1.19.2.1  bouyer 	*bg = ((u_int)attr >> 16) & 0xf;
    691  1.19.2.1  bouyer 	if (underline != NULL)
    692  1.19.2.1  bouyer 		*underline = (u_int)attr & 1;
    693  1.19.2.1  bouyer }
    694       1.4      ad 
    695       1.4      ad /*
    696       1.4      ad  * Erase rows. This isn't static, since 24-bpp uses it in special cases.
    697       1.4      ad  */
    698       1.4      ad void
    699       1.4      ad rasops_eraserows(cookie, row, num, attr)
    700       1.4      ad 	void *cookie;
    701       1.4      ad 	int row, num;
    702       1.4      ad 	long attr;
    703       1.4      ad {
    704       1.4      ad 	struct rasops_info *ri;
    705      1.14      ad 	int np, nw, cnt, delta;
    706       1.4      ad 	int32_t *dp, clr;
    707  1.19.2.1  bouyer 
    708       1.4      ad 	ri = (struct rasops_info *)cookie;
    709       1.4      ad 
    710       1.4      ad #ifdef RASOPS_CLIPPING
    711       1.4      ad 	if (row < 0) {
    712       1.4      ad 		num += row;
    713       1.4      ad 		row = 0;
    714       1.4      ad 	}
    715       1.4      ad 
    716       1.4      ad 	if ((row + num) > ri->ri_rows)
    717       1.4      ad 		num = ri->ri_rows - row;
    718  1.19.2.1  bouyer 
    719       1.4      ad 	if (num <= 0)
    720       1.4      ad 		return;
    721       1.4      ad #endif
    722       1.4      ad 
    723  1.19.2.1  bouyer 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
    724       1.4      ad 
    725  1.19.2.1  bouyer 	/*
    726  1.19.2.1  bouyer 	 * XXX The wsdisplay_emulops interface seems a little deficient in
    727  1.19.2.1  bouyer 	 * that there is no way to clear the *entire* screen. We provide a
    728  1.19.2.1  bouyer 	 * workaround here: if the entire console area is being cleared, and
    729      1.13      ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    730  1.19.2.1  bouyer 	 */
    731      1.13      ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    732      1.13      ad 		np = ri->ri_stride >> 5;
    733      1.13      ad 		nw = (ri->ri_stride >> 2) & 7;
    734      1.13      ad 		num = ri->ri_height;
    735      1.14      ad 		dp = (int32_t *)ri->ri_origbits;
    736      1.14      ad 		delta = 0;
    737      1.13      ad 	} else {
    738      1.13      ad 		np = ri->ri_emustride >> 5;
    739      1.13      ad 		nw = (ri->ri_emustride >> 2) & 7;
    740      1.13      ad 		num *= ri->ri_font->fontheight;
    741      1.14      ad 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    742      1.14      ad 		delta = ri->ri_delta;
    743      1.13      ad 	}
    744  1.19.2.1  bouyer 
    745       1.4      ad 	while (num--) {
    746       1.4      ad 		for (cnt = np; cnt; cnt--) {
    747       1.4      ad 			dp[0] = clr;
    748       1.4      ad 			dp[1] = clr;
    749       1.4      ad 			dp[2] = clr;
    750       1.4      ad 			dp[3] = clr;
    751       1.4      ad 			dp[4] = clr;
    752       1.4      ad 			dp[5] = clr;
    753       1.4      ad 			dp[6] = clr;
    754       1.4      ad 			dp[7] = clr;
    755       1.4      ad 			dp += 8;
    756       1.4      ad 		}
    757  1.19.2.1  bouyer 
    758       1.4      ad 		for (cnt = nw; cnt; cnt--) {
    759       1.4      ad 			*(int32_t *)dp = clr;
    760       1.4      ad 			DELTA(dp, 4, int32_t *);
    761  1.19.2.1  bouyer 		}
    762  1.19.2.1  bouyer 
    763      1.14      ad 		DELTA(dp, delta, int32_t *);
    764       1.4      ad 	}
    765       1.4      ad }
    766       1.4      ad 
    767       1.4      ad /*
    768       1.4      ad  * Actually turn the cursor on or off. This does the dirty work for
    769       1.4      ad  * rasops_cursor().
    770       1.4      ad  */
    771       1.4      ad static void
    772       1.4      ad rasops_do_cursor(ri)
    773       1.4      ad 	struct rasops_info *ri;
    774       1.4      ad {
    775  1.19.2.1  bouyer 	int full1, height, cnt, slop1, slop2, row, col;
    776       1.4      ad 	u_char *dp, *rp;
    777  1.19.2.1  bouyer 
    778       1.4      ad 	row = ri->ri_crow;
    779       1.4      ad 	col = ri->ri_ccol;
    780  1.19.2.1  bouyer 
    781       1.4      ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    782       1.4      ad 	height = ri->ri_font->fontheight;
    783  1.19.2.1  bouyer 	slop1 = (4 - ((long)rp & 3)) & 3;
    784  1.19.2.1  bouyer 
    785       1.4      ad 	if (slop1 > ri->ri_xscale)
    786       1.4      ad 		slop1 = ri->ri_xscale;
    787  1.19.2.1  bouyer 
    788       1.4      ad 	slop2 = (ri->ri_xscale - slop1) & 3;
    789       1.4      ad 	full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
    790  1.19.2.1  bouyer 
    791       1.4      ad 	if ((slop1 | slop2) == 0) {
    792       1.4      ad 		/* A common case */
    793       1.4      ad 		while (height--) {
    794       1.4      ad 			dp = rp;
    795       1.4      ad 			rp += ri->ri_stride;
    796  1.19.2.1  bouyer 
    797       1.4      ad 			for (cnt = full1; cnt; cnt--) {
    798  1.19.2.1  bouyer 				*(int32_t *)dp ^= ~0;
    799       1.4      ad 				dp += 4;
    800       1.4      ad 			}
    801       1.4      ad 		}
    802       1.4      ad 	} else {
    803       1.4      ad 		/* XXX this is stupid.. use masks instead */
    804       1.4      ad 		while (height--) {
    805       1.4      ad 			dp = rp;
    806       1.4      ad 			rp += ri->ri_stride;
    807  1.19.2.1  bouyer 
    808       1.4      ad 			if (slop1 & 1)
    809  1.19.2.1  bouyer 				*dp++ ^= ~0;
    810       1.4      ad 
    811       1.4      ad 			if (slop1 & 2) {
    812  1.19.2.1  bouyer 				*(int16_t *)dp ^= ~0;
    813       1.4      ad 				dp += 2;
    814       1.4      ad 			}
    815  1.19.2.1  bouyer 
    816       1.4      ad 			for (cnt = full1; cnt; cnt--) {
    817  1.19.2.1  bouyer 				*(int32_t *)dp ^= ~0;
    818       1.4      ad 				dp += 4;
    819       1.4      ad 			}
    820       1.4      ad 
    821       1.4      ad 			if (slop2 & 1)
    822  1.19.2.1  bouyer 				*dp++ ^= ~0;
    823       1.4      ad 
    824       1.4      ad 			if (slop2 & 2)
    825  1.19.2.1  bouyer 				*(int16_t *)dp ^= ~0;
    826       1.4      ad 		}
    827       1.4      ad 	}
    828       1.4      ad }
    829       1.4      ad 
    830       1.4      ad /*
    831       1.4      ad  * Erase columns.
    832       1.4      ad  */
    833       1.4      ad void
    834       1.4      ad rasops_erasecols(cookie, row, col, num, attr)
    835       1.4      ad 	void *cookie;
    836       1.4      ad 	int row, col, num;
    837       1.4      ad 	long attr;
    838       1.4      ad {
    839       1.4      ad 	int n8, height, cnt, slop1, slop2, clr;
    840       1.4      ad 	struct rasops_info *ri;
    841       1.4      ad 	int32_t *rp, *dp;
    842  1.19.2.1  bouyer 
    843       1.4      ad 	ri = (struct rasops_info *)cookie;
    844  1.19.2.1  bouyer 
    845  1.19.2.1  bouyer #ifdef RASOPS_CLIPPING
    846       1.4      ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    847       1.4      ad 		return;
    848       1.4      ad 
    849       1.4      ad 	if (col < 0) {
    850       1.4      ad 		num += col;
    851       1.4      ad 		col = 0;
    852       1.4      ad 	}
    853       1.4      ad 
    854       1.4      ad 	if ((col + num) > ri->ri_cols)
    855       1.4      ad 		num = ri->ri_cols - col;
    856  1.19.2.1  bouyer 
    857       1.4      ad 	if (num <= 0)
    858       1.4      ad 		return;
    859       1.4      ad #endif
    860  1.19.2.1  bouyer 
    861       1.4      ad 	num = num * ri->ri_xscale;
    862       1.4      ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    863       1.4      ad 	height = ri->ri_font->fontheight;
    864  1.19.2.1  bouyer 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
    865  1.19.2.1  bouyer 
    866       1.4      ad 	/* Don't bother using the full loop for <= 32 pels */
    867       1.4      ad 	if (num <= 32) {
    868       1.6      ad 		if (((num | ri->ri_xscale) & 3) == 0) {
    869       1.6      ad 			/* Word aligned blt */
    870       1.6      ad 			num >>= 2;
    871       1.6      ad 
    872       1.6      ad 			while (height--) {
    873       1.6      ad 				dp = rp;
    874       1.6      ad 				DELTA(rp, ri->ri_stride, int32_t *);
    875  1.19.2.1  bouyer 
    876       1.6      ad 				for (cnt = num; cnt; cnt--)
    877       1.6      ad 					*dp++ = clr;
    878       1.6      ad 			}
    879       1.6      ad 		} else if (((num | ri->ri_xscale) & 1) == 0) {
    880  1.19.2.1  bouyer 			/*
    881       1.4      ad 			 * Halfword aligned blt. This is needed so the
    882  1.19.2.1  bouyer 			 * 15/16 bit ops can use this function.
    883       1.4      ad 			 */
    884       1.4      ad 			num >>= 1;
    885       1.4      ad 
    886       1.4      ad 			while (height--) {
    887       1.4      ad 				dp = rp;
    888       1.4      ad 				DELTA(rp, ri->ri_stride, int32_t *);
    889       1.4      ad 
    890       1.4      ad 				for (cnt = num; cnt; cnt--) {
    891       1.4      ad 					*(int16_t *)dp = clr;
    892       1.4      ad 					DELTA(dp, 2, int32_t *);
    893       1.4      ad 				}
    894       1.4      ad 			}
    895       1.4      ad 		} else {
    896       1.4      ad 			while (height--) {
    897       1.4      ad 				dp = rp;
    898       1.4      ad 				DELTA(rp, ri->ri_stride, int32_t *);
    899       1.4      ad 
    900       1.4      ad 				for (cnt = num; cnt; cnt--) {
    901       1.4      ad 					*(u_char *)dp = clr;
    902       1.4      ad 					DELTA(dp, 1, int32_t *);
    903       1.4      ad 				}
    904       1.4      ad 			}
    905       1.4      ad 		}
    906  1.19.2.1  bouyer 
    907       1.4      ad 		return;
    908       1.4      ad 	}
    909  1.19.2.1  bouyer 
    910  1.19.2.1  bouyer 	slop1 = (4 - ((long)rp & 3)) & 3;
    911       1.4      ad 	slop2 = (num - slop1) & 3;
    912       1.4      ad 	num -= slop1 + slop2;
    913       1.4      ad 	n8 = num >> 5;
    914       1.4      ad 	num = (num >> 2) & 7;
    915       1.4      ad 
    916       1.4      ad 	while (height--) {
    917       1.4      ad 		dp = rp;
    918       1.4      ad 		DELTA(rp, ri->ri_stride, int32_t *);
    919  1.19.2.1  bouyer 
    920       1.4      ad 		/* Align span to 4 bytes */
    921       1.4      ad 		if (slop1 & 1) {
    922       1.4      ad 			*(u_char *)dp = clr;
    923       1.4      ad 			DELTA(dp, 1, int32_t *);
    924       1.4      ad 		}
    925       1.4      ad 
    926       1.4      ad 		if (slop1 & 2) {
    927       1.4      ad 			*(int16_t *)dp = clr;
    928       1.4      ad 			DELTA(dp, 2, int32_t *);
    929       1.4      ad 		}
    930  1.19.2.1  bouyer 
    931       1.4      ad 		/* Write 32 bytes per loop */
    932       1.4      ad 		for (cnt = n8; cnt; cnt--) {
    933       1.4      ad 			dp[0] = clr;
    934       1.4      ad 			dp[1] = clr;
    935       1.4      ad 			dp[2] = clr;
    936       1.4      ad 			dp[3] = clr;
    937       1.4      ad 			dp[4] = clr;
    938       1.4      ad 			dp[5] = clr;
    939       1.4      ad 			dp[6] = clr;
    940       1.4      ad 			dp[7] = clr;
    941       1.4      ad 			dp += 8;
    942       1.4      ad 		}
    943  1.19.2.1  bouyer 
    944  1.19.2.1  bouyer 		/* Write 4 bytes per loop */
    945       1.4      ad 		for (cnt = num; cnt; cnt--)
    946       1.4      ad 			*dp++ = clr;
    947  1.19.2.1  bouyer 
    948  1.19.2.1  bouyer 		/* Write unaligned trailing slop */
    949       1.4      ad 		if (slop2 & 1) {
    950       1.4      ad 			*(u_char *)dp = clr;
    951       1.4      ad 			DELTA(dp, 1, int32_t *);
    952       1.4      ad 		}
    953       1.4      ad 
    954       1.4      ad 		if (slop2 & 2)
    955       1.4      ad 			*(int16_t *)dp = clr;
    956       1.4      ad 	}
    957       1.1      ad }
    958