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