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