rasops1.c revision 1.14 1 /* $NetBSD: rasops1.c,v 1.14 2001/11/13 07:00:23 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.14 2001/11/13 07:00:23 lukem Exp $");
41
42 #include "opt_rasops.h"
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/time.h>
48 #include <machine/endian.h>
49
50 #include <dev/wscons/wsdisplayvar.h>
51 #include <dev/wscons/wsconsio.h>
52 #include <dev/rasops/rasops.h>
53 #include <dev/rasops/rasops_masks.h>
54
55 static void rasops1_copycols __P((void *, int, int, int, int));
56 static void rasops1_erasecols __P((void *, int, int, int, long));
57 static void rasops1_do_cursor __P((struct rasops_info *));
58 static void rasops1_putchar __P((void *, int, int col, u_int, long));
59 #ifndef RASOPS_SMALL
60 static void rasops1_putchar8 __P((void *, int, int col, u_int, long));
61 static void rasops1_putchar16 __P((void *, int, int col, u_int, long));
62 #endif
63
64 /*
65 * Initialize rasops_info struct for this colordepth.
66 */
67 void
68 rasops1_init(ri)
69 struct rasops_info *ri;
70 {
71
72 switch (ri->ri_font->fontwidth) {
73 #ifndef RASOPS_SMALL
74 case 8:
75 ri->ri_ops.putchar = rasops1_putchar8;
76 break;
77 case 16:
78 ri->ri_ops.putchar = rasops1_putchar16;
79 break;
80 #endif
81 default:
82 ri->ri_ops.putchar = rasops1_putchar;
83 break;
84 }
85
86 if ((ri->ri_font->fontwidth & 7) != 0) {
87 ri->ri_ops.erasecols = rasops1_erasecols;
88 ri->ri_ops.copycols = rasops1_copycols;
89 ri->ri_do_cursor = rasops1_do_cursor;
90 }
91 }
92
93 /*
94 * Paint a single character. This is the generic version, this is ugly.
95 */
96 static void
97 rasops1_putchar(cookie, row, col, uc, attr)
98 void *cookie;
99 int row, col;
100 u_int uc;
101 long attr;
102 {
103 u_int fs, rs, fb, bg, fg, lmask, rmask;
104 u_int32_t height, width;
105 struct rasops_info *ri;
106 int32_t *rp;
107 u_char *fr;
108
109 ri = (struct rasops_info *)cookie;
110
111 #ifdef RASOPS_CLIPPING
112 /* Catches 'row < 0' case too */
113 if ((unsigned)row >= (unsigned)ri->ri_rows)
114 return;
115
116 if ((unsigned)col >= (unsigned)ri->ri_cols)
117 return;
118 #endif
119
120 col *= ri->ri_font->fontwidth;
121 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
122 height = ri->ri_font->fontheight;
123 width = ri->ri_font->fontwidth;
124 col = col & 31;
125 rs = ri->ri_stride;
126
127 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
128 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
129
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;
139 }
140
141 /* Single word, one mask */
142 if ((col + width) <= 32) {
143 rmask = rasops_pmask[col][width];
144 lmask = ~rmask;
145
146 if (uc == (u_int)-1) {
147 bg &= rmask;
148
149 while (height--) {
150 *rp = (*rp & lmask) | bg;
151 DELTA(rp, rs, int32_t *);
152 }
153 } else {
154 /* NOT fontbits if bg is white */
155 if (bg) {
156 while (height--) {
157 fb = ~(fr[3] | (fr[2] << 8) |
158 (fr[1] << 16) | (fr[0] << 24));
159 *rp = (*rp & lmask)
160 | (MBE(fb >> col) & rmask);
161
162 fr += fs;
163 DELTA(rp, rs, int32_t *);
164 }
165 } else {
166 while (height--) {
167 fb = (fr[3] | (fr[2] << 8) |
168 (fr[1] << 16) | (fr[0] << 24));
169 *rp = (*rp & lmask)
170 | (MBE(fb >> col) & rmask);
171
172 fr += fs;
173 DELTA(rp, rs, int32_t *);
174 }
175 }
176 }
177
178 /* Do underline */
179 if ((attr & 1) != 0) {
180 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
181 *rp = (*rp & lmask) | (fg & rmask);
182 }
183 } else {
184 lmask = ~rasops_lmask[col];
185 rmask = ~rasops_rmask[(col + width) & 31];
186
187 if (uc == (u_int)-1) {
188 width = bg & ~rmask;
189 bg = bg & ~lmask;
190
191 while (height--) {
192 rp[0] = (rp[0] & lmask) | bg;
193 rp[1] = (rp[1] & rmask) | width;
194 DELTA(rp, rs, int32_t *);
195 }
196 } else {
197 width = 32 - col;
198
199 /* NOT fontbits if bg is white */
200 if (bg) {
201 while (height--) {
202 fb = ~(fr[3] | (fr[2] << 8) |
203 (fr[1] << 16) | (fr[0] << 24));
204
205 rp[0] = (rp[0] & lmask)
206 | MBE((u_int)fb >> col);
207
208 rp[1] = (rp[1] & rmask)
209 | (MBE((u_int)fb << width) & ~rmask);
210
211 fr += fs;
212 DELTA(rp, rs, int32_t *);
213 }
214 } else {
215 while (height--) {
216 fb = (fr[3] | (fr[2] << 8) |
217 (fr[1] << 16) | (fr[0] << 24));
218
219 rp[0] = (rp[0] & lmask)
220 | MBE(fb >> col);
221
222 rp[1] = (rp[1] & rmask)
223 | (MBE(fb << width) & ~rmask);
224
225 fr += fs;
226 DELTA(rp, rs, int32_t *);
227 }
228 }
229 }
230
231 /* Do underline */
232 if ((attr & 1) != 0) {
233 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
234 rp[0] = (rp[0] & lmask) | (fg & ~lmask);
235 rp[1] = (rp[1] & rmask) | (fg & ~rmask);
236 }
237 }
238 }
239
240 #ifndef RASOPS_SMALL
241 /*
242 * Paint a single character. This is for 8-pixel wide fonts.
243 */
244 static void
245 rasops1_putchar8(cookie, row, col, uc, attr)
246 void *cookie;
247 int row, col;
248 u_int uc;
249 long attr;
250 {
251 int height, fs, rs, bg, fg;
252 struct rasops_info *ri;
253 u_char *fr, *rp;
254
255 ri = (struct rasops_info *)cookie;
256
257 #ifdef RASOPS_CLIPPING
258 /* Catches 'row < 0' case too */
259 if ((unsigned)row >= (unsigned)ri->ri_rows)
260 return;
261
262 if ((unsigned)col >= (unsigned)ri->ri_cols)
263 return;
264 #endif
265
266 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
267 height = ri->ri_font->fontheight;
268 rs = ri->ri_stride;
269
270 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
271 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
272
273 /* If fg and bg match this becomes a space character */
274 if (fg == bg || uc == ' ') {
275 while (height--) {
276 *rp = bg;
277 rp += rs;
278 }
279 } else {
280 uc -= ri->ri_font->firstchar;
281 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
282 fs = ri->ri_font->stride;
283
284 /* NOT fontbits if bg is white */
285 if (bg) {
286 while (height--) {
287 *rp = ~*fr;
288 fr += fs;
289 rp += rs;
290 }
291 } else {
292 while (height--) {
293 *rp = *fr;
294 fr += fs;
295 rp += rs;
296 }
297 }
298
299 }
300
301 /* Do underline */
302 if ((attr & 1) != 0)
303 rp[-(ri->ri_stride << 1)] = fg;
304 }
305
306 /*
307 * Paint a single character. This is for 16-pixel wide fonts.
308 */
309 static void
310 rasops1_putchar16(cookie, row, col, uc, attr)
311 void *cookie;
312 int row, col;
313 u_int uc;
314 long attr;
315 {
316 int height, fs, rs, bg, fg;
317 struct rasops_info *ri;
318 u_char *fr, *rp;
319
320 ri = (struct rasops_info *)cookie;
321
322 #ifdef RASOPS_CLIPPING
323 /* Catches 'row < 0' case too */
324 if ((unsigned)row >= (unsigned)ri->ri_rows)
325 return;
326
327 if ((unsigned)col >= (unsigned)ri->ri_cols)
328 return;
329 #endif
330
331 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
332 height = ri->ri_font->fontheight;
333 rs = ri->ri_stride;
334
335 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
336 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
337
338 /* If fg and bg match this becomes a space character */
339 if (fg == bg || uc == ' ') {
340 while (height--) {
341 *(int16_t *)rp = bg;
342 rp += rs;
343 }
344 } else {
345 uc -= ri->ri_font->firstchar;
346 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
347 fs = ri->ri_font->stride;
348
349 /* NOT fontbits if bg is white */
350 if (bg) {
351 while (height--) {
352 rp[0] = ~fr[0];
353 rp[1] = ~fr[1];
354 fr += fs;
355 rp += rs;
356 }
357 } else {
358 while (height--) {
359 rp[0] = fr[0];
360 rp[1] = fr[1];
361 fr += fs;
362 rp += rs;
363 }
364 }
365 }
366
367 /* Do underline */
368 if ((attr & 1) != 0)
369 *(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
370 }
371 #endif /* !RASOPS_SMALL */
372
373 /*
374 * Grab routines common to depths where (bpp < 8)
375 */
376 #define NAME(ident) rasops1_##ident
377 #define PIXEL_SHIFT 0
378
379 #include <dev/rasops/rasops_bitops.h>
380