rasops32.c revision 1.3 1 /* $NetBSD: rasops32.c,v 1.3 1999/04/26 04:27:47 ad Exp $ */
2
3 /*
4 * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 #include "opt_rasops.h"
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.3 1999/04/26 04:27:47 ad Exp $");
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/time.h>
38
39 #include <dev/wscons/wsdisplayvar.h>
40 #include <dev/wscons/wsconsio.h>
41 #include <dev/rasops/rasops.h>
42
43 static void rasops32_putchar __P((void *, int, int, u_int, long attr));
44 void rasops32_init __P((struct rasops_info *ri));
45
46
47 /*
48 * Initalize a 'rasops_info' descriptor for this depth.
49 */
50 void
51 rasops32_init(ri)
52 struct rasops_info *ri;
53 {
54
55 if (ri->ri_rnum == 0) {
56 ri->ri_rnum = 8;
57 ri->ri_rpos = 0;
58 ri->ri_gnum = 8;
59 ri->ri_gpos = 8;
60 ri->ri_bnum = 8;
61 ri->ri_bpos = 16;
62 }
63
64 ri->ri_ops.putchar = rasops32_putchar;
65 }
66
67
68 /*
69 * Paint a single character.
70 */
71 static void
72 rasops32_putchar(cookie, row, col, uc, attr)
73 void *cookie;
74 int row, col;
75 u_int uc;
76 long attr;
77 {
78 struct rasops_info *ri;
79 int32_t *dp, *rp, clr[2];
80 u_char *fr;
81 int width, height, cnt, fs, fb;
82
83 ri = (struct rasops_info *)cookie;
84
85 #ifdef RASOPS_CLIPPING
86 /* Catches 'row < 0' case too */
87 if ((unsigned)row >= (unsigned)ri->ri_rows)
88 return;
89
90 if ((unsigned)col >= (unsigned)ri->ri_cols)
91 return;
92 #endif
93
94 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
95
96 height = ri->ri_font->fontheight;
97 width = ri->ri_font->fontwidth;
98
99 clr[0] = ri->ri_devcmap[(attr >> 16) & 15];
100 clr[1] = ri->ri_devcmap[(attr >> 24) & 15];
101
102 if (uc == ' ') {
103 while (height--) {
104 dp = rp;
105 DELTA(rp, ri->ri_stride, int32_t *);
106
107 for (cnt = width; cnt; cnt--)
108 *dp++ = clr[0];
109 }
110 } else {
111 uc -= ri->ri_font->firstchar;
112 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
113 fs = ri->ri_font->stride;
114
115 while (height--) {
116 dp = rp;
117 fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | (fr[0] << 24);
118 fr += fs;
119 DELTA(rp, ri->ri_stride, int32_t *);
120
121 for (cnt = width; cnt; cnt--) {
122 *dp++ = clr[(fb >> 31) & 1];
123 fb <<= 1;
124 }
125 }
126 }
127
128 /* Do underline */
129 if (attr & 1) {
130 DELTA(rp, -(ri->ri_stride << 1), int32_t *);
131
132 while (width--)
133 *rp++ = clr[1];
134 }
135 }
136