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