Home | History | Annotate | Line # | Download | only in rasops
rasops8.c revision 1.34.30.2
      1  1.34.30.2    martin /* 	$NetBSD: rasops8.c,v 1.34.30.2 2020/04/13 08:04:47 martin Exp $	*/
      2        1.1        ad 
      3        1.4        ad /*-
      4        1.4        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5        1.1        ad  * All rights reserved.
      6        1.1        ad  *
      7        1.4        ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.9        ad  * by Andrew Doran.
      9        1.4        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.4        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.4        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.4        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.4        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.4        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.4        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.4        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.4        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.4        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.4        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.4        ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.2        ad 
     32       1.12     lukem #include <sys/cdefs.h>
     33  1.34.30.2    martin __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.34.30.2 2020/04/13 08:04:47 martin Exp $");
     34       1.12     lukem 
     35  1.34.30.2    martin #ifdef _KERNEL_OPT
     36        1.1        ad #include "opt_rasops.h"
     37  1.34.30.2    martin #endif
     38        1.1        ad 
     39        1.1        ad #include <sys/param.h>
     40        1.1        ad 
     41        1.1        ad #include <dev/wscons/wsdisplayvar.h>
     42        1.1        ad #include <dev/wscons/wsconsio.h>
     43  1.34.30.2    martin 
     44  1.34.30.2    martin #define	_RASOPS_PRIVATE
     45  1.34.30.2    martin #define	RASOPS_DEPTH	8
     46        1.1        ad #include <dev/rasops/rasops.h>
     47        1.1        ad 
     48  1.34.30.2    martin static void 	rasops8_putchar(void *, int, int, u_int, long);
     49  1.34.30.2    martin static void 	rasops8_putchar_aa(void *, int, int, u_int, long);
     50        1.7        ad #ifndef RASOPS_SMALL
     51  1.34.30.2    martin static void 	rasops8_putchar8(void *, int, int, u_int, long);
     52  1.34.30.2    martin static void 	rasops8_putchar12(void *, int, int, u_int, long);
     53  1.34.30.2    martin static void 	rasops8_putchar16(void *, int, int, u_int, long);
     54       1.18     perry static void	rasops8_makestamp(struct rasops_info *ri, long);
     55       1.10     bjh21 #endif
     56        1.1        ad 
     57  1.34.30.2    martin #ifndef RASOPS_SMALL
     58  1.34.30.2    martin /* stamp for optimized character blitting */
     59  1.34.30.2    martin static uint32_t			stamp[16];
     60  1.34.30.2    martin static long			stamp_attr;
     61  1.34.30.2    martin static struct rasops_info	*stamp_ri;
     62  1.34.30.2    martin 
     63        1.1        ad /*
     64        1.1        ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     65        1.1        ad  * destination = STAMP_READ(offset)
     66        1.1        ad  */
     67  1.34.30.2    martin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 2 : (fb) << 2)
     68  1.34.30.2    martin #define	STAMP_MASK		(0xf << 2)
     69  1.34.30.2    martin #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     70  1.34.30.2    martin #endif
     71        1.1        ad 
     72        1.1        ad /*
     73       1.11       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     74        1.1        ad  */
     75        1.1        ad void
     76       1.25       dsl rasops8_init(struct rasops_info *ri)
     77        1.1        ad {
     78        1.8        pk 
     79       1.28  macallan 	if (ri->ri_flg & RI_8BIT_IS_RGB) {
     80  1.34.30.2    martin 		ri->ri_rnum = ri->ri_gnum = 3;
     81  1.34.30.2    martin 		ri->ri_bnum = 2;
     82  1.34.30.2    martin 
     83       1.28  macallan 		ri->ri_rpos = 5;
     84       1.28  macallan 		ri->ri_gpos = 2;
     85       1.28  macallan 		ri->ri_bpos = 0;
     86       1.28  macallan 	}
     87        1.1        ad 
     88  1.34.30.2    martin 	if (FONT_IS_ALPHA(ri->ri_font)) {
     89  1.34.30.2    martin 		ri->ri_ops.putchar = rasops8_putchar_aa;
     90        1.1        ad 		return;
     91        1.8        pk 	}
     92       1.30  macallan 
     93  1.34.30.2    martin 	switch (ri->ri_font->fontwidth) {
     94  1.34.30.2    martin #ifndef RASOPS_SMALL
     95  1.34.30.2    martin 	case 8:
     96  1.34.30.2    martin 		ri->ri_ops.putchar = rasops8_putchar8;
     97  1.34.30.2    martin 		break;
     98  1.34.30.2    martin 	case 12:
     99  1.34.30.2    martin 		ri->ri_ops.putchar = rasops8_putchar12;
    100  1.34.30.2    martin 		break;
    101  1.34.30.2    martin 	case 16:
    102  1.34.30.2    martin 		ri->ri_ops.putchar = rasops8_putchar16;
    103  1.34.30.2    martin 		break;
    104  1.34.30.2    martin #endif /* !RASOPS_SMALL */
    105  1.34.30.2    martin 	default:
    106  1.34.30.2    martin 		ri->ri_ops.putchar = rasops8_putchar;
    107       1.30  macallan 		return;
    108  1.34.30.2    martin 	}
    109       1.30  macallan 
    110  1.34.30.2    martin #ifndef RASOPS_SMALL
    111  1.34.30.2    martin 	stamp_attr = -1;
    112  1.34.30.2    martin 	stamp_ri = NULL;
    113       1.30  macallan #endif
    114  1.34.30.2    martin }
    115       1.30  macallan 
    116  1.34.30.2    martin /* rasops8_putchar */
    117  1.34.30.2    martin #undef	RASOPS_AA
    118  1.34.30.2    martin #include <dev/rasops/rasops_putchar.h>
    119       1.30  macallan 
    120  1.34.30.2    martin /* rasops8_putchar_aa */
    121  1.34.30.2    martin #define	RASOPS_AA
    122  1.34.30.2    martin #include <dev/rasops/rasops_putchar.h>
    123  1.34.30.2    martin #undef	RASOPS_AA
    124       1.30  macallan 
    125        1.7        ad #ifndef RASOPS_SMALL
    126        1.1        ad /*
    127  1.34.30.2    martin  * Recompute the blitting stamp.
    128        1.1        ad  */
    129        1.1        ad static void
    130       1.25       dsl rasops8_makestamp(struct rasops_info *ri, long attr)
    131        1.1        ad {
    132        1.1        ad 	int i;
    133  1.34.30.2    martin 	uint32_t bg, fg;
    134        1.5        ad 
    135        1.1        ad 	stamp_attr = attr;
    136  1.34.30.2    martin 	stamp_ri = ri;
    137  1.34.30.2    martin 
    138  1.34.30.2    martin 	bg = ATTR_BG(ri, attr) & 0xff;
    139  1.34.30.2    martin 	fg = ATTR_FG(ri, attr) & 0xff;
    140        1.8        pk 
    141        1.1        ad 	for (i = 0; i < 16; i++) {
    142  1.34.30.2    martin #if BYTE_ORDER == LITTLE_ENDIAN
    143  1.34.30.2    martin 		if ((ri->ri_flg & RI_BSWAP) == 0)
    144        1.1        ad #else
    145  1.34.30.2    martin 		if ((ri->ri_flg & RI_BSWAP) != 0)
    146        1.1        ad #endif
    147  1.34.30.2    martin 		{
    148       1.16       uwe 			/* little endian */
    149  1.34.30.2    martin 			stamp[i]  = (i & 8 ? fg : bg);
    150  1.34.30.2    martin 			stamp[i] |= (i & 4 ? fg : bg) << 8;
    151  1.34.30.2    martin 			stamp[i] |= (i & 2 ? fg : bg) << 16;
    152  1.34.30.2    martin 			stamp[i] |= (i & 1 ? fg : bg) << 24;
    153       1.16       uwe 		} else {
    154       1.16       uwe 			/* big endian */
    155  1.34.30.2    martin 			stamp[i]  = (i & 1 ? fg : bg);
    156  1.34.30.2    martin 			stamp[i] |= (i & 2 ? fg : bg) << 8;
    157  1.34.30.2    martin 			stamp[i] |= (i & 4 ? fg : bg) << 16;
    158  1.34.30.2    martin 			stamp[i] |= (i & 8 ? fg : bg) << 24;
    159       1.16       uwe 		}
    160        1.1        ad 	}
    161        1.1        ad }
    162        1.1        ad 
    163        1.1        ad /*
    164  1.34.30.2    martin  * Width-optimized putchar functions
    165        1.1        ad  */
    166  1.34.30.2    martin #define	RASOPS_WIDTH	8
    167  1.34.30.2    martin #include <dev/rasops/rasops_putchar_width.h>
    168  1.34.30.2    martin #undef	RASOPS_WIDTH
    169        1.1        ad 
    170  1.34.30.2    martin #define	RASOPS_WIDTH	12
    171  1.34.30.2    martin #include <dev/rasops/rasops_putchar_width.h>
    172  1.34.30.2    martin #undef	RASOPS_WIDTH
    173        1.1        ad 
    174  1.34.30.2    martin #define	RASOPS_WIDTH	16
    175  1.34.30.2    martin #include <dev/rasops/rasops_putchar_width.h>
    176  1.34.30.2    martin #undef	RASOPS_WIDTH
    177       1.17    petrov 
    178        1.7        ad #endif /* !RASOPS_SMALL */
    179