1 /* $NetBSD: pcdisplay_subr.c,v 1.25.8.2 2007/08/12 19:52:27 bouyer 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@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.25.8.2 2007/08/12 19:52:27 bouyer 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 #include "opt_wsdisplay_compat.h" /* for WSDISPLAY_CHARFUNCS */
45
46 void
47 pcdisplay_cursor_init(scr, existing)
48 struct pcdisplayscreen *scr;
49 int existing;
50 {
51 #ifdef PCDISPLAY_SOFTCURSOR
52 bus_space_tag_t memt;
53 bus_space_handle_t memh;
54 int off;
55
56 pcdisplay_6845_write(scr->hdl, curstart, 0x10);
57 pcdisplay_6845_write(scr->hdl, curend, 0x10);
58
59 if (existing) {
60 /*
61 * This is the first screen. At this point, scr->mem is NULL
62 * (no backing store), so we can't use pcdisplay_cursor() to
63 * do this.
64 */
65 memt = scr->hdl->ph_memt;
66 memh = scr->hdl->ph_memh;
67 off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) * 2
68 + scr->dispoffset;
69
70 scr->cursortmp = bus_space_read_2(memt, memh, off);
71 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
72 } else
73 scr->cursortmp = 0;
74 #else
75 /*
76 * Firmware might not have initialized the cursor shape. Make
77 * sure there's something we can see.
78 * Don't touch the hardware if this is not the first screen.
79 */
80 if (existing) {
81 pcdisplay_6845_write(scr->hdl, curstart,
82 scr->type->fontheight - 2);
83 pcdisplay_6845_write(scr->hdl, curend,
84 scr->type->fontheight - 1);
85 }
86 #endif
87 scr->cursoron = 1;
88 }
89
90 void
91 pcdisplay_cursor(id, on, row, col)
92 void *id;
93 int on, row, col;
94 {
95 #ifdef PCDISPLAY_SOFTCURSOR
96 struct pcdisplayscreen *scr = id;
97 bus_space_tag_t memt = scr->hdl->ph_memt;
98 bus_space_handle_t memh = scr->hdl->ph_memh;
99 int off;
100
101 /* Remove old cursor image */
102 if (scr->cursoron) {
103 off = scr->cursorrow * scr->type->ncols + scr->cursorcol;
104 if (scr->active)
105 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
106 scr->cursortmp);
107 else
108 scr->mem[off] = scr->cursortmp;
109 }
110
111 scr->cursorrow = row;
112 scr->cursorcol = col;
113
114 if ((scr->cursoron = on) == 0)
115 return;
116
117 off = (scr->cursorrow * scr->type->ncols + scr->cursorcol);
118 if (scr->active) {
119 off = off * 2 + scr->dispoffset;
120 scr->cursortmp = bus_space_read_2(memt, memh, off);
121 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
122 } else {
123 scr->cursortmp = scr->mem[off];
124 scr->mem[off] = scr->cursortmp ^ 0x7700;
125 }
126 #else /* PCDISPLAY_SOFTCURSOR */
127 struct pcdisplayscreen *scr = id;
128 int pos;
129
130 scr->cursorrow = row;
131 scr->cursorcol = col;
132 scr->cursoron = on;
133
134 if (scr->active) {
135 if (!on)
136 pos = 0x3fff;
137 else
138 pos = scr->dispoffset / 2
139 + row * scr->type->ncols + col;
140
141 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
142 pcdisplay_6845_write(scr->hdl, cursorl, pos);
143 }
144 #endif /* PCDISPLAY_SOFTCURSOR */
145 }
146
147 #if 0
148 unsigned int
149 pcdisplay_mapchar_simple(id, uni)
150 void *id;
151 int uni;
152 {
153 if (uni < 128)
154 return (uni);
155
156 return (1); /* XXX ??? smiley */
157 }
158 #endif
159
160 void
161 pcdisplay_putchar(id, row, col, c, attr)
162 void *id;
163 int row, col;
164 u_int c;
165 long attr;
166 {
167 struct pcdisplayscreen *scr = id;
168 bus_space_tag_t memt = scr->hdl->ph_memt;
169 bus_space_handle_t memh = scr->hdl->ph_memh;
170 size_t off;
171
172 off = row * scr->type->ncols + col;
173
174 /* check for bogus row and column sizes */
175 if (__predict_false(off >= (scr->type->ncols * scr->type->nrows)))
176 return;
177
178 if (scr->active)
179 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
180 c | (attr << 8));
181 else
182 scr->mem[off] = c | (attr << 8);
183
184 scr->visibleoffset = scr->dispoffset;
185 }
186
187 void
188 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
189 void *id;
190 int row, srccol, dstcol, ncols;
191 {
192 struct pcdisplayscreen *scr = id;
193 bus_space_tag_t memt = scr->hdl->ph_memt;
194 bus_space_handle_t memh = scr->hdl->ph_memh;
195 bus_size_t srcoff, dstoff;
196
197 srcoff = dstoff = row * scr->type->ncols;
198 srcoff += srccol;
199 dstoff += dstcol;
200
201 if (scr->active)
202 bus_space_copy_region_2(memt, memh,
203 scr->dispoffset + srcoff * 2,
204 memh, scr->dispoffset + dstoff * 2,
205 ncols);
206 else
207 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
208 }
209
210 void
211 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
212 void *id;
213 int row, startcol, ncols;
214 long fillattr;
215 {
216 struct pcdisplayscreen *scr = id;
217 bus_space_tag_t memt = scr->hdl->ph_memt;
218 bus_space_handle_t memh = scr->hdl->ph_memh;
219 bus_size_t off;
220 u_int16_t val;
221 int i;
222
223 off = row * scr->type->ncols + startcol;
224
225 val = (fillattr << 8) | ' ';
226
227 if (scr->active)
228 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
229 val, ncols);
230 else
231 for (i = 0; i < ncols; i++)
232 scr->mem[off + i] = val;
233 }
234
235 void
236 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
237 void *id;
238 int srcrow, dstrow, nrows;
239 {
240 struct pcdisplayscreen *scr = id;
241 bus_space_tag_t memt = scr->hdl->ph_memt;
242 bus_space_handle_t memh = scr->hdl->ph_memh;
243 int ncols = scr->type->ncols;
244 bus_size_t srcoff, dstoff;
245
246 srcoff = srcrow * ncols + 0;
247 dstoff = dstrow * ncols + 0;
248
249 if (scr->active)
250 bus_space_copy_region_2(memt, memh,
251 scr->dispoffset + srcoff * 2,
252 memh, scr->dispoffset + dstoff * 2,
253 nrows * ncols);
254 else
255 memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
256 nrows * ncols * 2);
257 }
258
259 void
260 pcdisplay_eraserows(id, startrow, nrows, fillattr)
261 void *id;
262 int startrow, nrows;
263 long fillattr;
264 {
265 struct pcdisplayscreen *scr = id;
266 bus_space_tag_t memt = scr->hdl->ph_memt;
267 bus_space_handle_t memh = scr->hdl->ph_memh;
268 bus_size_t off, count;
269 u_int16_t val;
270 u_int i;
271
272 off = startrow * scr->type->ncols;
273 count = nrows * scr->type->ncols;
274
275 val = (fillattr << 8) | ' ';
276
277 if (scr->active)
278 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
279 val, count);
280 else
281 for (i = 0; i < count; i++)
282 scr->mem[off + i] = val;
283 }
284
285 #ifdef WSDISPLAY_CHARFUNCS
286 int
287 pcdisplay_getwschar(id, wschar)
288 void *id;
289 struct wsdisplay_char *wschar;
290 {
291 struct pcdisplayscreen *scr = id;
292 bus_space_tag_t memt = scr->hdl->ph_memt;
293 bus_space_handle_t memh = scr->hdl->ph_memh;
294 int off;
295 uint16_t chardata;
296 uint8_t attrbyte;
297
298 off = wschar->row * scr->type->ncols + wschar->col;
299 if (off >= scr->type->ncols * scr->type->nrows)
300 return -1;
301
302 if (scr->active)
303 chardata = bus_space_read_2(memt, memh,
304 scr->dispoffset + off * 2);
305 else
306 chardata = scr->mem[off];
307
308 wschar->letter = (chardata & 0x00FF);
309 wschar->flags = 0;
310 attrbyte = (chardata & 0xFF00) >> 8;
311 if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT;
312 if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK;
313 wschar->foreground = attrbyte & 0x07;
314 wschar->background = (attrbyte >> 4) & 0x07;
315
316 return 0;
317 }
318
319 int
320 pcdisplay_putwschar(id, wschar)
321 void *id;
322 struct wsdisplay_char *wschar;
323 {
324 struct pcdisplayscreen *scr = id;
325 bus_space_tag_t memt = scr->hdl->ph_memt;
326 bus_space_handle_t memh = scr->hdl->ph_memh;
327 int off;
328 uint16_t chardata;
329 uint8_t attrbyte;
330
331 off = wschar->row * scr->type->ncols + wschar->col;
332 if (off >= (scr->type->ncols * scr->type->nrows))
333 return -1;
334
335 attrbyte = wschar->background & 0x07;
336 if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08;
337 attrbyte <<= 4;
338 attrbyte |= wschar->foreground & 0x07;
339 if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08;
340 chardata = (attrbyte << 8) | wschar->letter;
341
342 if (scr->active)
343 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
344 chardata);
345 else
346 scr->mem[off] = chardata;
347
348 return 0;
349 }
350 #endif /* WSDISPLAY_CHARFUNCS */
Cache object: 0fba474d9d0cbfe9d858d34773cd8c69
|