Home | History | Annotate | Line # | Download | only in rasops
rasops8.c revision 1.46
      1  1.46       rin /* 	$NetBSD: rasops8.c,v 1.46 2019/07/31 02:04:14 rin 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.46       rin __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.46 2019/07/31 02:04:14 rin Exp $");
     34  1.12     lukem 
     35   1.1        ad #include "opt_rasops.h"
     36   1.1        ad 
     37   1.1        ad #include <sys/param.h>
     38   1.1        ad #include <sys/systm.h>
     39   1.1        ad #include <sys/time.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.45       rin 
     44  1.45       rin #define	_RASOPS_PRIVATE
     45   1.1        ad #include <dev/rasops/rasops.h>
     46   1.1        ad 
     47  1.43       rin static void 	rasops8_putchar(void *, int, int, u_int, long);
     48  1.43       rin static void 	rasops8_putchar_aa(void *, int, int, u_int, long);
     49   1.7        ad #ifndef RASOPS_SMALL
     50  1.43       rin static void 	rasops8_putchar8(void *, int, int, u_int, long);
     51  1.43       rin static void 	rasops8_putchar12(void *, int, int, u_int, long);
     52  1.43       rin static void 	rasops8_putchar16(void *, int, int, u_int, long);
     53  1.18     perry static void	rasops8_makestamp(struct rasops_info *ri, long);
     54  1.10     bjh21 #endif
     55   1.1        ad 
     56   1.1        ad /*
     57   1.1        ad  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
     58   1.1        ad  * destination = STAMP_READ(offset)
     59   1.1        ad  */
     60  1.43       rin #define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 2 : (fb) << 2)
     61  1.43       rin #define	STAMP_MASK		(0xf << 2)
     62  1.43       rin #define	STAMP_READ(o)		(*(uint32_t *)((uint8_t *)stamp + (o)))
     63   1.1        ad 
     64   1.1        ad /*
     65  1.11       wiz  * Initialize a 'rasops_info' descriptor for this depth.
     66   1.1        ad  */
     67   1.1        ad void
     68  1.25       dsl rasops8_init(struct rasops_info *ri)
     69   1.1        ad {
     70   1.8        pk 
     71  1.43       rin 	if (ri->ri_flg & RI_8BIT_IS_RGB) {
     72  1.43       rin 		ri->ri_rnum = ri->ri_gnum = 3;
     73  1.43       rin 		ri->ri_bnum = 2;
     74  1.43       rin 
     75  1.43       rin 		ri->ri_rpos = 5;
     76  1.43       rin 		ri->ri_gpos = 2;
     77  1.43       rin 		ri->ri_bpos = 0;
     78  1.43       rin 	}
     79  1.43       rin 
     80  1.33    martin 	if (FONT_IS_ALPHA(ri->ri_font)) {
     81  1.30  macallan 		ri->ri_ops.putchar = rasops8_putchar_aa;
     82  1.43       rin 		return;
     83  1.43       rin 	}
     84  1.43       rin 
     85  1.43       rin 	switch (ri->ri_font->fontwidth) {
     86   1.7        ad #ifndef RASOPS_SMALL
     87  1.43       rin 	case 8:
     88  1.43       rin 		ri->ri_ops.putchar = rasops8_putchar8;
     89  1.43       rin 		break;
     90  1.43       rin 	case 12:
     91  1.43       rin 		ri->ri_ops.putchar = rasops8_putchar12;
     92  1.43       rin 		break;
     93  1.43       rin 	case 16:
     94  1.43       rin 		ri->ri_ops.putchar = rasops8_putchar16;
     95  1.43       rin 		break;
     96   1.7        ad #endif /* !RASOPS_SMALL */
     97  1.43       rin 	default:
     98  1.43       rin 		ri->ri_ops.putchar = rasops8_putchar;
     99  1.46       rin 		return;
    100  1.28  macallan 	}
    101  1.46       rin 
    102  1.46       rin #ifndef RASOPS_SMALL
    103  1.46       rin 	rasops_allocstamp(ri, sizeof(uint32_t) * 16);
    104  1.46       rin #endif
    105   1.1        ad }
    106   1.1        ad 
    107  1.42       rin #define	RASOPS_DEPTH	8
    108  1.42       rin #include "rasops_putchar.h"
    109  1.44       rin #include "rasops_putchar_aa.h"
    110  1.30  macallan 
    111   1.7        ad #ifndef RASOPS_SMALL
    112   1.1        ad /*
    113   1.1        ad  * Recompute the 4x1 blitting stamp.
    114   1.1        ad  */
    115   1.1        ad static void
    116  1.25       dsl rasops8_makestamp(struct rasops_info *ri, long attr)
    117   1.1        ad {
    118  1.46       rin 	uint32_t *stamp = (uint32_t *)ri->ri_stamp;
    119  1.37       rin 	uint32_t fg, bg;
    120   1.1        ad 	int i;
    121   1.5        ad 
    122  1.43       rin 	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xff;
    123  1.43       rin 	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xff;
    124  1.46       rin 	ri->ri_stamp_attr = attr;
    125   1.8        pk 
    126   1.1        ad 	for (i = 0; i < 16; i++) {
    127  1.16       uwe #if BYTE_ORDER == BIG_ENDIAN
    128  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
    129   1.1        ad #else
    130  1.16       uwe #define NEED_LITTLE_ENDIAN_STAMP 0
    131   1.1        ad #endif
    132  1.16       uwe 		if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
    133  1.16       uwe 			/* little endian */
    134  1.43       rin 			stamp[i]  = (i & 8 ? fg : bg);
    135  1.43       rin 			stamp[i] |= (i & 4 ? fg : bg) << 8;
    136  1.43       rin 			stamp[i] |= (i & 2 ? fg : bg) << 16;
    137  1.43       rin 			stamp[i] |= (i & 1 ? fg : bg) << 24;
    138  1.16       uwe 		} else {
    139  1.16       uwe 			/* big endian */
    140  1.43       rin 			stamp[i]  = (i & 1 ? fg : bg);
    141  1.43       rin 			stamp[i] |= (i & 2 ? fg : bg) << 8;
    142  1.43       rin 			stamp[i] |= (i & 4 ? fg : bg) << 16;
    143  1.43       rin 			stamp[i] |= (i & 8 ? fg : bg) << 24;
    144  1.16       uwe 		}
    145   1.1        ad 	}
    146   1.1        ad }
    147   1.1        ad 
    148  1.42       rin #define	RASOPS_WIDTH	8
    149  1.42       rin #include "rasops_putchar_width.h"
    150  1.42       rin #undef	RASOPS_WIDTH
    151  1.42       rin 
    152  1.42       rin #define	RASOPS_WIDTH	12
    153  1.42       rin #include "rasops_putchar_width.h"
    154  1.42       rin #undef	RASOPS_WIDTH
    155  1.42       rin 
    156  1.42       rin #define	RASOPS_WIDTH	16
    157  1.42       rin #include "rasops_putchar_width.h"
    158  1.42       rin #undef	RASOPS_WIDTH
    159  1.17    petrov 
    160   1.1        ad #endif
    161