vga.c revision 1.25 1 1.25 ad /* $NetBSD: vga.c,v 1.25 2000/01/25 02:44:03 ad Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 drochner * All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Author: Chris G. Demetriou
8 1.1 drochner *
9 1.1 drochner * Permission to use, copy, modify and distribute this software and
10 1.1 drochner * its documentation is hereby granted, provided that both the copyright
11 1.1 drochner * notice and this permission notice appear in all copies of the
12 1.1 drochner * software, derivative works or modified versions, and any portions
13 1.1 drochner * thereof, and that both notices appear in supporting documentation.
14 1.1 drochner *
15 1.1 drochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 drochner * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 drochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 drochner *
19 1.1 drochner * Carnegie Mellon requests users of this software to return to
20 1.1 drochner *
21 1.1 drochner * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 drochner * School of Computer Science
23 1.1 drochner * Carnegie Mellon University
24 1.1 drochner * Pittsburgh PA 15213-3890
25 1.1 drochner *
26 1.1 drochner * any improvements or extensions that they make and grant Carnegie the
27 1.1 drochner * rights to redistribute these changes.
28 1.1 drochner */
29 1.1 drochner
30 1.1 drochner #include <sys/param.h>
31 1.1 drochner #include <sys/systm.h>
32 1.1 drochner #include <sys/kernel.h>
33 1.1 drochner #include <sys/device.h>
34 1.1 drochner #include <sys/malloc.h>
35 1.1 drochner #include <sys/queue.h>
36 1.1 drochner #include <machine/bus.h>
37 1.1 drochner
38 1.1 drochner #include <dev/isa/isavar.h>
39 1.1 drochner #include <dev/isa/isareg.h>
40 1.1 drochner
41 1.4 drochner #include <dev/ic/mc6845reg.h>
42 1.4 drochner #include <dev/ic/pcdisplayvar.h>
43 1.4 drochner #include <dev/ic/vgareg.h>
44 1.4 drochner #include <dev/ic/vgavar.h>
45 1.4 drochner
46 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
47 1.1 drochner #include <dev/wscons/wsconsio.h>
48 1.14 drochner #include <dev/wscons/unicode.h>
49 1.1 drochner
50 1.3 drochner #include <dev/ic/pcdisplay.h>
51 1.1 drochner
52 1.16 drochner #include "opt_wsdisplay_compat.h" /* for WSCONS_SUPPORT_PCVTFONTS */
53 1.16 drochner
54 1.12 drochner static struct vgafont {
55 1.12 drochner char name[16];
56 1.12 drochner int height;
57 1.12 drochner int encoding;
58 1.12 drochner #ifdef notyet
59 1.12 drochner int firstchar, numchars;
60 1.12 drochner #endif
61 1.12 drochner int slot;
62 1.12 drochner } vga_builtinfont = {
63 1.12 drochner "builtin",
64 1.12 drochner 16,
65 1.12 drochner WSDISPLAY_FONTENC_IBM,
66 1.12 drochner #ifdef notyet
67 1.12 drochner 0, 256,
68 1.12 drochner #endif
69 1.12 drochner 0
70 1.12 drochner };
71 1.12 drochner
72 1.1 drochner struct vgascreen {
73 1.4 drochner struct pcdisplayscreen pcs;
74 1.4 drochner
75 1.1 drochner LIST_ENTRY(vgascreen) next;
76 1.1 drochner
77 1.1 drochner struct vga_config *cfg;
78 1.1 drochner
79 1.1 drochner /* videostate */
80 1.12 drochner struct vgafont *fontset1, *fontset2;
81 1.1 drochner /* font data */
82 1.1 drochner /* palette */
83 1.8 drochner
84 1.8 drochner int mindispoffset, maxdispoffset;
85 1.1 drochner };
86 1.1 drochner
87 1.1 drochner struct vga_config {
88 1.1 drochner struct vga_handle hdl;
89 1.1 drochner
90 1.1 drochner int nscreens;
91 1.1 drochner LIST_HEAD(, vgascreen) screens;
92 1.1 drochner struct vgascreen *active; /* current display */
93 1.11 drochner const struct wsscreen_descr *currenttype;
94 1.12 drochner int currentfontset1, currentfontset2;
95 1.5 drochner
96 1.5 drochner int vc_biosmapped;
97 1.5 drochner bus_space_tag_t vc_biostag;
98 1.5 drochner bus_space_handle_t vc_bioshdl;
99 1.12 drochner
100 1.12 drochner struct vgafont *vc_fonts[8];
101 1.22 drochner
102 1.22 drochner struct vgascreen *wantedscreen;
103 1.22 drochner void (*switchcb) __P((void *, int, int));
104 1.22 drochner void *switchcbarg;
105 1.1 drochner };
106 1.1 drochner
107 1.1 drochner static int vgaconsole, vga_console_type, vga_console_attached;
108 1.1 drochner static struct vgascreen vga_console_screen;
109 1.1 drochner static struct vga_config vga_console_vc;
110 1.1 drochner
111 1.12 drochner int vga_selectfont __P((struct vga_config *, struct vgascreen *,
112 1.12 drochner char *, char *));
113 1.4 drochner void vga_init_screen __P((struct vga_config *, struct vgascreen *,
114 1.4 drochner const struct wsscreen_descr *,
115 1.3 drochner int, long *));
116 1.1 drochner void vga_init __P((struct vga_config *, bus_space_tag_t,
117 1.1 drochner bus_space_tag_t));
118 1.12 drochner static void vga_setfont __P((struct vga_config *, struct vgascreen *));
119 1.1 drochner
120 1.13 drochner static int vga_mapchar __P((void *, int, unsigned int *));
121 1.3 drochner static int vga_alloc_attr __P((void *, int, int, int, long *));
122 1.8 drochner void vga_copyrows __P((void *, int, int, int));
123 1.1 drochner
124 1.1 drochner const struct wsdisplay_emulops vga_emulops = {
125 1.4 drochner pcdisplay_cursor,
126 1.12 drochner vga_mapchar,
127 1.6 drochner pcdisplay_putchar,
128 1.4 drochner pcdisplay_copycols,
129 1.4 drochner pcdisplay_erasecols,
130 1.8 drochner vga_copyrows,
131 1.4 drochner pcdisplay_eraserows,
132 1.3 drochner vga_alloc_attr
133 1.3 drochner };
134 1.3 drochner
135 1.3 drochner /*
136 1.3 drochner * translate WS(=ANSI) color codes to standard pc ones
137 1.3 drochner */
138 1.6 drochner static unsigned char fgansitopc[] = {
139 1.3 drochner #ifdef __alpha__
140 1.3 drochner /*
141 1.3 drochner * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
142 1.3 drochner * XXX We should probably not bother with this
143 1.3 drochner * XXX (reinitialize the palette registers).
144 1.3 drochner */
145 1.3 drochner FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
146 1.3 drochner FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
147 1.3 drochner #else
148 1.3 drochner FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
149 1.3 drochner FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
150 1.3 drochner #endif
151 1.3 drochner }, bgansitopc[] = {
152 1.3 drochner #ifdef __alpha__
153 1.3 drochner BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
154 1.3 drochner BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
155 1.3 drochner #else
156 1.3 drochner BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
157 1.3 drochner BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
158 1.3 drochner #endif
159 1.1 drochner };
160 1.1 drochner
161 1.1 drochner const struct wsscreen_descr vga_stdscreen = {
162 1.1 drochner "80x25", 80, 25,
163 1.1 drochner &vga_emulops,
164 1.3 drochner 8, 16,
165 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
166 1.3 drochner }, vga_stdscreen_mono = {
167 1.3 drochner "80x25", 80, 25,
168 1.3 drochner &vga_emulops,
169 1.3 drochner 8, 16,
170 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
171 1.12 drochner }, vga_stdscreen_bf = {
172 1.12 drochner "80x25bf", 80, 25,
173 1.12 drochner &vga_emulops,
174 1.12 drochner 8, 16,
175 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
176 1.17 drochner }, vga_40lscreen = {
177 1.17 drochner "80x40", 80, 40,
178 1.17 drochner &vga_emulops,
179 1.17 drochner 8, 10,
180 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
181 1.17 drochner }, vga_40lscreen_mono = {
182 1.17 drochner "80x40", 80, 40,
183 1.17 drochner &vga_emulops,
184 1.17 drochner 8, 10,
185 1.17 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
186 1.17 drochner }, vga_40lscreen_bf = {
187 1.17 drochner "80x40bf", 80, 40,
188 1.17 drochner &vga_emulops,
189 1.17 drochner 8, 10,
190 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
191 1.12 drochner }, vga_50lscreen = {
192 1.1 drochner "80x50", 80, 50,
193 1.1 drochner &vga_emulops,
194 1.3 drochner 8, 8,
195 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
196 1.3 drochner }, vga_50lscreen_mono = {
197 1.3 drochner "80x50", 80, 50,
198 1.3 drochner &vga_emulops,
199 1.3 drochner 8, 8,
200 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
201 1.12 drochner }, vga_50lscreen_bf = {
202 1.12 drochner "80x50bf", 80, 50,
203 1.12 drochner &vga_emulops,
204 1.12 drochner 8, 8,
205 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
206 1.1 drochner };
207 1.1 drochner
208 1.12 drochner #define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
209 1.12 drochner
210 1.2 drochner const struct wsscreen_descr *_vga_scrlist[] = {
211 1.1 drochner &vga_stdscreen,
212 1.12 drochner &vga_stdscreen_bf,
213 1.17 drochner &vga_40lscreen,
214 1.17 drochner &vga_40lscreen_bf,
215 1.1 drochner &vga_50lscreen,
216 1.12 drochner &vga_50lscreen_bf,
217 1.1 drochner /* XXX other formats, graphics screen? */
218 1.3 drochner }, *_vga_scrlist_mono[] = {
219 1.3 drochner &vga_stdscreen_mono,
220 1.17 drochner &vga_40lscreen_mono,
221 1.3 drochner &vga_50lscreen_mono,
222 1.3 drochner /* XXX other formats, graphics screen? */
223 1.1 drochner };
224 1.1 drochner
225 1.3 drochner const struct wsscreen_list vga_screenlist = {
226 1.3 drochner sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
227 1.3 drochner _vga_scrlist
228 1.3 drochner }, vga_screenlist_mono = {
229 1.3 drochner sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
230 1.3 drochner _vga_scrlist_mono
231 1.1 drochner };
232 1.1 drochner
233 1.1 drochner static int vga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
234 1.1 drochner static int vga_mmap __P((void *, off_t, int));
235 1.1 drochner static int vga_alloc_screen __P((void *, const struct wsscreen_descr *,
236 1.3 drochner void **, int *, int *, long *));
237 1.1 drochner static void vga_free_screen __P((void *, void *));
238 1.22 drochner static int vga_show_screen __P((void *, void *, int,
239 1.22 drochner void (*) (void *, int, int), void *));
240 1.12 drochner static int vga_load_font __P((void *, void *, struct wsdisplay_font *));
241 1.1 drochner
242 1.22 drochner void vga_doswitch __P((struct vga_config *));
243 1.22 drochner
244 1.1 drochner const struct wsdisplay_accessops vga_accessops = {
245 1.1 drochner vga_ioctl,
246 1.1 drochner vga_mmap,
247 1.1 drochner vga_alloc_screen,
248 1.1 drochner vga_free_screen,
249 1.1 drochner vga_show_screen,
250 1.1 drochner vga_load_font
251 1.1 drochner };
252 1.1 drochner
253 1.1 drochner /*
254 1.1 drochner * The following functions implement back-end configuration grabbing
255 1.1 drochner * and attachment.
256 1.1 drochner */
257 1.1 drochner int
258 1.1 drochner vga_common_probe(iot, memt)
259 1.1 drochner bus_space_tag_t iot, memt;
260 1.1 drochner {
261 1.1 drochner bus_space_handle_t ioh_vga, ioh_6845, memh;
262 1.4 drochner u_int8_t regval;
263 1.1 drochner u_int16_t vgadata;
264 1.1 drochner int gotio_vga, gotio_6845, gotmem, mono, rv;
265 1.1 drochner int dispoffset;
266 1.1 drochner
267 1.1 drochner gotio_vga = gotio_6845 = gotmem = rv = 0;
268 1.1 drochner
269 1.1 drochner if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
270 1.1 drochner goto bad;
271 1.1 drochner gotio_vga = 1;
272 1.1 drochner
273 1.1 drochner /* read "misc output register" */
274 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, 0xc);
275 1.4 drochner mono = !(regval & 1);
276 1.1 drochner
277 1.1 drochner if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
278 1.1 drochner goto bad;
279 1.1 drochner gotio_6845 = 1;
280 1.1 drochner
281 1.1 drochner if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
282 1.1 drochner goto bad;
283 1.1 drochner gotmem = 1;
284 1.1 drochner
285 1.1 drochner dispoffset = (mono ? 0x10000 : 0x18000);
286 1.1 drochner
287 1.1 drochner vgadata = bus_space_read_2(memt, memh, dispoffset);
288 1.1 drochner bus_space_write_2(memt, memh, dispoffset, 0xa55a);
289 1.4 drochner if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
290 1.4 drochner goto bad;
291 1.1 drochner bus_space_write_2(memt, memh, dispoffset, vgadata);
292 1.1 drochner
293 1.4 drochner /*
294 1.4 drochner * check if this is really a VGA
295 1.4 drochner * (try to write "Color Select" register as XFree86 does)
296 1.4 drochner * XXX check before if at least EGA?
297 1.4 drochner */
298 1.4 drochner /* reset state */
299 1.4 drochner (void) bus_space_read_1(iot, ioh_6845, 10);
300 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
301 1.4 drochner 20 | 0x20); /* colselect | enable */
302 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
303 1.4 drochner /* toggle the implemented bits */
304 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
305 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
306 1.4 drochner 20 | 0x20);
307 1.4 drochner /* read back */
308 1.4 drochner if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
309 1.4 drochner goto bad;
310 1.4 drochner /* restore contents */
311 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
312 1.4 drochner
313 1.4 drochner rv = 1;
314 1.1 drochner bad:
315 1.1 drochner if (gotio_vga)
316 1.1 drochner bus_space_unmap(iot, ioh_vga, 0x10);
317 1.1 drochner if (gotio_6845)
318 1.1 drochner bus_space_unmap(iot, ioh_6845, 0x10);
319 1.1 drochner if (gotmem)
320 1.1 drochner bus_space_unmap(memt, memh, 0x20000);
321 1.1 drochner
322 1.1 drochner return (rv);
323 1.1 drochner }
324 1.1 drochner
325 1.12 drochner /*
326 1.15 drochner * We want at least ASCII 32..127 be present in the
327 1.15 drochner * first font slot.
328 1.12 drochner */
329 1.12 drochner #define vga_valid_primary_font(f) \
330 1.12 drochner (f->encoding == WSDISPLAY_FONTENC_IBM || \
331 1.12 drochner f->encoding == WSDISPLAY_FONTENC_ISO)
332 1.12 drochner
333 1.12 drochner int
334 1.12 drochner vga_selectfont(vc, scr, name1, name2)
335 1.12 drochner struct vga_config *vc;
336 1.12 drochner struct vgascreen *scr;
337 1.15 drochner char *name1, *name2; /* NULL: take first found */
338 1.12 drochner {
339 1.12 drochner const struct wsscreen_descr *type = scr->pcs.type;
340 1.12 drochner struct vgafont *f1, *f2;
341 1.12 drochner int i;
342 1.12 drochner
343 1.12 drochner f1 = f2 = 0;
344 1.12 drochner
345 1.12 drochner for (i = 0; i < 8; i++) {
346 1.12 drochner struct vgafont *f = vc->vc_fonts[i];
347 1.12 drochner if (!f || f->height != type->fontheight)
348 1.12 drochner continue;
349 1.12 drochner if (!f1 &&
350 1.12 drochner vga_valid_primary_font(f) &&
351 1.12 drochner (!name1 || !strcmp(name1, f->name))) {
352 1.12 drochner f1 = f;
353 1.12 drochner continue;
354 1.12 drochner }
355 1.12 drochner if (!f2 &&
356 1.12 drochner VGA_SCREEN_CANTWOFONTS(type) &&
357 1.12 drochner (!name2 || !strcmp(name2, f->name))) {
358 1.12 drochner f2 = f;
359 1.12 drochner continue;
360 1.12 drochner }
361 1.12 drochner }
362 1.12 drochner
363 1.15 drochner /*
364 1.15 drochner * The request fails if no primary font was found,
365 1.15 drochner * or if a second font was requested but not found.
366 1.15 drochner */
367 1.12 drochner if (f1 && (!name2 || f2)) {
368 1.12 drochner #ifdef VGAFONTDEBUG
369 1.12 drochner if (scr != &vga_console_screen || vga_console_attached) {
370 1.12 drochner printf("vga (%s): font1=%s (slot %d)", type->name,
371 1.12 drochner f1->name, f1->slot);
372 1.12 drochner if (f2)
373 1.12 drochner printf(", font2=%s (slot %d)",
374 1.12 drochner f2->name, f2->slot);
375 1.12 drochner printf("\n");
376 1.12 drochner }
377 1.12 drochner #endif
378 1.12 drochner scr->fontset1 = f1;
379 1.12 drochner scr->fontset2 = f2;
380 1.12 drochner return (0);
381 1.12 drochner }
382 1.12 drochner return (ENXIO);
383 1.12 drochner }
384 1.12 drochner
385 1.1 drochner void
386 1.4 drochner vga_init_screen(vc, scr, type, existing, attrp)
387 1.4 drochner struct vga_config *vc;
388 1.1 drochner struct vgascreen *scr;
389 1.1 drochner const struct wsscreen_descr *type;
390 1.1 drochner int existing;
391 1.3 drochner long *attrp;
392 1.1 drochner {
393 1.8 drochner int cpos;
394 1.3 drochner int res;
395 1.1 drochner
396 1.4 drochner scr->cfg = vc;
397 1.4 drochner scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
398 1.4 drochner scr->pcs.type = type;
399 1.4 drochner scr->pcs.active = 0;
400 1.8 drochner scr->mindispoffset = 0;
401 1.8 drochner scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
402 1.1 drochner
403 1.1 drochner if (existing) {
404 1.1 drochner cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
405 1.1 drochner cpos |= vga_6845_read(&vc->hdl, cursorl);
406 1.1 drochner
407 1.1 drochner /* make sure we have a valid cursor position */
408 1.1 drochner if (cpos < 0 || cpos >= type->nrows * type->ncols)
409 1.1 drochner cpos = 0;
410 1.8 drochner
411 1.8 drochner scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
412 1.8 drochner scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
413 1.8 drochner
414 1.8 drochner /* make sure we have a valid memory offset */
415 1.8 drochner if (scr->pcs.dispoffset < scr->mindispoffset ||
416 1.8 drochner scr->pcs.dispoffset > scr->maxdispoffset)
417 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
418 1.8 drochner } else {
419 1.8 drochner cpos = 0;
420 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
421 1.1 drochner }
422 1.1 drochner
423 1.4 drochner scr->pcs.vc_crow = cpos / type->ncols;
424 1.4 drochner scr->pcs.vc_ccol = cpos % type->ncols;
425 1.25 ad pcdisplay_cursor_init(&scr->pcs, existing);
426 1.1 drochner
427 1.1 drochner #ifdef __alpha__
428 1.4 drochner if (!vc->hdl.vh_mono)
429 1.3 drochner /*
430 1.3 drochner * DEC firmware uses a blue background.
431 1.3 drochner */
432 1.3 drochner res = vga_alloc_attr(scr, WSCOL_WHITE, WSCOL_BLUE,
433 1.3 drochner WSATTR_WSCOLORS, attrp);
434 1.3 drochner else
435 1.3 drochner #endif
436 1.3 drochner res = vga_alloc_attr(scr, 0, 0, 0, attrp);
437 1.3 drochner #ifdef DIAGNOSTIC
438 1.3 drochner if (res)
439 1.3 drochner panic("vga_init_screen: attribute botch");
440 1.1 drochner #endif
441 1.1 drochner
442 1.4 drochner scr->pcs.mem = NULL;
443 1.15 drochner
444 1.15 drochner scr->fontset1 = scr->fontset2 = 0;
445 1.12 drochner if (vga_selectfont(vc, scr, 0, 0)) {
446 1.12 drochner if (scr == &vga_console_screen)
447 1.12 drochner panic("vga_init_screen: no font");
448 1.12 drochner else
449 1.12 drochner printf("vga_init_screen: no font\n");
450 1.12 drochner }
451 1.15 drochner
452 1.1 drochner vc->nscreens++;
453 1.1 drochner LIST_INSERT_HEAD(&vc->screens, scr, next);
454 1.1 drochner }
455 1.1 drochner
456 1.1 drochner void
457 1.1 drochner vga_init(vc, iot, memt)
458 1.1 drochner struct vga_config *vc;
459 1.1 drochner bus_space_tag_t iot, memt;
460 1.1 drochner {
461 1.1 drochner struct vga_handle *vh = &vc->hdl;
462 1.1 drochner u_int8_t mor;
463 1.12 drochner int i;
464 1.1 drochner
465 1.1 drochner vh->vh_iot = iot;
466 1.1 drochner vh->vh_memt = memt;
467 1.1 drochner
468 1.1 drochner if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
469 1.1 drochner panic("vga_common_setup: couldn't map vga io");
470 1.1 drochner
471 1.1 drochner /* read "misc output register" */
472 1.1 drochner mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
473 1.4 drochner vh->vh_mono = !(mor & 1);
474 1.1 drochner
475 1.4 drochner if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
476 1.1 drochner &vh->vh_ioh_6845))
477 1.1 drochner panic("vga_common_setup: couldn't map 6845 io");
478 1.1 drochner
479 1.1 drochner if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
480 1.1 drochner panic("vga_common_setup: couldn't map memory");
481 1.1 drochner
482 1.1 drochner if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
483 1.4 drochner (vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
484 1.1 drochner &vh->vh_memh))
485 1.1 drochner panic("vga_common_setup: mem subrange failed");
486 1.5 drochner
487 1.5 drochner /* should only reserve the space (no need to map - save KVM) */
488 1.5 drochner vc->vc_biostag = memt;
489 1.5 drochner if (bus_space_map(vc->vc_biostag, 0xc0000, 0x8000, 0,
490 1.5 drochner &vc->vc_bioshdl))
491 1.5 drochner vc->vc_biosmapped = 0;
492 1.5 drochner else
493 1.5 drochner vc->vc_biosmapped = 1;
494 1.1 drochner
495 1.1 drochner vc->nscreens = 0;
496 1.1 drochner LIST_INIT(&vc->screens);
497 1.1 drochner vc->active = NULL;
498 1.11 drochner vc->currenttype = vh->vh_mono ? &vga_stdscreen_mono : &vga_stdscreen;
499 1.12 drochner
500 1.12 drochner vc->vc_fonts[0] = &vga_builtinfont;
501 1.23 drochner for (i = 1; i < 8; i++)
502 1.12 drochner vc->vc_fonts[i] = 0;
503 1.12 drochner
504 1.12 drochner vc->currentfontset1 = vc->currentfontset2 = 0;
505 1.1 drochner }
506 1.1 drochner
507 1.1 drochner void
508 1.1 drochner vga_common_attach(self, iot, memt, type)
509 1.1 drochner struct device *self;
510 1.1 drochner bus_space_tag_t iot, memt;
511 1.1 drochner int type;
512 1.1 drochner {
513 1.1 drochner int console;
514 1.1 drochner struct vga_config *vc;
515 1.1 drochner struct wsemuldisplaydev_attach_args aa;
516 1.1 drochner
517 1.1 drochner console = vga_is_console(iot, type);
518 1.1 drochner
519 1.1 drochner if (console) {
520 1.1 drochner vc = &vga_console_vc;
521 1.1 drochner vga_console_attached = 1;
522 1.1 drochner } else {
523 1.1 drochner vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
524 1.1 drochner vga_init(vc, iot, memt);
525 1.1 drochner }
526 1.1 drochner
527 1.1 drochner aa.console = console;
528 1.4 drochner aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
529 1.1 drochner aa.accessops = &vga_accessops;
530 1.1 drochner aa.accesscookie = vc;
531 1.1 drochner
532 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
533 1.1 drochner }
534 1.1 drochner
535 1.1 drochner int
536 1.1 drochner vga_cnattach(iot, memt, type, check)
537 1.1 drochner bus_space_tag_t iot, memt;
538 1.1 drochner int type, check;
539 1.1 drochner {
540 1.3 drochner long defattr;
541 1.3 drochner const struct wsscreen_descr *scr;
542 1.3 drochner
543 1.1 drochner if (check && !vga_common_probe(iot, memt))
544 1.1 drochner return (ENXIO);
545 1.1 drochner
546 1.1 drochner /* set up bus-independent VGA configuration */
547 1.1 drochner vga_init(&vga_console_vc, iot, memt);
548 1.11 drochner scr = vga_console_vc.currenttype;
549 1.4 drochner vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
550 1.1 drochner
551 1.4 drochner vga_console_screen.pcs.active = 1;
552 1.1 drochner vga_console_vc.active = &vga_console_screen;
553 1.1 drochner
554 1.3 drochner wsdisplay_cnattach(scr, &vga_console_screen,
555 1.4 drochner vga_console_screen.pcs.vc_ccol,
556 1.4 drochner vga_console_screen.pcs.vc_crow,
557 1.3 drochner defattr);
558 1.1 drochner
559 1.1 drochner vgaconsole = 1;
560 1.1 drochner vga_console_type = type;
561 1.1 drochner return (0);
562 1.1 drochner }
563 1.1 drochner
564 1.1 drochner int
565 1.1 drochner vga_is_console(iot, type)
566 1.1 drochner bus_space_tag_t iot;
567 1.1 drochner int type;
568 1.1 drochner {
569 1.1 drochner if (vgaconsole &&
570 1.1 drochner !vga_console_attached &&
571 1.1 drochner iot == vga_console_vc.hdl.vh_iot &&
572 1.1 drochner (vga_console_type == -1 || (type == vga_console_type)))
573 1.1 drochner return (1);
574 1.1 drochner return (0);
575 1.1 drochner }
576 1.1 drochner
577 1.1 drochner int
578 1.1 drochner vga_ioctl(v, cmd, data, flag, p)
579 1.1 drochner void *v;
580 1.1 drochner u_long cmd;
581 1.1 drochner caddr_t data;
582 1.1 drochner int flag;
583 1.1 drochner struct proc *p;
584 1.1 drochner {
585 1.1 drochner #if 0
586 1.1 drochner struct vga_config *vc = v;
587 1.1 drochner #endif
588 1.1 drochner
589 1.1 drochner switch (cmd) {
590 1.1 drochner #if 0
591 1.1 drochner case WSDISPLAYIO_GTYPE:
592 1.1 drochner *(int *)data = vc->vc_type;
593 1.1 drochner /* XXX should get detailed hardware information here */
594 1.10 augustss return 0;
595 1.10 augustss #else
596 1.10 augustss case WSDISPLAYIO_GTYPE:
597 1.10 augustss *(int *)data = WSDISPLAY_TYPE_UNKNOWN;
598 1.1 drochner return 0;
599 1.1 drochner #endif
600 1.12 drochner
601 1.1 drochner case WSDISPLAYIO_GINFO:
602 1.1 drochner case WSDISPLAYIO_GETCMAP:
603 1.1 drochner case WSDISPLAYIO_PUTCMAP:
604 1.1 drochner case WSDISPLAYIO_GVIDEO:
605 1.1 drochner case WSDISPLAYIO_SVIDEO:
606 1.1 drochner case WSDISPLAYIO_GCURPOS:
607 1.1 drochner case WSDISPLAYIO_SCURPOS:
608 1.1 drochner case WSDISPLAYIO_GCURMAX:
609 1.1 drochner case WSDISPLAYIO_GCURSOR:
610 1.1 drochner case WSDISPLAYIO_SCURSOR:
611 1.1 drochner /* NONE of these operations are by the generic VGA driver. */
612 1.1 drochner return ENOTTY;
613 1.1 drochner }
614 1.12 drochner
615 1.1 drochner return -1;
616 1.1 drochner }
617 1.1 drochner
618 1.1 drochner static int
619 1.1 drochner vga_mmap(v, offset, prot)
620 1.1 drochner void *v;
621 1.1 drochner off_t offset;
622 1.1 drochner int prot;
623 1.1 drochner {
624 1.1 drochner
625 1.1 drochner /* XXX */
626 1.1 drochner return -1;
627 1.1 drochner }
628 1.1 drochner
629 1.1 drochner int
630 1.3 drochner vga_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
631 1.1 drochner void *v;
632 1.1 drochner const struct wsscreen_descr *type;
633 1.1 drochner void **cookiep;
634 1.1 drochner int *curxp, *curyp;
635 1.3 drochner long *defattrp;
636 1.1 drochner {
637 1.1 drochner struct vga_config *vc = v;
638 1.1 drochner struct vgascreen *scr;
639 1.1 drochner
640 1.1 drochner if (vc->nscreens == 1) {
641 1.1 drochner /*
642 1.1 drochner * When allocating the second screen, get backing store
643 1.1 drochner * for the first one too.
644 1.1 drochner * XXX We could be more clever and use video RAM.
645 1.1 drochner */
646 1.4 drochner vc->screens.lh_first->pcs.mem =
647 1.1 drochner malloc(type->ncols * type->nrows * 2, M_DEVBUF, M_WAITOK);
648 1.1 drochner }
649 1.1 drochner
650 1.1 drochner scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
651 1.4 drochner vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
652 1.1 drochner
653 1.4 drochner if (vc->nscreens == 1) {
654 1.4 drochner scr->pcs.active = 1;
655 1.1 drochner vc->active = scr;
656 1.11 drochner vc->currenttype = type;
657 1.4 drochner } else {
658 1.4 drochner scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
659 1.4 drochner M_DEVBUF, M_WAITOK);
660 1.4 drochner pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
661 1.1 drochner }
662 1.1 drochner
663 1.1 drochner *cookiep = scr;
664 1.4 drochner *curxp = scr->pcs.vc_ccol;
665 1.4 drochner *curyp = scr->pcs.vc_crow;
666 1.1 drochner
667 1.1 drochner return (0);
668 1.1 drochner }
669 1.1 drochner
670 1.1 drochner void
671 1.1 drochner vga_free_screen(v, cookie)
672 1.1 drochner void *v;
673 1.1 drochner void *cookie;
674 1.1 drochner {
675 1.1 drochner struct vgascreen *vs = cookie;
676 1.11 drochner struct vga_config *vc = vs->cfg;
677 1.1 drochner
678 1.1 drochner LIST_REMOVE(vs, next);
679 1.1 drochner if (vs != &vga_console_screen)
680 1.1 drochner free(vs, M_DEVBUF);
681 1.1 drochner else
682 1.1 drochner panic("vga_free_screen: console");
683 1.11 drochner
684 1.11 drochner if (vc->active == vs)
685 1.11 drochner vc->active = 0;
686 1.1 drochner }
687 1.1 drochner
688 1.12 drochner static void
689 1.12 drochner vga_setfont(vc, scr)
690 1.12 drochner struct vga_config *vc;
691 1.12 drochner struct vgascreen *scr;
692 1.12 drochner {
693 1.12 drochner int fontslot1, fontslot2;
694 1.12 drochner
695 1.12 drochner fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
696 1.12 drochner fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
697 1.12 drochner if (vc->currentfontset1 != fontslot1 ||
698 1.12 drochner vc->currentfontset2 != fontslot2) {
699 1.12 drochner vga_setfontset(&vc->hdl, fontslot1, fontslot2);
700 1.12 drochner vc->currentfontset1 = fontslot1;
701 1.12 drochner vc->currentfontset2 = fontslot2;
702 1.12 drochner }
703 1.12 drochner }
704 1.12 drochner
705 1.22 drochner int
706 1.22 drochner vga_show_screen(v, cookie, waitok, cb, cbarg)
707 1.1 drochner void *v;
708 1.1 drochner void *cookie;
709 1.22 drochner int waitok;
710 1.22 drochner void (*cb) __P((void *, int, int));
711 1.22 drochner void *cbarg;
712 1.1 drochner {
713 1.4 drochner struct vgascreen *scr = cookie, *oldscr;
714 1.1 drochner struct vga_config *vc = scr->cfg;
715 1.22 drochner
716 1.22 drochner oldscr = vc->active; /* can be NULL! */
717 1.22 drochner if (scr == oldscr) {
718 1.22 drochner return (0);
719 1.22 drochner }
720 1.22 drochner
721 1.22 drochner vc->wantedscreen = cookie;
722 1.22 drochner vc->switchcb = cb;
723 1.22 drochner vc->switchcbarg = cbarg;
724 1.22 drochner if (cb) {
725 1.22 drochner timeout((void(*)(void *))vga_doswitch, vc, 0);
726 1.22 drochner return (EAGAIN);
727 1.22 drochner }
728 1.22 drochner
729 1.22 drochner vga_doswitch(vc);
730 1.22 drochner return (0);
731 1.22 drochner }
732 1.22 drochner
733 1.22 drochner void
734 1.22 drochner vga_doswitch(vc)
735 1.22 drochner struct vga_config *vc;
736 1.22 drochner {
737 1.22 drochner struct vgascreen *scr, *oldscr;
738 1.1 drochner struct vga_handle *vh = &vc->hdl;
739 1.22 drochner const struct wsscreen_descr *type;
740 1.1 drochner
741 1.22 drochner scr = vc->wantedscreen;
742 1.22 drochner if (!scr) {
743 1.22 drochner printf("vga_doswitch: disappeared\n");
744 1.22 drochner (*vc->switchcb)(vc->switchcbarg, EIO, 0);
745 1.22 drochner return;
746 1.22 drochner }
747 1.22 drochner type = scr->pcs.type;
748 1.11 drochner oldscr = vc->active; /* can be NULL! */
749 1.4 drochner #ifdef DIAGNOSTIC
750 1.11 drochner if (oldscr) {
751 1.11 drochner if (!oldscr->pcs.active)
752 1.11 drochner panic("vga_show_screen: not active");
753 1.11 drochner if (oldscr->pcs.type != vc->currenttype)
754 1.11 drochner panic("vga_show_screen: bad type");
755 1.11 drochner }
756 1.4 drochner #endif
757 1.4 drochner if (scr == oldscr) {
758 1.1 drochner return;
759 1.4 drochner }
760 1.4 drochner #ifdef DIAGNOSTIC
761 1.4 drochner if (scr->pcs.active)
762 1.4 drochner panic("vga_show_screen: active");
763 1.4 drochner #endif
764 1.4 drochner
765 1.11 drochner if (oldscr) {
766 1.11 drochner const struct wsscreen_descr *oldtype = oldscr->pcs.type;
767 1.1 drochner
768 1.11 drochner oldscr->pcs.active = 0;
769 1.11 drochner bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
770 1.11 drochner oldscr->pcs.dispoffset, oldscr->pcs.mem,
771 1.11 drochner oldtype->ncols * oldtype->nrows);
772 1.11 drochner }
773 1.1 drochner
774 1.11 drochner if (vc->currenttype != type) {
775 1.4 drochner vga_setscreentype(vh, type);
776 1.11 drochner vc->currenttype = type;
777 1.11 drochner }
778 1.12 drochner
779 1.12 drochner vga_setfont(vc, scr);
780 1.11 drochner /* XXX swich colours! */
781 1.1 drochner
782 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
783 1.11 drochner if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
784 1.8 drochner vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
785 1.8 drochner vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
786 1.8 drochner }
787 1.8 drochner
788 1.11 drochner bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
789 1.11 drochner scr->pcs.dispoffset, scr->pcs.mem,
790 1.11 drochner type->ncols * type->nrows);
791 1.11 drochner scr->pcs.active = 1;
792 1.1 drochner
793 1.4 drochner vc->active = scr;
794 1.1 drochner
795 1.4 drochner pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
796 1.4 drochner scr->pcs.vc_crow, scr->pcs.vc_ccol);
797 1.22 drochner
798 1.22 drochner vc->wantedscreen = 0;
799 1.22 drochner if (vc->switchcb)
800 1.22 drochner (*vc->switchcb)(vc->switchcbarg, 0, 0);
801 1.1 drochner }
802 1.1 drochner
803 1.1 drochner static int
804 1.12 drochner vga_load_font(v, cookie, data)
805 1.1 drochner void *v;
806 1.1 drochner void *cookie;
807 1.12 drochner struct wsdisplay_font *data;
808 1.1 drochner {
809 1.12 drochner struct vga_config *vc = v;
810 1.1 drochner struct vgascreen *scr = cookie;
811 1.12 drochner char *name2;
812 1.12 drochner int res, slot;
813 1.12 drochner struct vgafont *f;
814 1.12 drochner
815 1.12 drochner if (scr) {
816 1.12 drochner name2 = strchr(data->name, ',');
817 1.12 drochner if (name2)
818 1.12 drochner *name2++ = '\0';
819 1.12 drochner res = vga_selectfont(vc, scr, data->name, name2);
820 1.12 drochner if (!res)
821 1.12 drochner vga_setfont(vc, scr);
822 1.12 drochner return (res);
823 1.12 drochner }
824 1.1 drochner
825 1.12 drochner if (data->fontwidth != 8 || data->stride != 1)
826 1.1 drochner return (EINVAL); /* XXX 1 byte per line */
827 1.12 drochner if (data->firstchar != 0 || data->numchars != 256)
828 1.12 drochner return (EINVAL);
829 1.16 drochner #ifndef WSCONS_SUPPORT_PCVTFONTS
830 1.16 drochner if (data->encoding == WSDISPLAY_FONTENC_PCVT) {
831 1.16 drochner printf("vga: pcvt font support not built in, see vga(4)\n");
832 1.16 drochner return (EINVAL);
833 1.16 drochner }
834 1.16 drochner #endif
835 1.12 drochner
836 1.12 drochner for (slot = 0; slot < 8; slot++)
837 1.12 drochner if (!vc->vc_fonts[slot])
838 1.12 drochner break;
839 1.12 drochner if (slot == 8)
840 1.12 drochner return (ENOSPC);
841 1.12 drochner
842 1.12 drochner f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK);
843 1.12 drochner strncpy(f->name, data->name, sizeof(f->name));
844 1.12 drochner f->height = data->fontheight;
845 1.12 drochner f->encoding = data->encoding;
846 1.12 drochner #ifdef notyet
847 1.12 drochner f->firstchar = data->firstchar;
848 1.12 drochner f->numchars = data->numchars;
849 1.12 drochner #endif
850 1.12 drochner #ifdef VGAFONTDEBUG
851 1.12 drochner printf("vga: load %s (8x%d, enc %d) font to slot %d\n", f->name,
852 1.12 drochner f->height, f->encoding, slot);
853 1.12 drochner #endif
854 1.12 drochner vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data);
855 1.12 drochner f->slot = slot;
856 1.12 drochner vc->vc_fonts[slot] = f;
857 1.1 drochner
858 1.1 drochner return (0);
859 1.1 drochner }
860 1.1 drochner
861 1.3 drochner static int
862 1.3 drochner vga_alloc_attr(id, fg, bg, flags, attrp)
863 1.3 drochner void *id;
864 1.3 drochner int fg, bg;
865 1.3 drochner int flags;
866 1.3 drochner long *attrp;
867 1.3 drochner {
868 1.3 drochner struct vgascreen *scr = id;
869 1.3 drochner struct vga_config *vc = scr->cfg;
870 1.3 drochner
871 1.4 drochner if (vc->hdl.vh_mono) {
872 1.3 drochner if (flags & WSATTR_WSCOLORS)
873 1.3 drochner return (EINVAL);
874 1.3 drochner if (flags & WSATTR_REVERSE)
875 1.3 drochner *attrp = 0x70;
876 1.3 drochner else
877 1.3 drochner *attrp = 0x07;
878 1.3 drochner if (flags & WSATTR_UNDERLINE)
879 1.3 drochner *attrp |= FG_UNDERLINE;
880 1.3 drochner if (flags & WSATTR_HILIT)
881 1.3 drochner *attrp |= FG_INTENSE;
882 1.3 drochner } else {
883 1.3 drochner if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
884 1.3 drochner return (EINVAL);
885 1.3 drochner if (flags & WSATTR_WSCOLORS)
886 1.3 drochner *attrp = fgansitopc[fg] | bgansitopc[bg];
887 1.3 drochner else
888 1.3 drochner *attrp = 7;
889 1.3 drochner if (flags & WSATTR_HILIT)
890 1.3 drochner *attrp += 8;
891 1.3 drochner }
892 1.3 drochner if (flags & WSATTR_BLINK)
893 1.3 drochner *attrp |= FG_BLINK;
894 1.3 drochner return (0);
895 1.8 drochner }
896 1.8 drochner
897 1.8 drochner void
898 1.8 drochner vga_copyrows(id, srcrow, dstrow, nrows)
899 1.8 drochner void *id;
900 1.8 drochner int srcrow, dstrow, nrows;
901 1.8 drochner {
902 1.8 drochner struct vgascreen *scr = id;
903 1.8 drochner bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
904 1.8 drochner bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
905 1.8 drochner int ncols = scr->pcs.type->ncols;
906 1.8 drochner bus_size_t srcoff, dstoff;
907 1.8 drochner
908 1.8 drochner srcoff = srcrow * ncols + 0;
909 1.8 drochner dstoff = dstrow * ncols + 0;
910 1.8 drochner
911 1.8 drochner if (scr->pcs.active) {
912 1.8 drochner if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
913 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
914 1.20 ad int cursoron = scr->pcs.cursoron;
915 1.20 ad
916 1.21 mycroft if (cursoron)
917 1.21 mycroft pcdisplay_cursor(&scr->pcs, 0,
918 1.21 mycroft scr->pcs.vc_crow, scr->pcs.vc_ccol);
919 1.18 ad #endif
920 1.8 drochner /* scroll up whole screen */
921 1.8 drochner if ((scr->pcs.dispoffset + srcrow * ncols * 2)
922 1.8 drochner <= scr->maxdispoffset) {
923 1.8 drochner scr->pcs.dispoffset += srcrow * ncols * 2;
924 1.8 drochner } else {
925 1.8 drochner bus_space_copy_region_2(memt, memh,
926 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
927 1.8 drochner memh, scr->mindispoffset,
928 1.8 drochner nrows * ncols);
929 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
930 1.8 drochner }
931 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrh,
932 1.8 drochner scr->pcs.dispoffset >> 9);
933 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrl,
934 1.8 drochner scr->pcs.dispoffset >> 1);
935 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
936 1.21 mycroft if (cursoron)
937 1.21 mycroft pcdisplay_cursor(&scr->pcs, 1,
938 1.21 mycroft scr->pcs.vc_crow, scr->pcs.vc_ccol);
939 1.18 ad #endif
940 1.8 drochner } else {
941 1.8 drochner bus_space_copy_region_2(memt, memh,
942 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
943 1.8 drochner memh, scr->pcs.dispoffset + dstoff * 2,
944 1.8 drochner nrows * ncols);
945 1.8 drochner }
946 1.8 drochner } else
947 1.8 drochner bcopy(&scr->pcs.mem[srcoff], &scr->pcs.mem[dstoff],
948 1.8 drochner nrows * ncols * 2);
949 1.12 drochner }
950 1.12 drochner
951 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
952 1.12 drochner
953 1.12 drochner #define NOTYET 0xffff
954 1.12 drochner static u_int16_t pcvt_unichars[0xa0] = {
955 1.14 drochner /* 0 */ _e006U,
956 1.14 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
957 1.12 drochner NOTYET,
958 1.12 drochner 0x2409, /* SYMBOL FOR HORIZONTAL TABULATION */
959 1.12 drochner 0x240a, /* SYMBOL FOR LINE FEED */
960 1.12 drochner 0x240b, /* SYMBOL FOR VERTICAL TABULATION */
961 1.12 drochner 0x240c, /* SYMBOL FOR FORM FEED */
962 1.12 drochner 0x240d, /* SYMBOL FOR CARRIAGE RETURN */
963 1.12 drochner NOTYET, NOTYET,
964 1.14 drochner /* 1 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
965 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
966 1.12 drochner /* 2 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
967 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
968 1.14 drochner /* 3 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
969 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
970 1.12 drochner /* 4 */ 0x03c1, /* GREEK SMALL LETTER RHO */
971 1.12 drochner 0x03c8, /* GREEK SMALL LETTER PSI */
972 1.12 drochner 0x2202, /* PARTIAL DIFFERENTIAL */
973 1.12 drochner 0x03bb, /* GREEK SMALL LETTER LAMDA */
974 1.12 drochner 0x03b9, /* GREEK SMALL LETTER IOTA */
975 1.12 drochner 0x03b7, /* GREEK SMALL LETTER ETA */
976 1.12 drochner 0x03b5, /* GREEK SMALL LETTER EPSILON */
977 1.12 drochner 0x03c7, /* GREEK SMALL LETTER CHI */
978 1.12 drochner 0x2228, /* LOGICAL OR */
979 1.12 drochner 0x2227, /* LOGICAL AND */
980 1.12 drochner 0x222a, /* UNION */
981 1.12 drochner 0x2283, /* SUPERSET OF */
982 1.12 drochner 0x2282, /* SUBSET OF */
983 1.12 drochner 0x03a5, /* GREEK CAPITAL LETTER UPSILON */
984 1.12 drochner 0x039e, /* GREEK CAPITAL LETTER XI */
985 1.12 drochner 0x03a8, /* GREEK CAPITAL LETTER PSI */
986 1.14 drochner /* 5 */ 0x03a0, /* GREEK CAPITAL LETTER PI */
987 1.12 drochner 0x21d2, /* RIGHTWARDS DOUBLE ARROW */
988 1.12 drochner 0x21d4, /* LEFT RIGHT DOUBLE ARROW */
989 1.12 drochner 0x039b, /* GREEK CAPITAL LETTER LAMDA */
990 1.12 drochner 0x0398, /* GREEK CAPITAL LETTER THETA */
991 1.12 drochner 0x2243, /* ASYMPTOTICALLY EQUAL TO */
992 1.12 drochner 0x2207, /* NABLA */
993 1.12 drochner 0x2206, /* INCREMENT */
994 1.12 drochner 0x221d, /* PROPORTIONAL TO */
995 1.12 drochner 0x2234, /* THEREFORE */
996 1.12 drochner 0x222b, /* INTEGRAL */
997 1.12 drochner 0x2215, /* DIVISION SLASH */
998 1.12 drochner 0x2216, /* SET MINUS */
999 1.14 drochner _e00eU,
1000 1.14 drochner _e00dU,
1001 1.14 drochner _e00bU,
1002 1.14 drochner /* 6 */ _e00cU,
1003 1.14 drochner _e007U,
1004 1.14 drochner _e008U,
1005 1.14 drochner _e009U,
1006 1.14 drochner _e00aU,
1007 1.12 drochner 0x221a, /* SQUARE ROOT */
1008 1.12 drochner 0x03c9, /* GREEK SMALL LETTER OMEGA */
1009 1.12 drochner 0x00a5, /* YEN SIGN */
1010 1.12 drochner 0x03be, /* GREEK SMALL LETTER XI */
1011 1.12 drochner 0x00fd, /* LATIN SMALL LETTER Y WITH ACUTE */
1012 1.12 drochner 0x00fe, /* LATIN SMALL LETTER THORN */
1013 1.12 drochner 0x00f0, /* LATIN SMALL LETTER ETH */
1014 1.12 drochner 0x00de, /* LATIN CAPITAL LETTER THORN */
1015 1.12 drochner 0x00dd, /* LATIN CAPITAL LETTER Y WITH ACUTE */
1016 1.12 drochner 0x00d7, /* MULTIPLICATION SIGN */
1017 1.12 drochner 0x00d0, /* LATIN CAPITAL LETTER ETH */
1018 1.14 drochner /* 7 */ 0x00be, /* VULGAR FRACTION THREE QUARTERS */
1019 1.12 drochner 0x00b8, /* CEDILLA */
1020 1.12 drochner 0x00b4, /* ACUTE ACCENT */
1021 1.12 drochner 0x00af, /* MACRON */
1022 1.12 drochner 0x00ae, /* REGISTERED SIGN */
1023 1.12 drochner 0x00ad, /* SOFT HYPHEN */
1024 1.12 drochner 0x00ac, /* NOT SIGN */
1025 1.12 drochner 0x00a8, /* DIAERESIS */
1026 1.12 drochner 0x2260, /* NOT EQUAL TO */
1027 1.14 drochner _e005U,
1028 1.14 drochner _e004U,
1029 1.14 drochner _e003U,
1030 1.14 drochner _e002U,
1031 1.14 drochner _e001U,
1032 1.12 drochner 0x03c5, /* GREEK SMALL LETTER UPSILON */
1033 1.12 drochner 0x00f8, /* LATIN SMALL LETTER O WITH STROKE */
1034 1.12 drochner /* 8 */ 0x0153, /* LATIN SMALL LIGATURE OE */
1035 1.12 drochner 0x00f5, /* LATIN SMALL LETTER O WITH TILDE !!!doc bug */
1036 1.12 drochner 0x00e3, /* LATIN SMALL LETTER A WITH TILDE */
1037 1.12 drochner 0x0178, /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
1038 1.12 drochner 0x00db, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
1039 1.12 drochner 0x00da, /* LATIN CAPITAL LETTER U WITH ACUTE */
1040 1.12 drochner 0x00d9, /* LATIN CAPITAL LETTER U WITH GRAVE */
1041 1.12 drochner 0x00d8, /* LATIN CAPITAL LETTER O WITH STROKE */
1042 1.12 drochner 0x0152, /* LATIN CAPITAL LIGATURE OE */
1043 1.12 drochner 0x00d5, /* LATIN CAPITAL LETTER O WITH TILDE */
1044 1.12 drochner 0x00d4, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
1045 1.12 drochner 0x00d3, /* LATIN CAPITAL LETTER O WITH ACUTE */
1046 1.12 drochner 0x00d2, /* LATIN CAPITAL LETTER O WITH GRAVE */
1047 1.12 drochner 0x00cf, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
1048 1.12 drochner 0x00ce, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
1049 1.12 drochner 0x00cd, /* LATIN CAPITAL LETTER I WITH ACUTE */
1050 1.14 drochner /* 9 */ 0x00cc, /* LATIN CAPITAL LETTER I WITH GRAVE */
1051 1.12 drochner 0x00cb, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
1052 1.12 drochner 0x00ca, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
1053 1.12 drochner 0x00c8, /* LATIN CAPITAL LETTER E WITH GRAVE */
1054 1.12 drochner 0x00c3, /* LATIN CAPITAL LETTER A WITH TILDE */
1055 1.12 drochner 0x00c2, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
1056 1.12 drochner 0x00c1, /* LATIN CAPITAL LETTER A WITH ACUTE */
1057 1.12 drochner 0x00c0, /* LATIN CAPITAL LETTER A WITH GRAVE */
1058 1.12 drochner 0x00b9, /* SUPERSCRIPT ONE */
1059 1.12 drochner 0x00b7, /* MIDDLE DOT */
1060 1.12 drochner 0x03b6, /* GREEK SMALL LETTER ZETA */
1061 1.12 drochner 0x00b3, /* SUPERSCRIPT THREE */
1062 1.12 drochner 0x00a9, /* COPYRIGHT SIGN */
1063 1.12 drochner 0x00a4, /* CURRENCY SIGN */
1064 1.12 drochner 0x03ba, /* GREEK SMALL LETTER KAPPA */
1065 1.14 drochner _e000U
1066 1.12 drochner };
1067 1.12 drochner
1068 1.13 drochner static int vga_pcvt_mapchar __P((int, unsigned int *));
1069 1.12 drochner
1070 1.12 drochner static int
1071 1.13 drochner vga_pcvt_mapchar(uni, index)
1072 1.12 drochner int uni;
1073 1.13 drochner unsigned int *index;
1074 1.12 drochner {
1075 1.12 drochner int i;
1076 1.12 drochner
1077 1.12 drochner for (i = 0; i < 0xa0; i++) /* 0xa0..0xff are reserved */
1078 1.13 drochner if (uni == pcvt_unichars[i]) {
1079 1.13 drochner *index = i;
1080 1.13 drochner return (5);
1081 1.13 drochner }
1082 1.13 drochner *index = 0x99; /* middle dot */
1083 1.13 drochner return (0);
1084 1.12 drochner }
1085 1.12 drochner
1086 1.12 drochner #endif /* WSCONS_SUPPORT_PCVTFONTS */
1087 1.12 drochner
1088 1.13 drochner static int _vga_mapchar __P((void *, struct vgafont *, int, unsigned int *));
1089 1.12 drochner
1090 1.12 drochner static int
1091 1.13 drochner _vga_mapchar(id, font, uni, index)
1092 1.12 drochner void *id;
1093 1.12 drochner struct vgafont *font;
1094 1.12 drochner int uni;
1095 1.13 drochner unsigned int *index;
1096 1.12 drochner {
1097 1.12 drochner
1098 1.12 drochner switch (font->encoding) {
1099 1.12 drochner case WSDISPLAY_FONTENC_ISO:
1100 1.13 drochner if (uni < 256) {
1101 1.13 drochner *index = uni;
1102 1.13 drochner return (5);
1103 1.13 drochner } else {
1104 1.13 drochner *index = ' ';
1105 1.13 drochner return (0);
1106 1.13 drochner }
1107 1.12 drochner break;
1108 1.12 drochner case WSDISPLAY_FONTENC_IBM:
1109 1.13 drochner return (pcdisplay_mapchar(id, uni, index));
1110 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
1111 1.12 drochner case WSDISPLAY_FONTENC_PCVT:
1112 1.13 drochner return (vga_pcvt_mapchar(uni, index));
1113 1.12 drochner #endif
1114 1.13 drochner default:
1115 1.16 drochner #ifdef VGAFONTDEBUG
1116 1.13 drochner printf("_vga_mapchar: encoding=%d\n", font->encoding);
1117 1.16 drochner #endif
1118 1.13 drochner *index = ' ';
1119 1.13 drochner return (0);
1120 1.12 drochner }
1121 1.12 drochner }
1122 1.12 drochner
1123 1.13 drochner static int
1124 1.13 drochner vga_mapchar(id, uni, index)
1125 1.12 drochner void *id;
1126 1.12 drochner int uni;
1127 1.13 drochner unsigned int *index;
1128 1.12 drochner {
1129 1.12 drochner struct vgascreen *scr = id;
1130 1.13 drochner unsigned int idx1, idx2;
1131 1.13 drochner int res1, res2;
1132 1.12 drochner
1133 1.13 drochner res1 = 0;
1134 1.13 drochner idx1 = ' '; /* space */
1135 1.13 drochner if (scr->fontset1)
1136 1.13 drochner res1 = _vga_mapchar(id, scr->fontset1, uni, &idx1);
1137 1.13 drochner res2 = -1;
1138 1.12 drochner if (scr->fontset2) {
1139 1.12 drochner KASSERT(VGA_SCREEN_CANTWOFONTS(scr->pcs.type));
1140 1.13 drochner res2 = _vga_mapchar(id, scr->fontset2, uni, &idx2);
1141 1.12 drochner }
1142 1.13 drochner if (res2 > res1) {
1143 1.14 drochner *index = idx2 | 0x0800; /* attribute bit 3 */
1144 1.14 drochner return (res2);
1145 1.13 drochner }
1146 1.13 drochner *index = idx1;
1147 1.13 drochner return (res1);
1148 1.1 drochner }
1149