Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / rasops / rasops4.c
blob317210bcc1f95435f508775c1dcbe3d39d811b14
1 /* $NetBSD: rasops4.c,v 1.8 2009/03/14 15:36:20 dsl Exp $ */
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.8 2009/03/14 15:36:20 dsl Exp $");
35 #include "opt_rasops.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40 #include <machine/endian.h>
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/rasops/rasops.h>
45 #include <dev/rasops/rasops_masks.h>
47 static void rasops4_copycols(void *, int, int, int, int);
48 static void rasops4_erasecols(void *, int, int, int, long);
49 static void rasops4_do_cursor(struct rasops_info *);
50 static void rasops4_putchar(void *, int, int col, u_int, long);
51 #ifndef RASOPS_SMALL
52 static void rasops4_putchar8(void *, int, int col, u_int, long);
53 static void rasops4_putchar12(void *, int, int col, u_int, long);
54 static void rasops4_putchar16(void *, int, int col, u_int, long);
55 static void rasops4_makestamp(struct rasops_info *, long);
58 * 4x1 stamp for optimized character blitting
60 static u_int16_t stamp[16];
61 static long stamp_attr;
62 static int stamp_mutex; /* XXX see note in README */
63 #endif
66 * Initialize rasops_info struct for this colordepth.
68 void
69 rasops4_init(struct rasops_info *ri)
72 switch (ri->ri_font->fontwidth) {
73 #ifndef RASOPS_SMALL
74 case 8:
75 ri->ri_ops.putchar = rasops4_putchar8;
76 break;
77 case 12:
78 ri->ri_ops.putchar = rasops4_putchar12;
79 break;
80 case 16:
81 ri->ri_ops.putchar = rasops4_putchar16;
82 break;
83 #endif /* !RASOPS_SMALL */
84 default:
85 panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!");
86 ri->ri_ops.putchar = rasops4_putchar;
87 break;
90 if ((ri->ri_font->fontwidth & 1) != 0) {
91 ri->ri_ops.erasecols = rasops4_erasecols;
92 ri->ri_ops.copycols = rasops4_copycols;
93 ri->ri_do_cursor = rasops4_do_cursor;
97 #ifdef notyet
99 * Paint a single character. This is the generic version, this is ugly.
101 static void
102 rasops4_putchar(void *cookie, int row, int col, u_int uc, long attr)
104 int height, width, fs, rs, fb, bg, fg, lmask, rmask;
105 struct rasops_info *ri;
106 int32_t *rp;
107 u_char *fr;
109 ri = (struct rasops_info *)cookie;
111 #ifdef RASOPS_CLIPPING
112 /* Catches 'row < 0' case too */
113 if ((unsigned)row >= (unsigned)ri->ri_rows)
114 return;
116 if ((unsigned)col >= (unsigned)ri->ri_cols)
117 return;
118 #endif
120 width = ri->ri_font->fontwidth << 1;
121 height = ri->ri_font->fontheight;
122 col *= width;
123 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
124 col = col & 31;
125 rs = ri->ri_stride;
127 bg = ri->ri_devcmap[(attr >> 16) & 0xf];
128 fg = ri->ri_devcmap[(attr >> 24) & 0xf];
130 /* If fg and bg match this becomes a space character */
131 if (fg == bg || uc == ' ') {
132 uc = (u_int)-1;
133 fr = 0; /* shutup gcc */
134 fs = 0; /* shutup gcc */
135 } else {
136 uc -= ri->ri_font->firstchar;
137 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
138 fs = ri->ri_font->stride;
141 /* Single word, one mask */
142 if ((col + width) <= 32) {
143 rmask = rasops_pmask[col][width];
144 lmask = ~rmask;
146 if (uc == (u_int)-1) {
147 bg &= rmask;
149 while (height--) {
150 *rp = (*rp & lmask) | bg;
151 DELTA(rp, rs, int32_t *);
153 } else {
154 while (height--) {
155 /* get bits, mask */
156 /* compose sl */
157 /* mask sl */
158 /* put word */
162 /* Do underline */
163 if (attr & 1) {
164 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
165 *rp = (*rp & lmask) | (fg & rmask);
167 } else {
168 lmask = ~rasops_lmask[col];
169 rmask = ~rasops_rmask[(col + width) & 31];
171 if (uc == (u_int)-1) {
172 bg = bg & ~lmask;
173 width = bg & ~rmask;
175 while (height--) {
176 rp[0] = (rp[0] & lmask) | bg;
177 rp[1] = (rp[1] & rmask) | width;
178 DELTA(rp, rs, int32_t *);
180 } else {
181 width = 32 - col;
183 /* NOT fontbits if bg is white */
184 while (height--) {
185 fb = ~(fr[3] | (fr[2] << 8) |
186 (fr[1] << 16) | (fr[0] << 24));
188 rp[0] = (rp[0] & lmask)
189 | MBE((u_int)fb >> col);
191 rp[1] = (rp[1] & rmask)
192 | (MBE((u_int)fb << width) & ~rmask);
194 fr += fs;
195 DELTA(rp, rs, int32_t *);
199 /* Do underline */
200 if (attr & 1) {
201 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
202 rp[0] = (rp[0] & lmask) | (fg & ~lmask);
203 rp[1] = (rp[1] & rmask) | (fg & ~rmask);
207 #endif
210 * Put a single character. This is the generic version.
212 static void
213 rasops4_putchar(void *cookie, int row, int col, u_int uc, long attr)
216 /* XXX punt */
219 #ifndef RASOPS_SMALL
221 * Recompute the blitting stamp.
223 static void
224 rasops4_makestamp(struct rasops_info *ri, long attr)
226 int i, fg, bg;
228 fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xf;
229 bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xf;
230 stamp_attr = attr;
232 for (i = 0; i < 16; i++) {
233 stamp[i] = (i & 1 ? fg : bg) << 8;
234 stamp[i] |= (i & 2 ? fg : bg) << 12;
235 stamp[i] |= (i & 4 ? fg : bg) << 0;
236 stamp[i] |= (i & 8 ? fg : bg) << 4;
241 * Put a single character. This is for 8-pixel wide fonts.
243 static void
244 rasops4_putchar8(void *cookie, int row, int col, u_int uc, long attr)
246 struct rasops_info *ri;
247 int height, fs, rs;
248 u_char *fr;
249 u_int16_t *rp;
251 /* Can't risk remaking the stamp if it's already in use */
252 if (stamp_mutex++) {
253 stamp_mutex--;
254 rasops4_putchar(cookie, row, col, uc, attr);
255 return;
258 ri = (struct rasops_info *)cookie;
260 #ifdef RASOPS_CLIPPING
261 /* Catches 'row < 0' case too */
262 if ((unsigned)row >= (unsigned)ri->ri_rows) {
263 stamp_mutex--;
264 return;
267 if ((unsigned)col >= (unsigned)ri->ri_cols) {
268 stamp_mutex--;
269 return;
271 #endif
273 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
274 height = ri->ri_font->fontheight;
275 rs = ri->ri_stride / sizeof(*rp);
277 /* Recompute stamp? */
278 if (attr != stamp_attr)
279 rasops4_makestamp(ri, attr);
281 if (uc == ' ') {
282 u_int16_t c = stamp[0];
283 while (height--) {
284 rp[0] = c;
285 rp[1] = c;
286 rp += rs;
288 } else {
289 uc -= ri->ri_font->firstchar;
290 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
291 fs = ri->ri_font->stride;
293 while (height--) {
294 rp[0] = stamp[(*fr >> 4) & 0xf];
295 rp[1] = stamp[*fr & 0xf];
296 fr += fs;
297 rp += rs;
301 /* Do underline */
302 if ((attr & 1) != 0) {
303 rp -= (rs << 1);
304 rp[0] = stamp[15];
305 rp[1] = stamp[15];
308 stamp_mutex--;
312 * Put a single character. This is for 12-pixel wide fonts.
314 static void
315 rasops4_putchar12(void *cookie, int row, int col, u_int uc, long attr)
317 struct rasops_info *ri;
318 int height, fs, rs;
319 u_char *fr;
320 u_int16_t *rp;
322 /* Can't risk remaking the stamp if it's already in use */
323 if (stamp_mutex++) {
324 stamp_mutex--;
325 rasops4_putchar(cookie, row, col, uc, attr);
326 return;
329 ri = (struct rasops_info *)cookie;
331 #ifdef RASOPS_CLIPPING
332 /* Catches 'row < 0' case too */
333 if ((unsigned)row >= (unsigned)ri->ri_rows) {
334 stamp_mutex--;
335 return;
338 if ((unsigned)col >= (unsigned)ri->ri_cols) {
339 stamp_mutex--;
340 return;
342 #endif
344 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
345 height = ri->ri_font->fontheight;
346 rs = ri->ri_stride / sizeof(*rp);
348 /* Recompute stamp? */
349 if (attr != stamp_attr)
350 rasops4_makestamp(ri, attr);
352 if (uc == ' ') {
353 u_int16_t c = stamp[0];
354 while (height--) {
355 rp[0] = c;
356 rp[1] = c;
357 rp[2] = c;
358 rp += rs;
360 } else {
361 uc -= ri->ri_font->firstchar;
362 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
363 fs = ri->ri_font->stride;
365 while (height--) {
366 rp[0] = stamp[(fr[0] >> 4) & 0xf];
367 rp[1] = stamp[fr[0] & 0xf];
368 rp[2] = stamp[(fr[1] >> 4) & 0xf];
369 fr += fs;
370 rp += rs;
374 /* Do underline */
375 if ((attr & 1) != 0) {
376 rp -= (rs << 1);
377 rp[0] = stamp[15];
378 rp[1] = stamp[15];
379 rp[2] = stamp[15];
382 stamp_mutex--;
386 * Put a single character. This is for 16-pixel wide fonts.
388 static void
389 rasops4_putchar16(void *cookie, int row, int col, u_int uc, long attr)
391 struct rasops_info *ri;
392 int height, fs, rs;
393 u_char *fr;
394 u_int16_t *rp;
396 /* Can't risk remaking the stamp if it's already in use */
397 if (stamp_mutex++) {
398 stamp_mutex--;
399 rasops4_putchar(cookie, row, col, uc, attr);
400 return;
403 ri = (struct rasops_info *)cookie;
405 #ifdef RASOPS_CLIPPING
406 /* Catches 'row < 0' case too */
407 if ((unsigned)row >= (unsigned)ri->ri_rows) {
408 stamp_mutex--;
409 return;
412 if ((unsigned)col >= (unsigned)ri->ri_cols) {
413 stamp_mutex--;
414 return;
416 #endif
418 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale);
419 height = ri->ri_font->fontheight;
420 rs = ri->ri_stride / sizeof(*rp);
422 /* Recompute stamp? */
423 if (attr != stamp_attr)
424 rasops4_makestamp(ri, attr);
426 if (uc == ' ') {
427 u_int16_t c = stamp[0];
428 while (height--) {
429 rp[0] = c;
430 rp[1] = c;
431 rp[2] = c;
432 rp[3] = c;
433 rp += rs;
435 } else {
436 uc -= ri->ri_font->firstchar;
437 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
438 fs = ri->ri_font->stride;
440 while (height--) {
441 rp[0] = stamp[(fr[0] >> 4) & 0xf];
442 rp[1] = stamp[fr[0] & 0xf];
443 rp[2] = stamp[(fr[1] >> 4) & 0xf];
444 rp[3] = stamp[fr[1] & 0xf];
445 fr += fs;
446 rp += rs;
450 /* Do underline */
451 if ((attr & 1) != 0) {
452 rp -= (rs << 1);
453 rp[0] = stamp[15];
454 rp[1] = stamp[15];
455 rp[2] = stamp[15];
456 rp[3] = stamp[15];
459 stamp_mutex--;
461 #endif /* !RASOPS_SMALL */
464 * Grab routines common to depths where (bpp < 8)
466 #define NAME(ident) rasops4_##ident
467 #define PIXEL_SHIFT 3
469 #include <dev/rasops/rasops_bitops.h>