xref: /openbsd-src/sys/dev/rasops/rasops32.c (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1 /*	$OpenBSD: rasops32.c,v 1.7 2010/08/28 12:48:14 miod 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 int 	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(struct rasops_info *ri)
48 {
49 
50 	if (ri->ri_rnum == 0) {
51 		ri->ri_rnum = 8;
52 		ri->ri_rpos = 0;
53 		ri->ri_gnum = 8;
54 		ri->ri_gpos = 8;
55 		ri->ri_bnum = 8;
56 		ri->ri_bpos = 16;
57 	}
58 
59 	ri->ri_ops.putchar = rasops32_putchar;
60 }
61 
62 /*
63  * Paint a single character.
64  */
65 int
66 rasops32_putchar(void *cookie, int row, int col, u_int uc, long attr)
67 {
68 	int width, height, cnt, fs, fb, clr[2];
69 	struct rasops_info *ri;
70 	int32_t *dp, *rp;
71 	u_char *fr;
72 
73 	ri = (struct rasops_info *)cookie;
74 
75 #ifdef RASOPS_CLIPPING
76 	/* Catches 'row < 0' case too */
77 	if ((unsigned)row >= (unsigned)ri->ri_rows)
78 		return 0;
79 
80 	if ((unsigned)col >= (unsigned)ri->ri_cols)
81 		return 0;
82 #endif
83 
84 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
85 
86 	height = ri->ri_font->fontheight;
87 	width = ri->ri_font->fontwidth;
88 
89 	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
90 	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
91 
92 	if (uc == ' ') {
93 		while (height--) {
94 			dp = rp;
95 			DELTA(rp, ri->ri_stride, int32_t *);
96 
97 			for (cnt = width; cnt; cnt--)
98 				*dp++ = clr[0];
99 		}
100 	} else {
101 		uc -= ri->ri_font->firstchar;
102 		fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
103 		fs = ri->ri_font->stride;
104 
105 		while (height--) {
106 			dp = rp;
107 			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
108 			    (fr[0] << 24);
109 			fr += fs;
110 			DELTA(rp, ri->ri_stride, int32_t *);
111 
112 			for (cnt = width; cnt; cnt--) {
113 				*dp++ = clr[(fb >> 31) & 1];
114 				fb <<= 1;
115 			}
116 		}
117 	}
118 
119 	/* Do underline */
120 	if ((attr & 1) != 0) {
121 		DELTA(rp, -(ri->ri_stride << 1), int32_t *);
122 
123 		while (width--)
124 			*rp++ = clr[1];
125 	}
126 
127 	return 0;
128 }
129