rasops2.c revision 1.26
1/* 	$NetBSD: rasops2.c,v 1.26 2019/07/29 03:01:09 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.26 2019/07/29 03:01:09 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#include <dev/rasops/rasops.h>
45#include <dev/rasops/rasops_masks.h>
46
47static void	rasops2_copycols(void *, int, int, int, int);
48static void	rasops2_erasecols(void *, int, int, int, long);
49static void	rasops2_do_cursor(struct rasops_info *);
50static void	rasops2_putchar(void *, int, int col, u_int, long);
51#ifndef RASOPS_SMALL
52static void	rasops2_putchar8(void *, int, int col, u_int, long);
53static void	rasops2_putchar12(void *, int, int col, u_int, long);
54static void	rasops2_putchar16(void *, int, int col, u_int, long);
55static void	rasops2_makestamp(struct rasops_info *, long);
56
57/*
58 * 4x1 stamp for optimized character blitting
59 */
60static uint8_t	stamp[16];
61static long	stamp_attr;
62static int	stamp_mutex;	/* XXX see note in README */
63#endif
64
65/*
66 * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
67 * destination = STAMP_READ(offset)
68 */
69#define	STAMP_SHIFT(fb, n)	((n) ? (fb) >> 4 : (fb))
70#define	STAMP_MASK		0xf
71#define	STAMP_READ(o)		stamp[o]
72
73/*
74 * Initialize rasops_info struct for this colordepth.
75 */
76void
77rasops2_init(struct rasops_info *ri)
78{
79
80	switch (ri->ri_font->fontwidth) {
81#ifndef RASOPS_SMALL
82	case 8:
83		ri->ri_ops.putchar = rasops2_putchar8;
84		break;
85	case 12:
86		ri->ri_ops.putchar = rasops2_putchar12;
87		break;
88	case 16:
89		ri->ri_ops.putchar = rasops2_putchar16;
90		break;
91#endif	/* !RASOPS_SMALL */
92	default:
93		panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
94		ri->ri_ops.putchar = rasops2_putchar;
95		break;
96	}
97
98	if ((ri->ri_font->fontwidth & 3) != 0) {
99		ri->ri_ops.erasecols = rasops2_erasecols;
100		ri->ri_ops.copycols = rasops2_copycols;
101		ri->ri_do_cursor = rasops2_do_cursor;
102	}
103}
104
105/*
106 * Put a single character. This is the generic version.
107 */
108static void
109rasops2_putchar(void *cookie, int row, int col, u_int uc, long attr)
110{
111
112	/* XXX punt */
113}
114
115#ifndef RASOPS_SMALL
116/*
117 * Recompute the blitting stamp.
118 */
119static void
120rasops2_makestamp(struct rasops_info *ri, long attr)
121{
122	int i, fg, bg;
123
124	fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
125	bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
126	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			/* littel endian */
136			stamp[i]  = (i & 8 ? fg : bg);
137			stamp[i] |= (i & 4 ? fg : bg) << 2;
138			stamp[i] |= (i & 2 ? fg : bg) << 4;
139			stamp[i] |= (i & 1 ? fg : bg) << 6;
140		} else {
141			/* big endian */
142			stamp[i]  = (i & 1 ? fg : bg);
143			stamp[i] |= (i & 2 ? fg : bg) << 2;
144			stamp[i] |= (i & 4 ? fg : bg) << 4;
145			stamp[i] |= (i & 8 ? fg : bg) << 6;
146		}
147	}
148}
149
150#define	RASOPS_DEPTH	2
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)	rasops2_##ident
170#define PIXEL_SHIFT	1
171
172#include <dev/rasops/rasops_bitops.h>
173