Home | History | Annotate | Line # | Download | only in rasops
rasops.c revision 1.1
      1  1.1  ad /* $NetBSD: rasops.c,v 1.1 1999/04/13 00:17:58 ad Exp $ */
      2  1.1  ad 
      3  1.1  ad /*-
      4  1.1  ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  ad  * by Andy Doran <ad (at) NetBSD.org>.
      9  1.1  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.1  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.1  ad  *    must display the following acknowledgement:
     20  1.1  ad  *        This product includes software developed by the NetBSD
     21  1.1  ad  *        Foundation, Inc. and its contributors.
     22  1.1  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  ad  *    contributors may be used to endorse or promote products derived
     24  1.1  ad  *    from this software without specific prior written permission.
     25  1.1  ad  *
     26  1.1  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ad  */
     38  1.1  ad #include <sys/cdefs.h>
     39  1.1  ad __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.1 1999/04/13 00:17:58 ad Exp $");
     40  1.1  ad 
     41  1.1  ad #include "opt_rasops.h"
     42  1.1  ad 
     43  1.1  ad #include <sys/types.h>
     44  1.1  ad #include <sys/param.h>
     45  1.1  ad #include <sys/systm.h>
     46  1.1  ad #include <sys/time.h>
     47  1.1  ad 
     48  1.1  ad #include <dev/wscons/wsdisplayvar.h>
     49  1.1  ad #include <dev/wscons/wsconsio.h>
     50  1.1  ad #include <dev/wsfont/wsfont.h>
     51  1.1  ad #include <dev/rasops/rasops.h>
     52  1.1  ad 
     53  1.1  ad /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
     54  1.1  ad u_char rasops_cmap[256*3] = {
     55  1.1  ad 	0x00, 0x00, 0x00, /* black */
     56  1.1  ad 	0x7f, 0x00, 0x00, /* red */
     57  1.1  ad 	0x00, 0x7f, 0x00, /* green */
     58  1.1  ad 	0x7f, 0x7f, 0x00, /* brown */
     59  1.1  ad 	0x00, 0x00, 0x7f, /* blue */
     60  1.1  ad 	0x7f, 0x00, 0x7f, /* magenta */
     61  1.1  ad 	0x00, 0x7f, 0x7f, /* cyan */
     62  1.1  ad 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
     63  1.1  ad 
     64  1.1  ad 	0x7f, 0x7f, 0x7f, /* black */
     65  1.1  ad 	0xff, 0x00, 0x00, /* red */
     66  1.1  ad 	0x00, 0xff, 0x00, /* green */
     67  1.1  ad 	0xff, 0xff, 0x00, /* brown */
     68  1.1  ad 	0x00, 0x00, 0xff, /* blue */
     69  1.1  ad 	0xff, 0x00, 0xff, /* magenta */
     70  1.1  ad 	0x00, 0xff, 0xff, /* cyan */
     71  1.1  ad 	0xff, 0xff, 0xff, /* white */
     72  1.1  ad };
     73  1.1  ad 
     74  1.1  ad /* True if color is gray */
     75  1.1  ad u_char rasops_isgray[16] = {
     76  1.1  ad 	1, 0, 0, 0,
     77  1.1  ad 	0, 0, 0, 1,
     78  1.1  ad 	1, 0, 0, 0,
     79  1.1  ad 	0, 0, 0, 1
     80  1.1  ad };
     81  1.1  ad 
     82  1.1  ad /* Common functions */
     83  1.1  ad static void	rasops_copycols __P((void *, int, int, int, int));
     84  1.1  ad static void	rasops_copyrows __P((void *, int, int, int));
     85  1.1  ad static int	rasops_mapchar __P((void *, int, u_int *));
     86  1.1  ad static void	rasops_cursor __P((void *, int, int, int));
     87  1.1  ad static int	rasops_alloc_cattr __P((void *, int, int, int, long *));
     88  1.1  ad static int	rasops_alloc_mattr __P((void *, int, int, int, long *));
     89  1.1  ad 
     90  1.1  ad /* Per-depth initalization functions */
     91  1.1  ad void	rasops1_init __P((struct rasops_info *));
     92  1.1  ad void	rasops8_init __P((struct rasops_info *));
     93  1.1  ad void	rasops15_init __P((struct rasops_info *));
     94  1.1  ad void	rasops24_init __P((struct rasops_info *));
     95  1.1  ad void	rasops32_init __P((struct rasops_info *));
     96  1.1  ad 
     97  1.1  ad /*
     98  1.1  ad  * Initalize a 'rasops_info' descriptor.
     99  1.1  ad  */
    100  1.1  ad int
    101  1.1  ad rasops_init(ri, wantrows, wantcols, clear, center)
    102  1.1  ad 	struct rasops_info *ri;
    103  1.1  ad 	int wantrows, wantcols, clear, center;
    104  1.1  ad {
    105  1.1  ad 
    106  1.1  ad 	/* Select a font if the caller doesn't care */
    107  1.1  ad 	if (ri->ri_font == NULL) {
    108  1.1  ad 		int cookie;
    109  1.1  ad 
    110  1.1  ad 		wsfont_init();
    111  1.1  ad 
    112  1.1  ad 		/* Want 8 pixel wide, don't care about aestethics */
    113  1.1  ad 		if ((cookie = wsfont_find(NULL, 8, 0, 0)) < 0)
    114  1.1  ad 			cookie = wsfont_find(NULL, 0, 0, 0);
    115  1.1  ad 
    116  1.1  ad 		if (cookie < 0) {
    117  1.1  ad 			printf("rasops_init: font table is empty\n");
    118  1.1  ad 			return (-1);
    119  1.1  ad 		}
    120  1.1  ad 
    121  1.1  ad 		if (wsfont_lock(cookie, &ri->ri_font,
    122  1.1  ad 		    WSFONT_LITTLE, WSFONT_LITTLE) < 0) {
    123  1.1  ad 			printf("rasops_init: couldn't lock font\n");
    124  1.1  ad 			return (-1);
    125  1.1  ad 		}
    126  1.1  ad 	}
    127  1.1  ad 
    128  1.1  ad 	/* This should never happen in reality... */
    129  1.1  ad #ifdef DEBUG
    130  1.1  ad 	if ((int)ri->ri_bits & 3) {
    131  1.1  ad 		printf("rasops_init: bits not aligned on 32-bit boundary\n");
    132  1.1  ad 		return (-1);
    133  1.1  ad 	}
    134  1.1  ad 
    135  1.1  ad 	if ((int)ri->ri_stride & 3) {
    136  1.1  ad 		printf("rasops_init: stride not aligned on 32-bit boundary\n");
    137  1.1  ad 		return (-1);
    138  1.1  ad 	}
    139  1.1  ad 
    140  1.1  ad 	if (ri->ri_font->fontwidth > 32) {
    141  1.1  ad 		printf("rasops_init: fontwidth > 32\n");
    142  1.1  ad 		return (-1);
    143  1.1  ad 	}
    144  1.1  ad #endif
    145  1.1  ad 
    146  1.1  ad 	/* Fix color palette. We need this for the cursor to work. */
    147  1.1  ad 	rasops_cmap[255*3+0] = 0xff;
    148  1.1  ad 	rasops_cmap[255*3+1] = 0xff;
    149  1.1  ad 	rasops_cmap[255*3+2] = 0xff;
    150  1.1  ad 
    151  1.1  ad 	/* Don't care if the caller wants a hideously small console */
    152  1.1  ad 	if (wantrows < 10)
    153  1.1  ad 		wantrows = 5000;
    154  1.1  ad 
    155  1.1  ad 	if (wantcols < 20)
    156  1.1  ad 		wantcols = 5000;
    157  1.1  ad 
    158  1.1  ad 	/* Now constrain what they get */
    159  1.1  ad 	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
    160  1.1  ad 	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
    161  1.1  ad 
    162  1.1  ad 	if (ri->ri_emuwidth > ri->ri_width)
    163  1.1  ad 		ri->ri_emuwidth = ri->ri_width;
    164  1.1  ad 
    165  1.1  ad 	if (ri->ri_emuheight > ri->ri_height)
    166  1.1  ad 		ri->ri_emuheight = ri->ri_height;
    167  1.1  ad 
    168  1.1  ad 	/* Reduce width until aligned on a 32-bit boundary */
    169  1.1  ad 	while ((ri->ri_emuwidth*ri->ri_depth & 31) != 0)
    170  1.1  ad 		ri->ri_emuwidth--;
    171  1.1  ad 
    172  1.1  ad 	ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
    173  1.1  ad 	ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
    174  1.1  ad 	ri->ri_emustride = ri->ri_emuwidth * ri->ri_depth >> 3;
    175  1.1  ad 	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
    176  1.1  ad 	ri->ri_ccol = 0;
    177  1.1  ad 	ri->ri_crow = 0;
    178  1.1  ad 	ri->ri_pelbytes = ri->ri_depth >> 3;
    179  1.1  ad 
    180  1.1  ad 	ri->ri_xscale = (ri->ri_font->fontwidth * ri->ri_depth) >> 3;
    181  1.1  ad 	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
    182  1.1  ad 	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
    183  1.1  ad 
    184  1.1  ad #ifdef DEBUG
    185  1.1  ad 	if (ri->ri_delta & 3)
    186  1.1  ad 		panic("rasops_init: delta isn't aligned on 32-bit boundary!");
    187  1.1  ad #endif
    188  1.1  ad 	/* Clear the entire display */
    189  1.1  ad 	if (clear)
    190  1.1  ad 		bzero(ri->ri_bits, ri->ri_stride * ri->ri_height);
    191  1.1  ad 
    192  1.1  ad 	/* Now centre our window if needs be */
    193  1.1  ad 	ri->ri_origbits = ri->ri_bits;
    194  1.1  ad 
    195  1.1  ad 	if (center) {
    196  1.1  ad 		ri->ri_bits += ((ri->ri_stride - ri->ri_emustride) >> 1) & ~3;
    197  1.1  ad 		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    198  1.1  ad 		    ri->ri_stride;
    199  1.1  ad 	}
    200  1.1  ad 
    201  1.1  ad 	/* Fill in defaults for operations set */
    202  1.1  ad 	ri->ri_ops.mapchar = rasops_mapchar;
    203  1.1  ad 	ri->ri_ops.copyrows = rasops_copyrows;
    204  1.1  ad 	ri->ri_ops.copycols = rasops_copycols;
    205  1.1  ad 	ri->ri_ops.cursor = rasops_cursor;
    206  1.1  ad 
    207  1.1  ad 	if (ri->ri_depth == 1 || ri->ri_forcemono)
    208  1.1  ad 		ri->ri_ops.alloc_attr = rasops_alloc_mattr;
    209  1.1  ad 	else
    210  1.1  ad 		ri->ri_ops.alloc_attr = rasops_alloc_cattr;
    211  1.1  ad 
    212  1.1  ad 	switch (ri->ri_depth) {
    213  1.1  ad #ifdef RASOPS1
    214  1.1  ad 	case 1:
    215  1.1  ad 		rasops1_init(ri);
    216  1.1  ad 		break;
    217  1.1  ad #endif
    218  1.1  ad 
    219  1.1  ad #ifdef RASOPS8
    220  1.1  ad 	case 8:
    221  1.1  ad 		rasops8_init(ri);
    222  1.1  ad 		break;
    223  1.1  ad #endif
    224  1.1  ad 
    225  1.1  ad #if defined(RASOPS15) || defined(RASOPS16)
    226  1.1  ad 	case 15:
    227  1.1  ad 	case 16:
    228  1.1  ad 		rasops15_init(ri);
    229  1.1  ad 		break;
    230  1.1  ad #endif
    231  1.1  ad 
    232  1.1  ad #ifdef RASOPS24
    233  1.1  ad 	case 24:
    234  1.1  ad 		rasops24_init(ri);
    235  1.1  ad 		break;
    236  1.1  ad #endif
    237  1.1  ad 
    238  1.1  ad #ifdef RASOPS24
    239  1.1  ad 	case 32:
    240  1.1  ad 		rasops32_init(ri);
    241  1.1  ad 		break;
    242  1.1  ad #endif
    243  1.1  ad 	default:
    244  1.1  ad 		ri->ri_flg = 0;
    245  1.1  ad 		return (-1);
    246  1.1  ad 	}
    247  1.1  ad 
    248  1.1  ad 	ri->ri_flg = RASOPS_INITTED;
    249  1.1  ad 	return (0);
    250  1.1  ad }
    251  1.1  ad 
    252  1.1  ad 
    253  1.1  ad /*
    254  1.1  ad  * Map a character.
    255  1.1  ad  */
    256  1.1  ad static int
    257  1.1  ad rasops_mapchar(cookie, c, cp)
    258  1.1  ad 	void *cookie;
    259  1.1  ad 	int c;
    260  1.1  ad 	u_int *cp;
    261  1.1  ad {
    262  1.1  ad 	struct rasops_info *ri;
    263  1.1  ad 
    264  1.1  ad 	ri = (struct rasops_info *)cookie;
    265  1.1  ad 
    266  1.1  ad 	if (c < ri->ri_font->firstchar) {
    267  1.1  ad 		*cp = ' ';
    268  1.1  ad 		return (0);
    269  1.1  ad 	}
    270  1.1  ad 
    271  1.1  ad 	if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
    272  1.1  ad 		*cp = ' ';
    273  1.1  ad 		return (0);
    274  1.1  ad 	}
    275  1.1  ad 
    276  1.1  ad 	*cp = c;
    277  1.1  ad 	return (5);
    278  1.1  ad }
    279  1.1  ad 
    280  1.1  ad 
    281  1.1  ad /*
    282  1.1  ad  * Allocate a color attribute.
    283  1.1  ad  */
    284  1.1  ad static int
    285  1.1  ad rasops_alloc_cattr(cookie, fg, bg, flg, attr)
    286  1.1  ad 	void *cookie;
    287  1.1  ad 	int fg, bg, flg;
    288  1.1  ad 	long *attr;
    289  1.1  ad {
    290  1.1  ad 	int swap;
    291  1.1  ad 
    292  1.1  ad #ifdef RASOPS_CLIPPING
    293  1.1  ad 	fg &= 7;
    294  1.1  ad 	bg &= 7;
    295  1.1  ad 	flg &= 255;
    296  1.1  ad #endif
    297  1.1  ad 	if (flg & WSATTR_BLINK)
    298  1.1  ad 		return (EINVAL);
    299  1.1  ad 
    300  1.1  ad 	if (flg & WSATTR_REVERSE) {
    301  1.1  ad 		swap = fg;
    302  1.1  ad 		fg = bg;
    303  1.1  ad 		bg = swap;
    304  1.1  ad 	}
    305  1.1  ad 
    306  1.1  ad 	if (flg & WSATTR_HILIT)
    307  1.1  ad 		fg += 8;
    308  1.1  ad 
    309  1.1  ad 	flg = ((flg & WSATTR_UNDERLINE) ? 1 : 0);
    310  1.1  ad 
    311  1.1  ad 	if (rasops_isgray[fg])
    312  1.1  ad 		flg |= 2;
    313  1.1  ad 
    314  1.1  ad 	if (rasops_isgray[bg])
    315  1.1  ad 		flg |= 4;
    316  1.1  ad 
    317  1.1  ad 	*attr = (bg << 16) | (fg << 24) | flg;
    318  1.1  ad 	return 0;
    319  1.1  ad }
    320  1.1  ad 
    321  1.1  ad 
    322  1.1  ad /*
    323  1.1  ad  * Allocate a mono attribute.
    324  1.1  ad  */
    325  1.1  ad static int
    326  1.1  ad rasops_alloc_mattr(cookie, fg, bg, flg, attr)
    327  1.1  ad 	void *cookie;
    328  1.1  ad 	int fg, bg, flg;
    329  1.1  ad 	long *attr;
    330  1.1  ad {
    331  1.1  ad 	int swap;
    332  1.1  ad 
    333  1.1  ad #ifdef RASOPS_CLIPPING
    334  1.1  ad 	flg &= 255;
    335  1.1  ad #endif
    336  1.1  ad 	fg = fg ? 1 : 0;
    337  1.1  ad 	bg = bg ? 1 : 0;
    338  1.1  ad 
    339  1.1  ad 	if (flg & WSATTR_BLINK)
    340  1.1  ad 		return (EINVAL);
    341  1.1  ad 
    342  1.1  ad 	if (!(flg & WSATTR_REVERSE) ^ !(flg & WSATTR_HILIT)) {
    343  1.1  ad 		swap = fg;
    344  1.1  ad 		fg = bg;
    345  1.1  ad 		bg = swap;
    346  1.1  ad 	}
    347  1.1  ad 
    348  1.1  ad 	*attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
    349  1.1  ad 	return 0;
    350  1.1  ad }
    351  1.1  ad 
    352  1.1  ad 
    353  1.1  ad /*
    354  1.1  ad  * Copy rows.
    355  1.1  ad  */
    356  1.1  ad static void
    357  1.1  ad rasops_copyrows(cookie, src, dst, num)
    358  1.1  ad 	void *cookie;
    359  1.1  ad 	int src, dst, num;
    360  1.1  ad {
    361  1.1  ad 	struct rasops_info *ri;
    362  1.1  ad 	int32_t *sp, *dp, *srp, *drp;
    363  1.1  ad 	int n8, n1, cnt;
    364  1.1  ad 
    365  1.1  ad 	ri = (struct rasops_info *)cookie;
    366  1.1  ad 
    367  1.1  ad #ifdef RASOPS_CLIPPING
    368  1.1  ad 	if (dst == src)
    369  1.1  ad 		return;
    370  1.1  ad 
    371  1.1  ad 	if (src < 0) {
    372  1.1  ad 		num += src;
    373  1.1  ad 		src = 0;
    374  1.1  ad 	}
    375  1.1  ad 
    376  1.1  ad 	if ((src + num) > ri->ri_rows)
    377  1.1  ad 		num = ri->ri_rows - src;
    378  1.1  ad 
    379  1.1  ad 	if (dst < 0) {
    380  1.1  ad 		num += dst;
    381  1.1  ad 		dst = 0;
    382  1.1  ad 	}
    383  1.1  ad 
    384  1.1  ad 	if ((dst + num) > ri->ri_rows)
    385  1.1  ad 		num = ri->ri_rows - dst;
    386  1.1  ad 
    387  1.1  ad 	if (num <= 0)
    388  1.1  ad 		return;
    389  1.1  ad #endif
    390  1.1  ad 
    391  1.1  ad 	num *= ri->ri_font->fontheight;
    392  1.1  ad 	n8 = ri->ri_emustride >> 5;
    393  1.1  ad 	n1 = (ri->ri_emustride >> 2) & 7;
    394  1.1  ad 
    395  1.1  ad 	if (dst < src) {
    396  1.1  ad 		sp = (int32_t *)(ri->ri_bits + src * ri->ri_yscale);
    397  1.1  ad 		dp = (int32_t *)(ri->ri_bits + dst * ri->ri_yscale);
    398  1.1  ad 
    399  1.1  ad 		while (num--) {
    400  1.1  ad 			for (cnt = n8; cnt; cnt--) {
    401  1.1  ad 				dp[0] = sp[0];
    402  1.1  ad 				dp[1] = sp[1];
    403  1.1  ad 				dp[2] = sp[2];
    404  1.1  ad 				dp[3] = sp[3];
    405  1.1  ad 				dp[4] = sp[4];
    406  1.1  ad 				dp[5] = sp[5];
    407  1.1  ad 				dp[6] = sp[6];
    408  1.1  ad 				dp[7] = sp[7];
    409  1.1  ad 				dp += 8;
    410  1.1  ad 				sp += 8;
    411  1.1  ad 			}
    412  1.1  ad 
    413  1.1  ad 			for (cnt = n1; cnt; cnt--)
    414  1.1  ad 				*dp++ = *sp++;
    415  1.1  ad 
    416  1.1  ad 			DELTA(dp, ri->ri_delta, int32_t *);
    417  1.1  ad 			DELTA(sp, ri->ri_delta, int32_t *);
    418  1.1  ad 		}
    419  1.1  ad 	} else {
    420  1.1  ad 		src = ri->ri_font->fontheight * src + num - 1;
    421  1.1  ad 		dst = ri->ri_font->fontheight * dst + num - 1;
    422  1.1  ad 
    423  1.1  ad 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_stride);
    424  1.1  ad 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_stride);
    425  1.1  ad 
    426  1.1  ad 		while (num--) {
    427  1.1  ad 			dp = drp;
    428  1.1  ad 			sp = srp;
    429  1.1  ad 			DELTA(srp, -ri->ri_stride, int32_t *);
    430  1.1  ad 			DELTA(drp, -ri->ri_stride, int32_t *);
    431  1.1  ad 
    432  1.1  ad 			for (cnt = n8; cnt; cnt--) {
    433  1.1  ad 				dp[0] = sp[0];
    434  1.1  ad 				dp[1] = sp[1];
    435  1.1  ad 				dp[2] = sp[2];
    436  1.1  ad 				dp[3] = sp[3];
    437  1.1  ad 				dp[4] = sp[4];
    438  1.1  ad 				dp[5] = sp[5];
    439  1.1  ad 				dp[6] = sp[6];
    440  1.1  ad 				dp[7] = sp[7];
    441  1.1  ad 				dp += 8;
    442  1.1  ad 				sp += 8;
    443  1.1  ad 			}
    444  1.1  ad 
    445  1.1  ad 			for (cnt = n1; cnt; cnt--)
    446  1.1  ad 				*dp++ = *sp++;
    447  1.1  ad 		}
    448  1.1  ad 	}
    449  1.1  ad }
    450  1.1  ad 
    451  1.1  ad 
    452  1.1  ad /*
    453  1.1  ad  * Copy columns. This is slow, and hard to optimize due to alignment,
    454  1.1  ad  * and the fact that we have to copy both left->right and right->left.
    455  1.1  ad  * We simply cop-out here and use bcopy(), since it handles all of
    456  1.1  ad  * these cases anyway.
    457  1.1  ad  */
    458  1.1  ad static void
    459  1.1  ad rasops_copycols(cookie, row, src, dst, num)
    460  1.1  ad 	void *cookie;
    461  1.1  ad 	int row, src, dst, num;
    462  1.1  ad {
    463  1.1  ad 	struct rasops_info *ri;
    464  1.1  ad 	u_char *sp, *dp;
    465  1.1  ad 	int height;
    466  1.1  ad 
    467  1.1  ad 	ri = (struct rasops_info *)cookie;
    468  1.1  ad 
    469  1.1  ad #ifdef RASOPS_CLIPPING
    470  1.1  ad 	if (dst == src)
    471  1.1  ad 		return;
    472  1.1  ad 
    473  1.1  ad 	if (row < 0 || row >= ri->ri_rows)
    474  1.1  ad 		return;
    475  1.1  ad 
    476  1.1  ad 	if (src < 0) {
    477  1.1  ad 		num += src;
    478  1.1  ad 		src = 0;
    479  1.1  ad 	}
    480  1.1  ad 
    481  1.1  ad 	if ((src + num) > ri->ri_cols)
    482  1.1  ad 		num = ri->ri_cols - src;
    483  1.1  ad 
    484  1.1  ad 	if (dst < 0) {
    485  1.1  ad 		num += dst;
    486  1.1  ad 		dst = 0;
    487  1.1  ad 	}
    488  1.1  ad 
    489  1.1  ad 	if ((dst + num) > ri->ri_cols)
    490  1.1  ad 		num = ri->ri_cols - dst;
    491  1.1  ad 
    492  1.1  ad 	if (num <= 0)
    493  1.1  ad 		return;
    494  1.1  ad #endif
    495  1.1  ad 
    496  1.1  ad 	num *= ri->ri_xscale;
    497  1.1  ad 	row *= ri->ri_yscale;
    498  1.1  ad 	height = ri->ri_font->fontheight;
    499  1.1  ad 
    500  1.1  ad 	sp = ri->ri_bits + row + src * ri->ri_xscale;
    501  1.1  ad 	dp = ri->ri_bits + row + dst * ri->ri_xscale;
    502  1.1  ad 
    503  1.1  ad 	while (height--) {
    504  1.1  ad 		bcopy(sp, dp, num);
    505  1.1  ad 		dp += ri->ri_stride;
    506  1.1  ad 		sp += ri->ri_stride;
    507  1.1  ad 	}
    508  1.1  ad }
    509  1.1  ad 
    510  1.1  ad 
    511  1.1  ad /*
    512  1.1  ad  * Turn cursor off/on.
    513  1.1  ad  */
    514  1.1  ad static void
    515  1.1  ad rasops_cursor(cookie, on, row, col)
    516  1.1  ad 	void *cookie;
    517  1.1  ad 	int on, row, col;
    518  1.1  ad {
    519  1.1  ad 	struct rasops_info *ri;
    520  1.1  ad 
    521  1.1  ad 	ri = (struct rasops_info *)cookie;
    522  1.1  ad 
    523  1.1  ad 	/* Turn old cursor off */
    524  1.1  ad 	if (ri->ri_flg & RASOPS_CURSOR)
    525  1.1  ad #ifdef RASOPS_CLIPPING
    526  1.1  ad 		if (!(ri->ri_flg & RASOPS_CURSOR_CLIPPED))
    527  1.1  ad #endif
    528  1.1  ad 			ri->ri_do_cursor(ri);
    529  1.1  ad 
    530  1.1  ad 	/* Select new cursor */
    531  1.1  ad #ifdef RASOPS_CLIPPING
    532  1.1  ad 	ri->ri_flg &= ~RASOPS_CURSOR_CLIPPED;
    533  1.1  ad 
    534  1.1  ad 	if (row < 0 || row >= ri->ri_rows)
    535  1.1  ad 		ri->ri_flg |= RASOPS_CURSOR_CLIPPED;
    536  1.1  ad 	else if (col < 0 || col >= ri->ri_cols)
    537  1.1  ad 		ri->ri_flg |= RASOPS_CURSOR_CLIPPED;
    538  1.1  ad #endif
    539  1.1  ad 	ri->ri_crow = row;
    540  1.1  ad 	ri->ri_ccol = col;
    541  1.1  ad 
    542  1.1  ad 	if (on) {
    543  1.1  ad 		ri->ri_flg |= RASOPS_CURSOR;
    544  1.1  ad #ifdef RASOPS_CLIPPING
    545  1.1  ad 		if (!(ri->ri_flg & RASOPS_CURSOR_CLIPPED))
    546  1.1  ad #endif
    547  1.1  ad 			ri->ri_do_cursor(ri);
    548  1.1  ad 	} else
    549  1.1  ad 		ri->ri_flg &= ~RASOPS_CURSOR;
    550  1.1  ad }
    551  1.1  ad 
    552  1.1  ad 
    553  1.1  ad #if (RASOPS15 + RASOPS16 + RASOPS32)
    554  1.1  ad /*
    555  1.1  ad  * Make the device colormap
    556  1.1  ad  */
    557  1.1  ad void
    558  1.1  ad rasops_init_devcmap(ri)
    559  1.1  ad 	struct rasops_info *ri;
    560  1.1  ad {
    561  1.1  ad 	int i, c;
    562  1.1  ad 	u_char *p;
    563  1.1  ad 
    564  1.1  ad 	p = rasops_cmap;
    565  1.1  ad 
    566  1.1  ad 	for (i = 0; i < 16; i++) {
    567  1.1  ad 		if (ri->ri_rnum <= 8)
    568  1.1  ad 			c = (*p++ >> (8 - ri->ri_rnum)) << ri->ri_rpos;
    569  1.1  ad 		else
    570  1.1  ad 			c = (*p++ << (ri->ri_rnum - 8)) << ri->ri_rpos;
    571  1.1  ad 
    572  1.1  ad 		if (ri->ri_gnum <= 8)
    573  1.1  ad 			c = (*p++ >> (8 - ri->ri_gnum)) << ri->ri_gpos;
    574  1.1  ad 		else
    575  1.1  ad 			c = (*p++ << (ri->ri_gnum - 8)) << ri->ri_gpos;
    576  1.1  ad 
    577  1.1  ad 		if (ri->ri_bnum <= 8)
    578  1.1  ad 			c = (*p++ >> (8 - ri->ri_bnum)) << ri->ri_bpos;
    579  1.1  ad 		else
    580  1.1  ad 			c = (*p++ << (ri->ri_bnum - 8)) << ri->ri_bpos;
    581  1.1  ad 
    582  1.1  ad 		ri->ri_devcmap[i] = c;
    583  1.1  ad 	}
    584  1.1  ad }
    585  1.1  ad #endif
    586  1.1  ad 
    587  1.1  ad 
    588  1.1  ad /*
    589  1.1  ad  * Unpack a rasops attribute
    590  1.1  ad  */
    591  1.1  ad void
    592  1.1  ad rasops_unpack_attr(attr, fg, bg, underline)
    593  1.1  ad 	long attr;
    594  1.1  ad 	int *fg, *bg, *underline;
    595  1.1  ad {
    596  1.1  ad 
    597  1.1  ad 	*fg = ((u_int)attr >> 24) & 15;
    598  1.1  ad 	*bg = ((u_int)attr >> 16) & 15;
    599  1.1  ad 	*underline = (u_int)attr & 1;
    600  1.1  ad }
    601