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