rasops1.c revision 1.28 1 1.28 rin /* $NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin 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.28 rin __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin 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.25 rin uint32_t height, width;
92 1.23 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
93 1.23 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
94 1.26 rin uint32_t *rp, *hrp = NULL, tmp, tmp2;
95 1.25 rin uint8_t *fr;
96 1.11 pk
97 1.11 pk #ifdef RASOPS_CLIPPING
98 1.11 pk /* Catches 'row < 0' case too */
99 1.4 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
100 1.4 ad return;
101 1.4 ad
102 1.4 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
103 1.4 ad return;
104 1.4 ad #endif
105 1.4 ad
106 1.4 ad col *= ri->ri_font->fontwidth;
107 1.26 rin rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
108 1.26 rin ((col >> 3) & ~3));
109 1.21 macallan if (ri->ri_hwbits)
110 1.26 rin hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
111 1.21 macallan ((col >> 3) & ~3));
112 1.23 macallan height = font->fontheight;
113 1.23 macallan width = font->fontwidth;
114 1.4 ad col = col & 31;
115 1.4 ad rs = ri->ri_stride;
116 1.11 pk
117 1.9 ad bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
118 1.9 ad fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
119 1.4 ad
120 1.4 ad /* If fg and bg match this becomes a space character */
121 1.4 ad if (fg == bg || uc == ' ') {
122 1.4 ad uc = (u_int)-1;
123 1.4 ad fr = 0; /* shutup gcc */
124 1.4 ad fs = 0; /* shutup gcc */
125 1.4 ad } else {
126 1.28 rin fr = FONT_GLYPH(uc, font, ri);
127 1.23 macallan fs = font->stride;
128 1.4 ad }
129 1.11 pk
130 1.4 ad /* Single word, one mask */
131 1.4 ad if ((col + width) <= 32) {
132 1.4 ad rmask = rasops_pmask[col][width];
133 1.4 ad lmask = ~rmask;
134 1.11 pk
135 1.4 ad if (uc == (u_int)-1) {
136 1.4 ad bg &= rmask;
137 1.11 pk
138 1.4 ad while (height--) {
139 1.21 macallan tmp = (*rp & lmask) | bg;
140 1.21 macallan *rp = tmp;
141 1.26 rin DELTA(rp, rs, uint32_t *);
142 1.21 macallan if (ri->ri_hwbits) {
143 1.21 macallan *hrp = tmp;
144 1.26 rin DELTA(hrp, rs, uint32_t *);
145 1.21 macallan }
146 1.4 ad }
147 1.4 ad } else {
148 1.4 ad /* NOT fontbits if bg is white */
149 1.4 ad if (bg) {
150 1.4 ad while (height--) {
151 1.11 pk fb = ~(fr[3] | (fr[2] << 8) |
152 1.4 ad (fr[1] << 16) | (fr[0] << 24));
153 1.21 macallan tmp = (*rp & lmask)
154 1.4 ad | (MBE(fb >> col) & rmask);
155 1.21 macallan *rp = tmp;
156 1.4 ad
157 1.4 ad fr += fs;
158 1.26 rin DELTA(rp, rs, uint32_t *);
159 1.21 macallan if (ri->ri_hwbits) {
160 1.21 macallan *hrp = tmp;
161 1.26 rin DELTA(hrp, rs, uint32_t *);
162 1.21 macallan }
163 1.4 ad }
164 1.4 ad } else {
165 1.4 ad while (height--) {
166 1.11 pk fb = (fr[3] | (fr[2] << 8) |
167 1.4 ad (fr[1] << 16) | (fr[0] << 24));
168 1.21 macallan tmp = (*rp & lmask)
169 1.4 ad | (MBE(fb >> col) & rmask);
170 1.21 macallan *rp = tmp;
171 1.11 pk
172 1.4 ad fr += fs;
173 1.26 rin DELTA(rp, rs, uint32_t *);
174 1.21 macallan if (ri->ri_hwbits) {
175 1.21 macallan *hrp = tmp;
176 1.26 rin DELTA(hrp, rs, uint32_t *);
177 1.21 macallan }
178 1.4 ad }
179 1.4 ad }
180 1.4 ad }
181 1.11 pk
182 1.4 ad /* Do underline */
183 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
184 1.26 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
185 1.21 macallan tmp = (*rp & lmask) | (fg & rmask);
186 1.21 macallan *rp = tmp;
187 1.21 macallan if (ri->ri_hwbits) {
188 1.26 rin DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
189 1.21 macallan *hrp = tmp;
190 1.21 macallan }
191 1.4 ad }
192 1.4 ad } else {
193 1.4 ad lmask = ~rasops_lmask[col];
194 1.4 ad rmask = ~rasops_rmask[(col + width) & 31];
195 1.11 pk
196 1.4 ad if (uc == (u_int)-1) {
197 1.8 mouse width = bg & ~rmask;
198 1.4 ad bg = bg & ~lmask;
199 1.11 pk
200 1.4 ad while (height--) {
201 1.21 macallan tmp = (rp[0] & lmask) | bg;
202 1.21 macallan tmp2 = (rp[1] & rmask) | width;
203 1.21 macallan rp[0] = tmp;
204 1.21 macallan rp[1] = tmp2;
205 1.26 rin DELTA(rp, rs, uint32_t *);
206 1.21 macallan if (ri->ri_hwbits) {
207 1.21 macallan hrp[0] = tmp;
208 1.21 macallan hrp[1] = tmp2;
209 1.26 rin DELTA(hrp, rs, uint32_t *);
210 1.21 macallan }
211 1.4 ad }
212 1.4 ad } else {
213 1.4 ad width = 32 - col;
214 1.11 pk
215 1.4 ad /* NOT fontbits if bg is white */
216 1.4 ad if (bg) {
217 1.4 ad while (height--) {
218 1.11 pk fb = ~(fr[3] | (fr[2] << 8) |
219 1.4 ad (fr[1] << 16) | (fr[0] << 24));
220 1.11 pk
221 1.27 rin tmp = (rp[0] & lmask) |
222 1.27 rin MBE((u_int)fb >> col);
223 1.4 ad
224 1.27 rin tmp2 = (rp[1] & rmask) |
225 1.27 rin (MBE((u_int)fb << width) & ~rmask);
226 1.21 macallan rp[0] = tmp;
227 1.21 macallan rp[1] = tmp2;
228 1.4 ad fr += fs;
229 1.26 rin DELTA(rp, rs, uint32_t *);
230 1.21 macallan if (ri->ri_hwbits) {
231 1.21 macallan hrp[0] = tmp;
232 1.21 macallan hrp[1] = tmp2;
233 1.26 rin DELTA(hrp, rs, uint32_t *);
234 1.21 macallan }
235 1.4 ad }
236 1.4 ad } else {
237 1.4 ad while (height--) {
238 1.11 pk fb = (fr[3] | (fr[2] << 8) |
239 1.4 ad (fr[1] << 16) | (fr[0] << 24));
240 1.4 ad
241 1.27 rin tmp = (rp[0] & lmask) |
242 1.27 rin MBE(fb >> col);
243 1.4 ad
244 1.27 rin tmp2 = (rp[1] & rmask) |
245 1.27 rin (MBE(fb << width) & ~rmask);
246 1.21 macallan rp[0] = tmp;
247 1.21 macallan rp[1] = tmp2;
248 1.4 ad fr += fs;
249 1.26 rin DELTA(rp, rs, uint32_t *);
250 1.21 macallan if (ri->ri_hwbits) {
251 1.21 macallan hrp[0] = tmp;
252 1.21 macallan hrp[1] = tmp2;
253 1.26 rin DELTA(hrp, rs, uint32_t *);
254 1.21 macallan }
255 1.4 ad }
256 1.4 ad }
257 1.4 ad }
258 1.1 ad
259 1.4 ad /* Do underline */
260 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
261 1.26 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
262 1.21 macallan tmp = (rp[0] & lmask) | (fg & ~lmask);
263 1.21 macallan tmp2 = (rp[1] & rmask) | (fg & ~rmask);
264 1.21 macallan rp[0] = tmp;
265 1.21 macallan rp[1] = tmp2;
266 1.21 macallan if (ri->ri_hwbits) {
267 1.26 rin DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
268 1.21 macallan hrp[0] = tmp;
269 1.21 macallan hrp[1] = tmp2;
270 1.21 macallan }
271 1.4 ad }
272 1.4 ad }
273 1.1 ad }
274 1.1 ad
275 1.10 ad #ifndef RASOPS_SMALL
276 1.1 ad /*
277 1.1 ad * Paint a single character. This is for 8-pixel wide fonts.
278 1.1 ad */
279 1.1 ad static void
280 1.20 dsl rasops1_putchar8(void *cookie, int row, int col, u_int uc, long attr)
281 1.1 ad {
282 1.1 ad int height, fs, rs, bg, fg;
283 1.23 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
284 1.23 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
285 1.25 rin uint8_t *fr, *rp, *hrp = NULL;
286 1.11 pk
287 1.11 pk #ifdef RASOPS_CLIPPING
288 1.11 pk /* Catches 'row < 0' case too */
289 1.3 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
290 1.1 ad return;
291 1.1 ad
292 1.3 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
293 1.1 ad return;
294 1.1 ad #endif
295 1.1 ad
296 1.3 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
297 1.21 macallan if (ri->ri_hwbits)
298 1.22 macallan hrp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
299 1.23 macallan height = font->fontheight;
300 1.1 ad rs = ri->ri_stride;
301 1.11 pk
302 1.9 ad bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
303 1.9 ad fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
304 1.11 pk
305 1.1 ad /* If fg and bg match this becomes a space character */
306 1.1 ad if (fg == bg || uc == ' ') {
307 1.1 ad while (height--) {
308 1.1 ad *rp = bg;
309 1.1 ad rp += rs;
310 1.21 macallan if (ri->ri_hwbits) {
311 1.21 macallan *hrp = bg;
312 1.21 macallan hrp += rs;
313 1.21 macallan }
314 1.1 ad }
315 1.1 ad } else {
316 1.28 rin fr = FONT_GLYPH(uc, font, ri);
317 1.23 macallan fs = font->stride;
318 1.11 pk
319 1.1 ad /* NOT fontbits if bg is white */
320 1.1 ad if (bg) {
321 1.1 ad while (height--) {
322 1.1 ad *rp = ~*fr;
323 1.21 macallan rp += rs;
324 1.21 macallan if (ri->ri_hwbits) {
325 1.21 macallan *hrp = ~*fr;
326 1.21 macallan hrp += rs;
327 1.21 macallan }
328 1.1 ad fr += fs;
329 1.21 macallan
330 1.1 ad }
331 1.1 ad } else {
332 1.1 ad while (height--) {
333 1.1 ad *rp = *fr;
334 1.21 macallan rp += rs;
335 1.21 macallan if (ri->ri_hwbits) {
336 1.21 macallan *hrp = *fr;
337 1.21 macallan hrp += rs;
338 1.21 macallan }
339 1.1 ad fr += fs;
340 1.1 ad }
341 1.1 ad }
342 1.4 ad
343 1.1 ad }
344 1.1 ad
345 1.1 ad /* Do underline */
346 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
347 1.1 ad rp[-(ri->ri_stride << 1)] = fg;
348 1.22 macallan if (ri->ri_hwbits) {
349 1.22 macallan hrp[-(ri->ri_stride << 1)] = fg;
350 1.22 macallan }
351 1.22 macallan }
352 1.1 ad }
353 1.1 ad
354 1.1 ad /*
355 1.1 ad * Paint a single character. This is for 16-pixel wide fonts.
356 1.1 ad */
357 1.1 ad static void
358 1.20 dsl rasops1_putchar16(void *cookie, int row, int col, u_int uc, long attr)
359 1.1 ad {
360 1.1 ad int height, fs, rs, bg, fg;
361 1.23 macallan struct rasops_info *ri = (struct rasops_info *)cookie;
362 1.23 macallan struct wsdisplay_font *font = PICK_FONT(ri, uc);
363 1.25 rin uint8_t *fr, *rp, *hrp = NULL;
364 1.11 pk
365 1.11 pk #ifdef RASOPS_CLIPPING
366 1.11 pk /* Catches 'row < 0' case too */
367 1.3 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
368 1.1 ad return;
369 1.1 ad
370 1.3 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
371 1.1 ad return;
372 1.1 ad #endif
373 1.1 ad
374 1.3 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
375 1.21 macallan if (ri->ri_hwbits)
376 1.21 macallan hrp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
377 1.23 macallan height = font->fontheight;
378 1.1 ad rs = ri->ri_stride;
379 1.11 pk
380 1.9 ad bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
381 1.9 ad fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
382 1.9 ad
383 1.1 ad /* If fg and bg match this becomes a space character */
384 1.1 ad if (fg == bg || uc == ' ') {
385 1.1 ad while (height--) {
386 1.21 macallan /* XXX alignment?! */
387 1.26 rin *(uint16_t *)rp = bg;
388 1.1 ad rp += rs;
389 1.21 macallan if (ri->ri_hwbits) {
390 1.26 rin *(uint16_t *)hrp = bg;
391 1.21 macallan hrp += rs;
392 1.21 macallan }
393 1.1 ad }
394 1.1 ad } else {
395 1.28 rin fr = FONT_GLYPH(uc, font, ri);
396 1.23 macallan fs = font->stride;
397 1.11 pk
398 1.1 ad /* NOT fontbits if bg is white */
399 1.1 ad if (bg) {
400 1.1 ad while (height--) {
401 1.1 ad rp[0] = ~fr[0];
402 1.1 ad rp[1] = ~fr[1];
403 1.21 macallan rp += rs;
404 1.21 macallan if (ri->ri_hwbits) {
405 1.21 macallan hrp[0] = ~fr[0];
406 1.21 macallan hrp[1] = ~fr[1];
407 1.21 macallan hrp += rs;
408 1.21 macallan }
409 1.1 ad fr += fs;
410 1.1 ad }
411 1.1 ad } else {
412 1.1 ad while (height--) {
413 1.1 ad rp[0] = fr[0];
414 1.1 ad rp[1] = fr[1];
415 1.21 macallan rp += rs;
416 1.21 macallan if (ri->ri_hwbits) {
417 1.21 macallan hrp[0] = fr[0];
418 1.21 macallan hrp[1] = fr[1];
419 1.21 macallan hrp += rs;
420 1.21 macallan }
421 1.1 ad fr += fs;
422 1.1 ad }
423 1.1 ad }
424 1.1 ad }
425 1.1 ad
426 1.1 ad /* Do underline */
427 1.24 mlelstv if ((attr & WSATTR_UNDERLINE) != 0) {
428 1.21 macallan /* XXX alignment?! */
429 1.26 rin *(uint16_t *)(rp - (ri->ri_stride << 1)) = fg;
430 1.23 macallan if (ri->ri_hwbits) {
431 1.26 rin *(uint16_t *)(hrp - (ri->ri_stride << 1)) = fg;
432 1.23 macallan }
433 1.23 macallan }
434 1.1 ad }
435 1.10 ad #endif /* !RASOPS_SMALL */
436 1.1 ad
437 1.1 ad /*
438 1.4 ad * Grab routines common to depths where (bpp < 8)
439 1.1 ad */
440 1.4 ad #define NAME(ident) rasops1_##ident
441 1.4 ad #define PIXEL_SHIFT 0
442 1.1 ad
443 1.4 ad #include <dev/rasops/rasops_bitops.h>
444