rasops15.c revision 1.2 1 1.2 ad /* $NetBSD: rasops15.c,v 1.2 1999/04/13 00:40:09 ad Exp $ */
2 1.1 ad
3 1.2 ad /*
4 1.2 ad * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * Redistribution and use in source and binary forms, with or without
8 1.1 ad * modification, are permitted provided that the following conditions
9 1.1 ad * are met:
10 1.1 ad * 1. Redistributions of source code must retain the above copyright
11 1.1 ad * notice, this list of conditions and the following disclaimer.
12 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ad * notice, this list of conditions and the following disclaimer in the
14 1.1 ad * documentation and/or other materials provided with the distribution.
15 1.1 ad *
16 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.2 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.2 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.2 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.2 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.2 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.2 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2 ad * SUCH DAMAGE.
27 1.2 ad *
28 1.1 ad */
29 1.2 ad
30 1.1 ad #include "opt_rasops.h"
31 1.1 ad #ifdef RASOPS15
32 1.1 ad
33 1.1 ad #include <sys/cdefs.h>
34 1.2 ad __KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.2 1999/04/13 00:40:09 ad Exp $");
35 1.1 ad
36 1.1 ad #include <sys/types.h>
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.1 ad #include <dev/wscons/wsdisplayvar.h>
42 1.1 ad #include <dev/wscons/wsconsio.h>
43 1.1 ad #include <dev/rasops/rasops.h>
44 1.1 ad
45 1.1 ad static void rasops15_putchar __P((void *, int, int, u_int, long attr));
46 1.1 ad static void rasops15_putchar8 __P((void *, int, int, u_int, long attr));
47 1.1 ad static void rasops15_putchar12 __P((void *, int, int, u_int, long attr));
48 1.1 ad static void rasops15_putchar16 __P((void *, int, int, u_int, long attr));
49 1.1 ad static void rasops15_erasecols __P((void *, int, int, int, long));
50 1.1 ad static void rasops15_eraserows __P((void *, int, int, long));
51 1.1 ad static void rasops15_makestamp __P((struct rasops_info *, long));
52 1.1 ad static int32_t rasops15_bg_color __P((struct rasops_info *, long));
53 1.1 ad static void rasops15_do_cursor __P((struct rasops_info *));
54 1.1 ad
55 1.1 ad void rasops15_init __P((struct rasops_info *ri));
56 1.1 ad
57 1.1 ad /*
58 1.1 ad * (2x2)x1 stamp for optimized character blitting
59 1.1 ad */
60 1.1 ad static int32_t stamp[32];
61 1.1 ad static long stamp_attr;
62 1.1 ad static int stamp_mutex; /* XXX see note in readme */
63 1.1 ad
64 1.1 ad /*
65 1.1 ad * XXX this confuses the hell out of gcc2 (not egcs) which always insists
66 1.1 ad * that the shift count is negative.
67 1.1 ad *
68 1.1 ad * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
69 1.1 ad * destination int32_t[0] = STAMP_READ(offset)
70 1.1 ad * destination int32_t[1] = STAMP_READ(offset + 4)
71 1.1 ad */
72 1.1 ad #define STAMP_SHIFT(fb,n) ((n*4-3) >= 0 ? (fb)>>(n*4-3):(fb)<<-(n*4-3))
73 1.1 ad #define STAMP_MASK (15 << 3)
74 1.1 ad #define STAMP_READ(o) (*(int32_t *)((caddr_t)stamp + (o)))
75 1.1 ad
76 1.1 ad
77 1.1 ad /*
78 1.1 ad * Initalize rasops_info struct for this colordepth.
79 1.1 ad */
80 1.1 ad void
81 1.1 ad rasops15_init(ri)
82 1.1 ad struct rasops_info *ri;
83 1.1 ad {
84 1.1 ad
85 1.1 ad switch (ri->ri_font->fontwidth) {
86 1.1 ad case 8:
87 1.1 ad ri->ri_ops.putchar = rasops15_putchar8;
88 1.1 ad break;
89 1.1 ad
90 1.1 ad case 12:
91 1.1 ad ri->ri_ops.putchar = rasops15_putchar12;
92 1.1 ad break;
93 1.1 ad
94 1.1 ad case 16:
95 1.1 ad ri->ri_ops.putchar = rasops15_putchar16;
96 1.1 ad break;
97 1.1 ad
98 1.1 ad default:
99 1.1 ad ri->ri_ops.putchar = rasops15_putchar;
100 1.1 ad break;
101 1.1 ad }
102 1.1 ad
103 1.1 ad /* Select defaults for color masks if none selected */
104 1.1 ad if (ri->ri_rnum == 0) {
105 1.1 ad ri->ri_rnum = 5;
106 1.1 ad ri->ri_rpos = 0;
107 1.1 ad ri->ri_gnum = 5 + (ri->ri_depth == 16);
108 1.1 ad ri->ri_gpos = 5;
109 1.1 ad ri->ri_bnum = 5;
110 1.1 ad ri->ri_bpos = 10 + (ri->ri_depth == 16);
111 1.1 ad }
112 1.1 ad
113 1.1 ad ri->ri_ops.erasecols = rasops15_erasecols;
114 1.1 ad ri->ri_ops.eraserows = rasops15_eraserows;
115 1.1 ad ri->ri_do_cursor = rasops15_do_cursor;
116 1.1 ad rasops_init_devcmap(ri);
117 1.1 ad }
118 1.1 ad
119 1.1 ad
120 1.1 ad /*
121 1.1 ad * Get background color from attribute and copy across all 4 bytes
122 1.1 ad * in a int32_t.
123 1.1 ad */
124 1.1 ad static __inline__ int32_t
125 1.1 ad rasops15_bg_color(ri, attr)
126 1.1 ad struct rasops_info *ri;
127 1.1 ad long attr;
128 1.1 ad {
129 1.1 ad int32_t bg;
130 1.1 ad
131 1.1 ad bg = ri->ri_devcmap[((u_int)attr >> 16) & 15];
132 1.1 ad return bg | (bg << 16);
133 1.1 ad }
134 1.1 ad
135 1.1 ad
136 1.1 ad /*
137 1.1 ad * Actually turn the cursor on or off. This does the dirty work for
138 1.1 ad * rasops_cursor().
139 1.1 ad */
140 1.1 ad static void
141 1.1 ad rasops15_do_cursor(ri)
142 1.1 ad struct rasops_info *ri;
143 1.1 ad {
144 1.1 ad u_char *rp, *dp;
145 1.1 ad int full1, height, cnt, slop1, slop2, row, col;
146 1.1 ad int32_t planemask;
147 1.1 ad
148 1.1 ad row = ri->ri_crow;
149 1.1 ad col = ri->ri_ccol;
150 1.1 ad
151 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
152 1.1 ad height = ri->ri_font->fontheight;
153 1.1 ad
154 1.1 ad slop1 = (int)rp & 2;
155 1.1 ad slop2 = (ri->ri_xscale - slop1) & 2;
156 1.1 ad full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
157 1.1 ad planemask = ri->ri_devcmap[15] | (ri->ri_devcmap[15] << 16);
158 1.1 ad
159 1.1 ad while (height--) {
160 1.1 ad dp = rp;
161 1.1 ad rp += ri->ri_stride;
162 1.1 ad
163 1.1 ad if (slop1) {
164 1.1 ad *(int16_t *)dp ^= (int16_t)planemask;
165 1.1 ad dp += 2;
166 1.1 ad }
167 1.1 ad
168 1.1 ad for (cnt = full1; cnt; cnt--) {
169 1.1 ad *(int32_t *)dp ^= planemask;
170 1.1 ad dp += 4;
171 1.1 ad }
172 1.1 ad
173 1.1 ad if (slop2)
174 1.1 ad *(int16_t *)dp ^= (int16_t)planemask;
175 1.1 ad }
176 1.1 ad }
177 1.1 ad
178 1.1 ad
179 1.1 ad /*
180 1.1 ad * Erase columns.
181 1.1 ad */
182 1.1 ad static void
183 1.1 ad rasops15_erasecols(cookie, row, col, num, attr)
184 1.1 ad void *cookie;
185 1.1 ad int row, num;
186 1.1 ad long attr;
187 1.1 ad {
188 1.1 ad int n8, clr, height, cnt, slop1, slop2;
189 1.1 ad struct rasops_info *ri;
190 1.1 ad int32_t *dp;
191 1.1 ad u_char *rp;
192 1.1 ad
193 1.1 ad ri = (struct rasops_info *)cookie;
194 1.1 ad
195 1.1 ad #ifdef RASOPS_CLIPPING
196 1.1 ad /* Catches 'row < 0' case too */
197 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
198 1.1 ad return;
199 1.1 ad
200 1.1 ad if (col < 0) {
201 1.1 ad num += col;
202 1.1 ad col = 0;
203 1.1 ad }
204 1.1 ad
205 1.1 ad if ((col + num) > ri->ri_cols)
206 1.1 ad num = ri->ri_cols - col;
207 1.1 ad
208 1.1 ad if (num <= 0)
209 1.1 ad return;
210 1.1 ad #endif
211 1.1 ad
212 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
213 1.1 ad num *= ri->ri_xscale;
214 1.1 ad clr = rasops15_bg_color(ri, attr);
215 1.1 ad height = ri->ri_font->fontheight;
216 1.1 ad
217 1.1 ad slop1 = (int)rp & 2;
218 1.1 ad slop2 = (num - slop1) & 2;
219 1.1 ad num = num - slop1 - slop2;
220 1.1 ad n8 = num >> 5;
221 1.1 ad num = (num >> 2) & 7;
222 1.1 ad
223 1.1 ad while (height--) {
224 1.1 ad dp = (u_int32_t *)rp;
225 1.1 ad rp += ri->ri_stride;
226 1.1 ad
227 1.1 ad /* Align span to 4 bytes */
228 1.1 ad if (slop1) {
229 1.1 ad *(int16_t *)dp = (int16_t)clr;
230 1.1 ad DELTA(dp, 2, int32_t *);
231 1.1 ad }
232 1.1 ad
233 1.1 ad /* Write 32 bytes per loop */
234 1.1 ad for (cnt = n8; cnt; cnt--) {
235 1.1 ad dp[0] = clr;
236 1.1 ad dp[1] = clr;
237 1.1 ad dp[2] = clr;
238 1.1 ad dp[3] = clr;
239 1.1 ad dp[4] = clr;
240 1.1 ad dp[5] = clr;
241 1.1 ad dp[6] = clr;
242 1.1 ad dp[7] = clr;
243 1.1 ad dp += 8;
244 1.1 ad }
245 1.1 ad
246 1.1 ad /* Write 4 bytes per loop */
247 1.1 ad for (cnt = num; cnt; cnt--)
248 1.1 ad *dp++ = clr;
249 1.1 ad
250 1.1 ad /* Write unaligned trailing slop */
251 1.1 ad if (slop2)
252 1.1 ad *(int16_t *)dp = (int16_t)clr;
253 1.1 ad }
254 1.1 ad }
255 1.1 ad
256 1.1 ad
257 1.1 ad /*
258 1.1 ad * Paint a single character.
259 1.1 ad */
260 1.1 ad static void
261 1.1 ad rasops15_putchar(cookie, row, col, uc, attr)
262 1.1 ad void *cookie;
263 1.1 ad int row, col;
264 1.1 ad u_int uc;
265 1.1 ad long attr;
266 1.1 ad {
267 1.1 ad struct rasops_info *ri;
268 1.1 ad int fb, width, height, cnt, clr[2];
269 1.1 ad u_char *dp, *rp, *fr;
270 1.1 ad
271 1.1 ad if (uc == (u_int)-1) {
272 1.1 ad rasops15_erasecols(cookie, row, col, 1, attr);
273 1.1 ad return;
274 1.1 ad }
275 1.1 ad
276 1.1 ad ri = (struct rasops_info *)cookie;
277 1.1 ad
278 1.1 ad #ifdef RASOPS_CLIPPING
279 1.1 ad /* Catches 'row < 0' case too */
280 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
281 1.1 ad return;
282 1.1 ad
283 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
284 1.1 ad return;
285 1.1 ad #endif
286 1.1 ad
287 1.1 ad uc -= ri->ri_font->firstchar;
288 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
289 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
290 1.1 ad
291 1.1 ad height = ri->ri_font->fontheight;
292 1.1 ad width = ri->ri_font->fontwidth;
293 1.1 ad
294 1.1 ad clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 15];
295 1.1 ad clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 15];
296 1.1 ad
297 1.1 ad while (height--) {
298 1.1 ad dp = rp;
299 1.1 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
300 1.1 ad fr += ri->ri_font->stride;
301 1.1 ad rp += ri->ri_stride;
302 1.1 ad
303 1.1 ad for (cnt = width; cnt; cnt--) {
304 1.1 ad *(int16_t *)dp = (int16_t)clr[(fb >> 31) & 1];
305 1.1 ad fb <<= 1;
306 1.1 ad dp += 2;
307 1.1 ad }
308 1.1 ad }
309 1.1 ad }
310 1.1 ad
311 1.1 ad
312 1.1 ad /*
313 1.1 ad * Recompute the (2x2)x1 blitting stamp.
314 1.1 ad */
315 1.1 ad static void
316 1.1 ad rasops15_makestamp(ri, attr)
317 1.1 ad struct rasops_info *ri;
318 1.1 ad long attr;
319 1.1 ad {
320 1.1 ad int32_t fg, bg;
321 1.1 ad int i;
322 1.1 ad
323 1.1 ad fg = ri->ri_devcmap[((u_int)attr >> 24) & 15];
324 1.1 ad bg = ri->ri_devcmap[((u_int)attr >> 16) & 15];
325 1.1 ad stamp_attr = attr;
326 1.1 ad
327 1.1 ad for (i = 0; i < 16; i++) {
328 1.1 ad #if BYTE_ORDER == LITTLE_ENDIAN
329 1.1 ad stamp[i << 1] = (i & 8 ? fg : bg);
330 1.1 ad stamp[i << 1] |= ((i & 4 ? fg : bg) << 16);
331 1.1 ad stamp[(i << 1) + 1] = (i & 2 ? fg : bg);
332 1.1 ad stamp[(i << 1) + 1] |= ((i & 1 ? fg : bg) << 16);
333 1.1 ad #else
334 1.1 ad stamp[i << 1] = (i & 1 ? fg : bg);
335 1.1 ad stamp[i << 1] |= ((i & 2 ? fg : bg) << 16);
336 1.1 ad stamp[(i << 1) + 1] = (i & 4 ? fg : bg);
337 1.1 ad stamp[(i << 1) + 1] |= ((i & 8 ? fg : bg) << 16);
338 1.1 ad #endif
339 1.1 ad }
340 1.1 ad }
341 1.1 ad
342 1.1 ad
343 1.1 ad /*
344 1.1 ad * Paint a single character. This is for 8-pixel wide fonts.
345 1.1 ad */
346 1.1 ad static void
347 1.1 ad rasops15_putchar8(cookie, row, col, uc, attr)
348 1.1 ad void *cookie;
349 1.1 ad int row, col;
350 1.1 ad u_int uc;
351 1.1 ad long attr;
352 1.1 ad {
353 1.1 ad struct rasops_info *ri;
354 1.1 ad int height, so, fs;
355 1.1 ad int32_t *rp;
356 1.1 ad u_char *fr;
357 1.1 ad
358 1.1 ad /* Can't risk remaking the stamp if it's already in use */
359 1.1 ad if (stamp_mutex++) {
360 1.1 ad stamp_mutex--;
361 1.1 ad rasops15_putchar(cookie, row, col, uc, attr);
362 1.1 ad return;
363 1.1 ad }
364 1.1 ad
365 1.1 ad ri = (struct rasops_info *)cookie;
366 1.1 ad
367 1.1 ad #ifdef RASOPS_CLIPPING
368 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
369 1.1 ad stamp_mutex--;
370 1.1 ad return;
371 1.1 ad }
372 1.1 ad
373 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
374 1.1 ad stamp_mutex--;
375 1.1 ad return;
376 1.1 ad }
377 1.1 ad #endif
378 1.1 ad
379 1.1 ad /* Recompute stamp? */
380 1.1 ad if (attr != stamp_attr)
381 1.1 ad rasops15_makestamp(ri, attr);
382 1.1 ad
383 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
384 1.1 ad height = ri->ri_font->fontheight;
385 1.1 ad
386 1.1 ad if (uc == (u_int)-1) {
387 1.1 ad while (height--) {
388 1.1 ad rp[0] = stamp[0];
389 1.1 ad rp[1] = stamp[0];
390 1.1 ad rp[2] = stamp[0];
391 1.1 ad rp[3] = stamp[0];
392 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
393 1.1 ad }
394 1.1 ad } else {
395 1.1 ad uc -= ri->ri_font->firstchar;
396 1.1 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
397 1.1 ad fs = ri->ri_font->stride;
398 1.1 ad
399 1.1 ad while (height--) {
400 1.1 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
401 1.1 ad rp[0] = STAMP_READ(so);
402 1.1 ad rp[1] = STAMP_READ(so + 4);
403 1.1 ad
404 1.1 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
405 1.1 ad rp[2] = STAMP_READ(so);
406 1.1 ad rp[3] = STAMP_READ(so + 4);
407 1.1 ad
408 1.1 ad fr += fs;
409 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
410 1.1 ad }
411 1.1 ad }
412 1.1 ad
413 1.1 ad stamp_mutex--;
414 1.1 ad }
415 1.1 ad
416 1.1 ad
417 1.1 ad /*
418 1.1 ad * Paint a single character. This is for 12-pixel wide fonts.
419 1.1 ad */
420 1.1 ad static void
421 1.1 ad rasops15_putchar12(cookie, row, col, uc, attr)
422 1.1 ad void *cookie;
423 1.1 ad int row, col;
424 1.1 ad u_int uc;
425 1.1 ad long attr;
426 1.1 ad {
427 1.1 ad struct rasops_info *ri;
428 1.1 ad int height, so, fs;
429 1.1 ad int32_t *rp;
430 1.1 ad u_char *fr;
431 1.1 ad
432 1.1 ad /* Can't risk remaking the stamp if it's already in use */
433 1.1 ad if (stamp_mutex++) {
434 1.1 ad stamp_mutex--;
435 1.1 ad rasops15_putchar(cookie, row, col, uc, attr);
436 1.1 ad return;
437 1.1 ad }
438 1.1 ad
439 1.1 ad ri = (struct rasops_info *)cookie;
440 1.1 ad
441 1.1 ad #ifdef RASOPS_CLIPPING
442 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
443 1.1 ad stamp_mutex--;
444 1.1 ad return;
445 1.1 ad }
446 1.1 ad
447 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
448 1.1 ad stamp_mutex--;
449 1.1 ad return;
450 1.1 ad }
451 1.1 ad #endif
452 1.1 ad
453 1.1 ad /* Recompute stamp? */
454 1.1 ad if (attr != stamp_attr)
455 1.1 ad rasops15_makestamp(ri, attr);
456 1.1 ad
457 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
458 1.1 ad height = ri->ri_font->fontheight;
459 1.1 ad
460 1.1 ad if (uc == (u_int)-1) {
461 1.1 ad while (height--) {
462 1.1 ad rp[0] = stamp[0];
463 1.1 ad rp[1] = stamp[0];
464 1.1 ad rp[2] = stamp[0];
465 1.1 ad rp[3] = stamp[0];
466 1.1 ad rp[4] = stamp[0];
467 1.1 ad rp[5] = stamp[0];
468 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
469 1.1 ad }
470 1.1 ad } else {
471 1.1 ad uc -= ri->ri_font->firstchar;
472 1.1 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
473 1.1 ad fs = ri->ri_font->stride;
474 1.1 ad
475 1.1 ad while (height--) {
476 1.1 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
477 1.1 ad rp[0] = STAMP_READ(so);
478 1.1 ad rp[1] = STAMP_READ(so + 4);
479 1.1 ad
480 1.1 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
481 1.1 ad rp[2] = STAMP_READ(so);
482 1.1 ad rp[3] = STAMP_READ(so + 4);
483 1.1 ad
484 1.1 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
485 1.1 ad rp[4] = STAMP_READ(so);
486 1.1 ad rp[5] = STAMP_READ(so + 4);
487 1.1 ad
488 1.1 ad fr += fs;
489 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
490 1.1 ad }
491 1.1 ad }
492 1.1 ad
493 1.1 ad stamp_mutex--;
494 1.1 ad }
495 1.1 ad
496 1.1 ad
497 1.1 ad /*
498 1.1 ad * Paint a single character. This is for 16-pixel wide fonts.
499 1.1 ad */
500 1.1 ad static void
501 1.1 ad rasops15_putchar16(cookie, row, col, uc, attr)
502 1.1 ad void *cookie;
503 1.1 ad int row, col;
504 1.1 ad u_int uc;
505 1.1 ad long attr;
506 1.1 ad {
507 1.1 ad struct rasops_info *ri;
508 1.1 ad int height, so, fs;
509 1.1 ad int32_t *rp;
510 1.1 ad u_char *fr;
511 1.1 ad
512 1.1 ad /* Can't risk remaking the stamp if it's already in use */
513 1.1 ad if (stamp_mutex++) {
514 1.1 ad stamp_mutex--;
515 1.1 ad rasops15_putchar(cookie, row, col, uc, attr);
516 1.1 ad return;
517 1.1 ad }
518 1.1 ad
519 1.1 ad ri = (struct rasops_info *)cookie;
520 1.1 ad
521 1.1 ad #ifdef RASOPS_CLIPPING
522 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
523 1.1 ad stamp_mutex--;
524 1.1 ad return;
525 1.1 ad }
526 1.1 ad
527 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
528 1.1 ad stamp_mutex--;
529 1.1 ad return;
530 1.1 ad }
531 1.1 ad #endif
532 1.1 ad
533 1.1 ad /* Recompute stamp? */
534 1.1 ad if (attr != stamp_attr)
535 1.1 ad rasops15_makestamp(ri, attr);
536 1.1 ad
537 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
538 1.1 ad height = ri->ri_font->fontheight;
539 1.1 ad
540 1.1 ad if (uc == (u_int)-1) {
541 1.1 ad while (height--) {
542 1.1 ad rp[0] = stamp[0];
543 1.1 ad rp[1] = stamp[0];
544 1.1 ad rp[2] = stamp[0];
545 1.1 ad rp[3] = stamp[0];
546 1.1 ad rp[4] = stamp[0];
547 1.1 ad rp[5] = stamp[0];
548 1.1 ad rp[6] = stamp[0];
549 1.1 ad rp[7] = stamp[0];
550 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
551 1.1 ad }
552 1.1 ad } else {
553 1.1 ad uc -= ri->ri_font->firstchar;
554 1.1 ad fr = (u_char *)ri->ri_font->data + uc*ri->ri_fontscale;
555 1.1 ad fs = ri->ri_font->stride;
556 1.1 ad
557 1.1 ad while (height--) {
558 1.1 ad so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
559 1.1 ad rp[0] = STAMP_READ(so);
560 1.1 ad rp[1] = STAMP_READ(so + 4);
561 1.1 ad
562 1.1 ad so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
563 1.1 ad rp[2] = STAMP_READ(so);
564 1.1 ad rp[3] = STAMP_READ(so + 4);
565 1.1 ad
566 1.1 ad so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
567 1.1 ad rp[4] = STAMP_READ(so);
568 1.1 ad rp[5] = STAMP_READ(so + 4);
569 1.1 ad
570 1.1 ad so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
571 1.1 ad rp[6] = STAMP_READ(so);
572 1.1 ad rp[7] = STAMP_READ(so + 4);
573 1.1 ad
574 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
575 1.1 ad fr += fs;
576 1.1 ad }
577 1.1 ad }
578 1.1 ad
579 1.1 ad stamp_mutex--;
580 1.1 ad }
581 1.1 ad
582 1.1 ad
583 1.1 ad /*
584 1.1 ad * Erase rows.
585 1.1 ad */
586 1.1 ad static void
587 1.1 ad rasops15_eraserows(cookie, row, num, attr)
588 1.1 ad void *cookie;
589 1.1 ad int row, num;
590 1.1 ad long attr;
591 1.1 ad {
592 1.1 ad struct rasops_info *ri;
593 1.1 ad int32_t *dp, clr;
594 1.1 ad int n8, n1, cnt;
595 1.1 ad
596 1.1 ad ri = (struct rasops_info *)cookie;
597 1.1 ad
598 1.1 ad #ifdef RASOPS_CLIPPING
599 1.1 ad if (row < 0) {
600 1.1 ad num += row;
601 1.1 ad row = 0;
602 1.1 ad }
603 1.1 ad
604 1.1 ad if ((row + num) > ri->ri_rows)
605 1.1 ad num = ri->ri_rows - row;
606 1.1 ad
607 1.1 ad if (num <= 0)
608 1.1 ad return;
609 1.1 ad #endif
610 1.1 ad
611 1.1 ad num *= ri->ri_font->fontheight;
612 1.1 ad dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
613 1.1 ad clr = rasops15_bg_color(ri, attr);
614 1.1 ad
615 1.1 ad n8 = ri->ri_emustride >> 5;
616 1.1 ad n1 = (ri->ri_emustride >> 2) & 7;
617 1.1 ad
618 1.1 ad while (num--) {
619 1.1 ad for (cnt = n8; cnt; cnt--) {
620 1.1 ad dp[0] = clr;
621 1.1 ad dp[1] = clr;
622 1.1 ad dp[2] = clr;
623 1.1 ad dp[3] = clr;
624 1.1 ad dp[4] = clr;
625 1.1 ad dp[5] = clr;
626 1.1 ad dp[6] = clr;
627 1.1 ad dp[7] = clr;
628 1.1 ad dp += 8;
629 1.1 ad }
630 1.1 ad
631 1.1 ad for (cnt = n1; cnt; cnt--)
632 1.1 ad *dp++ = clr;
633 1.1 ad
634 1.1 ad DELTA(dp, ri->ri_delta, int32_t *);
635 1.1 ad }
636 1.1 ad }
637 1.1 ad
638 1.1 ad #endif /* RASOPS15 */
639