rasops8.c revision 1.16.16.5 1 1.16.16.5 skrll /* $NetBSD: rasops8.c,v 1.16.16.5 2005/11/10 14:07:47 skrll 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.4 ad * 3. All advertising materials mentioning features or use of this software
19 1.4 ad * must display the following acknowledgement:
20 1.4 ad * This product includes software developed by the NetBSD
21 1.4 ad * Foundation, Inc. and its contributors.
22 1.4 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4 ad * contributors may be used to endorse or promote products derived
24 1.4 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.4 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.2 ad
39 1.12 lukem #include <sys/cdefs.h>
40 1.16.16.5 skrll __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.16.16.5 2005/11/10 14:07:47 skrll Exp $");
41 1.12 lukem
42 1.1 ad #include "opt_rasops.h"
43 1.1 ad
44 1.1 ad #include <sys/param.h>
45 1.1 ad #include <sys/systm.h>
46 1.1 ad #include <sys/time.h>
47 1.1 ad
48 1.1 ad #include <dev/wscons/wsdisplayvar.h>
49 1.1 ad #include <dev/wscons/wsconsio.h>
50 1.1 ad #include <dev/rasops/rasops.h>
51 1.1 ad
52 1.16.16.4 skrll static void rasops8_putchar(void *, int, int, u_int, long attr);
53 1.7 ad #ifndef RASOPS_SMALL
54 1.16.16.4 skrll static void rasops8_putchar8(void *, int, int, u_int, long attr);
55 1.16.16.4 skrll static void rasops8_putchar12(void *, int, int, u_int, long attr);
56 1.16.16.4 skrll static void rasops8_putchar16(void *, int, int, u_int, long attr);
57 1.16.16.4 skrll static void rasops8_makestamp(struct rasops_info *ri, long);
58 1.1 ad
59 1.8 pk /*
60 1.8 pk * 4x1 stamp for optimized character blitting
61 1.1 ad */
62 1.1 ad static int32_t stamp[16];
63 1.1 ad static long stamp_attr;
64 1.1 ad static int stamp_mutex; /* XXX see note in README */
65 1.10 bjh21 #endif
66 1.1 ad
67 1.1 ad /*
68 1.1 ad * XXX this confuses the hell out of gcc2 (not egcs) which always insists
69 1.1 ad * that the shift count is negative.
70 1.1 ad *
71 1.1 ad * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
72 1.1 ad * destination = STAMP_READ(offset)
73 1.1 ad */
74 1.1 ad #define STAMP_SHIFT(fb,n) ((n*4-2) >= 0 ? (fb)>>(n*4-2):(fb)<<-(n*4-2))
75 1.8 pk #define STAMP_MASK (0xf << 2)
76 1.1 ad #define STAMP_READ(o) (*(int32_t *)((caddr_t)stamp + (o)))
77 1.1 ad
78 1.1 ad /*
79 1.11 wiz * Initialize a 'rasops_info' descriptor for this depth.
80 1.1 ad */
81 1.1 ad void
82 1.1 ad rasops8_init(ri)
83 1.1 ad struct rasops_info *ri;
84 1.1 ad {
85 1.8 pk
86 1.1 ad switch (ri->ri_font->fontwidth) {
87 1.7 ad #ifndef RASOPS_SMALL
88 1.1 ad case 8:
89 1.1 ad ri->ri_ops.putchar = rasops8_putchar8;
90 1.1 ad break;
91 1.1 ad case 12:
92 1.1 ad ri->ri_ops.putchar = rasops8_putchar12;
93 1.1 ad break;
94 1.1 ad case 16:
95 1.1 ad ri->ri_ops.putchar = rasops8_putchar16;
96 1.1 ad break;
97 1.7 ad #endif /* !RASOPS_SMALL */
98 1.1 ad default:
99 1.1 ad ri->ri_ops.putchar = rasops8_putchar;
100 1.1 ad break;
101 1.1 ad }
102 1.1 ad }
103 1.1 ad
104 1.1 ad /*
105 1.3 ad * Put a single character.
106 1.1 ad */
107 1.1 ad static void
108 1.1 ad rasops8_putchar(cookie, row, col, uc, attr)
109 1.1 ad void *cookie;
110 1.1 ad int row, col;
111 1.1 ad u_int uc;
112 1.1 ad long attr;
113 1.1 ad {
114 1.7 ad int width, height, cnt, fs, fb;
115 1.7 ad u_char *dp, *rp, *fr, clr[2];
116 1.1 ad struct rasops_info *ri;
117 1.8 pk
118 1.1 ad ri = (struct rasops_info *)cookie;
119 1.1 ad
120 1.16.16.1 skrll if (!CHAR_IN_FONT(uc, ri->ri_font))
121 1.16.16.1 skrll return;
122 1.16.16.1 skrll
123 1.8 pk #ifdef RASOPS_CLIPPING
124 1.8 pk /* Catches 'row < 0' case too */
125 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
126 1.1 ad return;
127 1.1 ad
128 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
129 1.1 ad return;
130 1.1 ad #endif
131 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
132 1.1 ad
133 1.1 ad height = ri->ri_font->fontheight;
134 1.1 ad width = ri->ri_font->fontwidth;
135 1.8 pk clr[0] = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
136 1.8 pk clr[1] = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
137 1.8 pk
138 1.1 ad if (uc == ' ') {
139 1.8 pk u_char c = clr[0];
140 1.8 pk
141 1.1 ad while (height--) {
142 1.1 ad dp = rp;
143 1.1 ad rp += ri->ri_stride;
144 1.8 pk
145 1.1 ad for (cnt = width; cnt; cnt--)
146 1.8 pk *dp++ = c;
147 1.1 ad }
148 1.1 ad } else {
149 1.1 ad uc -= ri->ri_font->firstchar;
150 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
151 1.1 ad fs = ri->ri_font->stride;
152 1.1 ad
153 1.1 ad while (height--) {
154 1.1 ad dp = rp;
155 1.1 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
156 1.1 ad fr += fs;
157 1.1 ad rp += ri->ri_stride;
158 1.8 pk
159 1.1 ad for (cnt = width; cnt; cnt--) {
160 1.1 ad *dp++ = clr[(fb >> 31) & 1];
161 1.1 ad fb <<= 1;
162 1.1 ad }
163 1.1 ad }
164 1.8 pk }
165 1.1 ad
166 1.1 ad /* Do underline */
167 1.7 ad if ((attr & 1) != 0) {
168 1.8 pk u_char c = clr[1];
169 1.8 pk
170 1.1 ad rp -= (ri->ri_stride << 1);
171 1.1 ad
172 1.1 ad while (width--)
173 1.8 pk *rp++ = c;
174 1.8 pk }
175 1.1 ad }
176 1.1 ad
177 1.7 ad #ifndef RASOPS_SMALL
178 1.1 ad /*
179 1.1 ad * Recompute the 4x1 blitting stamp.
180 1.1 ad */
181 1.1 ad static void
182 1.6 ad rasops8_makestamp(ri, attr)
183 1.6 ad struct rasops_info *ri;
184 1.3 ad long attr;
185 1.1 ad {
186 1.7 ad int32_t fg, bg;
187 1.1 ad int i;
188 1.5 ad
189 1.8 pk fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff;
190 1.8 pk bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff;
191 1.1 ad stamp_attr = attr;
192 1.8 pk
193 1.1 ad for (i = 0; i < 16; i++) {
194 1.16 uwe #if BYTE_ORDER == BIG_ENDIAN
195 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP RI_BSWAP
196 1.1 ad #else
197 1.16 uwe #define NEED_LITTLE_ENDIAN_STAMP 0
198 1.1 ad #endif
199 1.16 uwe if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) {
200 1.16 uwe /* little endian */
201 1.16 uwe stamp[i] = (i & 8 ? fg : bg);
202 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 8);
203 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 16);
204 1.16 uwe stamp[i] |= ((i & 1 ? fg : bg) << 24);
205 1.16 uwe } else {
206 1.16 uwe /* big endian */
207 1.16 uwe stamp[i] = (i & 1 ? fg : bg);
208 1.16 uwe stamp[i] |= ((i & 2 ? fg : bg) << 8);
209 1.16 uwe stamp[i] |= ((i & 4 ? fg : bg) << 16);
210 1.16 uwe stamp[i] |= ((i & 8 ? fg : bg) << 24);
211 1.16 uwe }
212 1.1 ad }
213 1.1 ad }
214 1.1 ad
215 1.1 ad /*
216 1.3 ad * Put a single character. This is for 8-pixel wide fonts.
217 1.1 ad */
218 1.1 ad static void
219 1.1 ad rasops8_putchar8(cookie, row, col, uc, attr)
220 1.1 ad void *cookie;
221 1.1 ad int row, col;
222 1.1 ad u_int uc;
223 1.1 ad long attr;
224 1.1 ad {
225 1.1 ad struct rasops_info *ri;
226 1.1 ad int height, fs;
227 1.1 ad int32_t *rp;
228 1.1 ad u_char *fr;
229 1.8 pk
230 1.1 ad /* Can't risk remaking the stamp if it's already in use */
231 1.1 ad if (stamp_mutex++) {
232 1.1 ad stamp_mutex--;
233 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
234 1.1 ad return;
235 1.1 ad }
236 1.1 ad
237 1.1 ad ri = (struct rasops_info *)cookie;
238 1.1 ad
239 1.16.16.1 skrll if (!CHAR_IN_FONT(uc, ri->ri_font))
240 1.16.16.1 skrll return;
241 1.16.16.1 skrll
242 1.8 pk #ifdef RASOPS_CLIPPING
243 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
244 1.1 ad stamp_mutex--;
245 1.1 ad return;
246 1.1 ad }
247 1.1 ad
248 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
249 1.1 ad stamp_mutex--;
250 1.1 ad return;
251 1.1 ad }
252 1.1 ad #endif
253 1.1 ad
254 1.1 ad /* Recompute stamp? */
255 1.1 ad if (attr != stamp_attr)
256 1.6 ad rasops8_makestamp(ri, attr);
257 1.8 pk
258 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
259 1.1 ad height = ri->ri_font->fontheight;
260 1.8 pk
261 1.1 ad if (uc == ' ') {
262 1.1 ad while (height--) {
263 1.8 pk rp[0] = rp[1] = stamp[0];
264 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
265 1.8 pk }
266 1.1 ad } else {
267 1.1 ad uc -= ri->ri_font->firstchar;
268 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
269 1.1 ad fs = ri->ri_font->stride;
270 1.8 pk
271 1.1 ad while (height--) {
272 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
273 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
274 1.1 ad
275 1.1 ad fr += fs;
276 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
277 1.1 ad }
278 1.1 ad }
279 1.1 ad
280 1.1 ad /* Do underline */
281 1.7 ad if ((attr & 1) != 0) {
282 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
283 1.8 pk rp[0] = rp[1] = stamp[15];
284 1.8 pk }
285 1.8 pk
286 1.8 pk stamp_mutex--;
287 1.1 ad }
288 1.1 ad
289 1.1 ad /*
290 1.3 ad * Put a single character. This is for 12-pixel wide fonts.
291 1.1 ad */
292 1.1 ad static void
293 1.1 ad rasops8_putchar12(cookie, row, col, uc, attr)
294 1.1 ad void *cookie;
295 1.1 ad int row, col;
296 1.1 ad u_int uc;
297 1.1 ad long attr;
298 1.1 ad {
299 1.1 ad struct rasops_info *ri;
300 1.1 ad int height, fs;
301 1.1 ad int32_t *rp;
302 1.1 ad u_char *fr;
303 1.8 pk
304 1.1 ad /* Can't risk remaking the stamp if it's already in use */
305 1.1 ad if (stamp_mutex++) {
306 1.1 ad stamp_mutex--;
307 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
308 1.1 ad return;
309 1.1 ad }
310 1.1 ad
311 1.1 ad ri = (struct rasops_info *)cookie;
312 1.1 ad
313 1.16.16.1 skrll if (!CHAR_IN_FONT(uc, ri->ri_font))
314 1.16.16.1 skrll return;
315 1.16.16.1 skrll
316 1.8 pk #ifdef RASOPS_CLIPPING
317 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
318 1.1 ad stamp_mutex--;
319 1.1 ad return;
320 1.1 ad }
321 1.1 ad
322 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
323 1.1 ad stamp_mutex--;
324 1.1 ad return;
325 1.1 ad }
326 1.1 ad #endif
327 1.1 ad
328 1.1 ad /* Recompute stamp? */
329 1.1 ad if (attr != stamp_attr)
330 1.6 ad rasops8_makestamp(ri, attr);
331 1.8 pk
332 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
333 1.1 ad height = ri->ri_font->fontheight;
334 1.8 pk
335 1.1 ad if (uc == ' ') {
336 1.1 ad while (height--) {
337 1.8 pk int32_t c = stamp[0];
338 1.8 pk
339 1.8 pk rp[0] = rp[1] = rp[2] = c;
340 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
341 1.8 pk }
342 1.1 ad } else {
343 1.1 ad uc -= ri->ri_font->firstchar;
344 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
345 1.1 ad fs = ri->ri_font->stride;
346 1.8 pk
347 1.1 ad while (height--) {
348 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
349 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
350 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
351 1.8 pk
352 1.1 ad fr += fs;
353 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
354 1.1 ad }
355 1.8 pk }
356 1.1 ad
357 1.1 ad /* Do underline */
358 1.7 ad if ((attr & 1) != 0) {
359 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
360 1.8 pk rp[0] = rp[1] = rp[2] = stamp[15];
361 1.8 pk }
362 1.8 pk
363 1.1 ad stamp_mutex--;
364 1.1 ad }
365 1.1 ad
366 1.1 ad /*
367 1.3 ad * Put a single character. This is for 16-pixel wide fonts.
368 1.1 ad */
369 1.1 ad static void
370 1.1 ad rasops8_putchar16(cookie, row, col, uc, attr)
371 1.1 ad void *cookie;
372 1.1 ad int row, col;
373 1.1 ad u_int uc;
374 1.1 ad long attr;
375 1.1 ad {
376 1.1 ad struct rasops_info *ri;
377 1.1 ad int height, fs;
378 1.1 ad int32_t *rp;
379 1.1 ad u_char *fr;
380 1.1 ad
381 1.1 ad /* Can't risk remaking the stamp if it's already in use */
382 1.1 ad if (stamp_mutex++) {
383 1.1 ad stamp_mutex--;
384 1.1 ad rasops8_putchar(cookie, row, col, uc, attr);
385 1.1 ad return;
386 1.1 ad }
387 1.1 ad
388 1.1 ad ri = (struct rasops_info *)cookie;
389 1.1 ad
390 1.16.16.1 skrll if (!CHAR_IN_FONT(uc, ri->ri_font))
391 1.16.16.1 skrll return;
392 1.16.16.1 skrll
393 1.8 pk #ifdef RASOPS_CLIPPING
394 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
395 1.1 ad stamp_mutex--;
396 1.1 ad return;
397 1.1 ad }
398 1.1 ad
399 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
400 1.1 ad stamp_mutex--;
401 1.1 ad return;
402 1.1 ad }
403 1.1 ad #endif
404 1.1 ad
405 1.1 ad /* Recompute stamp? */
406 1.1 ad if (attr != stamp_attr)
407 1.6 ad rasops8_makestamp(ri, attr);
408 1.8 pk
409 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
410 1.1 ad height = ri->ri_font->fontheight;
411 1.8 pk
412 1.1 ad if (uc == ' ') {
413 1.8 pk while (height--)
414 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
415 1.1 ad } else {
416 1.1 ad uc -= ri->ri_font->firstchar;
417 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
418 1.1 ad fs = ri->ri_font->stride;
419 1.8 pk
420 1.1 ad while (height--) {
421 1.1 ad rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
422 1.1 ad rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
423 1.1 ad rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
424 1.1 ad rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
425 1.1 ad
426 1.1 ad fr += fs;
427 1.8 pk DELTA(rp, ri->ri_stride, int32_t *);
428 1.1 ad }
429 1.8 pk }
430 1.1 ad
431 1.1 ad /* Do underline */
432 1.7 ad if ((attr & 1) != 0) {
433 1.8 pk DELTA(rp, -(ri->ri_stride << 1), int32_t *);
434 1.8 pk rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
435 1.8 pk }
436 1.8 pk
437 1.1 ad stamp_mutex--;
438 1.1 ad }
439 1.7 ad #endif /* !RASOPS_SMALL */
440