xref: /netbsd-src/sys/dev/rasops/rasops32.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	 $NetBSD: rasops32.c,v 1.16 2008/04/28 20:23:56 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Andrew Doran.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.16 2008/04/28 20:23:56 martin Exp $");
34 
35 #include "opt_rasops.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40 
41 #include <dev/wscons/wsdisplayvar.h>
42 #include <dev/wscons/wsconsio.h>
43 #include <dev/rasops/rasops.h>
44 
45 static void 	rasops32_putchar(void *, int, int, u_int, long attr);
46 
47 /*
48  * Initialize 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  * Paint a single character.
69  */
70 static void
71 rasops32_putchar(cookie, row, col, uc, attr)
72 	void *cookie;
73 	int row, col;
74 	u_int uc;
75 	long attr;
76 {
77 	int width, height, cnt, fs, fb, clr[2];
78 	struct rasops_info *ri;
79 	int32_t *dp, *rp, *hp, *hrp;
80 	u_char *fr;
81 
82 	ri = (struct rasops_info *)cookie;
83 	hp = hrp = NULL;
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 	/* check if character fits into font limits */
95 	if (uc < ri->ri_font->firstchar ||
96 	    (uc - ri->ri_font->firstchar) >= ri->ri_font->numchars)
97 	    return;
98 
99 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
100 	if (ri->ri_hwbits)
101 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
102 		    col*ri->ri_xscale);
103 
104 	height = ri->ri_font->fontheight;
105 	width = ri->ri_font->fontwidth;
106 
107 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
108 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
109 
110 	if (uc == ' ') {
111 		while (height--) {
112 			dp = rp;
113 			DELTA(rp, ri->ri_stride, int32_t *);
114 			if (ri->ri_hwbits) {
115 				hp = hrp;
116 				DELTA(hrp, ri->ri_stride, int32_t *);
117 			}
118 
119 			for (cnt = width; cnt; cnt--) {
120 				*dp++ = clr[0];
121 				if (ri->ri_hwbits)
122 					*hp++ = clr[0];
123 			}
124 		}
125 	} else {
126 		uc -= ri->ri_font->firstchar;
127 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
128 		fs = ri->ri_font->stride;
129 
130 		while (height--) {
131 			dp = rp;
132 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
133 			    (fr[0] << 24);
134 			fr += fs;
135 			DELTA(rp, ri->ri_stride, int32_t *);
136 			if (ri->ri_hwbits) {
137 				hp = hrp;
138 				DELTA(hrp, ri->ri_stride, int32_t *);
139 			}
140 
141 			for (cnt = width; cnt; cnt--) {
142 				*dp++ = clr[(fb >> 31) & 1];
143 				if (ri->ri_hwbits)
144 					*hp++ = clr[(fb >> 31) & 1];
145 				fb <<= 1;
146 			}
147 		}
148 	}
149 
150 	/* Do underline */
151 	if ((attr & 1) != 0) {
152 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
153 		if (ri->ri_hwbits)
154 			DELTA(hrp, -(ri->ri_stride << 1), int32_t *);
155 
156 		while (width--) {
157 			*rp++ = clr[1];
158 			if (ri->ri_hwbits)
159 				*hrp++ = clr[1];
160 		}
161 	}
162 }
163