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