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