Home | History | Annotate | Line # | Download | only in rasops
rasops2.c revision 1.29
      1 /* 	$NetBSD: rasops2.c,v 1.29 2019/08/02 04:39:09 rin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.29 2019/08/02 04:39:09 rin Exp $");
     34 
     35 #include "opt_rasops.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/time.h>
     40 #include <machine/endian.h>
     41 
     42 #include <dev/wscons/wsdisplayvar.h>
     43 #include <dev/wscons/wsconsio.h>
     44 
     45 #define	_RASOPS_PRIVATE
     46 #define	RASOPS_DEPTH	2
     47 #include <dev/rasops/rasops.h>
     48 #include <dev/rasops/rasops_masks.h>
     49 
     50 static void	rasops2_copycols(void *, int, int, int, int);
     51 static void	rasops2_erasecols(void *, int, int, int, long);
     52 static void	rasops2_do_cursor(struct rasops_info *);
     53 static void	rasops2_putchar(void *, int, int col, u_int, long);
     54 #ifndef RASOPS_SMALL
     55 static void	rasops2_putchar8(void *, int, int col, u_int, long);
     56 static void	rasops2_putchar12(void *, int, int col, u_int, long);
     57 static void	rasops2_putchar16(void *, int, int col, u_int, long);
     58 static void	rasops2_makestamp(struct rasops_info *, long);
     59 #endif
     60 
     61 /*
     62  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     63  * destination = STAMP_READ(offset)
     64  */
     65 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     66 #define	STAMP_MASK		0xf
     67 #define	STAMP_READ(o)		stamp[o]
     68 
     69 /*
     70  * Initialize rasops_info struct for this colordepth.
     71  */
     72 void
     73 rasops2_init(struct rasops_info *ri)
     74 {
     75 
     76 	if ((ri->ri_font->fontwidth & 3) != 0) {
     77 		ri->ri_ops.erasecols = rasops2_erasecols;
     78 		ri->ri_ops.copycols = rasops2_copycols;
     79 		ri->ri_do_cursor = rasops2_do_cursor;
     80 	}
     81 
     82 	switch (ri->ri_font->fontwidth) {
     83 #ifndef RASOPS_SMALL
     84 	case 8:
     85 		ri->ri_ops.putchar = rasops2_putchar8;
     86 		break;
     87 	case 12:
     88 		ri->ri_ops.putchar = rasops2_putchar12;
     89 		break;
     90 	case 16:
     91 		ri->ri_ops.putchar = rasops2_putchar16;
     92 		break;
     93 #endif	/* !RASOPS_SMALL */
     94 	default:
     95 		ri->ri_ops.putchar = rasops2_putchar;
     96 		return;
     97 	}
     98 
     99 #ifndef RASOPS_SMALL
    100 	rasops_allocstamp(ri, sizeof(uint8_t) * 16);
    101 #endif
    102 }
    103 
    104 #ifndef RASOPS_SMALL
    105 /*
    106  * Recompute the blitting stamp.
    107  */
    108 static void
    109 rasops2_makestamp(struct rasops_info *ri, long attr)
    110 {
    111 	uint8_t *stamp = (uint8_t *)ri->ri_stamp;
    112 	int i, fg, bg;
    113 
    114 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
    115 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
    116 	ri->ri_stamp_attr = attr;
    117 
    118 	for (i = 0; i < 16; i++) {
    119 #if BYTE_ORDER == BIG_ENDIAN
    120 #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    121 #else
    122 #define NEED_LITTLE_ENDIAN_STAMP 0
    123 #endif
    124 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    125 			/* littel endian */
    126 			stamp[i]  = (i & 8 ? fg : bg);
    127 			stamp[i] |= (i & 4 ? fg : bg) << 2;
    128 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    129 			stamp[i] |= (i & 1 ? fg : bg) << 6;
    130 		} else {
    131 			/* big endian */
    132 			stamp[i]  = (i & 1 ? fg : bg);
    133 			stamp[i] |= (i & 2 ? fg : bg) << 2;
    134 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    135 			stamp[i] |= (i & 8 ? fg : bg) << 6;
    136 		}
    137 	}
    138 }
    139 
    140 #define	RASOPS_WIDTH	8
    141 #include "rasops_putchar_width.h"
    142 #undef	RASOPS_WIDTH
    143 
    144 #define	RASOPS_WIDTH	12
    145 #include "rasops_putchar_width.h"
    146 #undef	RASOPS_WIDTH
    147 
    148 #define	RASOPS_WIDTH	16
    149 #include "rasops_putchar_width.h"
    150 #undef	RASOPS_WIDTH
    151 
    152 #endif	/* !RASOPS_SMALL */
    153 
    154 /*
    155  * Grab routines common to depths where (bpp < 8)
    156  */
    157 #include <dev/rasops/rasops_bitops.h>
    158