Home | History | Annotate | Line # | Download | only in rasops
rasops2.c revision 1.30
      1 /* 	$NetBSD: rasops2.c,v 1.30 2019/08/07 11:47:33 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.30 2019/08/07 11:47:33 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 #ifndef RASOPS_SMALL
     62 /* 4x1 stamp for optimized character blitting */
     63 static uint8_t			stamp[16];
     64 static long			stamp_attr;
     65 static struct rasops_info	*stamp_ri;
     66 
     67 /*
     68  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     69  * destination = STAMP_READ(offset)
     70  */
     71 #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     72 #define	STAMP_MASK		0xf
     73 #define	STAMP_READ(o)		stamp[o]
     74 #endif
     75 
     76 /*
     77  * Initialize rasops_info struct for this colordepth.
     78  */
     79 void
     80 rasops2_init(struct rasops_info *ri)
     81 {
     82 
     83 	if ((ri->ri_font->fontwidth & 3) != 0) {
     84 		ri->ri_ops.erasecols = rasops2_erasecols;
     85 		ri->ri_ops.copycols = rasops2_copycols;
     86 		ri->ri_do_cursor = rasops2_do_cursor;
     87 	}
     88 
     89 	switch (ri->ri_font->fontwidth) {
     90 #ifndef RASOPS_SMALL
     91 	case 8:
     92 		ri->ri_ops.putchar = rasops2_putchar8;
     93 		break;
     94 	case 12:
     95 		ri->ri_ops.putchar = rasops2_putchar12;
     96 		break;
     97 	case 16:
     98 		ri->ri_ops.putchar = rasops2_putchar16;
     99 		break;
    100 #endif
    101 	default:
    102 		ri->ri_ops.putchar = rasops2_putchar;
    103 		return;
    104 	}
    105 
    106 #ifndef RASOPS_SMALL
    107 	stamp_attr = 0;
    108 	stamp_ri = NULL;
    109 #endif
    110 }
    111 
    112 #ifndef RASOPS_SMALL
    113 /*
    114  * Recompute the blitting stamp.
    115  */
    116 static void
    117 rasops2_makestamp(struct rasops_info *ri, long attr)
    118 {
    119 	int i, fg, bg;
    120 
    121 	stamp_attr = attr;
    122 	stamp_ri = ri;
    123 
    124 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
    125 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
    126 
    127 	for (i = 0; i < 16; i++) {
    128 #if BYTE_ORDER == BIG_ENDIAN
    129 #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    130 #else
    131 #define NEED_LITTLE_ENDIAN_STAMP 0
    132 #endif
    133 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    134 			/* littel endian */
    135 			stamp[i]  = (i & 8 ? fg : bg);
    136 			stamp[i] |= (i & 4 ? fg : bg) << 2;
    137 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    138 			stamp[i] |= (i & 1 ? fg : bg) << 6;
    139 		} else {
    140 			/* big endian */
    141 			stamp[i]  = (i & 1 ? fg : bg);
    142 			stamp[i] |= (i & 2 ? fg : bg) << 2;
    143 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    144 			stamp[i] |= (i & 8 ? fg : bg) << 6;
    145 		}
    146 	}
    147 }
    148 
    149 #define	RASOPS_WIDTH	8
    150 #include "rasops_putchar_width.h"
    151 #undef	RASOPS_WIDTH
    152 
    153 #define	RASOPS_WIDTH	12
    154 #include "rasops_putchar_width.h"
    155 #undef	RASOPS_WIDTH
    156 
    157 #define	RASOPS_WIDTH	16
    158 #include "rasops_putchar_width.h"
    159 #undef	RASOPS_WIDTH
    160 
    161 #endif	/* !RASOPS_SMALL */
    162 
    163 /*
    164  * Grab routines common to depths where (bpp < 8)
    165  */
    166 #include <dev/rasops/rasops_bitops.h>
    167