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