rasops32.c revision 1.2 1 1.2 ad /* $NetBSD: rasops32.c,v 1.2 1999/04/13 00:40:09 ad Exp $ */
2 1.1 ad
3 1.2 ad /*
4 1.2 ad * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * Redistribution and use in source and binary forms, with or without
8 1.1 ad * modification, are permitted provided that the following conditions
9 1.1 ad * are met:
10 1.1 ad * 1. Redistributions of source code must retain the above copyright
11 1.1 ad * notice, this list of conditions and the following disclaimer.
12 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ad * notice, this list of conditions and the following disclaimer in the
14 1.1 ad * documentation and/or other materials provided with the distribution.
15 1.1 ad *
16 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.2 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.2 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.2 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.2 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.2 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.2 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2 ad * SUCH DAMAGE.
27 1.2 ad *
28 1.1 ad */
29 1.2 ad
30 1.1 ad #include "opt_rasops.h"
31 1.1 ad #ifdef RASOPS32
32 1.1 ad
33 1.1 ad #include <sys/cdefs.h>
34 1.2 ad __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.2 1999/04/13 00:40:09 ad Exp $");
35 1.1 ad
36 1.1 ad #include <sys/types.h>
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
41 1.1 ad #include <dev/wscons/wsdisplayvar.h>
42 1.1 ad #include <dev/wscons/wsconsio.h>
43 1.1 ad #include <dev/rasops/rasops.h>
44 1.1 ad
45 1.1 ad static void rasops32_putchar __P((void *, int, int, u_int, long attr));
46 1.1 ad static void rasops32_erasecols __P((void *, int, int, int, long));
47 1.1 ad static void rasops32_eraserows __P((void *, int, int, long));
48 1.1 ad static int32_t rasops32_fg_color __P((struct rasops_info *, long));
49 1.1 ad static int32_t rasops32_bg_color __P((struct rasops_info *, long));
50 1.1 ad static void rasops32_do_cursor __P((struct rasops_info *));
51 1.1 ad void rasops32_init __P((struct rasops_info *ri));
52 1.1 ad
53 1.1 ad /*
54 1.1 ad * Initalize a 'rasops_info' descriptor for this depth.
55 1.1 ad */
56 1.1 ad void
57 1.1 ad rasops32_init(ri)
58 1.1 ad struct rasops_info *ri;
59 1.1 ad {
60 1.1 ad
61 1.1 ad /*
62 1.1 ad * This sucks. There is little optimization you can do with this
63 1.1 ad * colordepth on 32-bit machines.
64 1.1 ad *
65 1.1 ad * XXX c'mon sparc, alpha ppl?
66 1.1 ad */
67 1.1 ad ri->ri_ops.putchar = rasops32_putchar;
68 1.1 ad ri->ri_ops.erasecols = rasops32_erasecols;
69 1.1 ad ri->ri_ops.eraserows = rasops32_eraserows;
70 1.1 ad ri->ri_do_cursor = rasops32_do_cursor;
71 1.1 ad rasops_init_devcmap(ri);
72 1.1 ad }
73 1.1 ad
74 1.1 ad
75 1.1 ad /*
76 1.1 ad * Get background color from attribute.
77 1.1 ad */
78 1.1 ad static __inline__ int32_t
79 1.1 ad rasops32_bg_color(ri, attr)
80 1.1 ad struct rasops_info *ri;
81 1.1 ad long attr;
82 1.1 ad {
83 1.1 ad
84 1.1 ad return ri->ri_devcmap[((int32_t)attr >> 24) & 15];
85 1.1 ad }
86 1.1 ad
87 1.1 ad
88 1.1 ad /*
89 1.1 ad * Get foreground color from attribute.
90 1.1 ad */
91 1.1 ad static __inline__ int32_t
92 1.1 ad rasops32_fg_color(ri, attr)
93 1.1 ad struct rasops_info *ri;
94 1.1 ad long attr;
95 1.1 ad {
96 1.1 ad
97 1.1 ad return ri->ri_devcmap[((int32_t)attr >> 16) & 15];
98 1.1 ad }
99 1.1 ad
100 1.1 ad
101 1.1 ad /*
102 1.1 ad * Actually turn the cursor on or off. This does the dirty work for
103 1.1 ad * rasops_cursor().
104 1.1 ad */
105 1.1 ad static void
106 1.1 ad rasops32_do_cursor(ri)
107 1.1 ad struct rasops_info *ri;
108 1.1 ad {
109 1.1 ad u_char *rp;
110 1.1 ad int32_t *dp, planemask;
111 1.1 ad int num, height, cnt, row, col;
112 1.1 ad
113 1.1 ad row = ri->ri_crow;
114 1.1 ad col = ri->ri_ccol;
115 1.1 ad
116 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
117 1.1 ad height = ri->ri_font->fontheight;
118 1.1 ad num = ri->ri_xscale >> 2;
119 1.1 ad planemask = ri->ri_devcmap[15];
120 1.1 ad
121 1.1 ad while (height--) {
122 1.1 ad dp = (int32_t *)rp;
123 1.1 ad rp += ri->ri_stride;
124 1.1 ad
125 1.1 ad for (cnt = num; cnt; cnt--)
126 1.1 ad *dp++ ^= planemask;
127 1.1 ad }
128 1.1 ad }
129 1.1 ad
130 1.1 ad
131 1.1 ad /*
132 1.1 ad * Paint a single character.
133 1.1 ad */
134 1.1 ad static void
135 1.1 ad rasops32_putchar(cookie, row, col, uc, attr)
136 1.1 ad void *cookie;
137 1.1 ad int row, col;
138 1.1 ad u_int uc;
139 1.1 ad long attr;
140 1.1 ad {
141 1.1 ad struct rasops_info *ri;
142 1.1 ad int32_t *dp, *rp, clr[2];
143 1.1 ad u_char *fr;
144 1.1 ad int width, height, cnt, fs, fb;
145 1.1 ad
146 1.1 ad ri = (struct rasops_info *)cookie;
147 1.1 ad
148 1.1 ad #ifdef RASOPS_CLIPPING
149 1.1 ad /* Catches 'row < 0' case too */
150 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
151 1.1 ad return;
152 1.1 ad
153 1.1 ad if ((unsigned)col >= (unsigned)ri->ri_cols)
154 1.1 ad return;
155 1.1 ad #endif
156 1.1 ad
157 1.1 ad rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
158 1.1 ad
159 1.1 ad height = ri->ri_font->fontheight;
160 1.1 ad width = ri->ri_font->fontwidth;
161 1.1 ad clr[0] = rasops32_bg_color(ri, attr);
162 1.1 ad clr[1] = rasops32_fg_color(ri, attr);
163 1.1 ad
164 1.1 ad if (uc == ' ') {
165 1.1 ad while (height--) {
166 1.1 ad dp = rp;
167 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
168 1.1 ad
169 1.1 ad for (cnt = width; cnt; cnt--)
170 1.1 ad *dp++ = clr[0];
171 1.1 ad }
172 1.1 ad } else {
173 1.1 ad uc -= ri->ri_font->firstchar;
174 1.1 ad fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
175 1.1 ad fs = ri->ri_font->stride;
176 1.1 ad
177 1.1 ad while (height--) {
178 1.1 ad dp = rp;
179 1.1 ad fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
180 1.1 ad fr += fs;
181 1.1 ad DELTA(rp, ri->ri_stride, int32_t *);
182 1.1 ad
183 1.1 ad for (cnt = width; cnt; cnt--) {
184 1.1 ad *dp++ = clr[(fb >> 31) & 1];
185 1.1 ad fb <<= 1;
186 1.1 ad }
187 1.1 ad }
188 1.1 ad }
189 1.1 ad
190 1.1 ad /* Do underline */
191 1.1 ad if (attr & 1) {
192 1.1 ad DELTA(rp, -(ri->ri_stride << 1), int32_t *);
193 1.1 ad
194 1.1 ad while (width--)
195 1.1 ad *rp++ = clr[1];
196 1.1 ad }
197 1.1 ad }
198 1.1 ad
199 1.1 ad
200 1.1 ad /*
201 1.1 ad * Erase rows.
202 1.1 ad */
203 1.1 ad static void
204 1.1 ad rasops32_eraserows(cookie, row, num, attr)
205 1.1 ad void *cookie;
206 1.1 ad int row, num;
207 1.1 ad long attr;
208 1.1 ad {
209 1.1 ad struct rasops_info *ri;
210 1.1 ad int32_t *dp, clr;
211 1.1 ad int n8, n1, cnt;
212 1.1 ad
213 1.1 ad ri = (struct rasops_info *)cookie;
214 1.1 ad
215 1.1 ad #ifdef RASOPS_CLIPPING
216 1.1 ad if (row < 0) {
217 1.1 ad num += row;
218 1.1 ad row = 0;
219 1.1 ad }
220 1.1 ad
221 1.1 ad if ((row + num) > ri->ri_rows)
222 1.1 ad num = ri->ri_rows - row;
223 1.1 ad
224 1.1 ad if (num <= 0)
225 1.1 ad return;
226 1.1 ad #endif
227 1.1 ad
228 1.1 ad num *= ri->ri_font->fontheight;
229 1.1 ad dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
230 1.1 ad clr = rasops32_bg_color(ri, attr);
231 1.1 ad
232 1.1 ad n8 = ri->ri_emustride >> 5;
233 1.1 ad n1 = (ri->ri_emustride >> 2) & 7;
234 1.1 ad
235 1.1 ad while (num--) {
236 1.1 ad for (cnt = n8; cnt; cnt--) {
237 1.1 ad dp[0] = clr;
238 1.1 ad dp[1] = clr;
239 1.1 ad dp[2] = clr;
240 1.1 ad dp[3] = clr;
241 1.1 ad dp[4] = clr;
242 1.1 ad dp[5] = clr;
243 1.1 ad dp[6] = clr;
244 1.1 ad dp[7] = clr;
245 1.1 ad dp += 8;
246 1.1 ad }
247 1.1 ad
248 1.1 ad for (cnt = n1; cnt; cnt--)
249 1.1 ad *dp++ = clr;
250 1.1 ad
251 1.1 ad DELTA(dp, ri->ri_delta, int32_t *);
252 1.1 ad }
253 1.1 ad }
254 1.1 ad
255 1.1 ad
256 1.1 ad /*
257 1.1 ad * Erase columns.
258 1.1 ad */
259 1.1 ad static void
260 1.1 ad rasops32_erasecols(cookie, row, col, num, attr)
261 1.1 ad void *cookie;
262 1.1 ad int row, col, num;
263 1.1 ad long attr;
264 1.1 ad {
265 1.1 ad int n8, clr, height, cnt;
266 1.1 ad struct rasops_info *ri;
267 1.1 ad int32_t *dst;
268 1.1 ad u_char *rp;
269 1.1 ad
270 1.1 ad ri = (struct rasops_info *)cookie;
271 1.1 ad
272 1.1 ad #ifdef RASOPS_CLIPPING
273 1.1 ad if ((unsigned)row >= (unsigned)ri->ri_rows)
274 1.1 ad return;
275 1.1 ad
276 1.1 ad if (col < 0) {
277 1.1 ad num += col;
278 1.1 ad col = 0;
279 1.1 ad }
280 1.1 ad
281 1.1 ad if ((col + num) > ri->ri_cols)
282 1.1 ad num = ri->ri_cols - col;
283 1.1 ad
284 1.1 ad if (num <= 0)
285 1.1 ad return;
286 1.1 ad #endif
287 1.1 ad
288 1.1 ad num = num * ri->ri_xscale;
289 1.1 ad rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
290 1.1 ad clr = rasops32_bg_color(ri, attr);
291 1.1 ad height = ri->ri_font->fontheight;
292 1.1 ad n8 = num >> 5;
293 1.1 ad num = (num >> 2) & 7;
294 1.1 ad
295 1.1 ad while (height--) {
296 1.1 ad dst = (int32_t *)rp;
297 1.1 ad rp += ri->ri_stride;
298 1.1 ad
299 1.1 ad for (cnt = n8; cnt; cnt--) {
300 1.1 ad dst[0] = clr;
301 1.1 ad dst[1] = clr;
302 1.1 ad dst[2] = clr;
303 1.1 ad dst[3] = clr;
304 1.1 ad dst[4] = clr;
305 1.1 ad dst[5] = clr;
306 1.1 ad dst[6] = clr;
307 1.1 ad dst[7] = clr;
308 1.1 ad dst += 8;
309 1.1 ad }
310 1.1 ad
311 1.1 ad for (cnt = num; cnt; cnt--)
312 1.1 ad *dst++ = clr;
313 1.1 ad }
314 1.1 ad }
315 1.1 ad
316 1.1 ad #endif /* RASOPS32 */
317