rasops2.c revision 1.1 1 1.1 ad /* $NetBSD: rasops2.c,v 1.1 1999/04/26 04:27:47 ad Exp $ */
2 1.1 ad
3 1.1 ad /*
4 1.1 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.1 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 ad * SUCH DAMAGE.
27 1.1 ad *
28 1.1 ad */
29 1.1 ad
30 1.1 ad #include "opt_rasops.h"
31 1.1 ad #include <sys/cdefs.h>
32 1.1 ad __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.1 1999/04/26 04:27:47 ad Exp $");
33 1.1 ad
34 1.1 ad #include <sys/types.h>
35 1.1 ad #include <sys/param.h>
36 1.1 ad #include <sys/systm.h>
37 1.1 ad #include <sys/time.h>
38 1.1 ad #include <machine/endian.h>
39 1.1 ad
40 1.1 ad #include <dev/wscons/wsdisplayvar.h>
41 1.1 ad #include <dev/wscons/wsconsio.h>
42 1.1 ad #include <dev/rasops/rasops.h>
43 1.1 ad #include <dev/rasops/rasops_masks.h>
44 1.1 ad
45 1.1 ad static void rasops2_putchar __P((void *, int, int col, u_int, long));
46 1.1 ad static void rasops2_putchar8 __P((void *, int, int col, u_int, long));
47 1.1 ad static void rasops2_putchar12 __P((void *, int, int col, u_int, long));
48 1.1 ad static void rasops2_putchar16 __P((void *, int, int col, u_int, long));
49 1.1 ad static void rasops2_copycols __P((void *, int, int, int, int));
50 1.1 ad static void rasops2_erasecols __P((void *, int, int, int, long));
51 1.1 ad static void rasops2_do_cursor __P((struct rasops_info *));
52 1.1 ad static void rasops2_makestamp __P((struct rasops_info *, long));
53 1.1 ad
54 1.1 ad void rasops2_init __P((struct rasops_info *ri));
55 1.1 ad
56 1.1 ad /*
57 1.1 ad * 4x1 stamp for optimized character blitting
58 1.1 ad */
59 1.1 ad static int8_t stamp[16];
60 1.1 ad static long stamp_attr;
61 1.1 ad static int stamp_mutex; /* XXX see note in README */
62 1.1 ad
63 1.1 ad /*
64 1.1 ad * Initialize rasops_info struct for this colordepth.
65 1.1 ad */
66 1.1 ad void
67 1.1 ad rasops2_init(ri)
68 1.1 ad struct rasops_info *ri;
69 1.1 ad {
70 1.1 ad
71 1.1 ad switch (ri->ri_font->fontwidth) {
72 1.1 ad case 8:
73 1.1 ad ri->ri_ops.putchar = rasops2_putchar8;
74 1.1 ad break;
75 1.1 ad case 12:
76 1.1 ad ri->ri_ops.putchar = rasops2_putchar12;
77 1.1 ad break;
78 1.1 ad case 16:
79 1.1 ad ri->ri_ops.putchar = rasops2_putchar16;
80 1.1 ad break;
81 1.1 ad default:
82 1.1 ad panic("fontwidth not 8/12/16 - fixme!");
83 1.1 ad ri->ri_ops.putchar = rasops2_putchar;
84 1.1 ad break;
85 1.1 ad }
86 1.1 ad
87 1.1 ad if (ri->ri_font->fontwidth & 3) {
88 1.1 ad ri->ri_ops.erasecols = rasops2_erasecols;
89 1.1 ad ri->ri_ops.copycols = rasops2_copycols;
90 1.1 ad ri->ri_do_cursor = rasops2_do_cursor;
91 1.1 ad }
92 1.1 ad }
93 1.1 ad
94 1.1 ad
95 1.1 ad /*
96 1.1 ad * Recompute the blitting stamp.
97 1.1 ad */
98 1.1 ad static void
99 1.1 ad rasops2_makestamp(ri, attr)
100 1.1 ad struct rasops_info *ri;
101 1.1 ad long attr;
102 1.1 ad {
103 1.1 ad int i;
104 1.1 ad int32_t fg, bg;
105 1.1 ad
106 1.1 ad fg = ri->ri_devcmap[(attr >> 24) & 15] & 3;
107 1.1 ad bg = ri->ri_devcmap[(attr >> 16) & 15] & 3;
108 1.1 ad stamp_attr = attr;
109 1.1 ad
110 1.1 ad for (i = 0; i < 16; i++) {
111 1.1 ad stamp[i] = (i & 1 ? fg : bg);
112 1.1 ad stamp[i] |= (i & 2 ? fg : bg) << 2;
113 1.1 ad stamp[i] |= (i & 4 ? fg : bg) << 4;
114 1.1 ad stamp[i] |= (i & 8 ? fg : bg) << 6;
115 1.1 ad }
116 1.1 ad }
117 1.1 ad
118 1.1 ad #if 0
119 1.1 ad /*
120 1.1 ad * Paint a single character. This is the generic version, this is ugly.
121 1.1 ad */
122 1.1 ad static void
123 1.1 ad rasops2_putchar(cookie, row, col, uc, attr)
124 1.1 ad void *cookie;
125 1.1 ad int row, col;
126 1.1 ad u_int uc;
127 1.1 ad long attr;
128 1.1 ad {
129 1.1 ad int height, width, fs, rs, fb, bg, fg, lmask, rmask;
130 1.1 ad struct rasops_info *ri;
131 1.1 ad int32_t *rp;
132 1.1 ad u_char *fr;
133 1.1 ad
134 1.1 ad ri = (struct rasops_info *)cookie;
135 1.1 ad
136 1.1 ad #ifdef RASOPS_CLIPPING
137 1.1 ad /* Catches 'row < 0' case too */
138 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
139 1.1 ad return;
140 1.1 ad
141 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
142 1.1 ad return;
143 1.1 ad #endif
144 1.1 ad
145 1.1 ad width = ri->ri_font->fontwidth << 1;
146 1.1 ad height = ri->ri_font->fontheight;
147 1.1 ad col *= width;
148 1.1 ad rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
149 1.1 ad col = col & 31;
150 1.1 ad rs = ri->ri_stride;
151 1.1 ad
152 1.1 ad bg = ri->ri_devcmap[(attr >> 16) & 15];
153 1.1 ad fg = ri->ri_devcmap[(attr >> 24) & 15];
154 1.1 ad
155 1.1 ad /* If fg and bg match this becomes a space character */
156 1.1 ad if (fg == bg || uc == ' ') {
157 1.1 ad uc = (u_int)-1;
158 1.1 ad fr = 0; /* shutup gcc */
159 1.1 ad fs = 0; /* shutup gcc */
160 1.1 ad } else {
161 1.1 ad uc -= ri->ri_font->firstchar;
162 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
163 1.1 ad fs = ri->ri_font->stride;
164 1.1 ad }
165 1.1 ad
166 1.1 ad /* Single word, one mask */
167 1.1 ad if ((col + width) <= 32) {
168 1.1 ad rmask = rasops_pmask[col][width];
169 1.1 ad lmask = ~rmask;
170 1.1 ad
171 1.1 ad if (uc == (u_int)-1) {
172 1.1 ad bg &= rmask;
173 1.1 ad
174 1.1 ad while (height--) {
175 1.1 ad *rp = (*rp & lmask) | bg;
176 1.1 ad DELTA(rp, rs, int32_t *);
177 1.1 ad }
178 1.1 ad } else {
179 1.1 ad while (height--) {
180 1.1 ad /* get bits, mask */
181 1.1 ad /* compose sl */
182 1.1 ad /* mask sl */
183 1.1 ad /* put word */
184 1.1 ad }
185 1.1 ad }
186 1.1 ad
187 1.1 ad /* Do underline */
188 1.1 ad if (attr & 1) {
189 1.1 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
190 1.1 ad *rp = (*rp & lmask) | (fg & rmask);
191 1.1 ad }
192 1.1 ad } else {
193 1.1 ad lmask = ~rasops_lmask[col];
194 1.1 ad rmask = ~rasops_rmask[(col + width) & 31];
195 1.1 ad
196 1.1 ad if (uc == (u_int)-1) {
197 1.1 ad bg = bg & ~lmask;
198 1.1 ad width = bg & ~rmask;
199 1.1 ad
200 1.1 ad while (height--) {
201 1.1 ad rp[0] = (rp[0] & lmask) | bg;
202 1.1 ad rp[1] = (rp[1] & rmask) | width;
203 1.1 ad DELTA(rp, rs, int32_t *);
204 1.1 ad }
205 1.1 ad } else {
206 1.1 ad width = 32 - col;
207 1.1 ad
208 1.1 ad /* NOT fontbits if bg is white */
209 1.1 ad while (height--) {
210 1.1 ad fb = ~(fr[3] | (fr[2] << 8) |
211 1.1 ad (fr[1] << 16) | (fr[0] << 24));
212 1.1 ad
213 1.1 ad rp[0] = (rp[0] & lmask)
214 1.1 ad | MBE((u_int)fb >> col);
215 1.1 ad
216 1.1 ad rp[1] = (rp[1] & rmask)
217 1.1 ad | (MBE((u_int)fb << width) & ~rmask);
218 1.1 ad
219 1.1 ad fr += fs;
220 1.1 ad DELTA(rp, rs, int32_t *);
221 1.1 ad }
222 1.1 ad }
223 1.1 ad
224 1.1 ad /* Do underline */
225 1.1 ad if (attr & 1) {
226 1.1 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
227 1.1 ad rp[0] = (rp[0] & lmask) | (fg & ~lmask);
228 1.1 ad rp[1] = (rp[1] & rmask) | (fg & ~rmask);
229 1.1 ad }
230 1.1 ad }
231 1.1 ad }
232 1.1 ad #endif
233 1.1 ad
234 1.1 ad /*
235 1.1 ad * Put a single character. This is the generic version.
236 1.1 ad */
237 1.1 ad static void
238 1.1 ad rasops2_putchar(cookie, row, col, uc, attr)
239 1.1 ad void *cookie;
240 1.1 ad int row, col;
241 1.1 ad u_int uc;
242 1.1 ad long attr;
243 1.1 ad {
244 1.1 ad
245 1.1 ad /* XXX punt */
246 1.1 ad }
247 1.1 ad
248 1.1 ad
249 1.1 ad /*
250 1.1 ad * Put a single character. This is for 8-pixel wide fonts.
251 1.1 ad */
252 1.1 ad static void
253 1.1 ad rasops2_putchar8(cookie, row, col, uc, attr)
254 1.1 ad void *cookie;
255 1.1 ad int row, col;
256 1.1 ad u_int uc;
257 1.1 ad long attr;
258 1.1 ad {
259 1.1 ad struct rasops_info *ri;
260 1.1 ad int height, fs, rs;
261 1.1 ad u_char *fr, *rp;
262 1.1 ad
263 1.1 ad /* Can't risk remaking the stamp if it's already in use */
264 1.1 ad if (stamp_mutex++) {
265 1.1 ad stamp_mutex--;
266 1.1 ad rasops2_putchar(cookie, row, col, uc, attr);
267 1.1 ad return;
268 1.1 ad }
269 1.1 ad
270 1.1 ad ri = (struct rasops_info *)cookie;
271 1.1 ad
272 1.1 ad #ifdef RASOPS_CLIPPING
273 1.1 ad /* Catches 'row < 0' case too */
274 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
275 1.1 ad stamp_mutex--;
276 1.1 ad return;
277 1.1 ad }
278 1.1 ad
279 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
280 1.1 ad stamp_mutex--;
281 1.1 ad return;
282 1.1 ad }
283 1.1 ad #endif
284 1.1 ad
285 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
286 1.1 ad height = ri->ri_font->fontheight;
287 1.1 ad rs = ri->ri_stride;
288 1.1 ad
289 1.1 ad /* Recompute stamp? */
290 1.1 ad if (attr != stamp_attr)
291 1.1 ad rasops2_makestamp(ri, attr);
292 1.1 ad
293 1.1 ad if (uc == ' ') {
294 1.1 ad while (height--) {
295 1.1 ad *(int16_t *)rp = stamp[0];
296 1.1 ad rp += rs;
297 1.1 ad }
298 1.1 ad } else {
299 1.1 ad uc -= ri->ri_font->firstchar;
300 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
301 1.1 ad fs = ri->ri_font->stride;
302 1.1 ad
303 1.1 ad while (height--) {
304 1.1 ad rp[0] = stamp[(*fr >> 4) & 15];
305 1.1 ad rp[1] = stamp[*fr & 15];
306 1.1 ad fr += fs;
307 1.1 ad rp += rs;
308 1.1 ad }
309 1.1 ad }
310 1.1 ad
311 1.1 ad /* Do underline */
312 1.1 ad if (attr & 1)
313 1.1 ad *(int16_t *)(rp - (ri->ri_stride << 1)) = stamp[15];
314 1.1 ad
315 1.1 ad stamp_mutex--;
316 1.1 ad }
317 1.1 ad
318 1.1 ad
319 1.1 ad /*
320 1.1 ad * Put a single character. This is for 12-pixel wide fonts.
321 1.1 ad */
322 1.1 ad static void
323 1.1 ad rasops2_putchar12(cookie, row, col, uc, attr)
324 1.1 ad void *cookie;
325 1.1 ad int row, col;
326 1.1 ad u_int uc;
327 1.1 ad long attr;
328 1.1 ad {
329 1.1 ad struct rasops_info *ri;
330 1.1 ad int height, fs, rs;
331 1.1 ad u_char *fr, *rp;
332 1.1 ad
333 1.1 ad /* Can't risk remaking the stamp if it's already in use */
334 1.1 ad if (stamp_mutex++) {
335 1.1 ad stamp_mutex--;
336 1.1 ad rasops2_putchar(cookie, row, col, uc, attr);
337 1.1 ad return;
338 1.1 ad }
339 1.1 ad
340 1.1 ad ri = (struct rasops_info *)cookie;
341 1.1 ad
342 1.1 ad #ifdef RASOPS_CLIPPING
343 1.1 ad /* Catches 'row < 0' case too */
344 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
345 1.1 ad stamp_mutex--;
346 1.1 ad return;
347 1.1 ad }
348 1.1 ad
349 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
350 1.1 ad stamp_mutex--;
351 1.1 ad return;
352 1.1 ad }
353 1.1 ad #endif
354 1.1 ad
355 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
356 1.1 ad height = ri->ri_font->fontheight;
357 1.1 ad rs = ri->ri_stride;
358 1.1 ad
359 1.1 ad /* Recompute stamp? */
360 1.1 ad if (attr != stamp_attr)
361 1.1 ad rasops2_makestamp(ri, attr);
362 1.1 ad
363 1.1 ad if (uc == ' ') {
364 1.1 ad while (height--) {
365 1.1 ad rp[0] = stamp[0];
366 1.1 ad rp[1] = stamp[0];
367 1.1 ad rp[2] = stamp[0];
368 1.1 ad rp += rs;
369 1.1 ad }
370 1.1 ad } else {
371 1.1 ad uc -= ri->ri_font->firstchar;
372 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
373 1.1 ad fs = ri->ri_font->stride;
374 1.1 ad
375 1.1 ad while (height--) {
376 1.1 ad rp[0] = stamp[(fr[0] >> 4) & 15];
377 1.1 ad rp[1] = stamp[fr[0] & 15];
378 1.1 ad rp[2] = stamp[(fr[1] >> 4) & 15];
379 1.1 ad fr += fs;
380 1.1 ad rp += rs;
381 1.1 ad }
382 1.1 ad }
383 1.1 ad
384 1.1 ad /* Do underline */
385 1.1 ad if (attr & 1) {
386 1.1 ad rp -= ri->ri_stride << 1;
387 1.1 ad rp[0] = stamp[15];
388 1.1 ad rp[1] = stamp[15];
389 1.1 ad rp[2] = stamp[15];
390 1.1 ad }
391 1.1 ad
392 1.1 ad stamp_mutex--;
393 1.1 ad }
394 1.1 ad
395 1.1 ad
396 1.1 ad /*
397 1.1 ad * Put a single character. This is for 16-pixel wide fonts.
398 1.1 ad */
399 1.1 ad static void
400 1.1 ad rasops2_putchar16(cookie, row, col, uc, attr)
401 1.1 ad void *cookie;
402 1.1 ad int row, col;
403 1.1 ad u_int uc;
404 1.1 ad long attr;
405 1.1 ad {
406 1.1 ad struct rasops_info *ri;
407 1.1 ad int height, fs, rs;
408 1.1 ad u_char *fr, *rp;
409 1.1 ad
410 1.1 ad /* Can't risk remaking the stamp if it's already in use */
411 1.1 ad if (stamp_mutex++) {
412 1.1 ad stamp_mutex--;
413 1.1 ad rasops2_putchar(cookie, row, col, uc, attr);
414 1.1 ad return;
415 1.1 ad }
416 1.1 ad
417 1.1 ad ri = (struct rasops_info *)cookie;
418 1.1 ad
419 1.1 ad #ifdef RASOPS_CLIPPING
420 1.1 ad /* Catches 'row < 0' case too */
421 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows) {
422 1.1 ad stamp_mutex--;
423 1.1 ad return;
424 1.1 ad }
425 1.1 ad
426 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols) {
427 1.1 ad stamp_mutex--;
428 1.1 ad return;
429 1.1 ad }
430 1.1 ad #endif
431 1.1 ad
432 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
433 1.1 ad height = ri->ri_font->fontheight;
434 1.1 ad rs = ri->ri_stride;
435 1.1 ad
436 1.1 ad /* Recompute stamp? */
437 1.1 ad if (attr != stamp_attr)
438 1.1 ad rasops2_makestamp(ri, attr);
439 1.1 ad
440 1.1 ad if (uc == ' ') {
441 1.1 ad while (height--) {
442 1.1 ad *(int32_t *)rp = stamp[0];
443 1.1 ad rp += rs;
444 1.1 ad }
445 1.1 ad } else {
446 1.1 ad uc -= ri->ri_font->firstchar;
447 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
448 1.1 ad fs = ri->ri_font->stride;
449 1.1 ad
450 1.1 ad while (height--) {
451 1.1 ad rp[0] = stamp[(fr[0] >> 4) & 15];
452 1.1 ad rp[1] = stamp[fr[0] & 15];
453 1.1 ad rp[2] = stamp[(fr[1] >> 4) & 15];
454 1.1 ad rp[3] = stamp[fr[1] & 15];
455 1.1 ad fr += fs;
456 1.1 ad rp += rs;
457 1.1 ad }
458 1.1 ad }
459 1.1 ad
460 1.1 ad /* Do underline */
461 1.1 ad if (attr & 1)
462 1.1 ad *(int32_t *)(rp - (ri->ri_stride << 1)) = stamp[15];
463 1.1 ad
464 1.1 ad stamp_mutex--;
465 1.1 ad }
466 1.1 ad
467 1.1 ad /*
468 1.1 ad * Grab routines common to depths where (bpp < 8)
469 1.1 ad */
470 1.1 ad #define NAME(ident) rasops2_##ident
471 1.1 ad #define PIXEL_SHIFT 1
472 1.1 ad
473 1.1 ad #include <dev/rasops/rasops_bitops.h>
474