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