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