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