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