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