rasops32.c revision 1.2 1 /* $NetBSD: rasops32.c,v 1.2 1999/04/13 00:40:09 ad Exp $ */
2
3 /*
4 * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 #include "opt_rasops.h"
31 #ifdef RASOPS32
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.2 1999/04/13 00:40:09 ad Exp $");
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40
41 #include <dev/wscons/wsdisplayvar.h>
42 #include <dev/wscons/wsconsio.h>
43 #include <dev/rasops/rasops.h>
44
45 static void rasops32_putchar __P((void *, int, int, u_int, long attr));
46 static void rasops32_erasecols __P((void *, int, int, int, long));
47 static void rasops32_eraserows __P((void *, int, int, long));
48 static int32_t rasops32_fg_color __P((struct rasops_info *, long));
49 static int32_t rasops32_bg_color __P((struct rasops_info *, long));
50 static void rasops32_do_cursor __P((struct rasops_info *));
51 void rasops32_init __P((struct rasops_info *ri));
52
53 /*
54 * Initalize a 'rasops_info' descriptor for this depth.
55 */
56 void
57 rasops32_init(ri)
58 struct rasops_info *ri;
59 {
60
61 /*
62 * This sucks. There is little optimization you can do with this
63 * colordepth on 32-bit machines.
64 *
65 * XXX c'mon sparc, alpha ppl?
66 */
67 ri->ri_ops.putchar = rasops32_putchar;
68 ri->ri_ops.erasecols = rasops32_erasecols;
69 ri->ri_ops.eraserows = rasops32_eraserows;
70 ri->ri_do_cursor = rasops32_do_cursor;
71 rasops_init_devcmap(ri);
72 }
73
74
75 /*
76 * Get background color from attribute.
77 */
78 static __inline__ int32_t
79 rasops32_bg_color(ri, attr)
80 struct rasops_info *ri;
81 long attr;
82 {
83
84 return ri->ri_devcmap[((int32_t)attr >> 24) & 15];
85 }
86
87
88 /*
89 * Get foreground color from attribute.
90 */
91 static __inline__ int32_t
92 rasops32_fg_color(ri, attr)
93 struct rasops_info *ri;
94 long attr;
95 {
96
97 return ri->ri_devcmap[((int32_t)attr >> 16) & 15];
98 }
99
100
101 /*
102 * Actually turn the cursor on or off. This does the dirty work for
103 * rasops_cursor().
104 */
105 static void
106 rasops32_do_cursor(ri)
107 struct rasops_info *ri;
108 {
109 u_char *rp;
110 int32_t *dp, planemask;
111 int num, height, cnt, row, col;
112
113 row = ri->ri_crow;
114 col = ri->ri_ccol;
115
116 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
117 height = ri->ri_font->fontheight;
118 num = ri->ri_xscale >> 2;
119 planemask = ri->ri_devcmap[15];
120
121 while (height--) {
122 dp = (int32_t *)rp;
123 rp += ri->ri_stride;
124
125 for (cnt = num; cnt; cnt--)
126 *dp++ ^= planemask;
127 }
128 }
129
130
131 /*
132 * Paint a single character.
133 */
134 static void
135 rasops32_putchar(cookie, row, col, uc, attr)
136 void *cookie;
137 int row, col;
138 u_int uc;
139 long attr;
140 {
141 struct rasops_info *ri;
142 int32_t *dp, *rp, clr[2];
143 u_char *fr;
144 int width, height, cnt, fs, fb;
145
146 ri = (struct rasops_info *)cookie;
147
148 #ifdef RASOPS_CLIPPING
149 /* Catches 'row < 0' case too */
150 if ((unsigned)row >= (unsigned)ri->ri_rows)
151 return;
152
153 if ((unsigned)col >= (unsigned)ri->ri_cols)
154 return;
155 #endif
156
157 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
158
159 height = ri->ri_font->fontheight;
160 width = ri->ri_font->fontwidth;
161 clr[0] = rasops32_bg_color(ri, attr);
162 clr[1] = rasops32_fg_color(ri, attr);
163
164 if (uc == ' ') {
165 while (height--) {
166 dp = rp;
167 DELTA(rp, ri->ri_stride, int32_t *);
168
169 for (cnt = width; cnt; cnt--)
170 *dp++ = clr[0];
171 }
172 } else {
173 uc -= ri->ri_font->firstchar;
174 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
175 fs = ri->ri_font->stride;
176
177 while (height--) {
178 dp = rp;
179 fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
180 fr += fs;
181 DELTA(rp, ri->ri_stride, int32_t *);
182
183 for (cnt = width; cnt; cnt--) {
184 *dp++ = clr[(fb >> 31) & 1];
185 fb <<= 1;
186 }
187 }
188 }
189
190 /* Do underline */
191 if (attr & 1) {
192 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
193
194 while (width--)
195 *rp++ = clr[1];
196 }
197 }
198
199
200 /*
201 * Erase rows.
202 */
203 static void
204 rasops32_eraserows(cookie, row, num, attr)
205 void *cookie;
206 int row, num;
207 long attr;
208 {
209 struct rasops_info *ri;
210 int32_t *dp, clr;
211 int n8, n1, cnt;
212
213 ri = (struct rasops_info *)cookie;
214
215 #ifdef RASOPS_CLIPPING
216 if (row < 0) {
217 num += row;
218 row = 0;
219 }
220
221 if ((row + num) > ri->ri_rows)
222 num = ri->ri_rows - row;
223
224 if (num <= 0)
225 return;
226 #endif
227
228 num *= ri->ri_font->fontheight;
229 dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
230 clr = rasops32_bg_color(ri, attr);
231
232 n8 = ri->ri_emustride >> 5;
233 n1 = (ri->ri_emustride >> 2) & 7;
234
235 while (num--) {
236 for (cnt = n8; cnt; cnt--) {
237 dp[0] = clr;
238 dp[1] = clr;
239 dp[2] = clr;
240 dp[3] = clr;
241 dp[4] = clr;
242 dp[5] = clr;
243 dp[6] = clr;
244 dp[7] = clr;
245 dp += 8;
246 }
247
248 for (cnt = n1; cnt; cnt--)
249 *dp++ = clr;
250
251 DELTA(dp, ri->ri_delta, int32_t *);
252 }
253 }
254
255
256 /*
257 * Erase columns.
258 */
259 static void
260 rasops32_erasecols(cookie, row, col, num, attr)
261 void *cookie;
262 int row, col, num;
263 long attr;
264 {
265 int n8, clr, height, cnt;
266 struct rasops_info *ri;
267 int32_t *dst;
268 u_char *rp;
269
270 ri = (struct rasops_info *)cookie;
271
272 #ifdef RASOPS_CLIPPING
273 if ((unsigned)row >= (unsigned)ri->ri_rows)
274 return;
275
276 if (col < 0) {
277 num += col;
278 col = 0;
279 }
280
281 if ((col + num) > ri->ri_cols)
282 num = ri->ri_cols - col;
283
284 if (num <= 0)
285 return;
286 #endif
287
288 num = num * ri->ri_xscale;
289 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
290 clr = rasops32_bg_color(ri, attr);
291 height = ri->ri_font->fontheight;
292 n8 = num >> 5;
293 num = (num >> 2) & 7;
294
295 while (height--) {
296 dst = (int32_t *)rp;
297 rp += ri->ri_stride;
298
299 for (cnt = n8; cnt; cnt--) {
300 dst[0] = clr;
301 dst[1] = clr;
302 dst[2] = clr;
303 dst[3] = clr;
304 dst[4] = clr;
305 dst[5] = clr;
306 dst[6] = clr;
307 dst[7] = clr;
308 dst += 8;
309 }
310
311 for (cnt = num; cnt; cnt--)
312 *dst++ = clr;
313 }
314 }
315
316 #endif /* RASOPS32 */
317