Home | History | Annotate | Line # | Download | only in rasops
rasops.c revision 1.55
      1 /*	 $NetBSD: rasops.c,v 1.55 2007/02/02 02:10:24 ober Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.55 2007/02/02 02:10:24 ober Exp $");
     41 
     42 #include "opt_rasops.h"
     43 #include "rasops_glue.h"
     44 #include "opt_wsmsgattrs.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/time.h>
     49 
     50 #include <sys/bswap.h>
     51 #include <machine/endian.h>
     52 
     53 #include <dev/wscons/wsdisplayvar.h>
     54 #include <dev/wscons/wsconsio.h>
     55 #include <dev/wsfont/wsfont.h>
     56 #include <dev/rasops/rasops.h>
     57 
     58 #ifndef _KERNEL
     59 #include <errno.h>
     60 #endif
     61 
     62 /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
     63 const u_char rasops_cmap[256*3] = {
     64 	0x00, 0x00, 0x00, /* black */
     65 	0x7f, 0x00, 0x00, /* red */
     66 	0x00, 0x7f, 0x00, /* green */
     67 	0x7f, 0x7f, 0x00, /* brown */
     68 	0x00, 0x00, 0x7f, /* blue */
     69 	0x7f, 0x00, 0x7f, /* magenta */
     70 	0x00, 0x7f, 0x7f, /* cyan */
     71 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
     72 
     73 	0x7f, 0x7f, 0x7f, /* black */
     74 	0xff, 0x00, 0x00, /* red */
     75 	0x00, 0xff, 0x00, /* green */
     76 	0xff, 0xff, 0x00, /* brown */
     77 	0x00, 0x00, 0xff, /* blue */
     78 	0xff, 0x00, 0xff, /* magenta */
     79 	0x00, 0xff, 0xff, /* cyan */
     80 	0xff, 0xff, 0xff, /* white */
     81 
     82 	/*
     83 	 * For the cursor, we need at least the last (255th)
     84 	 * color to be white. Fill up white completely for
     85 	 * simplicity.
     86 	 */
     87 #define _CMWHITE 0xff, 0xff, 0xff,
     88 #define _CMWHITE16	_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     89 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     90 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     91 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE
     92 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     93 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     94 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 /* but not the last one */
     95 #undef _CMWHITE16
     96 #undef _CMWHITE
     97 
     98 	/*
     99 	 * For the cursor the fg/bg indices are bit inverted, so
    100 	 * provide complimentary colors in the upper 16 entries.
    101 	 */
    102 	0x7f, 0x7f, 0x7f, /* black */
    103 	0xff, 0x00, 0x00, /* red */
    104 	0x00, 0xff, 0x00, /* green */
    105 	0xff, 0xff, 0x00, /* brown */
    106 	0x00, 0x00, 0xff, /* blue */
    107 	0xff, 0x00, 0xff, /* magenta */
    108 	0x00, 0xff, 0xff, /* cyan */
    109 	0xff, 0xff, 0xff, /* white */
    110 
    111 	0x00, 0x00, 0x00, /* black */
    112 	0x7f, 0x00, 0x00, /* red */
    113 	0x00, 0x7f, 0x00, /* green */
    114 	0x7f, 0x7f, 0x00, /* brown */
    115 	0x00, 0x00, 0x7f, /* blue */
    116 	0x7f, 0x00, 0x7f, /* magenta */
    117 	0x00, 0x7f, 0x7f, /* cyan */
    118 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
    119 };
    120 
    121 /* True if color is gray */
    122 const u_char rasops_isgray[16] = {
    123 	1, 0, 0, 0,
    124 	0, 0, 0, 1,
    125 	1, 0, 0, 0,
    126 	0, 0, 0, 1
    127 };
    128 
    129 /* Generic functions */
    130 static void	rasops_copyrows(void *, int, int, int);
    131 static int	rasops_mapchar(void *, int, u_int *);
    132 static void	rasops_cursor(void *, int, int, int);
    133 static int	rasops_allocattr_color(void *, int, int, int, long *);
    134 static int	rasops_allocattr_mono(void *, int, int, int, long *);
    135 static void	rasops_do_cursor(struct rasops_info *);
    136 static void	rasops_init_devcmap(struct rasops_info *);
    137 
    138 #if NRASOPS_ROTATION > 0
    139 static void	rasops_copychar(void *, int, int, int, int);
    140 static void	rasops_copycols_rotated(void *, int, int, int, int);
    141 static void	rasops_copyrows_rotated(void *, int, int, int);
    142 static void	rasops_erasecols_rotated(void *, int, int, int, long);
    143 static void	rasops_eraserows_rotated(void *, int, int, long);
    144 static void	rasops_putchar_rotated(void *, int, int, u_int, long);
    145 static void	rasops_rotate_font(int *);
    146 
    147 /*
    148  * List of all rotated fonts
    149  */
    150 SLIST_HEAD(, rotatedfont) rotatedfonts = SLIST_HEAD_INITIALIZER(rotatedfonts);
    151 struct rotatedfont {
    152 	SLIST_ENTRY(rotatedfont) rf_next;
    153 	int rf_cookie;
    154 	int rf_rotated;
    155 };
    156 #endif	/* NRASOPS_ROTATION > 0 */
    157 
    158 /*
    159  * Initialize a 'rasops_info' descriptor.
    160  */
    161 int
    162 rasops_init(ri, wantrows, wantcols)
    163 	struct rasops_info *ri;
    164 	int wantrows, wantcols;
    165 {
    166 
    167 #ifdef _KERNEL
    168 	/* Select a font if the caller doesn't care */
    169 	if (ri->ri_font == NULL) {
    170 		int cookie;
    171 
    172 		wsfont_init();
    173 
    174 		/* Want 8 pixel wide, don't care about aestethics */
    175 		cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    176 		    WSDISPLAY_FONTORDER_L2R);
    177 		if (cookie <= 0)
    178 			cookie = wsfont_find(NULL, 0, 0, 0,
    179 			    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
    180 
    181 		if (cookie <= 0) {
    182 			printf("rasops_init: font table is empty\n");
    183 			return (-1);
    184 		}
    185 
    186 #if NRASOPS_ROTATION > 0
    187 		/*
    188 		 * Pick the rotated version of this font. This will create it
    189 		 * if necessary.
    190 		 */
    191 		if (ri->ri_flg & RI_ROTATE_CW)
    192 			rasops_rotate_font(&cookie);
    193 #endif
    194 
    195 		if (wsfont_lock(cookie, &ri->ri_font)) {
    196 			printf("rasops_init: couldn't lock font\n");
    197 			return (-1);
    198 		}
    199 
    200 		ri->ri_wsfcookie = cookie;
    201 	}
    202 #endif
    203 
    204 	/* This should never happen in reality... */
    205 #ifdef DEBUG
    206 	if ((long)ri->ri_bits & 3) {
    207 		printf("rasops_init: bits not aligned on 32-bit boundary\n");
    208 		return (-1);
    209 	}
    210 
    211 	if ((int)ri->ri_stride & 3) {
    212 		printf("rasops_init: stride not aligned on 32-bit boundary\n");
    213 		return (-1);
    214 	}
    215 #endif
    216 
    217 	if (rasops_reconfig(ri, wantrows, wantcols))
    218 		return (-1);
    219 
    220 	rasops_init_devcmap(ri);
    221 	return (0);
    222 }
    223 
    224 /*
    225  * Reconfigure (because parameters have changed in some way).
    226  */
    227 int
    228 rasops_reconfig(ri, wantrows, wantcols)
    229 	struct rasops_info *ri;
    230 	int wantrows, wantcols;
    231 {
    232 	int bpp, s;
    233 
    234 	s = splhigh();
    235 
    236 	if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
    237 		panic("rasops_init: fontwidth assumptions botched!");
    238 
    239 	/* Need this to frob the setup below */
    240 	bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
    241 
    242 	if ((ri->ri_flg & RI_CFGDONE) != 0)
    243 		ri->ri_bits = ri->ri_origbits;
    244 
    245 	/* Don't care if the caller wants a hideously small console */
    246 	if (wantrows < 10)
    247 		wantrows = 10;
    248 
    249 	if (wantcols < 20)
    250 		wantcols = 20;
    251 
    252 	/* Now constrain what they get */
    253 	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
    254 	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
    255 
    256 	if (ri->ri_emuwidth > ri->ri_width)
    257 		ri->ri_emuwidth = ri->ri_width;
    258 
    259 	if (ri->ri_emuheight > ri->ri_height)
    260 		ri->ri_emuheight = ri->ri_height;
    261 
    262 	/* Reduce width until aligned on a 32-bit boundary */
    263 	while ((ri->ri_emuwidth * bpp & 31) != 0)
    264 		ri->ri_emuwidth--;
    265 
    266 #if NRASOPS_ROTATION > 0
    267 	if (ri->ri_flg & RI_ROTATE_CW) {
    268 		ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
    269 		ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
    270 	} else
    271 #endif
    272 	{
    273 
    274 		ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
    275 		ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
    276 	}
    277 	ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
    278 	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
    279 	ri->ri_ccol = 0;
    280 	ri->ri_crow = 0;
    281 	ri->ri_pelbytes = bpp >> 3;
    282 
    283 	ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
    284 	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
    285 	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
    286 
    287 #ifdef DEBUG
    288 	if ((ri->ri_delta & 3) != 0)
    289 		panic("rasops_init: ri_delta not aligned on 32-bit boundary");
    290 #endif
    291 	/* Clear the entire display */
    292 	if ((ri->ri_flg & RI_CLEAR) != 0)
    293 		memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    294 
    295 	/* Now centre our window if needs be */
    296 	ri->ri_origbits = ri->ri_bits;
    297 
    298 	if ((ri->ri_flg & RI_CENTER) != 0) {
    299 		ri->ri_bits += (((ri->ri_width * bpp >> 3) -
    300 		    ri->ri_emustride) >> 1) & ~3;
    301 		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    302 		    ri->ri_stride;
    303 
    304 		ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
    305 		   / ri->ri_stride;
    306 		ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
    307 		   % ri->ri_stride) * 8 / bpp);
    308 	} else
    309 		ri->ri_xorigin = ri->ri_yorigin = 0;
    310 
    311 	/*
    312 	 * Fill in defaults for operations set.  XXX this nukes private
    313 	 * routines used by accelerated fb drivers.
    314 	 */
    315 	ri->ri_ops.mapchar = rasops_mapchar;
    316 	ri->ri_ops.copyrows = rasops_copyrows;
    317 	ri->ri_ops.copycols = rasops_copycols;
    318 	ri->ri_ops.erasecols = rasops_erasecols;
    319 	ri->ri_ops.eraserows = rasops_eraserows;
    320 	ri->ri_ops.cursor = rasops_cursor;
    321 	ri->ri_do_cursor = rasops_do_cursor;
    322 
    323 	if (ri->ri_depth < 8 || (ri->ri_flg & RI_FORCEMONO) != 0) {
    324 		ri->ri_ops.allocattr = rasops_allocattr_mono;
    325 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
    326 	} else {
    327 		ri->ri_ops.allocattr = rasops_allocattr_color;
    328 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
    329 		    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    330 	}
    331 
    332 	switch (ri->ri_depth) {
    333 #if NRASOPS1 > 0
    334 	case 1:
    335 		rasops1_init(ri);
    336 		break;
    337 #endif
    338 #if NRASOPS2 > 0
    339 	case 2:
    340 		rasops2_init(ri);
    341 		break;
    342 #endif
    343 #if NRASOPS4 > 0
    344 	case 4:
    345 		rasops4_init(ri);
    346 		break;
    347 #endif
    348 #if NRASOPS8 > 0
    349 	case 8:
    350 		rasops8_init(ri);
    351 		break;
    352 #endif
    353 #if NRASOPS15 > 0 || NRASOPS16 > 0
    354 	case 15:
    355 	case 16:
    356 		rasops15_init(ri);
    357 		break;
    358 #endif
    359 #if NRASOPS24 > 0
    360 	case 24:
    361 		rasops24_init(ri);
    362 		break;
    363 #endif
    364 #if NRASOPS32 > 0
    365 	case 32:
    366 		rasops32_init(ri);
    367 		break;
    368 #endif
    369 	default:
    370 		ri->ri_flg &= ~RI_CFGDONE;
    371 		splx(s);
    372 		return (-1);
    373 	}
    374 
    375 #if NRASOPS_ROTATION > 0
    376 	if (ri->ri_flg & RI_ROTATE_CW) {
    377 		ri->ri_real_ops = ri->ri_ops;
    378 		ri->ri_ops.copycols = rasops_copycols_rotated;
    379 		ri->ri_ops.copyrows = rasops_copyrows_rotated;
    380 		ri->ri_ops.erasecols = rasops_erasecols_rotated;
    381 		ri->ri_ops.eraserows = rasops_eraserows_rotated;
    382 		ri->ri_ops.putchar = rasops_putchar_rotated;
    383 	}
    384 #endif
    385 
    386 	ri->ri_flg |= RI_CFGDONE;
    387 	splx(s);
    388 	return (0);
    389 }
    390 
    391 /*
    392  * Map a character.
    393  */
    394 static int
    395 rasops_mapchar(cookie, c, cp)
    396 	void *cookie;
    397 	int c;
    398 	u_int *cp;
    399 {
    400 	struct rasops_info *ri;
    401 
    402 	ri = (struct rasops_info *)cookie;
    403 
    404 #ifdef DIAGNOSTIC
    405 	if (ri->ri_font == NULL)
    406 		panic("rasops_mapchar: no font selected");
    407 #endif
    408 
    409 	if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) {
    410 		if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
    411 			*cp = ' ';
    412 			return (0);
    413 
    414 		}
    415 	}
    416 
    417 	if (c < ri->ri_font->firstchar) {
    418 		*cp = ' ';
    419 		return (0);
    420 	}
    421 
    422 	if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
    423 		*cp = ' ';
    424 		return (0);
    425 	}
    426 
    427 	*cp = c;
    428 	return (5);
    429 }
    430 
    431 /*
    432  * Allocate a color attribute.
    433  */
    434 static int
    435 rasops_allocattr_color(void *cookie, int fg, int bg, int flg,
    436     long *attr)
    437 {
    438 	int swap;
    439 
    440 #ifdef RASOPS_CLIPPING
    441 	fg &= 7;
    442 	bg &= 7;
    443 #endif
    444 	if ((flg & WSATTR_BLINK) != 0)
    445 		return (EINVAL);
    446 
    447 	if ((flg & WSATTR_WSCOLORS) == 0) {
    448 #ifdef WS_DEFAULT_FG
    449 		fg = WS_DEFAULT_FG;
    450 #else
    451 		fg = WSCOL_WHITE;
    452 #endif
    453 #ifdef WS_DEFAULT_BG
    454 		bg = WS_DEFAULT_BG;
    455 #else
    456 		bg = WSCOL_BLACK;
    457 #endif
    458 	}
    459 
    460 	if ((flg & WSATTR_REVERSE) != 0) {
    461 		swap = fg;
    462 		fg = bg;
    463 		bg = swap;
    464 	}
    465 
    466 	if ((flg & WSATTR_HILIT) != 0)
    467 		fg += 8;
    468 
    469 	flg = ((flg & WSATTR_UNDERLINE) ? 1 : 0);
    470 
    471 	if (rasops_isgray[fg])
    472 		flg |= 2;
    473 
    474 	if (rasops_isgray[bg])
    475 		flg |= 4;
    476 
    477 	*attr = (bg << 16) | (fg << 24) | flg;
    478 	return (0);
    479 }
    480 
    481 /*
    482  * Allocate a mono attribute.
    483  */
    484 static int
    485 rasops_allocattr_mono(void *cookie, int fg, int bg, int flg,
    486     long *attr)
    487 {
    488 	int swap;
    489 
    490 	if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
    491 		return (EINVAL);
    492 
    493 	fg = 1;
    494 	bg = 0;
    495 
    496 	if ((flg & WSATTR_REVERSE) != 0) {
    497 		swap = fg;
    498 		fg = bg;
    499 		bg = swap;
    500 	}
    501 
    502 	*attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
    503 	return (0);
    504 }
    505 
    506 /*
    507  * Copy rows.
    508  */
    509 static void
    510 rasops_copyrows(cookie, src, dst, num)
    511 	void *cookie;
    512 	int src, dst, num;
    513 {
    514 	int32_t *sp, *dp, *hp, *srp, *drp, *hrp;
    515 	struct rasops_info *ri;
    516 	int n8, n1, cnt, delta;
    517 
    518 	ri = (struct rasops_info *)cookie;
    519 	hp = hrp = NULL;
    520 
    521 #ifdef RASOPS_CLIPPING
    522 	if (dst == src)
    523 		return;
    524 
    525 	if (src < 0) {
    526 		num += src;
    527 		src = 0;
    528 	}
    529 
    530 	if ((src + num) > ri->ri_rows)
    531 		num = ri->ri_rows - src;
    532 
    533 	if (dst < 0) {
    534 		num += dst;
    535 		dst = 0;
    536 	}
    537 
    538 	if ((dst + num) > ri->ri_rows)
    539 		num = ri->ri_rows - dst;
    540 
    541 	if (num <= 0)
    542 		return;
    543 #endif
    544 
    545 	num *= ri->ri_font->fontheight;
    546 	n8 = ri->ri_emustride >> 5;
    547 	n1 = (ri->ri_emustride >> 2) & 7;
    548 
    549 	if (dst < src) {
    550 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_yscale);
    551 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_yscale);
    552 		if (ri->ri_hwbits)
    553 			hrp = (int32_t *)(ri->ri_hwbits + dst *
    554 			    ri->ri_yscale);
    555 		delta = ri->ri_stride;
    556 	} else {
    557 		src = ri->ri_font->fontheight * src + num - 1;
    558 		dst = ri->ri_font->fontheight * dst + num - 1;
    559 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_stride);
    560 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_stride);
    561 		if (ri->ri_hwbits)
    562 			hrp = (int32_t *)(ri->ri_hwbits + dst *
    563 			    ri->ri_stride);
    564 
    565 		delta = -ri->ri_stride;
    566 	}
    567 
    568 	while (num--) {
    569 		dp = drp;
    570 		sp = srp;
    571 		if (ri->ri_hwbits)
    572 			hp = hrp;
    573 
    574 		DELTA(drp, delta, int32_t *);
    575 		DELTA(srp, delta, int32_t *);
    576 		if (ri->ri_hwbits)
    577 			DELTA(hrp, delta, int32_t *);
    578 
    579 		for (cnt = n8; cnt; cnt--) {
    580 			dp[0] = sp[0];
    581 			dp[1] = sp[1];
    582 			dp[2] = sp[2];
    583 			dp[3] = sp[3];
    584 			dp[4] = sp[4];
    585 			dp[5] = sp[5];
    586 			dp[6] = sp[6];
    587 			dp[7] = sp[7];
    588 			dp += 8;
    589 			sp += 8;
    590 		}
    591 		if (ri->ri_hwbits) {
    592 			sp -= (8 * n8);
    593 			for (cnt = n8; cnt; cnt--) {
    594 				hp[0] = sp[0];
    595 				hp[1] = sp[1];
    596 				hp[2] = sp[2];
    597 				hp[3] = sp[3];
    598 				hp[4] = sp[4];
    599 				hp[5] = sp[5];
    600 				hp[6] = sp[6];
    601 				hp[7] = sp[7];
    602 				hp += 8;
    603 				sp += 8;
    604 			}
    605 		}
    606 
    607 		for (cnt = n1; cnt; cnt--) {
    608 			*dp++ = *sp++;
    609 			if (ri->ri_hwbits)
    610 				*hp++ = *(sp - 1);
    611 		}
    612 	}
    613 }
    614 
    615 /*
    616  * Copy columns. This is slow, and hard to optimize due to alignment,
    617  * and the fact that we have to copy both left->right and right->left.
    618  * We simply cop-out here and use memmove(), since it handles all of
    619  * these cases anyway.
    620  */
    621 void
    622 rasops_copycols(cookie, row, src, dst, num)
    623 	void *cookie;
    624 	int row, src, dst, num;
    625 {
    626 	struct rasops_info *ri;
    627 	u_char *sp, *dp, *hp;
    628 	int height;
    629 
    630 	ri = (struct rasops_info *)cookie;
    631 	hp = NULL;
    632 
    633 #ifdef RASOPS_CLIPPING
    634 	if (dst == src)
    635 		return;
    636 
    637 	/* Catches < 0 case too */
    638 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    639 		return;
    640 
    641 	if (src < 0) {
    642 		num += src;
    643 		src = 0;
    644 	}
    645 
    646 	if ((src + num) > ri->ri_cols)
    647 		num = ri->ri_cols - src;
    648 
    649 	if (dst < 0) {
    650 		num += dst;
    651 		dst = 0;
    652 	}
    653 
    654 	if ((dst + num) > ri->ri_cols)
    655 		num = ri->ri_cols - dst;
    656 
    657 	if (num <= 0)
    658 		return;
    659 #endif
    660 
    661 	num *= ri->ri_xscale;
    662 	row *= ri->ri_yscale;
    663 	height = ri->ri_font->fontheight;
    664 
    665 	sp = ri->ri_bits + row + src * ri->ri_xscale;
    666 	dp = ri->ri_bits + row + dst * ri->ri_xscale;
    667 	if (ri->ri_hwbits)
    668 		hp = ri->ri_hwbits + row + dst * ri->ri_xscale;
    669 
    670 	while (height--) {
    671 		memmove(dp, sp, num);
    672 		if (ri->ri_hwbits) {
    673 			memcpy(hp, sp, num);
    674 			hp += ri->ri_stride;
    675 		}
    676 		dp += ri->ri_stride;
    677 		sp += ri->ri_stride;
    678 	}
    679 }
    680 
    681 /*
    682  * Turn cursor off/on.
    683  */
    684 static void
    685 rasops_cursor(cookie, on, row, col)
    686 	void *cookie;
    687 	int on, row, col;
    688 {
    689 	struct rasops_info *ri;
    690 
    691 	ri = (struct rasops_info *)cookie;
    692 
    693 	/* Turn old cursor off */
    694 	if ((ri->ri_flg & RI_CURSOR) != 0)
    695 #ifdef RASOPS_CLIPPING
    696 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    697 #endif
    698 			ri->ri_do_cursor(ri);
    699 
    700 	/* Select new cursor */
    701 #ifdef RASOPS_CLIPPING
    702 	ri->ri_flg &= ~RI_CURSORCLIP;
    703 
    704 	if (row < 0 || row >= ri->ri_rows)
    705 		ri->ri_flg |= RI_CURSORCLIP;
    706 	else if (col < 0 || col >= ri->ri_cols)
    707 		ri->ri_flg |= RI_CURSORCLIP;
    708 #endif
    709 	ri->ri_crow = row;
    710 	ri->ri_ccol = col;
    711 
    712 	if (on) {
    713 		ri->ri_flg |= RI_CURSOR;
    714 #ifdef RASOPS_CLIPPING
    715 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    716 #endif
    717 			ri->ri_do_cursor(ri);
    718 	} else
    719 		ri->ri_flg &= ~RI_CURSOR;
    720 }
    721 
    722 /*
    723  * Make the device colormap
    724  */
    725 static void
    726 rasops_init_devcmap(ri)
    727 	struct rasops_info *ri;
    728 {
    729 	const u_char *p;
    730 	int i, c;
    731 
    732 	switch (ri->ri_depth) {
    733 	case 1:
    734 		ri->ri_devcmap[0] = 0;
    735 		for (i = 1; i < 16; i++)
    736 			ri->ri_devcmap[i] = -1;
    737 		return;
    738 
    739 	case 2:
    740 		for (i = 1; i < 15; i++)
    741 			ri->ri_devcmap[i] = 0xaaaaaaaa;
    742 
    743 		ri->ri_devcmap[0] = 0;
    744 		ri->ri_devcmap[8] = 0x55555555;
    745 		ri->ri_devcmap[15] = -1;
    746 		return;
    747 
    748 	case 8:
    749 		for (i = 0; i < 16; i++)
    750 			ri->ri_devcmap[i] = i | (i<<8) | (i<<16) | (i<<24);
    751 		return;
    752 	}
    753 
    754 	p = rasops_cmap;
    755 
    756 	for (i = 0; i < 16; i++) {
    757 		if (ri->ri_rnum <= 8)
    758 			c = (*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
    759 		else
    760 			c = (*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
    761 		p++;
    762 
    763 		if (ri->ri_gnum <= 8)
    764 			c |= (*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
    765 		else
    766 			c |= (*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
    767 		p++;
    768 
    769 		if (ri->ri_bnum <= 8)
    770 			c |= (*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
    771 		else
    772 			c |= (*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
    773 		p++;
    774 
    775 		/* Fill the word for generic routines, which want this */
    776 		if (ri->ri_depth == 24)
    777 			c = c | ((c & 0xff) << 24);
    778 		else if (ri->ri_depth <= 16)
    779 			c = c | (c << 16);
    780 
    781 		/* 24bpp does bswap on the fly. {32,16,15}bpp do it here. */
    782 		if ((ri->ri_flg & RI_BSWAP) == 0)
    783 			ri->ri_devcmap[i] = c;
    784 		else if (ri->ri_depth == 32)
    785 			ri->ri_devcmap[i] = bswap32(c);
    786 		else if (ri->ri_depth == 16 || ri->ri_depth == 15)
    787 			ri->ri_devcmap[i] = bswap16(c);
    788 		else
    789 			ri->ri_devcmap[i] = c;
    790 	}
    791 }
    792 
    793 /*
    794  * Unpack a rasops attribute
    795  */
    796 void
    797 rasops_unpack_attr(attr, fg, bg, underline)
    798 	long attr;
    799 	int *fg, *bg, *underline;
    800 {
    801 
    802 	*fg = ((u_int)attr >> 24) & 0xf;
    803 	*bg = ((u_int)attr >> 16) & 0xf;
    804 	if (underline != NULL)
    805 		*underline = (u_int)attr & 1;
    806 }
    807 
    808 /*
    809  * Erase rows. This isn't static, since 24-bpp uses it in special cases.
    810  */
    811 void
    812 rasops_eraserows(cookie, row, num, attr)
    813 	void *cookie;
    814 	int row, num;
    815 	long attr;
    816 {
    817 	struct rasops_info *ri;
    818 	int np, nw, cnt, delta;
    819 	int32_t *dp, *hp, clr;
    820 	int i;
    821 
    822 	ri = (struct rasops_info *)cookie;
    823 	hp = NULL;
    824 
    825 #ifdef RASOPS_CLIPPING
    826 	if (row < 0) {
    827 		num += row;
    828 		row = 0;
    829 	}
    830 
    831 	if ((row + num) > ri->ri_rows)
    832 		num = ri->ri_rows - row;
    833 
    834 	if (num <= 0)
    835 		return;
    836 #endif
    837 
    838 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
    839 
    840 	/*
    841 	 * XXX The wsdisplay_emulops interface seems a little deficient in
    842 	 * that there is no way to clear the *entire* screen. We provide a
    843 	 * workaround here: if the entire console area is being cleared, and
    844 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    845 	 */
    846 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    847 		np = ri->ri_stride >> 5;
    848 		nw = (ri->ri_stride >> 2) & 7;
    849 		num = ri->ri_height;
    850 		dp = (int32_t *)ri->ri_origbits;
    851 		if (ri->ri_hwbits)
    852 			hp = (int32_t *)ri->ri_hwbits;
    853 		delta = 0;
    854 	} else {
    855 		np = ri->ri_emustride >> 5;
    856 		nw = (ri->ri_emustride >> 2) & 7;
    857 		num *= ri->ri_font->fontheight;
    858 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    859 		if (ri->ri_hwbits)
    860 			hp = (int32_t *)(ri->ri_hwbits + row *
    861 			    ri->ri_yscale);
    862 		delta = ri->ri_delta;
    863 	}
    864 
    865 	while (num--) {
    866 		for (cnt = np; cnt; cnt--) {
    867 			for (i = 0; i < 8; i++) {
    868 				dp[i] = clr;
    869 				if (ri->ri_hwbits)
    870 					hp[i] = clr;
    871 			}
    872 			dp += 8;
    873 			if (ri->ri_hwbits)
    874 				hp += 8;
    875 		}
    876 
    877 		for (cnt = nw; cnt; cnt--) {
    878 			*(int32_t *)dp = clr;
    879 			DELTA(dp, 4, int32_t *);
    880 			if (ri->ri_hwbits) {
    881 				*(int32_t *)hp = clr;
    882 				DELTA(hp, 4, int32_t *);
    883 			}
    884 		}
    885 
    886 		DELTA(dp, delta, int32_t *);
    887 		if (ri->ri_hwbits)
    888 			DELTA(hp, delta, int32_t *);
    889 	}
    890 }
    891 
    892 /*
    893  * Actually turn the cursor on or off. This does the dirty work for
    894  * rasops_cursor().
    895  */
    896 static void
    897 rasops_do_cursor(ri)
    898 	struct rasops_info *ri;
    899 {
    900 	int full1, height, cnt, slop1, slop2, row, col;
    901 	u_char *dp, *rp, *hrp, *hp;
    902 
    903 	hrp = hp = NULL;
    904 
    905 #if NRASOPS_ROTATION > 0
    906 	if (ri->ri_flg & RI_ROTATE_CW) {
    907 		/* Rotate rows/columns */
    908 		row = ri->ri_ccol;
    909 		col = ri->ri_rows - ri->ri_crow - 1;
    910 	} else
    911 #endif
    912 	{
    913 		row = ri->ri_crow;
    914 		col = ri->ri_ccol;
    915 	}
    916 
    917 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    918 	if (ri->ri_hwbits)
    919 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col
    920 		    * ri->ri_xscale;
    921 	height = ri->ri_font->fontheight;
    922 	slop1 = (4 - ((long)rp & 3)) & 3;
    923 
    924 	if (slop1 > ri->ri_xscale)
    925 		slop1 = ri->ri_xscale;
    926 
    927 	slop2 = (ri->ri_xscale - slop1) & 3;
    928 	full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
    929 
    930 	if ((slop1 | slop2) == 0) {
    931 		/* A common case */
    932 		while (height--) {
    933 			dp = rp;
    934 			rp += ri->ri_stride;
    935 			if (ri->ri_hwbits) {
    936 				hp = hrp;
    937 				hrp += ri->ri_stride;
    938 			}
    939 
    940 			for (cnt = full1; cnt; cnt--) {
    941 				*(int32_t *)dp ^= ~0;
    942 				dp += 4;
    943 				if (ri->ri_hwbits) {
    944 					*(int32_t *)hp ^= ~0;
    945 					hp += 4;
    946 				}
    947 			}
    948 		}
    949 	} else {
    950 		/* XXX this is stupid.. use masks instead */
    951 		while (height--) {
    952 			dp = rp;
    953 			rp += ri->ri_stride;
    954 			if (ri->ri_hwbits) {
    955 				hp = hrp;
    956 				hrp += ri->ri_stride;
    957 			}
    958 
    959 			if (slop1 & 1) {
    960 				*dp++ ^= ~0;
    961 				if (ri->ri_hwbits)
    962 					*hp++ ^= ~0;
    963 			}
    964 
    965 			if (slop1 & 2) {
    966 				*(int16_t *)dp ^= ~0;
    967 				dp += 2;
    968 				if (ri->ri_hwbits) {
    969 					*(int16_t *)hp ^= ~0;
    970 					hp += 2;
    971 				}
    972 			}
    973 
    974 			for (cnt = full1; cnt; cnt--) {
    975 				*(int32_t *)dp ^= ~0;
    976 				dp += 4;
    977 				if (ri->ri_hwbits) {
    978 					*(int32_t *)hp ^= ~0;
    979 					hp += 4;
    980 				}
    981 			}
    982 
    983 			if (slop2 & 1) {
    984 				*dp++ ^= ~0;
    985 				if (ri->ri_hwbits)
    986 					*hp++ ^= ~0;
    987 			}
    988 
    989 			if (slop2 & 2) {
    990 				*(int16_t *)dp ^= ~0;
    991 				if (ri->ri_hwbits)
    992 					*(int16_t *)hp ^= ~0;
    993 			}
    994 		}
    995 	}
    996 }
    997 
    998 /*
    999  * Erase columns.
   1000  */
   1001 void
   1002 rasops_erasecols(cookie, row, col, num, attr)
   1003 	void *cookie;
   1004 	int row, col, num;
   1005 	long attr;
   1006 {
   1007 	int n8, height, cnt, slop1, slop2, clr;
   1008 	struct rasops_info *ri;
   1009 	int32_t *rp, *dp, *hrp, *hp;
   1010 	int i;
   1011 
   1012 	ri = (struct rasops_info *)cookie;
   1013 	hrp = hp = NULL;
   1014 
   1015 #ifdef RASOPS_CLIPPING
   1016 	if ((unsigned)row >= (unsigned)ri->ri_rows)
   1017 		return;
   1018 
   1019 	if (col < 0) {
   1020 		num += col;
   1021 		col = 0;
   1022 	}
   1023 
   1024 	if ((col + num) > ri->ri_cols)
   1025 		num = ri->ri_cols - col;
   1026 
   1027 	if (num <= 0)
   1028 		return;
   1029 #endif
   1030 
   1031 	num = num * ri->ri_xscale;
   1032 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
   1033 	if (ri->ri_hwbits)
   1034 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
   1035 		    col*ri->ri_xscale);
   1036 	height = ri->ri_font->fontheight;
   1037 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
   1038 
   1039 	/* Don't bother using the full loop for <= 32 pels */
   1040 	if (num <= 32) {
   1041 		if (((num | ri->ri_xscale) & 3) == 0) {
   1042 			/* Word aligned blt */
   1043 			num >>= 2;
   1044 
   1045 			while (height--) {
   1046 				dp = rp;
   1047 				DELTA(rp, ri->ri_stride, int32_t *);
   1048 				if (ri->ri_hwbits) {
   1049 					hp = hrp;
   1050 					DELTA(hrp, ri->ri_stride, int32_t *);
   1051 				}
   1052 
   1053 				for (cnt = num; cnt; cnt--) {
   1054 					*dp++ = clr;
   1055 					if (ri->ri_hwbits)
   1056 						*hp++ = clr;
   1057 				}
   1058 			}
   1059 		} else if (((num | ri->ri_xscale) & 1) == 0) {
   1060 			/*
   1061 			 * Halfword aligned blt. This is needed so the
   1062 			 * 15/16 bit ops can use this function.
   1063 			 */
   1064 			num >>= 1;
   1065 
   1066 			while (height--) {
   1067 				dp = rp;
   1068 				DELTA(rp, ri->ri_stride, int32_t *);
   1069 				if (ri->ri_hwbits) {
   1070 					hp = hrp;
   1071 					DELTA(hrp, ri->ri_stride, int32_t *);
   1072 				}
   1073 
   1074 				for (cnt = num; cnt; cnt--) {
   1075 					*(int16_t *)dp = clr;
   1076 					DELTA(dp, 2, int32_t *);
   1077 					if (ri->ri_hwbits) {
   1078 						*(int16_t *)hp = clr;
   1079 						DELTA(hp, 2, int32_t *);
   1080 					}
   1081 				}
   1082 			}
   1083 		} else {
   1084 			while (height--) {
   1085 				dp = rp;
   1086 				DELTA(rp, ri->ri_stride, int32_t *);
   1087 				if (ri->ri_hwbits) {
   1088 					hp = hrp;
   1089 					DELTA(hrp, ri->ri_stride, int32_t *);
   1090 				}
   1091 
   1092 				for (cnt = num; cnt; cnt--) {
   1093 					*(u_char *)dp = clr;
   1094 					DELTA(dp, 1, int32_t *);
   1095 					if (ri->ri_hwbits) {
   1096 						*(u_char *)hp = clr;
   1097 						DELTA(hp, 1, int32_t *);
   1098 					}
   1099 				}
   1100 			}
   1101 		}
   1102 
   1103 		return;
   1104 	}
   1105 
   1106 	slop1 = (4 - ((long)rp & 3)) & 3;
   1107 	slop2 = (num - slop1) & 3;
   1108 	num -= slop1 + slop2;
   1109 	n8 = num >> 5;
   1110 	num = (num >> 2) & 7;
   1111 
   1112 	while (height--) {
   1113 		dp = rp;
   1114 		DELTA(rp, ri->ri_stride, int32_t *);
   1115 		if (ri->ri_hwbits) {
   1116 			hp = hrp;
   1117 			DELTA(hrp, ri->ri_stride, int32_t *);
   1118 		}
   1119 
   1120 		/* Align span to 4 bytes */
   1121 		if (slop1 & 1) {
   1122 			*(u_char *)dp = clr;
   1123 			DELTA(dp, 1, int32_t *);
   1124 			if (ri->ri_hwbits) {
   1125 				*(u_char *)hp = clr;
   1126 				DELTA(hp, 1, int32_t *);
   1127 			}
   1128 		}
   1129 
   1130 		if (slop1 & 2) {
   1131 			*(int16_t *)dp = clr;
   1132 			DELTA(dp, 2, int32_t *);
   1133 			if (ri->ri_hwbits) {
   1134 				*(int16_t *)hp = clr;
   1135 				DELTA(hp, 2, int32_t *);
   1136 			}
   1137 		}
   1138 
   1139 		/* Write 32 bytes per loop */
   1140 		for (cnt = n8; cnt; cnt--) {
   1141 			for (i = 0; i < 8; i++) {
   1142 				dp[i] = clr;
   1143 				if (ri->ri_hwbits)
   1144 					hp[i] = clr;
   1145 			}
   1146 			dp += 8;
   1147 			if (ri->ri_hwbits)
   1148 				hp += 8;
   1149 		}
   1150 
   1151 		/* Write 4 bytes per loop */
   1152 		for (cnt = num; cnt; cnt--) {
   1153 			*dp++ = clr;
   1154 			if (ri->ri_hwbits)
   1155 				*hp++ = clr;
   1156 		}
   1157 
   1158 		/* Write unaligned trailing slop */
   1159 		if (slop2 & 1) {
   1160 			*(u_char *)dp = clr;
   1161 			DELTA(dp, 1, int32_t *);
   1162 			if (ri->ri_hwbits) {
   1163 				*(u_char *)hp = clr;
   1164 				DELTA(hp, 1, int32_t *);
   1165 			}
   1166 		}
   1167 
   1168 		if (slop2 & 2) {
   1169 			*(int16_t *)dp = clr;
   1170 			if (ri->ri_hwbits)
   1171 				*(int16_t *)hp = clr;
   1172 		}
   1173 	}
   1174 }
   1175 
   1176 #if NRASOPS_ROTATION > 0
   1177 /*
   1178  * Quarter clockwise rotation routines (originally intended for the
   1179  * built-in Zaurus C3x00 display in 16bpp).
   1180  */
   1181 
   1182 #include <sys/malloc.h>
   1183 
   1184 static void
   1185 rasops_rotate_font(int *cookie)
   1186 {
   1187 	struct rotatedfont *f;
   1188 	int ncookie;
   1189 
   1190 	SLIST_FOREACH(f, &rotatedfonts, rf_next) {
   1191 		if (f->rf_cookie == *cookie) {
   1192 			*cookie = f->rf_rotated;
   1193 			return;
   1194 		}
   1195 	}
   1196 
   1197 	/*
   1198 	 * We did not find a rotated version of this font. Ask the wsfont
   1199 	 * code to compute one for us.
   1200 	 */
   1201 
   1202 	f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
   1203 	if (f == NULL)
   1204 		return;
   1205 
   1206 	if ((ncookie = wsfont_rotate(*cookie)) == -1)
   1207 		return;
   1208 
   1209 	f->rf_cookie = *cookie;
   1210 	f->rf_rotated = ncookie;
   1211 	SLIST_INSERT_HEAD(&rotatedfonts, f, rf_next);
   1212 
   1213 	*cookie = ncookie;
   1214 }
   1215 
   1216 static void
   1217 rasops_copychar(cookie, srcrow, dstrow, srccol, dstcol)
   1218 	void *cookie;
   1219 	int srcrow, dstrow, srccol, dstcol;
   1220 {
   1221 	struct rasops_info *ri;
   1222 	u_char *sp, *dp;
   1223 	int height;
   1224 	int r_srcrow, r_dstrow, r_srccol, r_dstcol;
   1225 
   1226 	ri = (struct rasops_info *)cookie;
   1227 
   1228 	r_srcrow = srccol;
   1229 	r_dstrow = dstcol;
   1230 	r_srccol = ri->ri_rows - srcrow - 1;
   1231 	r_dstcol = ri->ri_rows - dstrow - 1;
   1232 
   1233 	r_srcrow *= ri->ri_yscale;
   1234 	r_dstrow *= ri->ri_yscale;
   1235 	height = ri->ri_font->fontheight;
   1236 
   1237 	sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
   1238 	dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
   1239 
   1240 	while (height--) {
   1241 		memmove(dp, sp, ri->ri_xscale);
   1242 		dp += ri->ri_stride;
   1243 		sp += ri->ri_stride;
   1244 	}
   1245 }
   1246 
   1247 static void
   1248 rasops_putchar_rotated(cookie, row, col, uc, attr)
   1249 	void *cookie;
   1250 	int row, col;
   1251 	u_int uc;
   1252 	long attr;
   1253 {
   1254 	struct rasops_info *ri;
   1255 	u_char *rp;
   1256 	int height;
   1257 
   1258 	ri = (struct rasops_info *)cookie;
   1259 
   1260 	/* Do rotated char sans (side)underline */
   1261 	ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
   1262 	    attr & ~1);
   1263 
   1264 	/* Do rotated underline */
   1265 	rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) *
   1266 	    ri->ri_xscale;
   1267 	height = ri->ri_font->fontheight;
   1268 
   1269 	/* XXX this assumes 16-bit color depth */
   1270 	if ((attr & 1) != 0) {
   1271 		int16_t c = (int16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
   1272 
   1273 		while (height--) {
   1274 			*(int16_t *)rp = c;
   1275 			rp += ri->ri_stride;
   1276 		}
   1277 	}
   1278 }
   1279 
   1280 static void
   1281 rasops_erasecols_rotated(cookie, row, col, num, attr)
   1282 	void *cookie;
   1283 	int row, col, num;
   1284 	long attr;
   1285 {
   1286 	struct rasops_info *ri;
   1287 	int i;
   1288 
   1289 	ri = (struct rasops_info *)cookie;
   1290 
   1291 	for (i = col; i < col + num; i++)
   1292 		ri->ri_ops.putchar(cookie, row, i, ' ', attr);
   1293 }
   1294 
   1295 /* XXX: these could likely be optimised somewhat. */
   1296 static void
   1297 rasops_copyrows_rotated(cookie, src, dst, num)
   1298 	void *cookie;
   1299 	int src, dst, num;
   1300 {
   1301 	struct rasops_info *ri = (struct rasops_info *)cookie;
   1302 	int col, roff;
   1303 
   1304 	if (src > dst)
   1305 		for (roff = 0; roff < num; roff++)
   1306 			for (col = 0; col < ri->ri_cols; col++)
   1307 				rasops_copychar(cookie, src + roff, dst + roff,
   1308 				    col, col);
   1309 	else
   1310 		for (roff = num - 1; roff >= 0; roff--)
   1311 			for (col = 0; col < ri->ri_cols; col++)
   1312 				rasops_copychar(cookie, src + roff, dst + roff,
   1313 				    col, col);
   1314 }
   1315 
   1316 static void
   1317 rasops_copycols_rotated(cookie, row, src, dst, num)
   1318 	void *cookie;
   1319 	int row, src, dst, num;
   1320 {
   1321 	int coff;
   1322 
   1323 	if (src > dst)
   1324 		for (coff = 0; coff < num; coff++)
   1325 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1326 	else
   1327 		for (coff = num - 1; coff >= 0; coff--)
   1328 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1329 }
   1330 
   1331 static void
   1332 rasops_eraserows_rotated(cookie, row, num, attr)
   1333 	void *cookie;
   1334 	int row, num;
   1335 	long attr;
   1336 {
   1337 	struct rasops_info *ri;
   1338 	int col, rn;
   1339 
   1340 	ri = (struct rasops_info *)cookie;
   1341 
   1342 	for (rn = row; rn < row + num; rn++)
   1343 		for (col = 0; col < ri->ri_cols; col++)
   1344 			ri->ri_ops.putchar(cookie, rn, col, ' ', attr);
   1345 }
   1346 #endif	/* NRASOPS_ROTATION */
   1347