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