wscons_rops.c revision 1.5 1 /* $NetBSD: wscons_rops.c,v 1.5 1999/02/12 11:25:23 drochner Exp $ */
2
3 /*
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)rcons_subr.c 8.1 (Berkeley) 6/11/93
45 */
46
47 #include <sys/param.h>
48 #include <sys/device.h>
49
50 #include <dev/rcons/raster.h>
51 #include <dev/wscons/wscons_raster.h>
52 #include <dev/wscons/wsdisplayvar.h>
53
54 /*
55 * Paint (or unpaint) the cursor.
56 * Pays no lip service to hardware cursors.
57 */
58 void
59 rcons_cursor(id, on, row, col)
60 void *id;
61 int on, row, col;
62 {
63 register struct rcons *rc = id;
64 register int x, y;
65
66 /* turn the cursor off */
67 if (!on) {
68 /* make sure it's on */
69 if ((rc->rc_bits & RC_CURSOR) == 0)
70 return;
71
72 row = *rc->rc_crowp;
73 col = *rc->rc_ccolp;
74 } else {
75 /* unpaint the old copy. */
76 *rc->rc_crowp = row;
77 *rc->rc_ccolp = col;
78 }
79
80 x = col * rc->rc_font->width + rc->rc_xorigin;
81 y = row * rc->rc_font->height + rc->rc_yorigin;
82
83 raster_op(rc->rc_sp, x, y,
84 #ifdef notdef
85 /* XXX This is the right way but too slow */
86 rc->rc_font->chars[(int)' '].r->width,
87 rc->rc_font->chars[(int)' '].r->height,
88 #else
89 rc->rc_font->width, rc->rc_font->height,
90 #endif
91 RAS_INVERT,
92 (struct raster *) 0, 0, 0);
93
94 rc->rc_bits ^= RC_CURSOR;
95 }
96
97 int
98 rcons_mapchar(id, uni, index)
99 void *id;
100 int uni;
101 unsigned int *index;
102 {
103
104 if (uni < 128) {
105 *index = uni;
106 return (5);
107 }
108 *index = ' ';
109 return (0);
110 }
111
112 /*
113 * Actually write a string to the frame buffer.
114 */
115 void
116 rcons_putchar(id, row, col, uc, attr)
117 void *id;
118 int row, col;
119 u_int uc;
120 long attr;
121 {
122 struct rcons *rc = id;
123 register int x, y, op;
124 u_char help;
125
126 x = col * rc->rc_font->width + rc->rc_xorigin;
127 y = row * rc->rc_font->height + rc->rc_font_ascent + rc->rc_yorigin;
128
129 op = RAS_SRC;
130 if ((attr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
131 op = RAS_NOT(op);
132 help = uc & 0xff;
133 raster_textn(rc->rc_sp, x, y, op, rc->rc_font, &help, 1);
134 }
135
136 /*
137 * Possibly change to white-on-black or black-on-white modes.
138 */
139 void
140 rcons_invert(id, inverted)
141 void *id;
142 int inverted;
143 {
144 struct rcons *rc = id;
145
146 if (((rc->rc_bits & RC_INVERT) != 0) ^ inverted) {
147 /* Invert the display */
148 raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
149 RAS_INVERT, (struct raster *) 0, 0, 0);
150
151 /* Swap things around */
152 rc->rc_bits ^= RC_INVERT;
153 }
154 }
155
156 /*
157 * Copy columns (characters) in a row (line).
158 */
159 void
160 rcons_copycols(id, row, srccol, dstcol, ncols)
161 void *id;
162 int row, srccol, dstcol, ncols;
163 {
164 struct rcons *rc = id;
165 int y, srcx, dstx, nx;
166
167 y = rc->rc_yorigin + rc->rc_font->height * row;
168 srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
169 dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
170 nx = rc->rc_font->width * ncols;
171
172 raster_op(rc->rc_sp, dstx, y,
173 nx, rc->rc_font->height, RAS_SRC,
174 rc->rc_sp, srcx, y);
175 }
176
177 /*
178 * Clear columns (characters) in a row (line).
179 */
180 void
181 rcons_erasecols(id, row, startcol, ncols, fillattr)
182 void *id;
183 int row, startcol, ncols;
184 long fillattr;
185 {
186 struct rcons *rc = id;
187 int y, startx, nx, op;
188
189 y = rc->rc_yorigin + rc->rc_font->height * row;
190 startx = rc->rc_xorigin + rc->rc_font->width * startcol;
191 nx = rc->rc_font->width * ncols;
192
193 op = RAS_CLEAR;
194 if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
195 op = RAS_NOT(op);
196 raster_op(rc->rc_sp, startx, y,
197 nx, rc->rc_font->height, op,
198 (struct raster *) 0, 0, 0);
199 }
200
201 /*
202 * Copy rows (lines).
203 */
204 void
205 rcons_copyrows(id, srcrow, dstrow, nrows)
206 void *id;
207 int srcrow, dstrow, nrows;
208 {
209 struct rcons *rc = id;
210 int srcy, dsty, ny;
211
212 srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
213 dsty = rc->rc_yorigin + rc->rc_font->height * dstrow;
214 ny = rc->rc_font->height * nrows;
215
216 raster_op(rc->rc_sp, rc->rc_xorigin, dsty,
217 rc->rc_raswidth, ny, RAS_SRC,
218 rc->rc_sp, rc->rc_xorigin, srcy);
219 }
220
221 /*
222 * Erase rows (lines).
223 */
224 void
225 rcons_eraserows(id, startrow, nrows, fillattr)
226 void *id;
227 int startrow, nrows;
228 long fillattr;
229 {
230 struct rcons *rc = id;
231 int starty, ny, op;
232
233 starty = rc->rc_yorigin + rc->rc_font->height * startrow;
234 ny = rc->rc_font->height * nrows;
235
236 op = RAS_CLEAR;
237 if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
238 op = RAS_NOT(op);
239 raster_op(rc->rc_sp, rc->rc_xorigin, starty,
240 rc->rc_raswidth, ny, op,
241 (struct raster *) 0, 0, 0);
242 }
243
244 int
245 rcons_alloc_attr(id, fg, bg, flags, attrp)
246 void *id;
247 int fg, bg, flags;
248 long *attrp;
249 {
250 if (flags & (WSATTR_HILIT | WSATTR_BLINK |
251 WSATTR_UNDERLINE | WSATTR_WSCOLORS))
252 return (EINVAL);
253 if (flags & WSATTR_REVERSE)
254 *attrp = 1;
255 else
256 *attrp = 0;
257 return (0);
258 }
259