Home | History | Annotate | Line # | Download | only in rasops
rasops.c revision 1.85
      1  1.85       rin /*	 $NetBSD: rasops.c,v 1.85 2019/07/24 19:31:12 rin Exp $	*/
      2   1.1        ad 
      3   1.9        ad /*-
      4   1.9        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1        ad  * All rights reserved.
      6   1.1        ad  *
      7   1.9        ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.32        ad  * by Andrew Doran.
      9   1.9        ad  *
     10   1.1        ad  * Redistribution and use in source and binary forms, with or without
     11   1.1        ad  * modification, are permitted provided that the following conditions
     12   1.1        ad  * are met:
     13   1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14   1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15   1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        ad  *    documentation and/or other materials provided with the distribution.
     18   1.1        ad  *
     19   1.9        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.9        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.9        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.9        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.9        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.9        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.9        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.9        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.9        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.9        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.9        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        ad  */
     31   1.2        ad 
     32   1.1        ad #include <sys/cdefs.h>
     33  1.85       rin __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.85 2019/07/24 19:31:12 rin Exp $");
     34   1.1        ad 
     35  1.18        ad #include "opt_rasops.h"
     36   1.4        ad #include "rasops_glue.h"
     37  1.47  macallan #include "opt_wsmsgattrs.h"
     38   1.1        ad 
     39   1.1        ad #include <sys/param.h>
     40   1.1        ad #include <sys/systm.h>
     41   1.1        ad #include <sys/time.h>
     42  1.63  macallan #include <sys/kmem.h>
     43   1.1        ad 
     44  1.50       dsl #include <sys/bswap.h>
     45   1.4        ad #include <machine/endian.h>
     46   1.3        ad 
     47   1.1        ad #include <dev/wscons/wsdisplayvar.h>
     48   1.1        ad #include <dev/wscons/wsconsio.h>
     49   1.1        ad #include <dev/wsfont/wsfont.h>
     50   1.1        ad #include <dev/rasops/rasops.h>
     51   1.1        ad 
     52  1.11        ad #ifndef _KERNEL
     53  1.11        ad #include <errno.h>
     54  1.11        ad #endif
     55  1.11        ad 
     56  1.70  macallan #ifdef RASOPS_DEBUG
     57  1.70  macallan #define DPRINTF aprint_error
     58  1.70  macallan #else
     59  1.70  macallan #define DPRINTF while (0) printf
     60  1.70  macallan #endif
     61  1.70  macallan 
     62  1.70  macallan struct rasops_matchdata {
     63  1.70  macallan 	struct rasops_info *ri;
     64  1.70  macallan 	int wantcols, wantrows;
     65  1.70  macallan 	int bestscore;
     66  1.70  macallan 	struct wsdisplay_font *pick;
     67  1.70  macallan 	int ident;
     68  1.70  macallan };
     69  1.70  macallan 
     70   1.1        ad /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
     71  1.81       rin const uint8_t rasops_cmap[256*3] = {
     72   1.1        ad 	0x00, 0x00, 0x00, /* black */
     73   1.1        ad 	0x7f, 0x00, 0x00, /* red */
     74   1.1        ad 	0x00, 0x7f, 0x00, /* green */
     75   1.1        ad 	0x7f, 0x7f, 0x00, /* brown */
     76   1.1        ad 	0x00, 0x00, 0x7f, /* blue */
     77   1.1        ad 	0x7f, 0x00, 0x7f, /* magenta */
     78   1.1        ad 	0x00, 0x7f, 0x7f, /* cyan */
     79   1.1        ad 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
     80   1.1        ad 
     81   1.1        ad 	0x7f, 0x7f, 0x7f, /* black */
     82   1.1        ad 	0xff, 0x00, 0x00, /* red */
     83   1.1        ad 	0x00, 0xff, 0x00, /* green */
     84   1.1        ad 	0xff, 0xff, 0x00, /* brown */
     85   1.1        ad 	0x00, 0x00, 0xff, /* blue */
     86   1.1        ad 	0xff, 0x00, 0xff, /* magenta */
     87   1.1        ad 	0x00, 0xff, 0xff, /* cyan */
     88   1.1        ad 	0xff, 0xff, 0xff, /* white */
     89  1.23  drochner 
     90  1.23  drochner 	/*
     91  1.23  drochner 	 * For the cursor, we need at least the last (255th)
     92  1.23  drochner 	 * color to be white. Fill up white completely for
     93  1.23  drochner 	 * simplicity.
     94  1.23  drochner 	 */
     95  1.23  drochner #define _CMWHITE 0xff, 0xff, 0xff,
     96  1.23  drochner #define _CMWHITE16	_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     97  1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     98  1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     99  1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE
    100  1.23  drochner 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
    101  1.23  drochner 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
    102  1.44       uwe 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 /* but not the last one */
    103  1.23  drochner #undef _CMWHITE16
    104  1.23  drochner #undef _CMWHITE
    105  1.44       uwe 
    106  1.44       uwe 	/*
    107  1.44       uwe 	 * For the cursor the fg/bg indices are bit inverted, so
    108  1.44       uwe 	 * provide complimentary colors in the upper 16 entries.
    109  1.44       uwe 	 */
    110  1.44       uwe 	0x7f, 0x7f, 0x7f, /* black */
    111  1.44       uwe 	0xff, 0x00, 0x00, /* red */
    112  1.44       uwe 	0x00, 0xff, 0x00, /* green */
    113  1.44       uwe 	0xff, 0xff, 0x00, /* brown */
    114  1.44       uwe 	0x00, 0x00, 0xff, /* blue */
    115  1.44       uwe 	0xff, 0x00, 0xff, /* magenta */
    116  1.44       uwe 	0x00, 0xff, 0xff, /* cyan */
    117  1.44       uwe 	0xff, 0xff, 0xff, /* white */
    118  1.44       uwe 
    119  1.44       uwe 	0x00, 0x00, 0x00, /* black */
    120  1.44       uwe 	0x7f, 0x00, 0x00, /* red */
    121  1.44       uwe 	0x00, 0x7f, 0x00, /* green */
    122  1.44       uwe 	0x7f, 0x7f, 0x00, /* brown */
    123  1.44       uwe 	0x00, 0x00, 0x7f, /* blue */
    124  1.44       uwe 	0x7f, 0x00, 0x7f, /* magenta */
    125  1.44       uwe 	0x00, 0x7f, 0x7f, /* cyan */
    126  1.44       uwe 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
    127   1.1        ad };
    128   1.1        ad 
    129   1.1        ad /* True if color is gray */
    130  1.81       rin const uint8_t rasops_isgray[16] = {
    131  1.30        pk 	1, 0, 0, 0,
    132   1.1        ad 	0, 0, 0, 1,
    133   1.1        ad 	1, 0, 0, 0,
    134   1.1        ad 	0, 0, 0, 1
    135   1.1        ad };
    136   1.1        ad 
    137  1.85       rin #ifdef GENFB_MAC68K
    138  1.85       rin static const uint8_t apple_devcmap[16] = {
    139  1.85       rin 	0xff,	/* black	0x00, 0x00, 0x00 */
    140  1.85       rin 	0x6b,	/* red		0x99, 0x00, 0x00 */
    141  1.85       rin 	0xc5,	/* green	0x00, 0x99, 0x00 */
    142  1.85       rin 	0x59,	/* yellow	0x99, 0x99, 0x00 */
    143  1.85       rin 	0xd4,	/* blue		0x00, 0x00, 0x99 */
    144  1.85       rin 	0x68,	/* magenta	0x99, 0x00, 0x99 */
    145  1.85       rin 	0xc2,	/* cyan		0x00, 0x99, 0x99 */
    146  1.85       rin 	0x2b,	/* white	0xcc, 0xcc, 0xcc */
    147  1.85       rin 
    148  1.85       rin 	0x56,	/* black	0x99, 0x99, 0x99 */
    149  1.85       rin 	0x23,	/* red		0xff, 0x00, 0x00 */
    150  1.85       rin 	0xb9,	/* green	0x00, 0xff, 0x00 */
    151  1.85       rin 	0x05,	/* yellow	0xff, 0xff, 0x00 */
    152  1.85       rin 	0xd2,	/* blue		0x00, 0x00, 0xff */
    153  1.85       rin 	0x1e,	/* magenta	0xff, 0x00, 0xff */
    154  1.85       rin 	0xb4,	/* cyan		0x00, 0xff, 0xff */
    155  1.85       rin 	0x00,	/* white	0xff, 0xff, 0xff */
    156  1.85       rin };
    157  1.85       rin #endif
    158  1.85       rin 
    159   1.4        ad /* Generic functions */
    160  1.45     perry static void	rasops_copyrows(void *, int, int, int);
    161  1.45     perry static int	rasops_mapchar(void *, int, u_int *);
    162  1.45     perry static void	rasops_cursor(void *, int, int, int);
    163  1.45     perry static int	rasops_allocattr_color(void *, int, int, int, long *);
    164  1.45     perry static int	rasops_allocattr_mono(void *, int, int, int, long *);
    165  1.45     perry static void	rasops_do_cursor(struct rasops_info *);
    166  1.45     perry static void	rasops_init_devcmap(struct rasops_info *);
    167   1.1        ad 
    168  1.55      ober #if NRASOPS_ROTATION > 0
    169  1.62    nonaka static void	rasops_rotate_font(int *, int);
    170  1.55      ober static void	rasops_copychar(void *, int, int, int, int);
    171  1.62    nonaka 
    172  1.62    nonaka /* rotate clockwise */
    173  1.62    nonaka static void	rasops_copycols_rotated_cw(void *, int, int, int, int);
    174  1.62    nonaka static void	rasops_copyrows_rotated_cw(void *, int, int, int);
    175  1.62    nonaka static void	rasops_erasecols_rotated_cw(void *, int, int, int, long);
    176  1.62    nonaka static void	rasops_eraserows_rotated_cw(void *, int, int, long);
    177  1.62    nonaka static void	rasops_putchar_rotated_cw(void *, int, int, u_int, long);
    178  1.62    nonaka 
    179  1.62    nonaka /* rotate counter-clockwise */
    180  1.62    nonaka static void	rasops_copychar_ccw(void *, int, int, int, int);
    181  1.62    nonaka static void	rasops_copycols_rotated_ccw(void *, int, int, int, int);
    182  1.62    nonaka static void	rasops_copyrows_rotated_ccw(void *, int, int, int);
    183  1.62    nonaka #define rasops_erasecols_rotated_ccw rasops_erasecols_rotated_cw
    184  1.62    nonaka #define rasops_eraserows_rotated_ccw rasops_eraserows_rotated_cw
    185  1.62    nonaka static void	rasops_putchar_rotated_ccw(void *, int, int, u_int, long);
    186  1.55      ober 
    187  1.55      ober /*
    188  1.55      ober  * List of all rotated fonts
    189  1.55      ober  */
    190  1.55      ober SLIST_HEAD(, rotatedfont) rotatedfonts = SLIST_HEAD_INITIALIZER(rotatedfonts);
    191  1.55      ober struct rotatedfont {
    192  1.55      ober 	SLIST_ENTRY(rotatedfont) rf_next;
    193  1.55      ober 	int rf_cookie;
    194  1.55      ober 	int rf_rotated;
    195  1.55      ober };
    196  1.55      ober #endif	/* NRASOPS_ROTATION > 0 */
    197  1.55      ober 
    198  1.63  macallan void	rasops_make_box_chars_8(struct rasops_info *);
    199  1.63  macallan void	rasops_make_box_chars_16(struct rasops_info *);
    200  1.63  macallan void	rasops_make_box_chars_32(struct rasops_info *);
    201  1.67  macallan void	rasops_make_box_chars_alpha(struct rasops_info *);
    202  1.63  macallan 
    203  1.64  macallan extern int cold;
    204  1.64  macallan 
    205   1.1        ad /*
    206  1.37       wiz  * Initialize a 'rasops_info' descriptor.
    207   1.1        ad  */
    208   1.1        ad int
    209  1.60       dsl rasops_init(struct rasops_info *ri, int wantrows, int wantcols)
    210   1.1        ad {
    211  1.20        ad 
    212  1.63  macallan 	memset (&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
    213  1.30        pk #ifdef _KERNEL
    214   1.1        ad 	/* Select a font if the caller doesn't care */
    215   1.1        ad 	if (ri->ri_font == NULL) {
    216  1.67  macallan 		int cookie = -1;
    217  1.73   mlelstv 		int flags;
    218  1.30        pk 
    219   1.1        ad 		wsfont_init();
    220   1.1        ad 
    221  1.70  macallan 		/*
    222  1.70  macallan 		 * first, try to find something that's as close as possible
    223  1.70  macallan 		 * to the caller's requested terminal size
    224  1.70  macallan 		 */
    225  1.70  macallan 		if (wantrows == 0)
    226  1.70  macallan 			wantrows = RASOPS_DEFAULT_HEIGHT;
    227  1.70  macallan 		if (wantcols == 0)
    228  1.70  macallan 			wantcols = RASOPS_DEFAULT_WIDTH;
    229  1.73   mlelstv 
    230  1.73   mlelstv 		flags = WSFONT_FIND_BESTWIDTH | WSFONT_FIND_BITMAP;
    231  1.73   mlelstv 		if ((ri->ri_flg & RI_ENABLE_ALPHA) != 0)
    232  1.73   mlelstv 			flags |= WSFONT_FIND_ALPHA;
    233  1.75  macallan 		if ((ri->ri_flg & RI_PREFER_ALPHA) != 0)
    234  1.75  macallan 			flags |= WSFONT_PREFER_ALPHA;
    235  1.73   mlelstv 		cookie = wsfont_find(NULL,
    236  1.73   mlelstv 			ri->ri_width / wantcols,
    237  1.73   mlelstv 			0,
    238  1.73   mlelstv 			0,
    239  1.73   mlelstv 			WSDISPLAY_FONTORDER_L2R,
    240  1.73   mlelstv 			WSDISPLAY_FONTORDER_L2R,
    241  1.73   mlelstv 			flags);
    242   1.1        ad 
    243  1.70  macallan 		/*
    244  1.70  macallan 		 * this means there is no supported font in the list
    245  1.70  macallan 		 */
    246   1.7        ad 		if (cookie <= 0) {
    247  1.70  macallan 			aprint_error("rasops_init: font table is empty\n");
    248   1.1        ad 			return (-1);
    249   1.1        ad 		}
    250  1.30        pk 
    251  1.55      ober #if NRASOPS_ROTATION > 0
    252  1.55      ober 		/*
    253  1.55      ober 		 * Pick the rotated version of this font. This will create it
    254  1.55      ober 		 * if necessary.
    255  1.55      ober 		 */
    256  1.62    nonaka 		if (ri->ri_flg & RI_ROTATE_MASK) {
    257  1.62    nonaka 			if (ri->ri_flg & RI_ROTATE_CW)
    258  1.62    nonaka 				rasops_rotate_font(&cookie, WSFONT_ROTATE_CW);
    259  1.62    nonaka 			else if (ri->ri_flg & RI_ROTATE_CCW)
    260  1.62    nonaka 				rasops_rotate_font(&cookie, WSFONT_ROTATE_CCW);
    261  1.62    nonaka 		}
    262  1.55      ober #endif
    263  1.55      ober 
    264  1.39        ad 		if (wsfont_lock(cookie, &ri->ri_font)) {
    265  1.70  macallan 			aprint_error("rasops_init: couldn't lock font\n");
    266   1.1        ad 			return (-1);
    267   1.1        ad 		}
    268   1.8        ad 
    269   1.5        ad 		ri->ri_wsfcookie = cookie;
    270   1.1        ad 	}
    271   1.4        ad #endif
    272  1.30        pk 
    273   1.1        ad 	/* This should never happen in reality... */
    274   1.1        ad #ifdef DEBUG
    275  1.31  sommerfe 	if ((long)ri->ri_bits & 3) {
    276  1.70  macallan 		aprint_error("rasops_init: bits not aligned on 32-bit boundary\n");
    277   1.1        ad 		return (-1);
    278   1.1        ad 	}
    279   1.1        ad 
    280   1.1        ad 	if ((int)ri->ri_stride & 3) {
    281  1.70  macallan 		aprint_error("rasops_init: stride not aligned on 32-bit boundary\n");
    282   1.1        ad 		return (-1);
    283   1.1        ad 	}
    284   1.1        ad #endif
    285   1.4        ad 
    286  1.13        ad 	if (rasops_reconfig(ri, wantrows, wantcols))
    287   1.4        ad 		return (-1);
    288  1.46     perry 
    289   1.4        ad 	rasops_init_devcmap(ri);
    290   1.4        ad 	return (0);
    291   1.4        ad }
    292   1.4        ad 
    293   1.4        ad /*
    294  1.13        ad  * Reconfigure (because parameters have changed in some way).
    295   1.4        ad  */
    296   1.4        ad int
    297  1.60       dsl rasops_reconfig(struct rasops_info *ri, int wantrows, int wantcols)
    298   1.4        ad {
    299  1.63  macallan 	int bpp, s, len;
    300  1.30        pk 
    301  1.13        ad 	s = splhigh();
    302  1.30        pk 
    303  1.70  macallan 	if (wantrows == 0)
    304  1.70  macallan 		wantrows = RASOPS_DEFAULT_HEIGHT;
    305  1.70  macallan 	if (wantcols == 0)
    306  1.70  macallan 		wantcols = RASOPS_DEFAULT_WIDTH;
    307  1.70  macallan 
    308  1.63  macallan 	/* throw away old line drawing character bitmaps, if we have any */
    309  1.63  macallan 	if (ri->ri_optfont.data != NULL) {
    310  1.63  macallan 		kmem_free(ri->ri_optfont.data, ri->ri_optfont.stride *
    311  1.63  macallan 		    ri->ri_optfont.fontheight * ri->ri_optfont.numchars);
    312  1.63  macallan 		ri->ri_optfont.data = NULL;
    313  1.63  macallan 	}
    314  1.63  macallan 
    315  1.63  macallan 	/* autogenerate box drawing characters */
    316  1.64  macallan 	ri->ri_optfont.firstchar = WSFONT_FLAG_OPT;
    317  1.64  macallan 	ri->ri_optfont.numchars = 16;
    318  1.63  macallan 	ri->ri_optfont.fontwidth = ri->ri_font->fontwidth;
    319  1.63  macallan 	ri->ri_optfont.fontheight = ri->ri_font->fontheight;
    320  1.63  macallan 	ri->ri_optfont.stride = ri->ri_font->stride;
    321  1.64  macallan 	len = ri->ri_optfont.fontheight * ri->ri_optfont.stride *
    322  1.64  macallan 		      ri->ri_optfont.numchars;
    323  1.64  macallan 
    324  1.77       chs 	if ((ri->ri_flg & RI_NO_AUTO) == 0) {
    325  1.77       chs 		ri->ri_optfont.data = kmem_zalloc(len, KM_SLEEP);
    326  1.67  macallan 		if (ri->ri_optfont.stride < ri->ri_optfont.fontwidth) {
    327  1.67  macallan 			switch (ri->ri_optfont.stride) {
    328  1.67  macallan 			case 1:
    329  1.67  macallan 				rasops_make_box_chars_8(ri);
    330  1.67  macallan 				break;
    331  1.67  macallan 			case 2:
    332  1.67  macallan 				rasops_make_box_chars_16(ri);
    333  1.67  macallan 				break;
    334  1.67  macallan 			case 4:
    335  1.67  macallan 				rasops_make_box_chars_32(ri);
    336  1.67  macallan 				break;
    337  1.67  macallan 			}
    338  1.67  macallan 		} else {
    339  1.67  macallan 			rasops_make_box_chars_alpha(ri);
    340  1.63  macallan 		}
    341  1.64  macallan 	} else
    342  1.64  macallan 		memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
    343  1.63  macallan 
    344   1.4        ad 	if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
    345  1.42    provos 		panic("rasops_init: fontwidth assumptions botched!");
    346  1.30        pk 
    347   1.4        ad 	/* Need this to frob the setup below */
    348   1.4        ad 	bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
    349   1.4        ad 
    350  1.74    nonaka 	if ((ri->ri_flg & RI_CFGDONE) != 0) {
    351   1.4        ad 		ri->ri_bits = ri->ri_origbits;
    352  1.74    nonaka 		ri->ri_hwbits = ri->ri_hworigbits;
    353  1.74    nonaka 	}
    354  1.30        pk 
    355   1.1        ad 	/* Don't care if the caller wants a hideously small console */
    356   1.1        ad 	if (wantrows < 10)
    357  1.13        ad 		wantrows = 10;
    358  1.30        pk 
    359   1.1        ad 	if (wantcols < 20)
    360  1.13        ad 		wantcols = 20;
    361  1.30        pk 
    362   1.1        ad 	/* Now constrain what they get */
    363   1.1        ad 	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
    364   1.1        ad 	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
    365  1.30        pk 
    366   1.1        ad 	if (ri->ri_emuwidth > ri->ri_width)
    367   1.1        ad 		ri->ri_emuwidth = ri->ri_width;
    368  1.30        pk 
    369   1.1        ad 	if (ri->ri_emuheight > ri->ri_height)
    370   1.1        ad 		ri->ri_emuheight = ri->ri_height;
    371  1.30        pk 
    372   1.1        ad 	/* Reduce width until aligned on a 32-bit boundary */
    373  1.20        ad 	while ((ri->ri_emuwidth * bpp & 31) != 0)
    374   1.1        ad 		ri->ri_emuwidth--;
    375  1.30        pk 
    376  1.55      ober #if NRASOPS_ROTATION > 0
    377  1.62    nonaka 	if (ri->ri_flg & (RI_ROTATE_CW|RI_ROTATE_CCW)) {
    378  1.55      ober 		ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
    379  1.55      ober 		ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
    380  1.55      ober 	} else
    381  1.55      ober #endif
    382  1.55      ober 	{
    383  1.55      ober 
    384  1.55      ober 		ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
    385  1.55      ober 		ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
    386  1.55      ober 	}
    387   1.4        ad 	ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
    388   1.1        ad 	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
    389   1.1        ad 	ri->ri_ccol = 0;
    390   1.1        ad 	ri->ri_crow = 0;
    391   1.4        ad 	ri->ri_pelbytes = bpp >> 3;
    392  1.30        pk 
    393   1.4        ad 	ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
    394   1.1        ad 	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
    395   1.1        ad 	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
    396   1.1        ad 
    397  1.30        pk #ifdef DEBUG
    398  1.18        ad 	if ((ri->ri_delta & 3) != 0)
    399  1.13        ad 		panic("rasops_init: ri_delta not aligned on 32-bit boundary");
    400  1.30        pk #endif
    401  1.75  macallan 	ri->ri_origbits = ri->ri_bits;
    402  1.75  macallan 	ri->ri_hworigbits = ri->ri_hwbits;
    403  1.75  macallan 
    404   1.1        ad 	/* Clear the entire display */
    405  1.13        ad 	if ((ri->ri_flg & RI_CLEAR) != 0)
    406  1.13        ad 		memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    407  1.30        pk 
    408  1.30        pk 	/* Now centre our window if needs be */
    409  1.13        ad 	if ((ri->ri_flg & RI_CENTER) != 0) {
    410  1.46     perry 		ri->ri_bits += (((ri->ri_width * bpp >> 3) -
    411  1.36   nathanw 		    ri->ri_emustride) >> 1) & ~3;
    412  1.30        pk 		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    413   1.1        ad 		    ri->ri_stride;
    414  1.61  macallan 		if (ri->ri_hwbits != NULL) {
    415  1.61  macallan 			ri->ri_hwbits += (((ri->ri_width * bpp >> 3) -
    416  1.61  macallan 			    ri->ri_emustride) >> 1) & ~3;
    417  1.61  macallan 			ri->ri_hwbits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    418  1.61  macallan 			    ri->ri_stride;
    419  1.61  macallan 		}
    420  1.30        pk 		ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
    421   1.5        ad 		   / ri->ri_stride;
    422  1.30        pk 		ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
    423  1.28   nathanw 		   % ri->ri_stride) * 8 / bpp);
    424   1.5        ad 	} else
    425   1.5        ad 		ri->ri_xorigin = ri->ri_yorigin = 0;
    426   1.4        ad 
    427  1.30        pk 	/*
    428   1.4        ad 	 * Fill in defaults for operations set.  XXX this nukes private
    429   1.4        ad 	 * routines used by accelerated fb drivers.
    430   1.4        ad 	 */
    431   1.1        ad 	ri->ri_ops.mapchar = rasops_mapchar;
    432   1.1        ad 	ri->ri_ops.copyrows = rasops_copyrows;
    433   1.1        ad 	ri->ri_ops.copycols = rasops_copycols;
    434   1.4        ad 	ri->ri_ops.erasecols = rasops_erasecols;
    435   1.4        ad 	ri->ri_ops.eraserows = rasops_eraserows;
    436   1.1        ad 	ri->ri_ops.cursor = rasops_cursor;
    437   1.4        ad 	ri->ri_do_cursor = rasops_do_cursor;
    438  1.30        pk 
    439  1.76  macallan 	ri->ri_caps &= ~(WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
    440  1.76  macallan 		    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE);
    441  1.13        ad 	if (ri->ri_depth < 8 || (ri->ri_flg & RI_FORCEMONO) != 0) {
    442  1.41  junyoung 		ri->ri_ops.allocattr = rasops_allocattr_mono;
    443  1.76  macallan 		ri->ri_caps |= WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
    444   1.4        ad 	} else {
    445  1.41  junyoung 		ri->ri_ops.allocattr = rasops_allocattr_color;
    446  1.76  macallan 		ri->ri_caps |= WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
    447  1.24  drochner 		    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    448   1.4        ad 	}
    449   1.4        ad 
    450   1.1        ad 	switch (ri->ri_depth) {
    451  1.20        ad #if NRASOPS1 > 0
    452   1.1        ad 	case 1:
    453   1.1        ad 		rasops1_init(ri);
    454   1.1        ad 		break;
    455   1.1        ad #endif
    456  1.20        ad #if NRASOPS2 > 0
    457   1.4        ad 	case 2:
    458   1.4        ad 		rasops2_init(ri);
    459  1.34  takemura 		break;
    460  1.34  takemura #endif
    461  1.34  takemura #if NRASOPS4 > 0
    462  1.34  takemura 	case 4:
    463  1.34  takemura 		rasops4_init(ri);
    464   1.4        ad 		break;
    465   1.4        ad #endif
    466  1.20        ad #if NRASOPS8 > 0
    467   1.1        ad 	case 8:
    468   1.1        ad 		rasops8_init(ri);
    469   1.1        ad 		break;
    470   1.1        ad #endif
    471  1.20        ad #if NRASOPS15 > 0 || NRASOPS16 > 0
    472   1.1        ad 	case 15:
    473   1.1        ad 	case 16:
    474   1.1        ad 		rasops15_init(ri);
    475   1.1        ad 		break;
    476   1.1        ad #endif
    477  1.20        ad #if NRASOPS24 > 0
    478   1.1        ad 	case 24:
    479   1.1        ad 		rasops24_init(ri);
    480   1.1        ad 		break;
    481   1.1        ad #endif
    482  1.20        ad #if NRASOPS32 > 0
    483   1.1        ad 	case 32:
    484   1.1        ad 		rasops32_init(ri);
    485   1.1        ad 		break;
    486   1.1        ad #endif
    487   1.1        ad 	default:
    488  1.13        ad 		ri->ri_flg &= ~RI_CFGDONE;
    489  1.13        ad 		splx(s);
    490   1.1        ad 		return (-1);
    491   1.1        ad 	}
    492  1.30        pk 
    493  1.55      ober #if NRASOPS_ROTATION > 0
    494  1.62    nonaka 	if (ri->ri_flg & RI_ROTATE_MASK) {
    495  1.62    nonaka 		if (ri->ri_flg & RI_ROTATE_CW) {
    496  1.62    nonaka 			ri->ri_real_ops = ri->ri_ops;
    497  1.62    nonaka 			ri->ri_ops.copycols = rasops_copycols_rotated_cw;
    498  1.62    nonaka 			ri->ri_ops.copyrows = rasops_copyrows_rotated_cw;
    499  1.62    nonaka 			ri->ri_ops.erasecols = rasops_erasecols_rotated_cw;
    500  1.62    nonaka 			ri->ri_ops.eraserows = rasops_eraserows_rotated_cw;
    501  1.62    nonaka 			ri->ri_ops.putchar = rasops_putchar_rotated_cw;
    502  1.62    nonaka 		} else if (ri->ri_flg & RI_ROTATE_CCW) {
    503  1.62    nonaka 			ri->ri_real_ops = ri->ri_ops;
    504  1.62    nonaka 			ri->ri_ops.copycols = rasops_copycols_rotated_ccw;
    505  1.62    nonaka 			ri->ri_ops.copyrows = rasops_copyrows_rotated_ccw;
    506  1.62    nonaka 			ri->ri_ops.erasecols = rasops_erasecols_rotated_ccw;
    507  1.62    nonaka 			ri->ri_ops.eraserows = rasops_eraserows_rotated_ccw;
    508  1.62    nonaka 			ri->ri_ops.putchar = rasops_putchar_rotated_ccw;
    509  1.62    nonaka 		}
    510  1.55      ober 	}
    511  1.55      ober #endif
    512  1.55      ober 
    513  1.13        ad 	ri->ri_flg |= RI_CFGDONE;
    514  1.13        ad 	splx(s);
    515   1.1        ad 	return (0);
    516   1.1        ad }
    517   1.1        ad 
    518   1.1        ad /*
    519   1.1        ad  * Map a character.
    520   1.1        ad  */
    521   1.1        ad static int
    522  1.59       dsl rasops_mapchar(void *cookie, int c, u_int *cp)
    523   1.1        ad {
    524   1.1        ad 	struct rasops_info *ri;
    525  1.30        pk 
    526   1.1        ad 	ri = (struct rasops_info *)cookie;
    527   1.8        ad 
    528  1.30        pk #ifdef DIAGNOSTIC
    529   1.8        ad 	if (ri->ri_font == NULL)
    530  1.42    provos 		panic("rasops_mapchar: no font selected");
    531  1.30        pk #endif
    532  1.39        ad 
    533  1.63  macallan 	if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
    534  1.63  macallan 		*cp = ' ';
    535  1.63  macallan 		return (0);
    536  1.35    marcus 	}
    537  1.30        pk 
    538   1.1        ad 	if (c < ri->ri_font->firstchar) {
    539   1.1        ad 		*cp = ' ';
    540   1.1        ad 		return (0);
    541   1.1        ad 	}
    542  1.30        pk 
    543  1.63  macallan #if 0
    544   1.1        ad 	if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
    545   1.1        ad 		*cp = ' ';
    546   1.1        ad 		return (0);
    547   1.1        ad 	}
    548  1.63  macallan #endif
    549   1.1        ad 	*cp = c;
    550   1.1        ad 	return (5);
    551   1.1        ad }
    552   1.1        ad 
    553   1.1        ad /*
    554   1.1        ad  * Allocate a color attribute.
    555   1.1        ad  */
    556   1.1        ad static int
    557  1.54  christos rasops_allocattr_color(void *cookie, int fg, int bg, int flg,
    558  1.53  christos     long *attr)
    559   1.1        ad {
    560   1.1        ad 	int swap;
    561   1.1        ad 
    562  1.56       mjf 	if (__predict_false((unsigned int)fg >= sizeof(rasops_isgray) ||
    563  1.56       mjf 	    (unsigned int)bg >= sizeof(rasops_isgray)))
    564  1.56       mjf 		return (EINVAL);
    565  1.56       mjf 
    566   1.1        ad #ifdef RASOPS_CLIPPING
    567   1.1        ad 	fg &= 7;
    568   1.1        ad 	bg &= 7;
    569   1.1        ad #endif
    570  1.17        ad 	if ((flg & WSATTR_BLINK) != 0)
    571   1.1        ad 		return (EINVAL);
    572  1.23  drochner 
    573  1.23  drochner 	if ((flg & WSATTR_WSCOLORS) == 0) {
    574  1.48  macallan #ifdef WS_DEFAULT_FG
    575  1.48  macallan 		fg = WS_DEFAULT_FG;
    576  1.48  macallan #else
    577  1.48  macallan 		fg = WSCOL_WHITE;
    578  1.48  macallan #endif
    579  1.48  macallan #ifdef WS_DEFAULT_BG
    580  1.48  macallan 		bg = WS_DEFAULT_BG;
    581  1.48  macallan #else
    582  1.48  macallan 		bg = WSCOL_BLACK;
    583  1.48  macallan #endif
    584  1.23  drochner 	}
    585  1.23  drochner 
    586  1.17        ad 	if ((flg & WSATTR_REVERSE) != 0) {
    587   1.1        ad 		swap = fg;
    588   1.1        ad 		fg = bg;
    589   1.1        ad 		bg = swap;
    590   1.1        ad 	}
    591   1.1        ad 
    592  1.17        ad 	if ((flg & WSATTR_HILIT) != 0)
    593   1.1        ad 		fg += 8;
    594  1.30        pk 
    595  1.79   mlelstv 	flg = flg & WSATTR_USERMASK;
    596  1.30        pk 
    597   1.1        ad 	if (rasops_isgray[fg])
    598  1.79   mlelstv 		flg |= WSATTR_PRIVATE1;
    599   1.1        ad 
    600   1.1        ad 	if (rasops_isgray[bg])
    601  1.79   mlelstv 		flg |= WSATTR_PRIVATE2;
    602   1.1        ad 
    603   1.1        ad 	*attr = (bg << 16) | (fg << 24) | flg;
    604  1.17        ad 	return (0);
    605   1.1        ad }
    606   1.1        ad 
    607   1.1        ad /*
    608   1.1        ad  * Allocate a mono attribute.
    609   1.1        ad  */
    610   1.1        ad static int
    611  1.54  christos rasops_allocattr_mono(void *cookie, int fg, int bg, int flg,
    612  1.53  christos     long *attr)
    613   1.1        ad {
    614   1.1        ad 	int swap;
    615   1.1        ad 
    616  1.23  drochner 	if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
    617   1.1        ad 		return (EINVAL);
    618  1.23  drochner 
    619  1.23  drochner 	fg = 1;
    620  1.23  drochner 	bg = 0;
    621  1.23  drochner 
    622  1.17        ad 	if ((flg & WSATTR_REVERSE) != 0) {
    623   1.1        ad 		swap = fg;
    624   1.1        ad 		fg = bg;
    625   1.1        ad 		bg = swap;
    626   1.1        ad 	}
    627   1.1        ad 
    628   1.1        ad 	*attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
    629  1.17        ad 	return (0);
    630   1.1        ad }
    631   1.1        ad 
    632   1.1        ad /*
    633   1.1        ad  * Copy rows.
    634   1.1        ad  */
    635   1.1        ad static void
    636  1.60       dsl rasops_copyrows(void *cookie, int src, int dst, int num)
    637   1.1        ad {
    638  1.82       rin 	uint32_t *sp, *dp, *hp, *srp, *drp, *hrp;
    639   1.1        ad 	struct rasops_info *ri;
    640  1.18        ad 	int n8, n1, cnt, delta;
    641  1.30        pk 
    642   1.1        ad 	ri = (struct rasops_info *)cookie;
    643  1.51  jmcneill 	hp = hrp = NULL;
    644   1.1        ad 
    645   1.1        ad #ifdef RASOPS_CLIPPING
    646   1.1        ad 	if (dst == src)
    647   1.1        ad 		return;
    648  1.30        pk 
    649   1.1        ad 	if (src < 0) {
    650   1.1        ad 		num += src;
    651   1.1        ad 		src = 0;
    652   1.1        ad 	}
    653   1.1        ad 
    654   1.1        ad 	if ((src + num) > ri->ri_rows)
    655   1.1        ad 		num = ri->ri_rows - src;
    656   1.1        ad 
    657   1.1        ad 	if (dst < 0) {
    658   1.1        ad 		num += dst;
    659   1.1        ad 		dst = 0;
    660   1.1        ad 	}
    661   1.1        ad 
    662   1.1        ad 	if ((dst + num) > ri->ri_rows)
    663   1.1        ad 		num = ri->ri_rows - dst;
    664  1.30        pk 
    665   1.1        ad 	if (num <= 0)
    666   1.1        ad 		return;
    667   1.1        ad #endif
    668   1.1        ad 
    669   1.1        ad 	num *= ri->ri_font->fontheight;
    670   1.1        ad 	n8 = ri->ri_emustride >> 5;
    671   1.1        ad 	n1 = (ri->ri_emustride >> 2) & 7;
    672  1.30        pk 
    673   1.1        ad 	if (dst < src) {
    674  1.82       rin 		srp = (uint32_t *)(ri->ri_bits + src * ri->ri_yscale);
    675  1.82       rin 		drp = (uint32_t *)(ri->ri_bits + dst * ri->ri_yscale);
    676  1.51  jmcneill 		if (ri->ri_hwbits)
    677  1.82       rin 			hrp = (uint32_t *)(ri->ri_hwbits + dst *
    678  1.51  jmcneill 			    ri->ri_yscale);
    679  1.18        ad 		delta = ri->ri_stride;
    680   1.1        ad 	} else {
    681   1.1        ad 		src = ri->ri_font->fontheight * src + num - 1;
    682   1.1        ad 		dst = ri->ri_font->fontheight * dst + num - 1;
    683  1.82       rin 		srp = (uint32_t *)(ri->ri_bits + src * ri->ri_stride);
    684  1.82       rin 		drp = (uint32_t *)(ri->ri_bits + dst * ri->ri_stride);
    685  1.51  jmcneill 		if (ri->ri_hwbits)
    686  1.82       rin 			hrp = (uint32_t *)(ri->ri_hwbits + dst *
    687  1.51  jmcneill 			    ri->ri_stride);
    688  1.51  jmcneill 
    689  1.18        ad 		delta = -ri->ri_stride;
    690  1.18        ad 	}
    691  1.30        pk 
    692  1.18        ad 	while (num--) {
    693  1.18        ad 		dp = drp;
    694  1.18        ad 		sp = srp;
    695  1.51  jmcneill 		if (ri->ri_hwbits)
    696  1.51  jmcneill 			hp = hrp;
    697  1.51  jmcneill 
    698  1.82       rin 		DELTA(drp, delta, uint32_t *);
    699  1.82       rin 		DELTA(srp, delta, uint32_t *);
    700  1.51  jmcneill 		if (ri->ri_hwbits)
    701  1.82       rin 			DELTA(hrp, delta, uint32_t *);
    702  1.18        ad 
    703  1.18        ad 		for (cnt = n8; cnt; cnt--) {
    704  1.52  jmcneill 			dp[0] = sp[0];
    705  1.52  jmcneill 			dp[1] = sp[1];
    706  1.52  jmcneill 			dp[2] = sp[2];
    707  1.52  jmcneill 			dp[3] = sp[3];
    708  1.52  jmcneill 			dp[4] = sp[4];
    709  1.52  jmcneill 			dp[5] = sp[5];
    710  1.52  jmcneill 			dp[6] = sp[6];
    711  1.52  jmcneill 			dp[7] = sp[7];
    712  1.18        ad 			dp += 8;
    713  1.18        ad 			sp += 8;
    714  1.52  jmcneill 		}
    715  1.52  jmcneill 		if (ri->ri_hwbits) {
    716  1.52  jmcneill 			sp -= (8 * n8);
    717  1.52  jmcneill 			for (cnt = n8; cnt; cnt--) {
    718  1.52  jmcneill 				hp[0] = sp[0];
    719  1.52  jmcneill 				hp[1] = sp[1];
    720  1.52  jmcneill 				hp[2] = sp[2];
    721  1.52  jmcneill 				hp[3] = sp[3];
    722  1.52  jmcneill 				hp[4] = sp[4];
    723  1.52  jmcneill 				hp[5] = sp[5];
    724  1.52  jmcneill 				hp[6] = sp[6];
    725  1.52  jmcneill 				hp[7] = sp[7];
    726  1.51  jmcneill 				hp += 8;
    727  1.52  jmcneill 				sp += 8;
    728  1.52  jmcneill 			}
    729  1.18        ad 		}
    730  1.30        pk 
    731  1.51  jmcneill 		for (cnt = n1; cnt; cnt--) {
    732  1.18        ad 			*dp++ = *sp++;
    733  1.51  jmcneill 			if (ri->ri_hwbits)
    734  1.51  jmcneill 				*hp++ = *(sp - 1);
    735  1.51  jmcneill 		}
    736   1.1        ad 	}
    737   1.1        ad }
    738   1.1        ad 
    739   1.1        ad /*
    740   1.1        ad  * Copy columns. This is slow, and hard to optimize due to alignment,
    741   1.1        ad  * and the fact that we have to copy both left->right and right->left.
    742  1.43       uwe  * We simply cop-out here and use memmove(), since it handles all of
    743   1.1        ad  * these cases anyway.
    744   1.1        ad  */
    745   1.4        ad void
    746  1.60       dsl rasops_copycols(void *cookie, int row, int src, int dst, int num)
    747   1.1        ad {
    748   1.1        ad 	struct rasops_info *ri;
    749  1.81       rin 	uint8_t *sp, *dp, *hp;
    750   1.1        ad 	int height;
    751  1.30        pk 
    752   1.1        ad 	ri = (struct rasops_info *)cookie;
    753  1.51  jmcneill 	hp = NULL;
    754   1.1        ad 
    755   1.1        ad #ifdef RASOPS_CLIPPING
    756   1.1        ad 	if (dst == src)
    757   1.1        ad 		return;
    758  1.30        pk 
    759   1.3        ad 	/* Catches < 0 case too */
    760   1.3        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    761   1.1        ad 		return;
    762  1.30        pk 
    763   1.1        ad 	if (src < 0) {
    764   1.1        ad 		num += src;
    765   1.1        ad 		src = 0;
    766   1.1        ad 	}
    767   1.1        ad 
    768   1.1        ad 	if ((src + num) > ri->ri_cols)
    769   1.1        ad 		num = ri->ri_cols - src;
    770   1.1        ad 
    771   1.1        ad 	if (dst < 0) {
    772   1.1        ad 		num += dst;
    773   1.1        ad 		dst = 0;
    774   1.1        ad 	}
    775   1.1        ad 
    776   1.1        ad 	if ((dst + num) > ri->ri_cols)
    777   1.1        ad 		num = ri->ri_cols - dst;
    778  1.30        pk 
    779   1.1        ad 	if (num <= 0)
    780   1.1        ad 		return;
    781   1.1        ad #endif
    782  1.30        pk 
    783   1.1        ad 	num *= ri->ri_xscale;
    784   1.1        ad 	row *= ri->ri_yscale;
    785   1.1        ad 	height = ri->ri_font->fontheight;
    786  1.30        pk 
    787   1.1        ad 	sp = ri->ri_bits + row + src * ri->ri_xscale;
    788   1.1        ad 	dp = ri->ri_bits + row + dst * ri->ri_xscale;
    789  1.51  jmcneill 	if (ri->ri_hwbits)
    790  1.51  jmcneill 		hp = ri->ri_hwbits + row + dst * ri->ri_xscale;
    791  1.30        pk 
    792   1.1        ad 	while (height--) {
    793  1.43       uwe 		memmove(dp, sp, num);
    794  1.51  jmcneill 		if (ri->ri_hwbits) {
    795  1.51  jmcneill 			memcpy(hp, sp, num);
    796  1.51  jmcneill 			hp += ri->ri_stride;
    797  1.51  jmcneill 		}
    798   1.1        ad 		dp += ri->ri_stride;
    799   1.1        ad 		sp += ri->ri_stride;
    800   1.1        ad 	}
    801   1.1        ad }
    802   1.1        ad 
    803   1.1        ad /*
    804   1.1        ad  * Turn cursor off/on.
    805   1.1        ad  */
    806   1.1        ad static void
    807  1.60       dsl rasops_cursor(void *cookie, int on, int row, int col)
    808   1.1        ad {
    809   1.1        ad 	struct rasops_info *ri;
    810  1.30        pk 
    811   1.1        ad 	ri = (struct rasops_info *)cookie;
    812  1.30        pk 
    813   1.1        ad 	/* Turn old cursor off */
    814  1.13        ad 	if ((ri->ri_flg & RI_CURSOR) != 0)
    815  1.30        pk #ifdef RASOPS_CLIPPING
    816  1.13        ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    817   1.1        ad #endif
    818   1.1        ad 			ri->ri_do_cursor(ri);
    819   1.1        ad 
    820   1.1        ad 	/* Select new cursor */
    821   1.1        ad #ifdef RASOPS_CLIPPING
    822  1.13        ad 	ri->ri_flg &= ~RI_CURSORCLIP;
    823  1.30        pk 
    824   1.1        ad 	if (row < 0 || row >= ri->ri_rows)
    825  1.13        ad 		ri->ri_flg |= RI_CURSORCLIP;
    826   1.1        ad 	else if (col < 0 || col >= ri->ri_cols)
    827  1.13        ad 		ri->ri_flg |= RI_CURSORCLIP;
    828   1.1        ad #endif
    829   1.1        ad 	ri->ri_crow = row;
    830   1.1        ad 	ri->ri_ccol = col;
    831   1.1        ad 
    832   1.1        ad 	if (on) {
    833  1.13        ad 		ri->ri_flg |= RI_CURSOR;
    834  1.30        pk #ifdef RASOPS_CLIPPING
    835  1.13        ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    836   1.1        ad #endif
    837   1.1        ad 			ri->ri_do_cursor(ri);
    838  1.30        pk 	} else
    839  1.13        ad 		ri->ri_flg &= ~RI_CURSOR;
    840   1.1        ad }
    841   1.1        ad 
    842   1.1        ad /*
    843   1.1        ad  * Make the device colormap
    844   1.1        ad  */
    845   1.4        ad static void
    846  1.59       dsl rasops_init_devcmap(struct rasops_info *ri)
    847   1.1        ad {
    848  1.81       rin 	const uint8_t *p;
    849   1.1        ad 	int i, c;
    850  1.30        pk 
    851   1.4        ad 	switch (ri->ri_depth) {
    852   1.4        ad 	case 1:
    853   1.4        ad 		ri->ri_devcmap[0] = 0;
    854   1.4        ad 		for (i = 1; i < 16; i++)
    855   1.4        ad 			ri->ri_devcmap[i] = -1;
    856   1.4        ad 		return;
    857   1.4        ad 
    858   1.4        ad 	case 2:
    859   1.4        ad 		for (i = 1; i < 15; i++)
    860   1.4        ad 			ri->ri_devcmap[i] = 0xaaaaaaaa;
    861  1.30        pk 
    862   1.4        ad 		ri->ri_devcmap[0] = 0;
    863   1.4        ad 		ri->ri_devcmap[8] = 0x55555555;
    864   1.4        ad 		ri->ri_devcmap[15] = -1;
    865   1.4        ad 		return;
    866   1.4        ad 
    867   1.4        ad 	case 8:
    868  1.68  macallan 		if ((ri->ri_flg & RI_8BIT_IS_RGB) == 0) {
    869  1.85       rin 			for (i = 0; i < 16; i++) {
    870  1.85       rin #ifdef GENFB_MAC68K
    871  1.85       rin 				c = apple_devcmap[i];
    872  1.85       rin #else
    873  1.85       rin 				c = i;
    874  1.85       rin #endif
    875  1.68  macallan 				ri->ri_devcmap[i] =
    876  1.85       rin 				    c | (c<<8) | (c<<16) | (c<<24);
    877  1.85       rin 			}
    878  1.68  macallan 			return;
    879  1.68  macallan 		}
    880   1.4        ad 	}
    881  1.30        pk 
    882   1.1        ad 	p = rasops_cmap;
    883  1.30        pk 
    884  1.29   nathanw 	for (i = 0; i < 16; i++) {
    885   1.1        ad 		if (ri->ri_rnum <= 8)
    886  1.12        ad 			c = (*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
    887  1.30        pk 		else
    888  1.12        ad 			c = (*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
    889  1.29   nathanw 		p++;
    890   1.1        ad 
    891   1.1        ad 		if (ri->ri_gnum <= 8)
    892  1.12        ad 			c |= (*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
    893  1.30        pk 		else
    894  1.12        ad 			c |= (*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
    895  1.29   nathanw 		p++;
    896   1.1        ad 
    897   1.1        ad 		if (ri->ri_bnum <= 8)
    898  1.12        ad 			c |= (*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
    899  1.30        pk 		else
    900  1.12        ad 			c |= (*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
    901  1.29   nathanw 		p++;
    902   1.4        ad 
    903   1.4        ad 		/* Fill the word for generic routines, which want this */
    904   1.4        ad 		if (ri->ri_depth == 24)
    905   1.4        ad 			c = c | ((c & 0xff) << 24);
    906  1.69  macallan 		else if (ri->ri_depth == 8) {
    907  1.69  macallan 			c = c | (c << 8);
    908  1.69  macallan 			c |= c << 16;
    909  1.69  macallan 		} else if (ri->ri_depth <= 16)
    910   1.4        ad 			c = c | (c << 16);
    911   1.1        ad 
    912   1.4        ad 		/* 24bpp does bswap on the fly. {32,16,15}bpp do it here. */
    913  1.13        ad 		if ((ri->ri_flg & RI_BSWAP) == 0)
    914   1.3        ad 			ri->ri_devcmap[i] = c;
    915   1.4        ad 		else if (ri->ri_depth == 32)
    916   1.3        ad 			ri->ri_devcmap[i] = bswap32(c);
    917   1.4        ad 		else if (ri->ri_depth == 16 || ri->ri_depth == 15)
    918   1.3        ad 			ri->ri_devcmap[i] = bswap16(c);
    919   1.4        ad 		else
    920   1.4        ad 			ri->ri_devcmap[i] = c;
    921   1.1        ad 	}
    922   1.1        ad }
    923   1.1        ad 
    924   1.1        ad /*
    925   1.1        ad  * Unpack a rasops attribute
    926   1.1        ad  */
    927   1.1        ad void
    928  1.60       dsl rasops_unpack_attr(long attr, int *fg, int *bg, int *underline)
    929   1.1        ad {
    930  1.30        pk 
    931  1.30        pk 	*fg = ((u_int)attr >> 24) & 0xf;
    932  1.30        pk 	*bg = ((u_int)attr >> 16) & 0xf;
    933  1.25        ad 	if (underline != NULL)
    934  1.79   mlelstv 		*underline = (u_int)attr & WSATTR_UNDERLINE;
    935   1.4        ad }
    936   1.4        ad 
    937   1.4        ad /*
    938   1.4        ad  * Erase rows. This isn't static, since 24-bpp uses it in special cases.
    939   1.4        ad  */
    940   1.4        ad void
    941  1.60       dsl rasops_eraserows(void *cookie, int row, int num, long attr)
    942   1.4        ad {
    943   1.4        ad 	struct rasops_info *ri;
    944  1.14        ad 	int np, nw, cnt, delta;
    945  1.82       rin 	uint32_t *dp, *hp, clr;
    946  1.51  jmcneill 	int i;
    947  1.30        pk 
    948   1.4        ad 	ri = (struct rasops_info *)cookie;
    949  1.51  jmcneill 	hp = NULL;
    950   1.4        ad 
    951   1.4        ad #ifdef RASOPS_CLIPPING
    952   1.4        ad 	if (row < 0) {
    953   1.4        ad 		num += row;
    954   1.4        ad 		row = 0;
    955   1.4        ad 	}
    956   1.4        ad 
    957   1.4        ad 	if ((row + num) > ri->ri_rows)
    958   1.4        ad 		num = ri->ri_rows - row;
    959  1.30        pk 
    960   1.4        ad 	if (num <= 0)
    961   1.4        ad 		return;
    962   1.4        ad #endif
    963   1.4        ad 
    964  1.30        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
    965   1.4        ad 
    966  1.30        pk 	/*
    967  1.20        ad 	 * XXX The wsdisplay_emulops interface seems a little deficient in
    968  1.30        pk 	 * that there is no way to clear the *entire* screen. We provide a
    969  1.30        pk 	 * workaround here: if the entire console area is being cleared, and
    970  1.13        ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    971  1.30        pk 	 */
    972  1.13        ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    973  1.13        ad 		np = ri->ri_stride >> 5;
    974  1.13        ad 		nw = (ri->ri_stride >> 2) & 7;
    975  1.13        ad 		num = ri->ri_height;
    976  1.82       rin 		dp = (uint32_t *)ri->ri_origbits;
    977  1.51  jmcneill 		if (ri->ri_hwbits)
    978  1.82       rin 			hp = (uint32_t *)ri->ri_hworigbits;
    979  1.14        ad 		delta = 0;
    980  1.13        ad 	} else {
    981  1.13        ad 		np = ri->ri_emustride >> 5;
    982  1.13        ad 		nw = (ri->ri_emustride >> 2) & 7;
    983  1.13        ad 		num *= ri->ri_font->fontheight;
    984  1.82       rin 		dp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale);
    985  1.51  jmcneill 		if (ri->ri_hwbits)
    986  1.82       rin 			hp = (uint32_t *)(ri->ri_hwbits + row *
    987  1.51  jmcneill 			    ri->ri_yscale);
    988  1.14        ad 		delta = ri->ri_delta;
    989  1.13        ad 	}
    990  1.30        pk 
    991   1.4        ad 	while (num--) {
    992   1.4        ad 		for (cnt = np; cnt; cnt--) {
    993  1.51  jmcneill 			for (i = 0; i < 8; i++) {
    994  1.51  jmcneill 				dp[i] = clr;
    995  1.51  jmcneill 				if (ri->ri_hwbits)
    996  1.51  jmcneill 					hp[i] = clr;
    997  1.51  jmcneill 			}
    998   1.4        ad 			dp += 8;
    999  1.51  jmcneill 			if (ri->ri_hwbits)
   1000  1.51  jmcneill 				hp += 8;
   1001   1.4        ad 		}
   1002  1.30        pk 
   1003   1.4        ad 		for (cnt = nw; cnt; cnt--) {
   1004  1.82       rin 			*(uint32_t *)dp = clr;
   1005  1.82       rin 			DELTA(dp, 4, uint32_t *);
   1006  1.51  jmcneill 			if (ri->ri_hwbits) {
   1007  1.82       rin 				*(uint32_t *)hp = clr;
   1008  1.82       rin 				DELTA(hp, 4, uint32_t *);
   1009  1.51  jmcneill 			}
   1010  1.30        pk 		}
   1011  1.30        pk 
   1012  1.82       rin 		DELTA(dp, delta, uint32_t *);
   1013  1.51  jmcneill 		if (ri->ri_hwbits)
   1014  1.82       rin 			DELTA(hp, delta, uint32_t *);
   1015   1.4        ad 	}
   1016   1.4        ad }
   1017   1.4        ad 
   1018   1.4        ad /*
   1019   1.4        ad  * Actually turn the cursor on or off. This does the dirty work for
   1020   1.4        ad  * rasops_cursor().
   1021   1.4        ad  */
   1022   1.4        ad static void
   1023  1.59       dsl rasops_do_cursor(struct rasops_info *ri)
   1024   1.4        ad {
   1025  1.84       rin 	int full, height, cnt, slop1, slop2, row, col;
   1026  1.85       rin 	uint32_t tmp32, msk1, msk2;
   1027  1.84       rin 	uint8_t tmp8;
   1028  1.81       rin 	uint8_t *dp, *rp, *hrp, *hp;
   1029  1.51  jmcneill 
   1030  1.51  jmcneill 	hrp = hp = NULL;
   1031  1.30        pk 
   1032  1.55      ober #if NRASOPS_ROTATION > 0
   1033  1.62    nonaka 	if (ri->ri_flg & RI_ROTATE_MASK) {
   1034  1.62    nonaka 		if (ri->ri_flg & RI_ROTATE_CW) {
   1035  1.62    nonaka 			/* Rotate rows/columns */
   1036  1.62    nonaka 			row = ri->ri_ccol;
   1037  1.62    nonaka 			col = ri->ri_rows - ri->ri_crow - 1;
   1038  1.62    nonaka 		} else if (ri->ri_flg & RI_ROTATE_CCW) {
   1039  1.62    nonaka 			/* Rotate rows/columns */
   1040  1.62    nonaka 			row = ri->ri_cols - ri->ri_ccol - 1;
   1041  1.62    nonaka 			col = ri->ri_crow;
   1042  1.62    nonaka 		} else {	/* upside-down */
   1043  1.62    nonaka 			row = ri->ri_crow;
   1044  1.62    nonaka 			col = ri->ri_ccol;
   1045  1.62    nonaka 		}
   1046  1.55      ober 	} else
   1047  1.55      ober #endif
   1048  1.55      ober 	{
   1049  1.55      ober 		row = ri->ri_crow;
   1050  1.55      ober 		col = ri->ri_ccol;
   1051  1.55      ober 	}
   1052  1.30        pk 
   1053   1.4        ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
   1054  1.51  jmcneill 	if (ri->ri_hwbits)
   1055  1.51  jmcneill 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col
   1056  1.51  jmcneill 		    * ri->ri_xscale;
   1057   1.4        ad 	height = ri->ri_font->fontheight;
   1058  1.30        pk 
   1059  1.80       rin 	/*
   1060  1.80       rin 	 * For ri_xscale = 1:
   1061  1.80       rin 	 *
   1062  1.80       rin 	 * Logic below does not work for ri_xscale = 1, e.g.,
   1063  1.80       rin 	 * fontwidth = 8 and bpp = 1. So we take care of it.
   1064  1.80       rin 	 */
   1065  1.80       rin 	if (ri->ri_xscale == 1) {
   1066  1.80       rin 		while (height--) {
   1067  1.84       rin 			tmp8 = ~*rp;
   1068  1.80       rin 
   1069  1.80       rin 			*rp = tmp8;
   1070  1.80       rin 			rp += ri->ri_stride;
   1071  1.30        pk 
   1072  1.80       rin 			if (ri->ri_hwbits) {
   1073  1.80       rin 				*hrp = tmp8;
   1074  1.80       rin 				hrp += ri->ri_stride;
   1075  1.80       rin 			}
   1076  1.80       rin 		}
   1077  1.80       rin 		return;
   1078  1.80       rin 	}
   1079  1.80       rin 
   1080  1.80       rin 	/*
   1081  1.80       rin 	 * For ri_xscale = 2, 3, 4, ...:
   1082  1.80       rin 	 *
   1083  1.80       rin 	 * Note that siop1 <= ri_xscale even for ri_xscale = 2,
   1084  1.84       rin 	 * since rp % 3 = 0 or 2 (ri_stride % 4 = 0).
   1085  1.80       rin 	 */
   1086  1.80       rin 	slop1 = (4 - ((uintptr_t)rp & 3)) & 3;
   1087   1.4        ad 	slop2 = (ri->ri_xscale - slop1) & 3;
   1088  1.84       rin 	full = (ri->ri_xscale - slop1 - slop2) >> 2;
   1089  1.30        pk 
   1090  1.84       rin 	rp = (uint8_t *)((uintptr_t)rp & ~3);
   1091  1.84       rin 	hrp = (uint8_t *)((uintptr_t)hrp & ~3);
   1092  1.30        pk 
   1093  1.85       rin 	msk1 = be32toh(0xffffffffU >> (32 - (8 * slop1)));
   1094  1.85       rin 	msk2 = be32toh(0xffffffffU << (32 - (8 * slop2)));
   1095  1.85       rin 
   1096  1.84       rin 	while (height--) {
   1097  1.84       rin 		dp = rp;
   1098  1.84       rin 		rp += ri->ri_stride;
   1099  1.84       rin 		if (ri->ri_hwbits) {
   1100  1.84       rin 			hp = hrp;
   1101  1.84       rin 			hrp += ri->ri_stride;
   1102   1.4        ad 		}
   1103  1.78  macallan 
   1104  1.84       rin 		if (slop1) {
   1105  1.85       rin 			tmp32 = *(uint32_t *)dp ^ msk1;
   1106  1.84       rin 			*(uint32_t *)dp = tmp32;
   1107  1.84       rin 			dp += 4;
   1108  1.51  jmcneill 			if (ri->ri_hwbits) {
   1109  1.84       rin 				*(uint32_t *)hp = tmp32;
   1110  1.84       rin 				hp += 4;
   1111  1.51  jmcneill 			}
   1112  1.84       rin 		}
   1113  1.30        pk 
   1114  1.84       rin 		for (cnt = full; cnt; cnt--) {
   1115  1.84       rin 			tmp32 = ~*(uint32_t *)dp;
   1116  1.84       rin 			*(uint32_t *)dp = tmp32;
   1117  1.84       rin 			dp += 4;
   1118  1.84       rin 			if (ri->ri_hwbits) {
   1119  1.84       rin 				*(uint32_t *)hp = tmp32;
   1120  1.84       rin 				hp += 4;
   1121   1.4        ad 			}
   1122  1.84       rin 		}
   1123  1.30        pk 
   1124  1.84       rin 		if (slop2) {
   1125  1.85       rin 			tmp32 = *(uint32_t *)dp ^ msk2;
   1126  1.84       rin 			*(uint32_t *)dp = tmp32;
   1127  1.84       rin 			if (ri->ri_hwbits)
   1128  1.84       rin 				*(uint32_t *)hp = tmp32;
   1129   1.4        ad 		}
   1130   1.4        ad 	}
   1131   1.4        ad }
   1132   1.4        ad 
   1133   1.4        ad /*
   1134   1.4        ad  * Erase columns.
   1135   1.4        ad  */
   1136   1.4        ad void
   1137  1.60       dsl rasops_erasecols(void *cookie, int row, int col, int num, long attr)
   1138   1.4        ad {
   1139   1.4        ad 	int n8, height, cnt, slop1, slop2, clr;
   1140   1.4        ad 	struct rasops_info *ri;
   1141  1.82       rin 	uint32_t *rp, *dp, *hrp, *hp;
   1142  1.51  jmcneill 	int i;
   1143  1.30        pk 
   1144   1.4        ad 	ri = (struct rasops_info *)cookie;
   1145  1.51  jmcneill 	hrp = hp = NULL;
   1146  1.30        pk 
   1147  1.30        pk #ifdef RASOPS_CLIPPING
   1148   1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
   1149   1.4        ad 		return;
   1150   1.4        ad 
   1151   1.4        ad 	if (col < 0) {
   1152   1.4        ad 		num += col;
   1153   1.4        ad 		col = 0;
   1154   1.4        ad 	}
   1155   1.4        ad 
   1156   1.4        ad 	if ((col + num) > ri->ri_cols)
   1157   1.4        ad 		num = ri->ri_cols - col;
   1158  1.30        pk 
   1159   1.4        ad 	if (num <= 0)
   1160   1.4        ad 		return;
   1161   1.4        ad #endif
   1162  1.30        pk 
   1163   1.4        ad 	num = num * ri->ri_xscale;
   1164  1.82       rin 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
   1165  1.51  jmcneill 	if (ri->ri_hwbits)
   1166  1.82       rin 		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
   1167  1.51  jmcneill 		    col*ri->ri_xscale);
   1168   1.4        ad 	height = ri->ri_font->fontheight;
   1169  1.30        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
   1170  1.30        pk 
   1171   1.4        ad 	/* Don't bother using the full loop for <= 32 pels */
   1172   1.4        ad 	if (num <= 32) {
   1173   1.6        ad 		if (((num | ri->ri_xscale) & 3) == 0) {
   1174   1.6        ad 			/* Word aligned blt */
   1175   1.6        ad 			num >>= 2;
   1176   1.6        ad 
   1177   1.6        ad 			while (height--) {
   1178   1.6        ad 				dp = rp;
   1179  1.82       rin 				DELTA(rp, ri->ri_stride, uint32_t *);
   1180  1.51  jmcneill 				if (ri->ri_hwbits) {
   1181  1.51  jmcneill 					hp = hrp;
   1182  1.82       rin 					DELTA(hrp, ri->ri_stride, uint32_t *);
   1183  1.51  jmcneill 				}
   1184  1.30        pk 
   1185  1.51  jmcneill 				for (cnt = num; cnt; cnt--) {
   1186   1.6        ad 					*dp++ = clr;
   1187  1.51  jmcneill 					if (ri->ri_hwbits)
   1188  1.51  jmcneill 						*hp++ = clr;
   1189  1.51  jmcneill 				}
   1190   1.6        ad 			}
   1191   1.6        ad 		} else if (((num | ri->ri_xscale) & 1) == 0) {
   1192  1.30        pk 			/*
   1193   1.4        ad 			 * Halfword aligned blt. This is needed so the
   1194  1.30        pk 			 * 15/16 bit ops can use this function.
   1195   1.4        ad 			 */
   1196   1.4        ad 			num >>= 1;
   1197   1.4        ad 
   1198   1.4        ad 			while (height--) {
   1199   1.4        ad 				dp = rp;
   1200  1.82       rin 				DELTA(rp, ri->ri_stride, uint32_t *);
   1201  1.51  jmcneill 				if (ri->ri_hwbits) {
   1202  1.51  jmcneill 					hp = hrp;
   1203  1.82       rin 					DELTA(hrp, ri->ri_stride, uint32_t *);
   1204  1.51  jmcneill 				}
   1205   1.4        ad 
   1206   1.4        ad 				for (cnt = num; cnt; cnt--) {
   1207  1.82       rin 					*(uint16_t *)dp = clr;
   1208  1.82       rin 					DELTA(dp, 2, uint32_t *);
   1209  1.51  jmcneill 					if (ri->ri_hwbits) {
   1210  1.82       rin 						*(uint16_t *)hp = clr;
   1211  1.82       rin 						DELTA(hp, 2, uint32_t *);
   1212  1.51  jmcneill 					}
   1213   1.4        ad 				}
   1214   1.4        ad 			}
   1215   1.4        ad 		} else {
   1216   1.4        ad 			while (height--) {
   1217   1.4        ad 				dp = rp;
   1218  1.82       rin 				DELTA(rp, ri->ri_stride, uint32_t *);
   1219  1.51  jmcneill 				if (ri->ri_hwbits) {
   1220  1.51  jmcneill 					hp = hrp;
   1221  1.82       rin 					DELTA(hrp, ri->ri_stride, uint32_t *);
   1222  1.51  jmcneill 				}
   1223   1.4        ad 
   1224   1.4        ad 				for (cnt = num; cnt; cnt--) {
   1225  1.81       rin 					*(uint8_t *)dp = clr;
   1226  1.82       rin 					DELTA(dp, 1, uint32_t *);
   1227  1.51  jmcneill 					if (ri->ri_hwbits) {
   1228  1.81       rin 						*(uint8_t *)hp = clr;
   1229  1.82       rin 						DELTA(hp, 1, uint32_t *);
   1230  1.51  jmcneill 					}
   1231   1.4        ad 				}
   1232   1.4        ad 			}
   1233   1.4        ad 		}
   1234  1.30        pk 
   1235   1.4        ad 		return;
   1236   1.4        ad 	}
   1237  1.30        pk 
   1238  1.27  nisimura 	slop1 = (4 - ((long)rp & 3)) & 3;
   1239   1.4        ad 	slop2 = (num - slop1) & 3;
   1240   1.4        ad 	num -= slop1 + slop2;
   1241   1.4        ad 	n8 = num >> 5;
   1242   1.4        ad 	num = (num >> 2) & 7;
   1243   1.4        ad 
   1244   1.4        ad 	while (height--) {
   1245   1.4        ad 		dp = rp;
   1246  1.82       rin 		DELTA(rp, ri->ri_stride, uint32_t *);
   1247  1.51  jmcneill 		if (ri->ri_hwbits) {
   1248  1.51  jmcneill 			hp = hrp;
   1249  1.82       rin 			DELTA(hrp, ri->ri_stride, uint32_t *);
   1250  1.51  jmcneill 		}
   1251  1.30        pk 
   1252   1.4        ad 		/* Align span to 4 bytes */
   1253   1.4        ad 		if (slop1 & 1) {
   1254  1.81       rin 			*(uint8_t *)dp = clr;
   1255  1.82       rin 			DELTA(dp, 1, uint32_t *);
   1256  1.51  jmcneill 			if (ri->ri_hwbits) {
   1257  1.81       rin 				*(uint8_t *)hp = clr;
   1258  1.82       rin 				DELTA(hp, 1, uint32_t *);
   1259  1.51  jmcneill 			}
   1260   1.4        ad 		}
   1261   1.4        ad 
   1262   1.4        ad 		if (slop1 & 2) {
   1263  1.82       rin 			*(uint16_t *)dp = clr;
   1264  1.82       rin 			DELTA(dp, 2, uint32_t *);
   1265  1.51  jmcneill 			if (ri->ri_hwbits) {
   1266  1.82       rin 				*(uint16_t *)hp = clr;
   1267  1.82       rin 				DELTA(hp, 2, uint32_t *);
   1268  1.51  jmcneill 			}
   1269   1.4        ad 		}
   1270  1.30        pk 
   1271   1.4        ad 		/* Write 32 bytes per loop */
   1272   1.4        ad 		for (cnt = n8; cnt; cnt--) {
   1273  1.51  jmcneill 			for (i = 0; i < 8; i++) {
   1274  1.51  jmcneill 				dp[i] = clr;
   1275  1.51  jmcneill 				if (ri->ri_hwbits)
   1276  1.51  jmcneill 					hp[i] = clr;
   1277  1.51  jmcneill 			}
   1278   1.4        ad 			dp += 8;
   1279  1.51  jmcneill 			if (ri->ri_hwbits)
   1280  1.51  jmcneill 				hp += 8;
   1281   1.4        ad 		}
   1282  1.30        pk 
   1283  1.30        pk 		/* Write 4 bytes per loop */
   1284  1.51  jmcneill 		for (cnt = num; cnt; cnt--) {
   1285   1.4        ad 			*dp++ = clr;
   1286  1.51  jmcneill 			if (ri->ri_hwbits)
   1287  1.51  jmcneill 				*hp++ = clr;
   1288  1.51  jmcneill 		}
   1289  1.30        pk 
   1290  1.30        pk 		/* Write unaligned trailing slop */
   1291   1.4        ad 		if (slop2 & 1) {
   1292  1.81       rin 			*(uint8_t *)dp = clr;
   1293  1.82       rin 			DELTA(dp, 1, uint32_t *);
   1294  1.51  jmcneill 			if (ri->ri_hwbits) {
   1295  1.81       rin 				*(uint8_t *)hp = clr;
   1296  1.82       rin 				DELTA(hp, 1, uint32_t *);
   1297  1.51  jmcneill 			}
   1298   1.4        ad 		}
   1299   1.4        ad 
   1300  1.51  jmcneill 		if (slop2 & 2) {
   1301  1.82       rin 			*(uint16_t *)dp = clr;
   1302  1.51  jmcneill 			if (ri->ri_hwbits)
   1303  1.82       rin 				*(uint16_t *)hp = clr;
   1304  1.51  jmcneill 		}
   1305   1.4        ad 	}
   1306   1.1        ad }
   1307  1.55      ober 
   1308  1.55      ober #if NRASOPS_ROTATION > 0
   1309  1.55      ober /*
   1310  1.55      ober  * Quarter clockwise rotation routines (originally intended for the
   1311  1.55      ober  * built-in Zaurus C3x00 display in 16bpp).
   1312  1.55      ober  */
   1313  1.55      ober 
   1314  1.55      ober #include <sys/malloc.h>
   1315  1.55      ober 
   1316  1.55      ober static void
   1317  1.62    nonaka rasops_rotate_font(int *cookie, int rotate)
   1318  1.55      ober {
   1319  1.55      ober 	struct rotatedfont *f;
   1320  1.55      ober 	int ncookie;
   1321  1.55      ober 
   1322  1.55      ober 	SLIST_FOREACH(f, &rotatedfonts, rf_next) {
   1323  1.55      ober 		if (f->rf_cookie == *cookie) {
   1324  1.55      ober 			*cookie = f->rf_rotated;
   1325  1.55      ober 			return;
   1326  1.55      ober 		}
   1327  1.55      ober 	}
   1328  1.55      ober 
   1329  1.55      ober 	/*
   1330  1.55      ober 	 * We did not find a rotated version of this font. Ask the wsfont
   1331  1.55      ober 	 * code to compute one for us.
   1332  1.55      ober 	 */
   1333  1.55      ober 
   1334  1.55      ober 	f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
   1335  1.55      ober 	if (f == NULL)
   1336  1.72  riastrad 		goto fail0;
   1337  1.55      ober 
   1338  1.62    nonaka 	if ((ncookie = wsfont_rotate(*cookie, rotate)) == -1)
   1339  1.72  riastrad 		goto fail1;
   1340  1.55      ober 
   1341  1.55      ober 	f->rf_cookie = *cookie;
   1342  1.55      ober 	f->rf_rotated = ncookie;
   1343  1.55      ober 	SLIST_INSERT_HEAD(&rotatedfonts, f, rf_next);
   1344  1.55      ober 
   1345  1.55      ober 	*cookie = ncookie;
   1346  1.72  riastrad 	return;
   1347  1.72  riastrad 
   1348  1.72  riastrad fail1:	free(f, M_DEVBUF);
   1349  1.72  riastrad fail0:	/* Just use the existing font, I guess...  */
   1350  1.72  riastrad 	return;
   1351  1.55      ober }
   1352  1.55      ober 
   1353  1.55      ober static void
   1354  1.60       dsl rasops_copychar(void *cookie, int srcrow, int dstrow, int srccol, int dstcol)
   1355  1.55      ober {
   1356  1.55      ober 	struct rasops_info *ri;
   1357  1.81       rin 	uint8_t *sp, *dp;
   1358  1.55      ober 	int height;
   1359  1.55      ober 	int r_srcrow, r_dstrow, r_srccol, r_dstcol;
   1360  1.55      ober 
   1361  1.55      ober 	ri = (struct rasops_info *)cookie;
   1362  1.55      ober 
   1363  1.55      ober 	r_srcrow = srccol;
   1364  1.55      ober 	r_dstrow = dstcol;
   1365  1.55      ober 	r_srccol = ri->ri_rows - srcrow - 1;
   1366  1.55      ober 	r_dstcol = ri->ri_rows - dstrow - 1;
   1367  1.55      ober 
   1368  1.55      ober 	r_srcrow *= ri->ri_yscale;
   1369  1.55      ober 	r_dstrow *= ri->ri_yscale;
   1370  1.55      ober 	height = ri->ri_font->fontheight;
   1371  1.55      ober 
   1372  1.55      ober 	sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
   1373  1.55      ober 	dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
   1374  1.55      ober 
   1375  1.55      ober 	while (height--) {
   1376  1.55      ober 		memmove(dp, sp, ri->ri_xscale);
   1377  1.55      ober 		dp += ri->ri_stride;
   1378  1.55      ober 		sp += ri->ri_stride;
   1379  1.55      ober 	}
   1380  1.55      ober }
   1381  1.55      ober 
   1382  1.55      ober static void
   1383  1.62    nonaka rasops_putchar_rotated_cw(void *cookie, int row, int col, u_int uc, long attr)
   1384  1.55      ober {
   1385  1.55      ober 	struct rasops_info *ri;
   1386  1.81       rin 	uint8_t *rp;
   1387  1.55      ober 	int height;
   1388  1.55      ober 
   1389  1.55      ober 	ri = (struct rasops_info *)cookie;
   1390  1.55      ober 
   1391  1.56       mjf 	if (__predict_false((unsigned int)row > ri->ri_rows ||
   1392  1.56       mjf 	    (unsigned int)col > ri->ri_cols))
   1393  1.56       mjf 		return;
   1394  1.56       mjf 
   1395  1.56       mjf 	/* Avoid underflow */
   1396  1.56       mjf 	if ((ri->ri_rows - row - 1) < 0)
   1397  1.56       mjf 		return;
   1398  1.56       mjf 
   1399  1.55      ober 	/* Do rotated char sans (side)underline */
   1400  1.55      ober 	ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
   1401  1.79   mlelstv 	    attr & ~WSATTR_UNDERLINE);
   1402  1.55      ober 
   1403  1.55      ober 	/* Do rotated underline */
   1404  1.55      ober 	rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) *
   1405  1.55      ober 	    ri->ri_xscale;
   1406  1.55      ober 	height = ri->ri_font->fontheight;
   1407  1.55      ober 
   1408  1.55      ober 	/* XXX this assumes 16-bit color depth */
   1409  1.79   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
   1410  1.82       rin 		uint16_t c =
   1411  1.82       rin 		    (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
   1412  1.55      ober 
   1413  1.55      ober 		while (height--) {
   1414  1.82       rin 			*(uint16_t *)rp = c;
   1415  1.55      ober 			rp += ri->ri_stride;
   1416  1.55      ober 		}
   1417  1.55      ober 	}
   1418  1.55      ober }
   1419  1.55      ober 
   1420  1.55      ober static void
   1421  1.62    nonaka rasops_erasecols_rotated_cw(void *cookie, int row, int col, int num, long attr)
   1422  1.55      ober {
   1423  1.55      ober 	struct rasops_info *ri;
   1424  1.55      ober 	int i;
   1425  1.55      ober 
   1426  1.55      ober 	ri = (struct rasops_info *)cookie;
   1427  1.55      ober 
   1428  1.55      ober 	for (i = col; i < col + num; i++)
   1429  1.55      ober 		ri->ri_ops.putchar(cookie, row, i, ' ', attr);
   1430  1.55      ober }
   1431  1.55      ober 
   1432  1.55      ober /* XXX: these could likely be optimised somewhat. */
   1433  1.55      ober static void
   1434  1.62    nonaka rasops_copyrows_rotated_cw(void *cookie, int src, int dst, int num)
   1435  1.55      ober {
   1436  1.55      ober 	struct rasops_info *ri = (struct rasops_info *)cookie;
   1437  1.55      ober 	int col, roff;
   1438  1.55      ober 
   1439  1.55      ober 	if (src > dst)
   1440  1.55      ober 		for (roff = 0; roff < num; roff++)
   1441  1.55      ober 			for (col = 0; col < ri->ri_cols; col++)
   1442  1.55      ober 				rasops_copychar(cookie, src + roff, dst + roff,
   1443  1.55      ober 				    col, col);
   1444  1.55      ober 	else
   1445  1.55      ober 		for (roff = num - 1; roff >= 0; roff--)
   1446  1.55      ober 			for (col = 0; col < ri->ri_cols; col++)
   1447  1.55      ober 				rasops_copychar(cookie, src + roff, dst + roff,
   1448  1.55      ober 				    col, col);
   1449  1.55      ober }
   1450  1.55      ober 
   1451  1.55      ober static void
   1452  1.62    nonaka rasops_copycols_rotated_cw(void *cookie, int row, int src, int dst, int num)
   1453  1.55      ober {
   1454  1.55      ober 	int coff;
   1455  1.55      ober 
   1456  1.55      ober 	if (src > dst)
   1457  1.55      ober 		for (coff = 0; coff < num; coff++)
   1458  1.55      ober 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1459  1.55      ober 	else
   1460  1.55      ober 		for (coff = num - 1; coff >= 0; coff--)
   1461  1.55      ober 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1462  1.55      ober }
   1463  1.55      ober 
   1464  1.55      ober static void
   1465  1.62    nonaka rasops_eraserows_rotated_cw(void *cookie, int row, int num, long attr)
   1466  1.55      ober {
   1467  1.55      ober 	struct rasops_info *ri;
   1468  1.55      ober 	int col, rn;
   1469  1.55      ober 
   1470  1.55      ober 	ri = (struct rasops_info *)cookie;
   1471  1.55      ober 
   1472  1.55      ober 	for (rn = row; rn < row + num; rn++)
   1473  1.55      ober 		for (col = 0; col < ri->ri_cols; col++)
   1474  1.55      ober 			ri->ri_ops.putchar(cookie, rn, col, ' ', attr);
   1475  1.55      ober }
   1476  1.62    nonaka 
   1477  1.62    nonaka /*
   1478  1.62    nonaka  * Quarter counter-clockwise rotation routines (originally intended for the
   1479  1.62    nonaka  * built-in Sharp W-ZERO3 display in 16bpp).
   1480  1.62    nonaka  */
   1481  1.62    nonaka static void
   1482  1.62    nonaka rasops_copychar_ccw(void *cookie, int srcrow, int dstrow, int srccol, int dstcol)
   1483  1.62    nonaka {
   1484  1.62    nonaka 	struct rasops_info *ri;
   1485  1.81       rin 	uint8_t *sp, *dp;
   1486  1.62    nonaka 	int height;
   1487  1.62    nonaka 	int r_srcrow, r_dstrow, r_srccol, r_dstcol;
   1488  1.62    nonaka 
   1489  1.62    nonaka 	ri = (struct rasops_info *)cookie;
   1490  1.62    nonaka 
   1491  1.62    nonaka 	r_srcrow = ri->ri_cols - srccol - 1;
   1492  1.62    nonaka 	r_dstrow = ri->ri_cols - dstcol - 1;
   1493  1.62    nonaka 	r_srccol = srcrow;
   1494  1.62    nonaka 	r_dstcol = dstrow;
   1495  1.62    nonaka 
   1496  1.62    nonaka 	r_srcrow *= ri->ri_yscale;
   1497  1.62    nonaka 	r_dstrow *= ri->ri_yscale;
   1498  1.62    nonaka 	height = ri->ri_font->fontheight;
   1499  1.62    nonaka 
   1500  1.62    nonaka 	sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
   1501  1.62    nonaka 	dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
   1502  1.62    nonaka 
   1503  1.62    nonaka 	while (height--) {
   1504  1.62    nonaka 		memmove(dp, sp, ri->ri_xscale);
   1505  1.62    nonaka 		dp += ri->ri_stride;
   1506  1.62    nonaka 		sp += ri->ri_stride;
   1507  1.62    nonaka 	}
   1508  1.62    nonaka }
   1509  1.62    nonaka 
   1510  1.62    nonaka static void
   1511  1.62    nonaka rasops_putchar_rotated_ccw(void *cookie, int row, int col, u_int uc, long attr)
   1512  1.62    nonaka {
   1513  1.62    nonaka 	struct rasops_info *ri;
   1514  1.81       rin 	uint8_t *rp;
   1515  1.62    nonaka 	int height;
   1516  1.62    nonaka 
   1517  1.62    nonaka 	ri = (struct rasops_info *)cookie;
   1518  1.62    nonaka 
   1519  1.62    nonaka 	if (__predict_false((unsigned int)row > ri->ri_rows ||
   1520  1.62    nonaka 	    (unsigned int)col > ri->ri_cols))
   1521  1.62    nonaka 		return;
   1522  1.62    nonaka 
   1523  1.62    nonaka 	/* Avoid underflow */
   1524  1.62    nonaka 	if ((ri->ri_cols - col - 1) < 0)
   1525  1.62    nonaka 		return;
   1526  1.62    nonaka 
   1527  1.62    nonaka 	/* Do rotated char sans (side)underline */
   1528  1.62    nonaka 	ri->ri_real_ops.putchar(cookie, ri->ri_cols - col - 1, row, uc,
   1529  1.79   mlelstv 	    attr & ~WSATTR_UNDERLINE);
   1530  1.62    nonaka 
   1531  1.62    nonaka 	/* Do rotated underline */
   1532  1.62    nonaka 	rp = ri->ri_bits + (ri->ri_cols - col - 1) * ri->ri_yscale +
   1533  1.65   tsutsui 	    row * ri->ri_xscale +
   1534  1.65   tsutsui 	    (ri->ri_font->fontwidth - 1) * ri->ri_pelbytes;
   1535  1.62    nonaka 	height = ri->ri_font->fontheight;
   1536  1.62    nonaka 
   1537  1.62    nonaka 	/* XXX this assumes 16-bit color depth */
   1538  1.79   mlelstv 	if ((attr & WSATTR_UNDERLINE) != 0) {
   1539  1.82       rin 		uint16_t c =
   1540  1.82       rin 		    (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
   1541  1.62    nonaka 
   1542  1.62    nonaka 		while (height--) {
   1543  1.82       rin 			*(uint16_t *)rp = c;
   1544  1.62    nonaka 			rp += ri->ri_stride;
   1545  1.62    nonaka 		}
   1546  1.62    nonaka 	}
   1547  1.62    nonaka }
   1548  1.62    nonaka 
   1549  1.62    nonaka /* XXX: these could likely be optimised somewhat. */
   1550  1.62    nonaka static void
   1551  1.62    nonaka rasops_copyrows_rotated_ccw(void *cookie, int src, int dst, int num)
   1552  1.62    nonaka {
   1553  1.62    nonaka 	struct rasops_info *ri = (struct rasops_info *)cookie;
   1554  1.62    nonaka 	int col, roff;
   1555  1.62    nonaka 
   1556  1.62    nonaka 	if (src > dst)
   1557  1.62    nonaka 		for (roff = 0; roff < num; roff++)
   1558  1.62    nonaka 			for (col = 0; col < ri->ri_cols; col++)
   1559  1.62    nonaka 				rasops_copychar_ccw(cookie,
   1560  1.62    nonaka 				    src + roff, dst + roff, col, col);
   1561  1.62    nonaka 	else
   1562  1.62    nonaka 		for (roff = num - 1; roff >= 0; roff--)
   1563  1.62    nonaka 			for (col = 0; col < ri->ri_cols; col++)
   1564  1.62    nonaka 				rasops_copychar_ccw(cookie,
   1565  1.62    nonaka 				    src + roff, dst + roff, col, col);
   1566  1.62    nonaka }
   1567  1.62    nonaka 
   1568  1.62    nonaka static void
   1569  1.62    nonaka rasops_copycols_rotated_ccw(void *cookie, int row, int src, int dst, int num)
   1570  1.62    nonaka {
   1571  1.62    nonaka 	int coff;
   1572  1.62    nonaka 
   1573  1.62    nonaka 	if (src > dst)
   1574  1.62    nonaka 		for (coff = 0; coff < num; coff++)
   1575  1.62    nonaka 			rasops_copychar_ccw(cookie, row, row,
   1576  1.62    nonaka 			    src + coff, dst + coff);
   1577  1.62    nonaka 	else
   1578  1.62    nonaka 		for (coff = num - 1; coff >= 0; coff--)
   1579  1.62    nonaka 			rasops_copychar_ccw(cookie, row, row,
   1580  1.62    nonaka 			    src + coff, dst + coff);
   1581  1.62    nonaka }
   1582  1.55      ober #endif	/* NRASOPS_ROTATION */
   1583  1.63  macallan 
   1584  1.63  macallan void
   1585  1.63  macallan rasops_make_box_chars_16(struct rasops_info *ri)
   1586  1.63  macallan {
   1587  1.63  macallan 	uint16_t vert_mask, hmask_left, hmask_right;
   1588  1.63  macallan 	uint16_t *data = (uint16_t *)ri->ri_optfont.data;
   1589  1.63  macallan 	int c, i, mid;
   1590  1.63  macallan 
   1591  1.63  macallan 	vert_mask = 0xc000 >> ((ri->ri_font->fontwidth >> 1) - 1);
   1592  1.63  macallan 	hmask_left = 0xff00 << (8 - (ri->ri_font->fontwidth >> 1));
   1593  1.63  macallan 	hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1)>> 1);
   1594  1.63  macallan 	mid = (ri->ri_font->fontheight + 1) >> 1;
   1595  1.63  macallan 
   1596  1.63  macallan 	/* 0x00 would be empty anyway so don't bother */
   1597  1.63  macallan 	for (c = 1; c < 16; c++) {
   1598  1.63  macallan 		data += ri->ri_font->fontheight;
   1599  1.63  macallan 		if (c & 1) {
   1600  1.63  macallan 			/* upper segment */
   1601  1.63  macallan 			for (i = 0; i < mid; i++)
   1602  1.63  macallan 				data[i] = vert_mask;
   1603  1.63  macallan 		}
   1604  1.63  macallan 		if (c & 4) {
   1605  1.63  macallan 			/* lower segment */
   1606  1.63  macallan 			for (i = mid; i < ri->ri_font->fontheight; i++)
   1607  1.63  macallan 				data[i] = vert_mask;
   1608  1.63  macallan 		}
   1609  1.63  macallan 		if (c & 2) {
   1610  1.63  macallan 			/* right segment */
   1611  1.63  macallan 			i = ri->ri_font->fontheight >> 1;
   1612  1.63  macallan 			data[mid - 1] |= hmask_right;
   1613  1.63  macallan 			data[mid] |= hmask_right;
   1614  1.63  macallan 		}
   1615  1.63  macallan 		if (c & 8) {
   1616  1.63  macallan 			/* left segment */
   1617  1.63  macallan 			data[mid - 1] |= hmask_left;
   1618  1.63  macallan 			data[mid] |= hmask_left;
   1619  1.63  macallan 		}
   1620  1.63  macallan 	}
   1621  1.63  macallan }
   1622  1.63  macallan 
   1623  1.63  macallan void
   1624  1.63  macallan rasops_make_box_chars_8(struct rasops_info *ri)
   1625  1.63  macallan {
   1626  1.63  macallan 	uint8_t vert_mask, hmask_left, hmask_right;
   1627  1.63  macallan 	uint8_t *data = (uint8_t *)ri->ri_optfont.data;
   1628  1.63  macallan 	int c, i, mid;
   1629  1.63  macallan 
   1630  1.63  macallan 	vert_mask = 0xc0 >> ((ri->ri_font->fontwidth >> 1) - 1);
   1631  1.63  macallan 	hmask_left = 0xf0 << (4 - (ri->ri_font->fontwidth >> 1));
   1632  1.63  macallan 	hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1)>> 1);
   1633  1.63  macallan 	mid = (ri->ri_font->fontheight + 1) >> 1;
   1634  1.63  macallan 
   1635  1.63  macallan 	/* 0x00 would be empty anyway so don't bother */
   1636  1.63  macallan 	for (c = 1; c < 16; c++) {
   1637  1.63  macallan 		data += ri->ri_font->fontheight;
   1638  1.63  macallan 		if (c & 1) {
   1639  1.63  macallan 			/* upper segment */
   1640  1.63  macallan 			for (i = 0; i < mid; i++)
   1641  1.63  macallan 				data[i] = vert_mask;
   1642  1.63  macallan 		}
   1643  1.63  macallan 		if (c & 4) {
   1644  1.63  macallan 			/* lower segment */
   1645  1.63  macallan 			for (i = mid; i < ri->ri_font->fontheight; i++)
   1646  1.63  macallan 				data[i] = vert_mask;
   1647  1.63  macallan 		}
   1648  1.63  macallan 		if (c & 2) {
   1649  1.63  macallan 			/* right segment */
   1650  1.63  macallan 			i = ri->ri_font->fontheight >> 1;
   1651  1.63  macallan 			data[mid - 1] |= hmask_right;
   1652  1.63  macallan 			data[mid] |= hmask_right;
   1653  1.63  macallan 		}
   1654  1.63  macallan 		if (c & 8) {
   1655  1.63  macallan 			/* left segment */
   1656  1.63  macallan 			data[mid - 1] |= hmask_left;
   1657  1.63  macallan 			data[mid] |= hmask_left;
   1658  1.63  macallan 		}
   1659  1.63  macallan 	}
   1660  1.63  macallan }
   1661  1.63  macallan 
   1662  1.63  macallan void
   1663  1.63  macallan rasops_make_box_chars_32(struct rasops_info *ri)
   1664  1.63  macallan {
   1665  1.63  macallan 	uint32_t vert_mask, hmask_left, hmask_right;
   1666  1.63  macallan 	uint32_t *data = (uint32_t *)ri->ri_optfont.data;
   1667  1.63  macallan 	int c, i, mid;
   1668  1.63  macallan 
   1669  1.63  macallan 	vert_mask = 0xc0000000 >> ((ri->ri_font->fontwidth >> 1) - 1);
   1670  1.63  macallan 	hmask_left = 0xffff0000 << (16 - (ri->ri_font->fontwidth >> 1));
   1671  1.63  macallan 	hmask_right = hmask_left >> ((ri->ri_font->fontwidth + 1)>> 1);
   1672  1.63  macallan 	mid = (ri->ri_font->fontheight + 1) >> 1;
   1673  1.63  macallan 
   1674  1.63  macallan 	/* 0x00 would be empty anyway so don't bother */
   1675  1.63  macallan 	for (c = 1; c < 16; c++) {
   1676  1.63  macallan 		data += ri->ri_font->fontheight;
   1677  1.63  macallan 		if (c & 1) {
   1678  1.63  macallan 			/* upper segment */
   1679  1.63  macallan 			for (i = 0; i < mid; i++)
   1680  1.63  macallan 				data[i] = vert_mask;
   1681  1.63  macallan 		}
   1682  1.63  macallan 		if (c & 4) {
   1683  1.63  macallan 			/* lower segment */
   1684  1.63  macallan 			for (i = mid; i < ri->ri_font->fontheight; i++)
   1685  1.63  macallan 				data[i] = vert_mask;
   1686  1.63  macallan 		}
   1687  1.63  macallan 		if (c & 2) {
   1688  1.63  macallan 			/* right segment */
   1689  1.63  macallan 			i = ri->ri_font->fontheight >> 1;
   1690  1.63  macallan 			data[mid - 1] |= hmask_right;
   1691  1.63  macallan 			data[mid] |= hmask_right;
   1692  1.63  macallan 		}
   1693  1.63  macallan 		if (c & 8) {
   1694  1.63  macallan 			/* left segment */
   1695  1.63  macallan 			data[mid - 1] |= hmask_left;
   1696  1.63  macallan 			data[mid] |= hmask_left;
   1697  1.63  macallan 		}
   1698  1.63  macallan 	}
   1699  1.63  macallan }
   1700  1.67  macallan 
   1701  1.67  macallan void
   1702  1.67  macallan rasops_make_box_chars_alpha(struct rasops_info *ri)
   1703  1.67  macallan {
   1704  1.67  macallan 	uint8_t *data = (uint8_t *)ri->ri_optfont.data;
   1705  1.67  macallan 	uint8_t *ddata;
   1706  1.67  macallan 	int c, i, hmid, vmid, wi, he;
   1707  1.67  macallan 
   1708  1.67  macallan 	wi = ri->ri_font->fontwidth;
   1709  1.67  macallan 	he = ri->ri_font->fontheight;
   1710  1.67  macallan 
   1711  1.67  macallan 	vmid = (he + 1) >> 1;
   1712  1.67  macallan 	hmid = (wi + 1) >> 1;
   1713  1.67  macallan 
   1714  1.67  macallan 	/* 0x00 would be empty anyway so don't bother */
   1715  1.67  macallan 	for (c = 1; c < 16; c++) {
   1716  1.67  macallan 		data += ri->ri_fontscale;
   1717  1.67  macallan 		if (c & 1) {
   1718  1.67  macallan 			/* upper segment */
   1719  1.67  macallan 			ddata = data + hmid;
   1720  1.67  macallan 			for (i = 0; i <= vmid; i++) {
   1721  1.67  macallan 				*ddata = 0xff;
   1722  1.67  macallan 				ddata += wi;
   1723  1.67  macallan 			}
   1724  1.67  macallan 		}
   1725  1.67  macallan 		if (c & 4) {
   1726  1.67  macallan 			/* lower segment */
   1727  1.67  macallan 			ddata = data + wi * vmid + hmid;
   1728  1.67  macallan 			for (i = vmid; i < he; i++) {
   1729  1.67  macallan 				*ddata = 0xff;
   1730  1.67  macallan 				ddata += wi;
   1731  1.67  macallan 			}
   1732  1.67  macallan 		}
   1733  1.67  macallan 		if (c & 2) {
   1734  1.67  macallan 			/* right segment */
   1735  1.67  macallan 			ddata = data + wi * vmid + hmid;
   1736  1.67  macallan 			for (i = hmid; i < wi; i++) {
   1737  1.67  macallan 				*ddata = 0xff;
   1738  1.67  macallan 				ddata++;
   1739  1.67  macallan 			}
   1740  1.67  macallan 		}
   1741  1.67  macallan 		if (c & 8) {
   1742  1.67  macallan 			/* left segment */
   1743  1.67  macallan 			ddata = data + wi * vmid;
   1744  1.67  macallan 			for (i = 0; i <= hmid; i++) {
   1745  1.67  macallan 				*ddata = 0xff;
   1746  1.67  macallan 				ddata++;
   1747  1.67  macallan 			}
   1748  1.67  macallan 		}
   1749  1.67  macallan 	}
   1750  1.67  macallan }
   1751  1.75  macallan 
   1752  1.71  macallan /*
   1753  1.71  macallan  * Return a colour map appropriate for the given struct rasops_info in the
   1754  1.71  macallan  * same form used by rasops_cmap[]
   1755  1.71  macallan  * For now this is either a copy of rasops_cmap[] or an R3G3B2 map, it should
   1756  1.71  macallan  * probably be a linear ( or gamma corrected? ) ramp for higher depths.
   1757  1.71  macallan  */
   1758  1.71  macallan 
   1759  1.71  macallan int
   1760  1.71  macallan rasops_get_cmap(struct rasops_info *ri, uint8_t *palette, size_t bytes)
   1761  1.71  macallan {
   1762  1.71  macallan 	if ((ri->ri_depth == 8 ) && ((ri->ri_flg & RI_8BIT_IS_RGB) > 0)) {
   1763  1.71  macallan 		/* generate an R3G3B2 palette */
   1764  1.71  macallan 		int i, idx = 0;
   1765  1.71  macallan 		uint8_t tmp;
   1766  1.71  macallan 
   1767  1.71  macallan 		if (bytes < 768)
   1768  1.71  macallan 			return EINVAL;
   1769  1.71  macallan 		for (i = 0; i < 256; i++) {
   1770  1.71  macallan 			tmp = i & 0xe0;
   1771  1.71  macallan 			/*
   1772  1.71  macallan 			 * replicate bits so 0xe0 maps to a red value of 0xff
   1773  1.71  macallan 			 * in order to make white look actually white
   1774  1.71  macallan 			 */
   1775  1.71  macallan 			tmp |= (tmp >> 3) | (tmp >> 6);
   1776  1.71  macallan 			palette[idx] = tmp;
   1777  1.71  macallan 			idx++;
   1778  1.71  macallan 
   1779  1.71  macallan 			tmp = (i & 0x1c) << 3;
   1780  1.71  macallan 			tmp |= (tmp >> 3) | (tmp >> 6);
   1781  1.71  macallan 			palette[idx] = tmp;
   1782  1.71  macallan 			idx++;
   1783  1.71  macallan 
   1784  1.71  macallan 			tmp = (i & 0x03) << 6;
   1785  1.71  macallan 			tmp |= tmp >> 2;
   1786  1.71  macallan 			tmp |= tmp >> 4;
   1787  1.71  macallan 			palette[idx] = tmp;
   1788  1.71  macallan 			idx++;
   1789  1.71  macallan 		}
   1790  1.71  macallan 	} else {
   1791  1.71  macallan 		memcpy(palette, rasops_cmap, MIN(bytes, sizeof(rasops_cmap)));
   1792  1.71  macallan 	}
   1793  1.71  macallan 	return 0;
   1794  1.71  macallan }
   1795