rasops32.c revision 1.29.30.2 1 1.29.30.2 martin /* $NetBSD: rasops32.c,v 1.29.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.8 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.10 lukem #include <sys/cdefs.h>
33 1.29.30.2 martin __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.29.30.2 2020/04/13 08:04:47 martin Exp $");
34 1.10 lukem
35 1.29.30.2 martin #ifdef _KERNEL_OPT
36 1.1 ad #include "opt_rasops.h"
37 1.29.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.29.30.2 martin
44 1.29.30.2 martin #define _RASOPS_PRIVATE
45 1.29.30.2 martin #define RASOPS_DEPTH 32
46 1.1 ad #include <dev/rasops/rasops.h>
47 1.1 ad
48 1.29.30.2 martin static void rasops32_putchar(void *, int, int, u_int, long);
49 1.29.30.2 martin static void rasops32_putchar_aa(void *, int, int, u_int, long);
50 1.29.30.2 martin #ifndef RASOPS_SMALL
51 1.29.30.2 martin static void rasops32_putchar8(void *, int, int, u_int, long);
52 1.29.30.2 martin static void rasops32_putchar12(void *, int, int, u_int, long);
53 1.29.30.2 martin static void rasops32_putchar16(void *, int, int, u_int, long);
54 1.29.30.2 martin static void rasops32_makestamp(struct rasops_info *, long);
55 1.29.30.2 martin #endif
56 1.29.30.2 martin
57 1.29.30.2 martin #ifndef RASOPS_SMALL
58 1.29.30.2 martin /* stamp for optimized character blitting */
59 1.29.30.2 martin static uint32_t stamp[64];
60 1.29.30.2 martin static long stamp_attr;
61 1.29.30.2 martin static struct rasops_info *stamp_ri;
62 1.29.30.2 martin
63 1.29.30.2 martin /*
64 1.29.30.2 martin * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
65 1.29.30.2 martin * destination uint32_t[0] = STAMP_READ(offset)
66 1.29.30.2 martin * destination uint32_t[1] = STAMP_READ(offset + 4)
67 1.29.30.2 martin * destination uint32_t[2] = STAMP_READ(offset + 8)
68 1.29.30.2 martin * destination uint32_t[3] = STAMP_READ(offset + 12)
69 1.29.30.2 martin */
70 1.29.30.2 martin #define STAMP_SHIFT(fb, n) ((n) ? (fb) : (fb) << 4)
71 1.29.30.2 martin #define STAMP_MASK (0xf << 4)
72 1.29.30.2 martin #define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o)))
73 1.29.30.2 martin #endif
74 1.3 ad
75 1.1 ad /*
76 1.9 wiz * Initialize a 'rasops_info' descriptor for this depth.
77 1.1 ad */
78 1.1 ad void
79 1.17 dsl rasops32_init(struct rasops_info *ri)
80 1.1 ad {
81 1.1 ad
82 1.3 ad if (ri->ri_rnum == 0) {
83 1.29.30.2 martin ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
84 1.29.30.2 martin
85 1.3 ad ri->ri_rpos = 0;
86 1.3 ad ri->ri_gpos = 8;
87 1.3 ad ri->ri_bpos = 16;
88 1.1 ad }
89 1.7 pk
90 1.27 martin if (FONT_IS_ALPHA(ri->ri_font)) {
91 1.27 martin ri->ri_ops.putchar = rasops32_putchar_aa;
92 1.1 ad return;
93 1.29.30.2 martin }
94 1.1 ad
95 1.29.30.2 martin switch (ri->ri_font->fontwidth) {
96 1.29.30.2 martin #ifndef RASOPS_SMALL
97 1.29.30.2 martin case 8:
98 1.29.30.2 martin ri->ri_ops.putchar = rasops32_putchar8;
99 1.29.30.2 martin break;
100 1.29.30.2 martin case 12:
101 1.29.30.2 martin ri->ri_ops.putchar = rasops32_putchar12;
102 1.29.30.2 martin break;
103 1.29.30.2 martin case 16:
104 1.29.30.2 martin ri->ri_ops.putchar = rasops32_putchar16;
105 1.29.30.2 martin break;
106 1.1 ad #endif
107 1.29.30.2 martin default:
108 1.29.30.2 martin ri->ri_ops.putchar = rasops32_putchar;
109 1.24 macallan return;
110 1.23 macallan }
111 1.23 macallan
112 1.29.30.2 martin #ifndef RASOPS_SMALL
113 1.29.30.2 martin stamp_attr = -1;
114 1.29.30.2 martin stamp_ri = NULL;
115 1.29.30.2 martin #endif
116 1.23 macallan }
117 1.23 macallan
118 1.29.30.2 martin /* rasops32_putchar */
119 1.29.30.2 martin #undef RASOPS_AA
120 1.29.30.2 martin #include <dev/rasops/rasops_putchar.h>
121 1.29.30.2 martin
122 1.29.30.2 martin /* rasops32_putchar_aa */
123 1.29.30.2 martin #define RASOPS_AA
124 1.29.30.2 martin #include <dev/rasops/rasops_putchar.h>
125 1.29.30.2 martin #undef RASOPS_AA
126 1.29.30.2 martin
127 1.29.30.2 martin #ifndef RASOPS_SMALL
128 1.29.30.2 martin /*
129 1.29.30.2 martin * Recompute the blitting stamp.
130 1.29.30.2 martin */
131 1.23 macallan static void
132 1.29.30.2 martin rasops32_makestamp(struct rasops_info *ri, long attr)
133 1.23 macallan {
134 1.29.30.2 martin uint32_t fg, bg;
135 1.29.30.2 martin int i;
136 1.23 macallan
137 1.29.30.2 martin stamp_attr = attr;
138 1.29.30.2 martin stamp_ri = ri;
139 1.23 macallan
140 1.29.30.2 martin bg = ATTR_BG(ri, attr);
141 1.29.30.2 martin fg = ATTR_FG(ri, attr);
142 1.1 ad
143 1.29.30.2 martin for (i = 0; i < 64; i += 4) {
144 1.29.30.2 martin stamp[i + 0] = i & 32 ? fg : bg;
145 1.29.30.2 martin stamp[i + 1] = i & 16 ? fg : bg;
146 1.29.30.2 martin stamp[i + 2] = i & 8 ? fg : bg;
147 1.29.30.2 martin stamp[i + 3] = i & 4 ? fg : bg;
148 1.7 pk }
149 1.1 ad }
150 1.29.30.2 martin
151 1.29.30.2 martin /*
152 1.29.30.2 martin * Width-optimized putchar functions
153 1.29.30.2 martin */
154 1.29.30.2 martin #define RASOPS_WIDTH 8
155 1.29.30.2 martin #include <dev/rasops/rasops_putchar_width.h>
156 1.29.30.2 martin #undef RASOPS_WIDTH
157 1.29.30.2 martin
158 1.29.30.2 martin #define RASOPS_WIDTH 12
159 1.29.30.2 martin #include <dev/rasops/rasops_putchar_width.h>
160 1.29.30.2 martin #undef RASOPS_WIDTH
161 1.29.30.2 martin
162 1.29.30.2 martin #define RASOPS_WIDTH 16
163 1.29.30.2 martin #include <dev/rasops/rasops_putchar_width.h>
164 1.29.30.2 martin #undef RASOPS_WIDTH
165 1.29.30.2 martin
166 1.29.30.2 martin #endif /* !RASOPS_SMALL */
167