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