rasops24.c revision 1.9 1 1.9 ad /* $NetBSD: rasops24.c,v 1.9 1999/10/23 23:14:14 ad Exp $ */
2 1.1 ad
3 1.6 ad /*-
4 1.6 ad * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.6 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.6 ad * by Andy Doran.
9 1.6 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.6 ad * 3. All advertising materials mentioning features or use of this software
19 1.6 ad * must display the following acknowledgement:
20 1.6 ad * This product includes software developed by the NetBSD
21 1.6 ad * Foundation, Inc. and its contributors.
22 1.6 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6 ad * contributors may be used to endorse or promote products derived
24 1.6 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.6 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.2 ad
39 1.1 ad #include "opt_rasops.h"
40 1.3 ad #include <sys/cdefs.h>
41 1.9 ad __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.9 1999/10/23 23:14:14 ad Exp $");
42 1.1 ad
43 1.1 ad #include <sys/types.h>
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.4 ad #include <machine/endian.h>
49 1.4 ad #include <machine/bswap.h>
50 1.4 ad
51 1.1 ad #include <dev/wscons/wsdisplayvar.h>
52 1.1 ad #include <dev/wscons/wsconsio.h>
53 1.1 ad #include <dev/rasops/rasops.h>
54 1.1 ad
55 1.9 ad static void rasops24_erasecols __P((void *, int, int, int, long));
56 1.9 ad static void rasops24_eraserows __P((void *, int, int, long));
57 1.1 ad static void rasops24_putchar __P((void *, int, int, u_int, long attr));
58 1.9 ad #ifndef RASOPS_SMALL
59 1.4 ad static void rasops24_putchar8 __P((void *, int, int, u_int, long attr));
60 1.4 ad static void rasops24_putchar12 __P((void *, int, int, u_int, long attr));
61 1.4 ad static void rasops24_putchar16 __P((void *, int, int, u_int, long attr));
62 1.4 ad static void rasops24_makestamp __P((struct rasops_info *, long));
63 1.9 ad #endif
64 1.1 ad
65 1.4 ad /*
66 1.4 ad * 4x1 stamp for optimized character blitting
67 1.4 ad */
68 1.4 ad static int32_t stamp[64];
69 1.4 ad static long stamp_attr;
70 1.4 ad static int stamp_mutex; /* XXX see note in readme */
71 1.4 ad
72 1.4 ad /*
73 1.4 ad * XXX this confuses the hell out of gcc2 (not egcs) which always insists
74 1.4 ad * that the shift count is negative.
75 1.4 ad *
76 1.4 ad * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
77 1.4 ad * destination int32_t[0] = STAMP_READ(offset)
78 1.4 ad * destination int32_t[1] = STAMP_READ(offset + 4)
79 1.4 ad * destination int32_t[2] = STAMP_READ(offset + 8)
80 1.4 ad */
81 1.4 ad #define STAMP_SHIFT(fb,n) ((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4))
82 1.4 ad #define STAMP_MASK (15 << 4)
83 1.4 ad #define STAMP_READ(o) (*(int32_t *)((caddr_t)stamp + (o)))
84 1.4 ad
85 1.1 ad /*
86 1.1 ad * Initalize rasops_info struct for this colordepth.
87 1.1 ad */
88 1.1 ad void
89 1.1 ad rasops24_init(ri)
90 1.1 ad struct rasops_info *ri;
91 1.1 ad {
92 1.1 ad
93 1.1 ad switch (ri->ri_font->fontwidth) {
94 1.9 ad #ifndef RASOPS_SMALL
95 1.1 ad case 8:
96 1.4 ad ri->ri_ops.putchar = rasops24_putchar8;
97 1.1 ad break;
98 1.1 ad case 12:
99 1.4 ad ri->ri_ops.putchar = rasops24_putchar12;
100 1.1 ad break;
101 1.1 ad case 16:
102 1.4 ad ri->ri_ops.putchar = rasops24_putchar16;
103 1.1 ad break;
104 1.9 ad #endif
105 1.1 ad default:
106 1.4 ad ri->ri_ops.putchar = rasops24_putchar;
107 1.1 ad break;
108 1.1 ad }
109 1.4 ad
110 1.1 ad if (ri->ri_rnum == 0) {
111 1.1 ad ri->ri_rnum = 8;
112 1.4 ad ri->ri_rpos = 0;
113 1.1 ad ri->ri_gnum = 8;
114 1.4 ad ri->ri_gpos = 8;
115 1.1 ad ri->ri_bnum = 8;
116 1.1 ad ri->ri_bpos = 16;
117 1.1 ad }
118 1.4 ad
119 1.4 ad ri->ri_ops.erasecols = rasops24_erasecols;
120 1.4 ad ri->ri_ops.eraserows = rasops24_eraserows;
121 1.1 ad }
122 1.1 ad
123 1.1 ad /*
124 1.4 ad * Put a single character. This is the generic version.
125 1.4 ad * XXX this bites - we should use masks.
126 1.1 ad */
127 1.4 ad static void
128 1.4 ad rasops24_putchar(cookie, row, col, uc, attr)
129 1.4 ad void *cookie;
130 1.4 ad int row, col;
131 1.4 ad u_int uc;
132 1.1 ad long attr;
133 1.1 ad {
134 1.9 ad int fb, width, height, cnt, clr[2];
135 1.4 ad struct rasops_info *ri;
136 1.4 ad u_char *dp, *rp, *fr;
137 1.1 ad
138 1.4 ad ri = (struct rasops_info *)cookie;
139 1.1 ad
140 1.4 ad #ifdef RASOPS_CLIPPING
141 1.4 ad /* Catches 'row < 0' case too */
142 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
143 1.4 ad return;
144 1.1 ad
145 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
146 1.4 ad return;
147 1.4 ad #endif
148 1.1 ad
149 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
150 1.1 ad height = ri->ri_font->fontheight;
151 1.4 ad width = ri->ri_font->fontwidth;
152 1.1 ad
153 1.4 ad clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 15];
154 1.4 ad clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 15];
155 1.4 ad
156 1.4 ad if (uc == ' ') {
157 1.4 ad while (height--) {
158 1.4 ad dp = rp;
159 1.4 ad rp += ri->ri_stride;
160 1.4 ad
161 1.4 ad for (cnt = width; cnt; cnt--) {
162 1.4 ad *dp++ = clr[0] >> 16;
163 1.4 ad *dp++ = clr[0] >> 8;
164 1.4 ad *dp++ = clr[0];
165 1.4 ad }
166 1.4 ad }
167 1.4 ad } else {
168 1.4 ad uc -= ri->ri_font->firstchar;
169 1.4 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
170 1.1 ad
171 1.4 ad while (height--) {
172 1.4 ad dp = rp;
173 1.9 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
174 1.9 ad (fr[0] << 24);
175 1.4 ad fr += ri->ri_font->stride;
176 1.4 ad rp += ri->ri_stride;
177 1.4 ad
178 1.4 ad for (cnt = width; cnt; cnt--, fb <<= 1) {
179 1.4 ad if ((fb >> 31) & 1) {
180 1.4 ad *dp++ = clr[1] >> 16;
181 1.4 ad *dp++ = clr[1] >> 8;
182 1.4 ad *dp++ = clr[1];
183 1.4 ad } else {
184 1.4 ad *dp++ = clr[0] >> 16;
185 1.4 ad *dp++ = clr[0] >> 8;
186 1.4 ad *dp++ = clr[0];
187 1.4 ad }
188 1.4 ad }
189 1.4 ad }
190 1.4 ad }
191 1.1 ad
192 1.4 ad /* Do underline */
193 1.9 ad if ((attr & 1) != 0) {
194 1.4 ad rp -= ri->ri_stride << 1;
195 1.4 ad
196 1.4 ad while (width--) {
197 1.4 ad *rp++ = clr[1] >> 16;
198 1.4 ad *rp++ = clr[1] >> 8;
199 1.4 ad *rp++ = clr[1];
200 1.1 ad }
201 1.4 ad }
202 1.1 ad }
203 1.1 ad
204 1.9 ad #ifndef RASOPS_SMALL
205 1.9 ad /*
206 1.9 ad * Recompute the blitting stamp.
207 1.9 ad */
208 1.9 ad static void
209 1.9 ad rasops24_makestamp(ri, attr)
210 1.9 ad struct rasops_info *ri;
211 1.9 ad long attr;
212 1.9 ad {
213 1.9 ad u_int fg, bg, c1, c2, c3, c4;
214 1.9 ad int i;
215 1.9 ad
216 1.9 ad fg = ri->ri_devcmap[((u_int)attr >> 24) & 15] & 0xffffff;
217 1.9 ad bg = ri->ri_devcmap[((u_int)attr >> 16) & 15] & 0xffffff;
218 1.9 ad stamp_attr = attr;
219 1.9 ad
220 1.9 ad for (i = 0; i < 64; i += 4) {
221 1.9 ad #if BYTE_ORDER == LITTLE_ENDIAN
222 1.9 ad c1 = (i & 32 ? fg : bg);
223 1.9 ad c2 = (i & 16 ? fg : bg);
224 1.9 ad c3 = (i & 8 ? fg : bg);
225 1.9 ad c4 = (i & 4 ? fg : bg);
226 1.9 ad #else
227 1.9 ad c1 = (i & 8 ? fg : bg);
228 1.9 ad c2 = (i & 4 ? fg : bg);
229 1.9 ad c3 = (i & 16 ? fg : bg);
230 1.9 ad c4 = (i & 32 ? fg : bg);
231 1.9 ad #endif
232 1.9 ad stamp[i+0] = (c1 << 8) | (c2 >> 16);
233 1.9 ad stamp[i+1] = (c2 << 16) | (c3 >> 8);
234 1.9 ad stamp[i+2] = (c3 << 24) | c4;
235 1.9 ad
236 1.9 ad #if BYTE_ORDER == LITTLE_ENDIAN
237 1.9 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
238 1.9 ad #else
239 1.9 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
240 1.9 ad #endif
241 1.9 ad stamp[i+0] = bswap32(stamp[i+0]);
242 1.9 ad stamp[i+1] = bswap32(stamp[i+1]);
243 1.9 ad stamp[i+2] = bswap32(stamp[i+2]);
244 1.9 ad }
245 1.9 ad }
246 1.9 ad }
247 1.1 ad
248 1.1 ad /*
249 1.4 ad * Put a single character. This is for 8-pixel wide fonts.
250 1.1 ad */
251 1.1 ad static void
252 1.4 ad rasops24_putchar8(cookie, row, col, uc, attr)
253 1.1 ad void *cookie;
254 1.4 ad int row, col;
255 1.4 ad u_int uc;
256 1.1 ad long attr;
257 1.1 ad {
258 1.1 ad struct rasops_info *ri;
259 1.4 ad int height, so, fs;
260 1.4 ad int32_t *rp;
261 1.4 ad u_char *fr;
262 1.4 ad
263 1.4 ad /* Can't risk remaking the stamp if it's already in use */
264 1.4 ad if (stamp_mutex++) {
265 1.4 ad stamp_mutex--;
266 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
267 1.4 ad return;
268 1.4 ad }
269 1.4 ad
270 1.1 ad ri = (struct rasops_info *)cookie;
271 1.1 ad
272 1.1 ad #ifdef RASOPS_CLIPPING
273 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
274 1.4 ad stamp_mutex--;
275 1.1 ad return;
276 1.4 ad }
277 1.1 ad
278 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
279 1.4 ad stamp_mutex--;
280 1.4 ad return;
281 1.1 ad }
282 1.4 ad #endif
283 1.1 ad
284 1.4 ad /* Recompute stamp? */
285 1.4 ad if (attr != stamp_attr)
286 1.4 ad rasops24_makestamp(ri, attr);
287 1.1 ad
288 1.4 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
289 1.1 ad height = ri->ri_font->fontheight;
290 1.1 ad
291 1.4 ad if (uc == (u_int)-1) {
292 1.4 ad while (height--) {
293 1.4 ad rp[0] = stamp[0];
294 1.4 ad rp[1] = stamp[0];
295 1.4 ad rp[2] = stamp[0];
296 1.4 ad rp[3] = stamp[0];
297 1.4 ad rp[4] = stamp[0];
298 1.4 ad rp[5] = stamp[0];
299 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
300 1.4 ad }
301 1.4 ad } else {
302 1.4 ad uc -= ri->ri_font->firstchar;
303 1.4 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
304 1.4 ad fs = ri->ri_font->stride;
305 1.4 ad
306 1.4 ad while (height--) {
307 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
308 1.4 ad rp[0] = STAMP_READ(so);
309 1.4 ad rp[1] = STAMP_READ(so + 4);
310 1.4 ad rp[2] = STAMP_READ(so + 8);
311 1.4 ad
312 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
313 1.4 ad rp[3] = STAMP_READ(so);
314 1.4 ad rp[4] = STAMP_READ(so + 4);
315 1.4 ad rp[5] = STAMP_READ(so + 8);
316 1.1 ad
317 1.4 ad fr += fs;
318 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
319 1.1 ad }
320 1.4 ad }
321 1.4 ad
322 1.4 ad /* Do underline */
323 1.9 ad if ((attr & 1) != 0) {
324 1.4 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
325 1.4 ad rp[0] = STAMP_READ(30);
326 1.4 ad rp[1] = STAMP_READ(30);
327 1.4 ad rp[2] = STAMP_READ(30);
328 1.4 ad rp[3] = STAMP_READ(30);
329 1.4 ad rp[4] = STAMP_READ(30);
330 1.4 ad rp[5] = STAMP_READ(30);
331 1.4 ad }
332 1.1 ad
333 1.4 ad stamp_mutex--;
334 1.1 ad }
335 1.1 ad
336 1.1 ad /*
337 1.4 ad * Put a single character. This is for 12-pixel wide fonts.
338 1.1 ad */
339 1.1 ad static void
340 1.4 ad rasops24_putchar12(cookie, row, col, uc, attr)
341 1.1 ad void *cookie;
342 1.1 ad int row, col;
343 1.1 ad u_int uc;
344 1.1 ad long attr;
345 1.1 ad {
346 1.1 ad struct rasops_info *ri;
347 1.4 ad int height, so, fs;
348 1.4 ad int32_t *rp;
349 1.4 ad u_char *fr;
350 1.4 ad
351 1.4 ad /* Can't risk remaking the stamp if it's already in use */
352 1.4 ad if (stamp_mutex++) {
353 1.4 ad stamp_mutex--;
354 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
355 1.1 ad return;
356 1.1 ad }
357 1.4 ad
358 1.1 ad ri = (struct rasops_info *)cookie;
359 1.1 ad
360 1.1 ad #ifdef RASOPS_CLIPPING
361 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
362 1.4 ad stamp_mutex--;
363 1.1 ad return;
364 1.4 ad }
365 1.1 ad
366 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
367 1.4 ad stamp_mutex--;
368 1.1 ad return;
369 1.4 ad }
370 1.1 ad #endif
371 1.4 ad
372 1.4 ad /* Recompute stamp? */
373 1.4 ad if (attr != stamp_attr)
374 1.4 ad rasops24_makestamp(ri, attr);
375 1.1 ad
376 1.4 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
377 1.4 ad height = ri->ri_font->fontheight;
378 1.1 ad
379 1.4 ad if (uc == (u_int)-1) {
380 1.4 ad while (height--) {
381 1.4 ad rp[0] = stamp[0];
382 1.4 ad rp[1] = stamp[0];
383 1.4 ad rp[2] = stamp[0];
384 1.4 ad rp[3] = stamp[0];
385 1.4 ad rp[4] = stamp[0];
386 1.4 ad rp[5] = stamp[0];
387 1.4 ad rp[6] = stamp[0];
388 1.4 ad rp[7] = stamp[0];
389 1.4 ad rp[8] = stamp[0];
390 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
391 1.4 ad }
392 1.4 ad } else {
393 1.4 ad uc -= ri->ri_font->firstchar;
394 1.4 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
395 1.4 ad fs = ri->ri_font->stride;
396 1.4 ad
397 1.4 ad while (height--) {
398 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
399 1.4 ad rp[0] = STAMP_READ(so);
400 1.4 ad rp[1] = STAMP_READ(so + 4);
401 1.4 ad rp[2] = STAMP_READ(so + 8);
402 1.4 ad
403 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
404 1.4 ad rp[3] = STAMP_READ(so);
405 1.4 ad rp[4] = STAMP_READ(so + 4);
406 1.4 ad rp[5] = STAMP_READ(so + 8);
407 1.4 ad
408 1.4 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
409 1.4 ad rp[6] = STAMP_READ(so);
410 1.4 ad rp[7] = STAMP_READ(so + 4);
411 1.4 ad rp[8] = STAMP_READ(so + 8);
412 1.1 ad
413 1.4 ad fr += fs;
414 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
415 1.1 ad }
416 1.1 ad }
417 1.4 ad
418 1.4 ad /* Do underline */
419 1.9 ad if ((attr & 1) != 0) {
420 1.4 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
421 1.4 ad rp[0] = STAMP_READ(30);
422 1.4 ad rp[1] = STAMP_READ(30);
423 1.4 ad rp[2] = STAMP_READ(30);
424 1.4 ad rp[3] = STAMP_READ(30);
425 1.4 ad rp[4] = STAMP_READ(30);
426 1.4 ad rp[5] = STAMP_READ(30);
427 1.4 ad rp[6] = STAMP_READ(30);
428 1.4 ad rp[7] = STAMP_READ(30);
429 1.4 ad rp[8] = STAMP_READ(30);
430 1.4 ad }
431 1.4 ad
432 1.4 ad stamp_mutex--;
433 1.1 ad }
434 1.1 ad
435 1.1 ad /*
436 1.4 ad * Put a single character. This is for 16-pixel wide fonts.
437 1.1 ad */
438 1.1 ad static void
439 1.4 ad rasops24_putchar16(cookie, row, col, uc, attr)
440 1.4 ad void *cookie;
441 1.4 ad int row, col;
442 1.4 ad u_int uc;
443 1.4 ad long attr;
444 1.1 ad {
445 1.4 ad struct rasops_info *ri;
446 1.4 ad int height, so, fs;
447 1.4 ad int32_t *rp;
448 1.4 ad u_char *fr;
449 1.4 ad
450 1.4 ad /* Can't risk remaking the stamp if it's already in use */
451 1.4 ad if (stamp_mutex++) {
452 1.4 ad stamp_mutex--;
453 1.4 ad rasops24_putchar(cookie, row, col, uc, attr);
454 1.4 ad return;
455 1.4 ad }
456 1.4 ad
457 1.4 ad ri = (struct rasops_info *)cookie;
458 1.4 ad
459 1.4 ad #ifdef RASOPS_CLIPPING
460 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
461 1.4 ad stamp_mutex--;
462 1.4 ad return;
463 1.4 ad }
464 1.4 ad
465 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
466 1.4 ad stamp_mutex--;
467 1.4 ad return;
468 1.4 ad }
469 1.4 ad #endif
470 1.4 ad
471 1.4 ad /* Recompute stamp? */
472 1.5 ad if (attr != stamp_attr)
473 1.4 ad rasops24_makestamp(ri, attr);
474 1.5 ad
475 1.4 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
476 1.4 ad height = ri->ri_font->fontheight;
477 1.1 ad
478 1.4 ad if (uc == (u_int)-1) {
479 1.4 ad while (height--) {
480 1.4 ad rp[0] = stamp[0];
481 1.4 ad rp[1] = stamp[0];
482 1.4 ad rp[2] = stamp[0];
483 1.4 ad rp[3] = stamp[0];
484 1.4 ad rp[4] = stamp[0];
485 1.4 ad rp[5] = stamp[0];
486 1.4 ad rp[6] = stamp[0];
487 1.4 ad rp[7] = stamp[0];
488 1.4 ad rp[8] = stamp[0];
489 1.4 ad rp[9] = stamp[0];
490 1.4 ad rp[10] = stamp[0];
491 1.4 ad rp[11] = stamp[0];
492 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
493 1.4 ad }
494 1.4 ad } else {
495 1.4 ad uc -= ri->ri_font->firstchar;
496 1.4 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
497 1.4 ad fs = ri->ri_font->stride;
498 1.4 ad
499 1.4 ad while (height--) {
500 1.4 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
501 1.4 ad rp[0] = STAMP_READ(so);
502 1.4 ad rp[1] = STAMP_READ(so + 4);
503 1.4 ad rp[2] = STAMP_READ(so + 8);
504 1.4 ad
505 1.4 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
506 1.4 ad rp[3] = STAMP_READ(so);
507 1.4 ad rp[4] = STAMP_READ(so + 4);
508 1.4 ad rp[5] = STAMP_READ(so + 8);
509 1.4 ad
510 1.4 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
511 1.4 ad rp[6] = STAMP_READ(so);
512 1.4 ad rp[7] = STAMP_READ(so + 4);
513 1.4 ad rp[8] = STAMP_READ(so + 8);
514 1.4 ad
515 1.4 ad so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
516 1.4 ad rp[9] = STAMP_READ(so);
517 1.4 ad rp[10] = STAMP_READ(so + 4);
518 1.4 ad rp[11] = STAMP_READ(so + 8);
519 1.4 ad
520 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
521 1.4 ad fr += fs;
522 1.4 ad }
523 1.4 ad }
524 1.1 ad
525 1.4 ad /* Do underline */
526 1.9 ad if ((attr & 1) != 0) {
527 1.4 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
528 1.4 ad rp[0] = STAMP_READ(30);
529 1.4 ad rp[1] = STAMP_READ(30);
530 1.4 ad rp[2] = STAMP_READ(30);
531 1.4 ad rp[3] = STAMP_READ(30);
532 1.4 ad rp[4] = STAMP_READ(30);
533 1.4 ad rp[5] = STAMP_READ(30);
534 1.4 ad rp[6] = STAMP_READ(30);
535 1.4 ad rp[7] = STAMP_READ(30);
536 1.4 ad rp[8] = STAMP_READ(30);
537 1.4 ad rp[9] = STAMP_READ(30);
538 1.4 ad rp[10] = STAMP_READ(30);
539 1.4 ad rp[11] = STAMP_READ(30);
540 1.4 ad }
541 1.4 ad
542 1.4 ad stamp_mutex--;
543 1.1 ad }
544 1.1 ad
545 1.1 ad /*
546 1.4 ad * Erase rows. This is nice and easy due to alignment.
547 1.1 ad */
548 1.1 ad static void
549 1.1 ad rasops24_eraserows(cookie, row, num, attr)
550 1.1 ad void *cookie;
551 1.1 ad int row, num;
552 1.1 ad long attr;
553 1.1 ad {
554 1.8 ad int n9, n3, n1, cnt, stride, delta;
555 1.8 ad u_int32_t *dp, clr, stamp[3];
556 1.1 ad struct rasops_info *ri;
557 1.1 ad
558 1.4 ad /*
559 1.4 ad * If the color is gray, we can cheat and use the generic routines
560 1.4 ad * (which are faster, hopefully) since the r,g,b values are the same.
561 1.4 ad */
562 1.9 ad if ((attr & 4) != 0) {
563 1.4 ad rasops_eraserows(cookie, row, num, attr);
564 1.4 ad return;
565 1.4 ad }
566 1.4 ad
567 1.1 ad ri = (struct rasops_info *)cookie;
568 1.1 ad
569 1.1 ad #ifdef RASOPS_CLIPPING
570 1.1 ad if (row < 0) {
571 1.1 ad num += row;
572 1.1 ad row = 0;
573 1.1 ad }
574 1.1 ad
575 1.1 ad if ((row + num) > ri->ri_rows)
576 1.1 ad num = ri->ri_rows - row;
577 1.1 ad
578 1.1 ad if (num <= 0)
579 1.1 ad return;
580 1.1 ad #endif
581 1.4 ad
582 1.4 ad clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
583 1.4 ad stamp[0] = (clr << 8) | (clr >> 16);
584 1.4 ad stamp[1] = (clr << 16) | (clr >> 8);
585 1.4 ad stamp[2] = (clr << 24) | clr;
586 1.4 ad
587 1.4 ad #if BYTE_ORDER == LITTLE_ENDIAN
588 1.7 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
589 1.4 ad #else
590 1.7 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
591 1.4 ad #endif
592 1.4 ad stamp[0] = bswap32(stamp[0]);
593 1.4 ad stamp[1] = bswap32(stamp[1]);
594 1.4 ad stamp[2] = bswap32(stamp[2]);
595 1.4 ad }
596 1.4 ad
597 1.7 ad /*
598 1.7 ad * XXX the wsdisplay_emulops interface seems a little deficient in
599 1.7 ad * that there is no way to clear the *entire* screen. We provide a
600 1.7 ad * workaround here: if the entire console area is being cleared, and
601 1.7 ad * the RI_FULLCLEAR flag is set, clear the entire display.
602 1.7 ad */
603 1.7 ad if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
604 1.7 ad stride = ri->ri_stride;
605 1.7 ad num = ri->ri_height;
606 1.8 ad dp = (int32_t *)ri->ri_origbits;
607 1.8 ad delta = 0;
608 1.7 ad } else {
609 1.7 ad stride = ri->ri_emustride;
610 1.7 ad num *= ri->ri_font->fontheight;
611 1.8 ad dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
612 1.8 ad delta = ri->ri_delta;
613 1.7 ad }
614 1.7 ad
615 1.7 ad n9 = stride / 36;
616 1.1 ad cnt = (n9 << 5) + (n9 << 2); /* (32*n9) + (4*n9) */
617 1.7 ad n3 = (stride - cnt) / 12;
618 1.1 ad cnt += (n3 << 3) + (n3 << 2); /* (8*n3) + (4*n3) */
619 1.7 ad n1 = (stride - cnt) >> 2;
620 1.1 ad
621 1.4 ad while (num--) {
622 1.4 ad for (cnt = n9; cnt; cnt--) {
623 1.4 ad dp[0] = stamp[0];
624 1.4 ad dp[1] = stamp[1];
625 1.4 ad dp[2] = stamp[2];
626 1.4 ad dp[3] = stamp[0];
627 1.4 ad dp[4] = stamp[1];
628 1.4 ad dp[5] = stamp[2];
629 1.4 ad dp[6] = stamp[0];
630 1.4 ad dp[7] = stamp[1];
631 1.4 ad dp[8] = stamp[2];
632 1.4 ad dp += 9;
633 1.4 ad }
634 1.1 ad
635 1.4 ad for (cnt = n3; cnt; cnt--) {
636 1.4 ad dp[0] = stamp[0];
637 1.4 ad dp[1] = stamp[1];
638 1.4 ad dp[2] = stamp[2];
639 1.4 ad dp += 3;
640 1.4 ad }
641 1.1 ad
642 1.4 ad for (cnt = 0; cnt < n1; cnt++)
643 1.4 ad *dp++ = stamp[cnt];
644 1.4 ad
645 1.8 ad DELTA(dp, delta, int32_t *);
646 1.4 ad }
647 1.4 ad }
648 1.4 ad
649 1.4 ad /*
650 1.4 ad * Erase columns.
651 1.4 ad */
652 1.4 ad static void
653 1.4 ad rasops24_erasecols(cookie, row, col, num, attr)
654 1.4 ad void *cookie;
655 1.4 ad int row, col, num;
656 1.4 ad long attr;
657 1.4 ad {
658 1.4 ad int n12, n4, height, cnt, slop, clr, stamp[3];
659 1.4 ad struct rasops_info *ri;
660 1.4 ad int32_t *dp, *rp;
661 1.4 ad u_char *dbp;
662 1.4 ad
663 1.4 ad /*
664 1.4 ad * If the color is gray, we can cheat and use the generic routines
665 1.4 ad * (which are faster, hopefully) since the r,g,b values are the same.
666 1.4 ad */
667 1.9 ad if ((attr & 4) != 0) {
668 1.4 ad rasops_erasecols(cookie, row, col, num, attr);
669 1.4 ad return;
670 1.4 ad }
671 1.4 ad
672 1.4 ad ri = (struct rasops_info *)cookie;
673 1.4 ad
674 1.4 ad #ifdef RASOPS_CLIPPING
675 1.4 ad /* Catches 'row < 0' case too */
676 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
677 1.4 ad return;
678 1.4 ad
679 1.4 ad if (col < 0) {
680 1.4 ad num += col;
681 1.4 ad col = 0;
682 1.4 ad }
683 1.4 ad
684 1.4 ad if ((col + num) > ri->ri_cols)
685 1.4 ad num = ri->ri_cols - col;
686 1.4 ad
687 1.4 ad if (num <= 0)
688 1.4 ad return;
689 1.4 ad #endif
690 1.4 ad
691 1.4 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
692 1.4 ad num *= ri->ri_font->fontwidth;
693 1.4 ad height = ri->ri_font->fontheight;
694 1.4 ad
695 1.4 ad clr = ri->ri_devcmap[(attr >> 16) & 15] & 0xffffff;
696 1.4 ad stamp[0] = (clr << 8) | (clr >> 16);
697 1.4 ad stamp[1] = (clr << 16) | (clr >> 8);
698 1.4 ad stamp[2] = (clr << 24) | clr;
699 1.4 ad
700 1.4 ad #if BYTE_ORDER == LITTLE_ENDIAN
701 1.7 ad if ((ri->ri_flg & RI_BSWAP) == 0) {
702 1.4 ad #else
703 1.7 ad if ((ri->ri_flg & RI_BSWAP) != 0) {
704 1.4 ad #endif
705 1.4 ad stamp[0] = bswap32(stamp[0]);
706 1.4 ad stamp[1] = bswap32(stamp[1]);
707 1.4 ad stamp[2] = bswap32(stamp[2]);
708 1.4 ad }
709 1.4 ad
710 1.4 ad /*
711 1.4 ad * The current byte offset mod 4 tells us the number of 24-bit pels
712 1.4 ad * we need to write for alignment to 32-bits. Once we're aligned on
713 1.4 ad * a 32-bit boundary, we're also aligned on a 4 pixel boundary, so
714 1.4 ad * the stamp does not need to be rotated. The following shows the
715 1.9 ad * layout of 4 pels in a 3 word region and illustrates this:
716 1.4 ad *
717 1.4 ad * aaab bbcc cddd
718 1.4 ad */
719 1.4 ad slop = (int)rp & 3; num -= slop;
720 1.4 ad n12 = num / 12; num -= (n12 << 3) + (n12 << 2);
721 1.4 ad n4 = num >> 2; num &= 3;
722 1.4 ad
723 1.4 ad while (height--) {
724 1.4 ad dbp = (u_char *)rp;
725 1.4 ad DELTA(rp, ri->ri_stride, int32_t *);
726 1.4 ad
727 1.4 ad /* Align to 4 bytes */
728 1.7 ad /* XXX handle with masks, bring under control of RI_BSWAP */
729 1.4 ad for (cnt = slop; cnt; cnt--) {
730 1.4 ad *dbp++ = (clr >> 16);
731 1.4 ad *dbp++ = (clr >> 8);
732 1.4 ad *dbp++ = clr;
733 1.4 ad }
734 1.4 ad
735 1.4 ad dp = (int32_t *)dbp;
736 1.4 ad
737 1.4 ad /* 12 pels per loop */
738 1.4 ad for (cnt = n12; cnt; cnt--) {
739 1.4 ad dp[0] = stamp[0];
740 1.4 ad dp[1] = stamp[1];
741 1.4 ad dp[2] = stamp[2];
742 1.4 ad dp[3] = stamp[0];
743 1.4 ad dp[4] = stamp[1];
744 1.4 ad dp[5] = stamp[2];
745 1.4 ad dp[6] = stamp[0];
746 1.4 ad dp[7] = stamp[1];
747 1.4 ad dp[8] = stamp[2];
748 1.4 ad dp += 9;
749 1.1 ad }
750 1.1 ad
751 1.4 ad /* 4 pels per loop */
752 1.4 ad for (cnt = n4; cnt; cnt--) {
753 1.4 ad dp[0] = stamp[0];
754 1.4 ad dp[1] = stamp[1];
755 1.4 ad dp[2] = stamp[2];
756 1.4 ad dp += 3;
757 1.4 ad }
758 1.1 ad
759 1.4 ad /* Trailing slop */
760 1.7 ad /* XXX handle with masks, bring under control of RI_BSWAP */
761 1.4 ad dbp = (u_char *)dp;
762 1.4 ad for (cnt = num; cnt; cnt--) {
763 1.4 ad *dbp++ = (clr >> 16);
764 1.4 ad *dbp++ = (clr >> 8);
765 1.4 ad *dbp++ = clr;
766 1.4 ad }
767 1.1 ad }
768 1.1 ad }
769 1.9 ad #endif /* !RASOPS_SMALL */
770