Home | History | Annotate | Line # | Download | only in rasops
rasops4.c revision 1.22
      1 /* 	$NetBSD: rasops4.c,v 1.22 2019/07/31 02:04:14 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: rasops4.c,v 1.22 2019/07/31 02:04:14 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 #include <dev/rasops/rasops.h>
     47 #include <dev/rasops/rasops_masks.h>
     48 
     49 static void	rasops4_copycols(void *, int, int, int, int);
     50 static void	rasops4_erasecols(void *, int, int, int, long);
     51 static void	rasops4_do_cursor(struct rasops_info *);
     52 static void	rasops4_putchar(void *, int, int col, u_int, long);
     53 #ifndef RASOPS_SMALL
     54 static void	rasops4_putchar8(void *, int, int col, u_int, long);
     55 static void	rasops4_putchar12(void *, int, int col, u_int, long);
     56 static void	rasops4_putchar16(void *, int, int col, u_int, long);
     57 static void	rasops4_makestamp(struct rasops_info *, long);
     58 #endif
     59 
     60 /*
     61  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     62  * destination = STAMP_READ(offset)
     63  */
     64 #define STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
     65 #define STAMP_MASK		0xf
     66 #define STAMP_READ(o)		stamp[o]
     67 
     68 /*
     69  * Initialize rasops_info struct for this colordepth.
     70  */
     71 void
     72 rasops4_init(struct rasops_info *ri)
     73 {
     74 
     75 	if ((ri->ri_font->fontwidth & 1) != 0) {
     76 		ri->ri_ops.erasecols = rasops4_erasecols;
     77 		ri->ri_ops.copycols = rasops4_copycols;
     78 		ri->ri_do_cursor = rasops4_do_cursor;
     79 	}
     80 
     81 	switch (ri->ri_font->fontwidth) {
     82 #ifndef RASOPS_SMALL
     83 	case 8:
     84 		ri->ri_ops.putchar = rasops4_putchar8;
     85 		break;
     86 	case 12:
     87 		ri->ri_ops.putchar = rasops4_putchar12;
     88 		break;
     89 	case 16:
     90 		ri->ri_ops.putchar = rasops4_putchar16;
     91 		break;
     92 #endif	/* !RASOPS_SMALL */
     93 	default:
     94 		panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
     95 		ri->ri_ops.putchar = rasops4_putchar;
     96 		return;
     97 	}
     98 
     99 #ifndef RASOPS_SMALL
    100 	rasops_allocstamp(ri, sizeof(uint16_t) * 16);
    101 #endif
    102 }
    103 
    104 /*
    105  * Put a single character. This is the generic version.
    106  */
    107 static void
    108 rasops4_putchar(void *cookie, int row, int col, u_int uc, long attr)
    109 {
    110 
    111 	/* XXX punt */
    112 }
    113 
    114 #ifndef RASOPS_SMALL
    115 /*
    116  * Recompute the blitting stamp.
    117  */
    118 static void
    119 rasops4_makestamp(struct rasops_info *ri, long attr)
    120 {
    121 	uint16_t *stamp = (uint16_t *)ri->ri_stamp;
    122 	int i, fg, bg;
    123 
    124 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xf;
    125 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xf;
    126 	ri->ri_stamp_attr = attr;
    127 
    128 	for (i = 0; i < 16; i++) {
    129 #if BYTE_ORDER == BIG_ENDIAN
    130 #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    131 #else
    132 #define NEED_LITTLE_ENDIAN_STAMP 0
    133 #endif
    134 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    135 			/* little endian */
    136 			stamp[i]  = (i & 1 ? fg : bg) << 12;
    137 			stamp[i] |= (i & 2 ? fg : bg) << 8;
    138 			stamp[i] |= (i & 4 ? fg : bg) << 4;
    139 			stamp[i] |= (i & 8 ? fg : bg) << 0;
    140 		} else {
    141 			/* big endian */
    142 			stamp[i]  = (i & 1 ? fg : bg) << 0;
    143 			stamp[i] |= (i & 2 ? fg : bg) << 4;
    144 			stamp[i] |= (i & 4 ? fg : bg) << 8;
    145 			stamp[i] |= (i & 8 ? fg : bg) << 12;
    146 		}
    147 	}
    148 }
    149 
    150 #define	RASOPS_DEPTH	4
    151 
    152 #define	RASOPS_WIDTH	8
    153 #include "rasops_putchar_width.h"
    154 #undef	RASOPS_WIDTH
    155 
    156 #define	RASOPS_WIDTH	12
    157 #include "rasops_putchar_width.h"
    158 #undef	RASOPS_WIDTH
    159 
    160 #define	RASOPS_WIDTH	16
    161 #include "rasops_putchar_width.h"
    162 #undef	RASOPS_WIDTH
    163 
    164 #endif	/* !RASOPS_SMALL */
    165 
    166 /*
    167  * Grab routines common to depths where (bpp < 8)
    168  */
    169 #define NAME(ident)	rasops4_##ident
    170 #define PIXEL_SHIFT	3
    171 
    172 #include <dev/rasops/rasops_bitops.h>
    173