pcdisplay_subr.c revision 1.21 1 /* $NetBSD: pcdisplay_subr.c,v 1.21 2002/06/26 23:05:33 christos Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: pcdisplay_subr.c,v 1.21 2002/06/26 23:05:33 christos Exp $");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 #include <machine/bus.h>
37
38 #include <dev/ic/mc6845reg.h>
39 #include <dev/ic/pcdisplayvar.h>
40 #include <dev/wscons/wsconsio.h>
41
42 #include <dev/wscons/wsdisplayvar.h>
43
44 void
45 pcdisplay_cursor_init(scr, existing)
46 struct pcdisplayscreen *scr;
47 int existing;
48 {
49 #ifdef PCDISPLAY_SOFTCURSOR
50 bus_space_tag_t memt;
51 bus_space_handle_t memh;
52 int off;
53
54 pcdisplay_6845_write(scr->hdl, curstart, 0x10);
55 pcdisplay_6845_write(scr->hdl, curend, 0x10);
56
57 if (existing) {
58 /*
59 * This is the first screen. At this point, scr->mem is NULL
60 * (no backing store), so we can't use pcdisplay_cursor() to
61 * do this.
62 */
63 memt = scr->hdl->ph_memt;
64 memh = scr->hdl->ph_memh;
65 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol) * 2 +
66 scr->dispoffset;
67
68 scr->cursortmp = bus_space_read_2(memt, memh, off);
69 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
70 } else
71 scr->cursortmp = 0;
72 #else
73 /*
74 * Firmware might not have initialized the cursor shape. Make
75 * sure there's something we can see.
76 * Don't touch the hardware if this is not the first screen.
77 */
78 if (existing) {
79 pcdisplay_6845_write(scr->hdl, curstart,
80 scr->type->fontheight - 2);
81 pcdisplay_6845_write(scr->hdl, curend,
82 scr->type->fontheight - 1);
83 }
84 #endif
85 scr->cursoron = 1;
86 }
87
88 void
89 pcdisplay_cursor(id, on, row, col)
90 void *id;
91 int on, row, col;
92 {
93 #ifdef PCDISPLAY_SOFTCURSOR
94 struct pcdisplayscreen *scr = id;
95 bus_space_tag_t memt = scr->hdl->ph_memt;
96 bus_space_handle_t memh = scr->hdl->ph_memh;
97 int off;
98
99 /* Remove old cursor image */
100 if (scr->cursoron) {
101 off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
102 if (scr->active)
103 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
104 scr->cursortmp);
105 else
106 scr->mem[off] = scr->cursortmp;
107 }
108
109 scr->vc_crow = row;
110 scr->vc_ccol = col;
111
112 if ((scr->cursoron = on) == 0)
113 return;
114
115 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
116 if (scr->active) {
117 off = off * 2 + scr->dispoffset;
118 scr->cursortmp = bus_space_read_2(memt, memh, off);
119 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
120 } else {
121 scr->cursortmp = scr->mem[off];
122 scr->mem[off] = scr->cursortmp ^ 0x7700;
123 }
124 #else /* PCDISPLAY_SOFTCURSOR */
125 struct pcdisplayscreen *scr = id;
126 int pos;
127
128 scr->vc_crow = row;
129 scr->vc_ccol = col;
130 scr->cursoron = on;
131
132 if (scr->active) {
133 if (!on)
134 pos = 0x3fff;
135 else
136 pos = scr->dispoffset / 2
137 + row * scr->type->ncols + col;
138
139 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
140 pcdisplay_6845_write(scr->hdl, cursorl, pos);
141 }
142 #endif /* PCDISPLAY_SOFTCURSOR */
143 }
144
145 #if 0
146 unsigned int
147 pcdisplay_mapchar_simple(id, uni)
148 void *id;
149 int uni;
150 {
151 if (uni < 128)
152 return (uni);
153
154 return (1); /* XXX ??? smiley */
155 }
156 #endif
157
158 void
159 pcdisplay_putchar(id, row, col, c, attr)
160 void *id;
161 int row, col;
162 u_int c;
163 long attr;
164 {
165 struct pcdisplayscreen *scr = id;
166 bus_space_tag_t memt = scr->hdl->ph_memt;
167 bus_space_handle_t memh = scr->hdl->ph_memh;
168 int off;
169
170 off = row * scr->type->ncols + col;
171
172 if (scr->active)
173 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
174 c | (attr << 8));
175 else
176 scr->mem[off] = c | (attr << 8);
177 }
178
179 void
180 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
181 void *id;
182 int row, srccol, dstcol, ncols;
183 {
184 struct pcdisplayscreen *scr = id;
185 bus_space_tag_t memt = scr->hdl->ph_memt;
186 bus_space_handle_t memh = scr->hdl->ph_memh;
187 bus_size_t srcoff, dstoff;
188
189 srcoff = dstoff = row * scr->type->ncols;
190 srcoff += srccol;
191 dstoff += dstcol;
192
193 if (scr->active)
194 bus_space_copy_region_2(memt, memh,
195 scr->dispoffset + srcoff * 2,
196 memh, scr->dispoffset + dstoff * 2,
197 ncols);
198 else
199 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
200 }
201
202 void
203 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
204 void *id;
205 int row, startcol, ncols;
206 long fillattr;
207 {
208 struct pcdisplayscreen *scr = id;
209 bus_space_tag_t memt = scr->hdl->ph_memt;
210 bus_space_handle_t memh = scr->hdl->ph_memh;
211 bus_size_t off;
212 u_int16_t val;
213 int i;
214
215 off = row * scr->type->ncols + startcol;
216
217 val = (fillattr << 8) | ' ';
218
219 if (scr->active)
220 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
221 val, ncols);
222 else
223 for (i = 0; i < ncols; i++)
224 scr->mem[off + i] = val;
225 }
226
227 void
228 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
229 void *id;
230 int srcrow, dstrow, nrows;
231 {
232 struct pcdisplayscreen *scr = id;
233 bus_space_tag_t memt = scr->hdl->ph_memt;
234 bus_space_handle_t memh = scr->hdl->ph_memh;
235 int ncols = scr->type->ncols;
236 bus_size_t srcoff, dstoff;
237
238 srcoff = srcrow * ncols + 0;
239 dstoff = dstrow * ncols + 0;
240
241 if (scr->active)
242 bus_space_copy_region_2(memt, memh,
243 scr->dispoffset + srcoff * 2,
244 memh, scr->dispoffset + dstoff * 2,
245 nrows * ncols);
246 else
247 memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
248 nrows * ncols * 2);
249 }
250
251 void
252 pcdisplay_eraserows(id, startrow, nrows, fillattr)
253 void *id;
254 int startrow, nrows;
255 long fillattr;
256 {
257 struct pcdisplayscreen *scr = id;
258 bus_space_tag_t memt = scr->hdl->ph_memt;
259 bus_space_handle_t memh = scr->hdl->ph_memh;
260 bus_size_t off, count;
261 u_int16_t val;
262 int i;
263
264 off = startrow * scr->type->ncols;
265 count = nrows * scr->type->ncols;
266
267 val = (fillattr << 8) | ' ';
268
269 if (scr->active)
270 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
271 val, count);
272 else
273 for (i = 0; i < count; i++)
274 scr->mem[off + i] = val;
275 }
276
277 int
278 pcdisplay_getwschar(id, wschar)
279 void *id;
280 struct wsdisplay_char *wschar;
281 {
282 struct pcdisplayscreen *scr = id;
283 bus_space_tag_t memt = scr->hdl->ph_memt;
284 bus_space_handle_t memh = scr->hdl->ph_memh;
285 int off;
286 uint16_t chardata;
287 uint8_t attrbyte;
288
289 off = wschar->row * scr->type->ncols + wschar->col;
290 if (off >= scr->type->ncols * scr->type->nrows)
291 return -1;
292
293 if (scr->active)
294 chardata = bus_space_read_2(memt, memh,
295 scr->dispoffset + off * 2);
296 else
297 chardata = scr->mem[off];
298
299 wschar->letter = (chardata & 0x00FF);
300 wschar->flags = 0;
301 attrbyte = (chardata & 0xFF00) >> 8;
302 if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT;
303 if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK;
304 wschar->foreground = attrbyte & 0x07;
305 wschar->background = (attrbyte >> 4) & 0x07;
306
307 return 0;
308 }
309
310 int
311 pcdisplay_putwschar(id, wschar)
312 void *id;
313 struct wsdisplay_char *wschar;
314 {
315 struct pcdisplayscreen *scr = id;
316 bus_space_tag_t memt = scr->hdl->ph_memt;
317 bus_space_handle_t memh = scr->hdl->ph_memh;
318 int off;
319 uint16_t chardata;
320 uint8_t attrbyte;
321
322 off = wschar->row * scr->type->ncols + wschar->col;
323 if (off >= (scr->type->ncols * scr->type->nrows))
324 return -1;
325
326 attrbyte = wschar->background & 0x07;
327 if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08;
328 attrbyte <<= 4;
329 attrbyte |= wschar->foreground & 0x07;
330 if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08;
331 chardata = (attrbyte << 8) | wschar->letter;
332
333 if (scr->active)
334 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
335 chardata);
336 else
337 scr->mem[off] = chardata;
338
339 return 0;
340 }
341