vga.c revision 1.69 1 1.69 jdolecek /* $NetBSD: vga.c,v 1.69 2003/02/09 10:29:35 jdolecek 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.43 lukem
30 1.43 lukem #include <sys/cdefs.h>
31 1.69 jdolecek __KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.69 2003/02/09 10:29:35 jdolecek Exp $");
32 1.1 drochner
33 1.1 drochner #include <sys/param.h>
34 1.1 drochner #include <sys/systm.h>
35 1.26 thorpej #include <sys/callout.h>
36 1.1 drochner #include <sys/kernel.h>
37 1.1 drochner #include <sys/device.h>
38 1.1 drochner #include <sys/malloc.h>
39 1.1 drochner #include <sys/queue.h>
40 1.1 drochner #include <machine/bus.h>
41 1.1 drochner
42 1.4 drochner #include <dev/ic/mc6845reg.h>
43 1.4 drochner #include <dev/ic/pcdisplayvar.h>
44 1.4 drochner #include <dev/ic/vgareg.h>
45 1.4 drochner #include <dev/ic/vgavar.h>
46 1.4 drochner
47 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
48 1.1 drochner #include <dev/wscons/wsconsio.h>
49 1.14 drochner #include <dev/wscons/unicode.h>
50 1.37 drochner #include <dev/wsfont/wsfont.h>
51 1.1 drochner
52 1.3 drochner #include <dev/ic/pcdisplay.h>
53 1.1 drochner
54 1.57 christos /* for WSCONS_SUPPORT_PCVTFONTS and WSDISPLAY_CHARFUNCS */
55 1.57 christos #include "opt_wsdisplay_compat.h"
56 1.16 drochner
57 1.68 tsutsui int vga_no_builtinfont = 0;
58 1.68 tsutsui
59 1.37 drochner static struct wsdisplay_font _vga_builtinfont = {
60 1.66 tsutsui "builtin", /* typeface name */
61 1.66 tsutsui 0, /* firstchar */
62 1.66 tsutsui 256, /* numbers */
63 1.66 tsutsui WSDISPLAY_FONTENC_IBM, /* encoding */
64 1.66 tsutsui 8, /* width */
65 1.66 tsutsui 16, /* height */
66 1.66 tsutsui 1, /* stride */
67 1.66 tsutsui WSDISPLAY_FONTORDER_L2R, /* bit order */
68 1.66 tsutsui 0, /* byte order */
69 1.66 tsutsui NULL /* data */
70 1.12 drochner };
71 1.12 drochner
72 1.37 drochner struct egavga_font {
73 1.37 drochner struct wsdisplay_font *wsfont;
74 1.58 drochner int cookie; /* wsfont handle, -1 invalid */
75 1.37 drochner int slot; /* in adapter RAM */
76 1.37 drochner int usecount;
77 1.37 drochner TAILQ_ENTRY(egavga_font) next; /* LRU queue */
78 1.37 drochner };
79 1.37 drochner
80 1.37 drochner static struct egavga_font vga_builtinfont = {
81 1.37 drochner &_vga_builtinfont,
82 1.58 drochner -1, 0
83 1.37 drochner };
84 1.37 drochner
85 1.38 drochner #ifdef VGA_CONSOLE_SCREENTYPE
86 1.38 drochner static struct egavga_font vga_consolefont;
87 1.38 drochner #endif
88 1.38 drochner
89 1.1 drochner struct vgascreen {
90 1.4 drochner struct pcdisplayscreen pcs;
91 1.4 drochner
92 1.1 drochner LIST_ENTRY(vgascreen) next;
93 1.1 drochner
94 1.1 drochner struct vga_config *cfg;
95 1.1 drochner
96 1.1 drochner /* videostate */
97 1.37 drochner struct egavga_font *fontset1, *fontset2;
98 1.1 drochner /* font data */
99 1.1 drochner /* palette */
100 1.8 drochner
101 1.8 drochner int mindispoffset, maxdispoffset;
102 1.1 drochner };
103 1.1 drochner
104 1.1 drochner static int vgaconsole, vga_console_type, vga_console_attached;
105 1.1 drochner static struct vgascreen vga_console_screen;
106 1.1 drochner static struct vga_config vga_console_vc;
107 1.1 drochner
108 1.37 drochner struct egavga_font *egavga_getfont(struct vga_config *, struct vgascreen *,
109 1.69 jdolecek const char *, int);
110 1.37 drochner void egavga_unreffont(struct vga_config *, struct egavga_font *);
111 1.37 drochner
112 1.69 jdolecek int vga_selectfont(struct vga_config *, struct vgascreen *, const char *,
113 1.69 jdolecek const char *);
114 1.45 junyoung void vga_init_screen(struct vga_config *, struct vgascreen *,
115 1.45 junyoung const struct wsscreen_descr *, int, long *);
116 1.45 junyoung void vga_init(struct vga_config *, bus_space_tag_t, bus_space_tag_t);
117 1.45 junyoung static void vga_setfont(struct vga_config *, struct vgascreen *);
118 1.45 junyoung
119 1.45 junyoung static int vga_mapchar(void *, int, unsigned int *);
120 1.59 junyoung static int vga_allocattr(void *, int, int, int, long *);
121 1.45 junyoung static void vga_copyrows(void *, int, int, int);
122 1.1 drochner
123 1.1 drochner const struct wsdisplay_emulops vga_emulops = {
124 1.4 drochner pcdisplay_cursor,
125 1.12 drochner vga_mapchar,
126 1.6 drochner pcdisplay_putchar,
127 1.4 drochner pcdisplay_copycols,
128 1.4 drochner pcdisplay_erasecols,
129 1.8 drochner vga_copyrows,
130 1.4 drochner pcdisplay_eraserows,
131 1.59 junyoung vga_allocattr
132 1.3 drochner };
133 1.3 drochner
134 1.3 drochner /*
135 1.3 drochner * translate WS(=ANSI) color codes to standard pc ones
136 1.3 drochner */
137 1.35 jdolecek static const unsigned char fgansitopc[] = {
138 1.3 drochner #ifdef __alpha__
139 1.3 drochner /*
140 1.3 drochner * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
141 1.3 drochner * XXX We should probably not bother with this
142 1.3 drochner * XXX (reinitialize the palette registers).
143 1.3 drochner */
144 1.3 drochner FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
145 1.3 drochner FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
146 1.3 drochner #else
147 1.3 drochner FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
148 1.3 drochner FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
149 1.3 drochner #endif
150 1.3 drochner }, bgansitopc[] = {
151 1.3 drochner #ifdef __alpha__
152 1.3 drochner BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
153 1.3 drochner BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
154 1.3 drochner #else
155 1.3 drochner BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
156 1.3 drochner BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
157 1.3 drochner #endif
158 1.1 drochner };
159 1.1 drochner
160 1.33 lukem const struct wsscreen_descr vga_25lscreen = {
161 1.1 drochner "80x25", 80, 25,
162 1.1 drochner &vga_emulops,
163 1.3 drochner 8, 16,
164 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
165 1.33 lukem }, vga_25lscreen_mono = {
166 1.3 drochner "80x25", 80, 25,
167 1.3 drochner &vga_emulops,
168 1.3 drochner 8, 16,
169 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
170 1.33 lukem }, vga_25lscreen_bf = {
171 1.12 drochner "80x25bf", 80, 25,
172 1.12 drochner &vga_emulops,
173 1.12 drochner 8, 16,
174 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
175 1.17 drochner }, vga_40lscreen = {
176 1.17 drochner "80x40", 80, 40,
177 1.17 drochner &vga_emulops,
178 1.17 drochner 8, 10,
179 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
180 1.17 drochner }, vga_40lscreen_mono = {
181 1.17 drochner "80x40", 80, 40,
182 1.17 drochner &vga_emulops,
183 1.17 drochner 8, 10,
184 1.17 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
185 1.17 drochner }, vga_40lscreen_bf = {
186 1.17 drochner "80x40bf", 80, 40,
187 1.17 drochner &vga_emulops,
188 1.17 drochner 8, 10,
189 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
190 1.12 drochner }, vga_50lscreen = {
191 1.1 drochner "80x50", 80, 50,
192 1.1 drochner &vga_emulops,
193 1.3 drochner 8, 8,
194 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
195 1.3 drochner }, vga_50lscreen_mono = {
196 1.3 drochner "80x50", 80, 50,
197 1.3 drochner &vga_emulops,
198 1.3 drochner 8, 8,
199 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
200 1.12 drochner }, vga_50lscreen_bf = {
201 1.12 drochner "80x50bf", 80, 50,
202 1.12 drochner &vga_emulops,
203 1.12 drochner 8, 8,
204 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
205 1.30 drochner }, vga_24lscreen = {
206 1.30 drochner "80x24", 80, 24,
207 1.30 drochner &vga_emulops,
208 1.30 drochner 8, 16,
209 1.30 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
210 1.30 drochner }, vga_24lscreen_mono = {
211 1.30 drochner "80x24", 80, 24,
212 1.30 drochner &vga_emulops,
213 1.30 drochner 8, 16,
214 1.30 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
215 1.30 drochner }, vga_24lscreen_bf = {
216 1.30 drochner "80x24bf", 80, 24,
217 1.30 drochner &vga_emulops,
218 1.30 drochner 8, 16,
219 1.30 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
220 1.1 drochner };
221 1.1 drochner
222 1.12 drochner #define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
223 1.12 drochner
224 1.2 drochner const struct wsscreen_descr *_vga_scrlist[] = {
225 1.33 lukem &vga_25lscreen,
226 1.33 lukem &vga_25lscreen_bf,
227 1.17 drochner &vga_40lscreen,
228 1.17 drochner &vga_40lscreen_bf,
229 1.1 drochner &vga_50lscreen,
230 1.12 drochner &vga_50lscreen_bf,
231 1.30 drochner &vga_24lscreen,
232 1.30 drochner &vga_24lscreen_bf,
233 1.1 drochner /* XXX other formats, graphics screen? */
234 1.3 drochner }, *_vga_scrlist_mono[] = {
235 1.33 lukem &vga_25lscreen_mono,
236 1.17 drochner &vga_40lscreen_mono,
237 1.3 drochner &vga_50lscreen_mono,
238 1.30 drochner &vga_24lscreen_mono,
239 1.3 drochner /* XXX other formats, graphics screen? */
240 1.1 drochner };
241 1.1 drochner
242 1.3 drochner const struct wsscreen_list vga_screenlist = {
243 1.3 drochner sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
244 1.3 drochner _vga_scrlist
245 1.3 drochner }, vga_screenlist_mono = {
246 1.3 drochner sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
247 1.3 drochner _vga_scrlist_mono
248 1.1 drochner };
249 1.1 drochner
250 1.45 junyoung static int vga_ioctl(void *, u_long, caddr_t, int, struct proc *);
251 1.45 junyoung static paddr_t vga_mmap(void *, off_t, int);
252 1.45 junyoung static int vga_alloc_screen(void *, const struct wsscreen_descr *,
253 1.45 junyoung void **, int *, int *, long *);
254 1.45 junyoung static void vga_free_screen(void *, void *);
255 1.45 junyoung static int vga_show_screen(void *, void *, int,
256 1.45 junyoung void (*)(void *, int, int), void *);
257 1.45 junyoung static int vga_load_font(void *, void *, struct wsdisplay_font *);
258 1.57 christos #ifdef WSDISPLAY_CHARFUNCS
259 1.53 christos static int vga_getwschar(void *, struct wsdisplay_char *);
260 1.53 christos static int vga_putwschar(void *, struct wsdisplay_char *);
261 1.57 christos #endif /* WSDISPLAY_CHARFUNCS */
262 1.1 drochner
263 1.45 junyoung void vga_doswitch(struct vga_config *);
264 1.22 drochner
265 1.1 drochner const struct wsdisplay_accessops vga_accessops = {
266 1.1 drochner vga_ioctl,
267 1.1 drochner vga_mmap,
268 1.1 drochner vga_alloc_screen,
269 1.1 drochner vga_free_screen,
270 1.1 drochner vga_show_screen,
271 1.53 christos vga_load_font,
272 1.53 christos NULL,
273 1.57 christos #ifdef WSDISPLAY_CHARFUNCS
274 1.53 christos vga_getwschar,
275 1.53 christos vga_putwschar
276 1.57 christos #else /* WSDISPLAY_CHARFUNCS */
277 1.57 christos NULL,
278 1.57 christos NULL
279 1.57 christos #endif /* WSDISPLAY_CHARFUNCS */
280 1.1 drochner };
281 1.1 drochner
282 1.12 drochner /*
283 1.15 drochner * We want at least ASCII 32..127 be present in the
284 1.15 drochner * first font slot.
285 1.12 drochner */
286 1.12 drochner #define vga_valid_primary_font(f) \
287 1.37 drochner (f->wsfont->encoding == WSDISPLAY_FONTENC_IBM || \
288 1.37 drochner f->wsfont->encoding == WSDISPLAY_FONTENC_ISO || \
289 1.37 drochner f->wsfont->encoding == WSDISPLAY_FONTENC_ISO7)
290 1.37 drochner
291 1.37 drochner struct egavga_font *
292 1.69 jdolecek egavga_getfont(struct vga_config *vc, struct vgascreen *scr, const char *name,
293 1.45 junyoung int primary)
294 1.37 drochner {
295 1.37 drochner struct egavga_font *f;
296 1.37 drochner int cookie;
297 1.37 drochner struct wsdisplay_font *wf;
298 1.37 drochner
299 1.37 drochner TAILQ_FOREACH(f, &vc->vc_fontlist, next) {
300 1.37 drochner if (wsfont_matches(f->wsfont, name,
301 1.66 tsutsui 8, scr->pcs.type->fontheight, 0) &&
302 1.37 drochner (!primary || vga_valid_primary_font(f))) {
303 1.37 drochner #ifdef VGAFONTDEBUG
304 1.37 drochner if (scr != &vga_console_screen || vga_console_attached)
305 1.37 drochner printf("vga_getfont: %s already present\n",
306 1.66 tsutsui name ? name : "<default>");
307 1.37 drochner #endif
308 1.37 drochner goto found;
309 1.37 drochner }
310 1.37 drochner }
311 1.37 drochner
312 1.48 ad cookie = wsfont_find(name, 8, scr->pcs.type->fontheight, 0,
313 1.66 tsutsui WSDISPLAY_FONTORDER_L2R, 0);
314 1.37 drochner /* XXX obey "primary" */
315 1.37 drochner if (cookie == -1) {
316 1.37 drochner #ifdef VGAFONTDEBUG
317 1.37 drochner if (scr != &vga_console_screen || vga_console_attached)
318 1.51 drochner printf("vga_getfont: %s not found\n",
319 1.66 tsutsui name ? name : "<default>");
320 1.37 drochner #endif
321 1.37 drochner return (0);
322 1.37 drochner }
323 1.37 drochner
324 1.47 ad if (wsfont_lock(cookie, &wf))
325 1.37 drochner return (0);
326 1.37 drochner
327 1.38 drochner #ifdef VGA_CONSOLE_SCREENTYPE
328 1.38 drochner if (scr == &vga_console_screen)
329 1.38 drochner f = &vga_consolefont;
330 1.38 drochner else
331 1.38 drochner #endif
332 1.37 drochner f = malloc(sizeof(struct egavga_font), M_DEVBUF, M_NOWAIT);
333 1.37 drochner if (!f) {
334 1.37 drochner wsfont_unlock(cookie);
335 1.37 drochner return (0);
336 1.37 drochner }
337 1.37 drochner f->wsfont = wf;
338 1.37 drochner f->cookie = cookie;
339 1.37 drochner f->slot = -1; /* not yet loaded */
340 1.37 drochner f->usecount = 0; /* incremented below */
341 1.37 drochner TAILQ_INSERT_TAIL(&vc->vc_fontlist, f, next);
342 1.37 drochner
343 1.37 drochner found:
344 1.37 drochner f->usecount++;
345 1.37 drochner #ifdef VGAFONTDEBUG
346 1.37 drochner if (scr != &vga_console_screen || vga_console_attached)
347 1.37 drochner printf("vga_getfont: usecount=%d\n", f->usecount);
348 1.37 drochner #endif
349 1.37 drochner return (f);
350 1.37 drochner }
351 1.37 drochner
352 1.37 drochner void
353 1.45 junyoung egavga_unreffont(struct vga_config *vc, struct egavga_font *f)
354 1.37 drochner {
355 1.37 drochner
356 1.37 drochner f->usecount--;
357 1.37 drochner #ifdef VGAFONTDEBUG
358 1.37 drochner printf("vga_unreffont: usecount=%d\n", f->usecount);
359 1.37 drochner #endif
360 1.58 drochner if (f->usecount == 0 && f->cookie != -1) {
361 1.37 drochner TAILQ_REMOVE(&vc->vc_fontlist, f, next);
362 1.41 drochner if (f->slot != -1) {
363 1.41 drochner KASSERT(vc->vc_fonts[f->slot] == f);
364 1.41 drochner vc->vc_fonts[f->slot] = 0;
365 1.41 drochner }
366 1.37 drochner wsfont_unlock(f->cookie);
367 1.38 drochner #ifdef VGA_CONSOLE_SCREENTYPE
368 1.38 drochner if (f != &vga_consolefont)
369 1.38 drochner #endif
370 1.37 drochner free(f, M_DEVBUF);
371 1.37 drochner }
372 1.37 drochner }
373 1.12 drochner
374 1.12 drochner int
375 1.69 jdolecek vga_selectfont(struct vga_config *vc, struct vgascreen *scr, const char *name1,
376 1.69 jdolecek const char *name2)
377 1.12 drochner {
378 1.12 drochner const struct wsscreen_descr *type = scr->pcs.type;
379 1.37 drochner struct egavga_font *f1, *f2;
380 1.12 drochner
381 1.37 drochner f1 = egavga_getfont(vc, scr, name1, 1);
382 1.37 drochner if (!f1)
383 1.37 drochner return (ENXIO);
384 1.12 drochner
385 1.37 drochner if (VGA_SCREEN_CANTWOFONTS(type) && name2) {
386 1.37 drochner f2 = egavga_getfont(vc, scr, name2, 0);
387 1.37 drochner if (!f2) {
388 1.37 drochner egavga_unreffont(vc, f1);
389 1.37 drochner return (ENXIO);
390 1.12 drochner }
391 1.37 drochner } else
392 1.37 drochner f2 = 0;
393 1.12 drochner
394 1.12 drochner #ifdef VGAFONTDEBUG
395 1.37 drochner if (scr != &vga_console_screen || vga_console_attached) {
396 1.37 drochner printf("vga (%s): font1=%s (slot %d)", type->name,
397 1.66 tsutsui f1->wsfont->name, f1->slot);
398 1.37 drochner if (f2)
399 1.37 drochner printf(", font2=%s (slot %d)",
400 1.66 tsutsui f2->wsfont->name, f2->slot);
401 1.37 drochner printf("\n");
402 1.37 drochner }
403 1.12 drochner #endif
404 1.37 drochner if (scr->fontset1)
405 1.37 drochner egavga_unreffont(vc, scr->fontset1);
406 1.37 drochner scr->fontset1 = f1;
407 1.37 drochner if (scr->fontset2)
408 1.37 drochner egavga_unreffont(vc, scr->fontset2);
409 1.37 drochner scr->fontset2 = f2;
410 1.37 drochner return (0);
411 1.12 drochner }
412 1.12 drochner
413 1.1 drochner void
414 1.45 junyoung vga_init_screen(struct vga_config *vc, struct vgascreen *scr,
415 1.45 junyoung const struct wsscreen_descr *type, int existing, long *attrp)
416 1.1 drochner {
417 1.8 drochner int cpos;
418 1.3 drochner int res;
419 1.1 drochner
420 1.4 drochner scr->cfg = vc;
421 1.4 drochner scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
422 1.4 drochner scr->pcs.type = type;
423 1.39 drochner scr->pcs.active = existing;
424 1.8 drochner scr->mindispoffset = 0;
425 1.63 drochner if (vc->vc_quirks & VGA_QUIRK_NOFASTSCROLL)
426 1.63 drochner scr->maxdispoffset = 0;
427 1.63 drochner else
428 1.63 drochner scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
429 1.1 drochner
430 1.1 drochner if (existing) {
431 1.39 drochner vc->active = scr;
432 1.39 drochner
433 1.1 drochner cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
434 1.1 drochner cpos |= vga_6845_read(&vc->hdl, cursorl);
435 1.1 drochner
436 1.1 drochner /* make sure we have a valid cursor position */
437 1.1 drochner if (cpos < 0 || cpos >= type->nrows * type->ncols)
438 1.1 drochner cpos = 0;
439 1.8 drochner
440 1.8 drochner scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
441 1.8 drochner scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
442 1.8 drochner
443 1.8 drochner /* make sure we have a valid memory offset */
444 1.8 drochner if (scr->pcs.dispoffset < scr->mindispoffset ||
445 1.8 drochner scr->pcs.dispoffset > scr->maxdispoffset)
446 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
447 1.40 drochner
448 1.40 drochner if (type != vc->currenttype) {
449 1.40 drochner vga_setscreentype(&vc->hdl, type);
450 1.40 drochner vc->currenttype = type;
451 1.40 drochner }
452 1.8 drochner } else {
453 1.8 drochner cpos = 0;
454 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
455 1.1 drochner }
456 1.1 drochner
457 1.60 junyoung scr->pcs.cursorrow = cpos / type->ncols;
458 1.60 junyoung scr->pcs.cursorcol = cpos % type->ncols;
459 1.25 ad pcdisplay_cursor_init(&scr->pcs, existing);
460 1.1 drochner
461 1.1 drochner #ifdef __alpha__
462 1.4 drochner if (!vc->hdl.vh_mono)
463 1.3 drochner /*
464 1.3 drochner * DEC firmware uses a blue background.
465 1.3 drochner */
466 1.59 junyoung res = vga_allocattr(scr, WSCOL_WHITE, WSCOL_BLUE,
467 1.66 tsutsui WSATTR_WSCOLORS, attrp);
468 1.3 drochner else
469 1.3 drochner #endif
470 1.59 junyoung res = vga_allocattr(scr, 0, 0, 0, attrp);
471 1.3 drochner #ifdef DIAGNOSTIC
472 1.3 drochner if (res)
473 1.3 drochner panic("vga_init_screen: attribute botch");
474 1.1 drochner #endif
475 1.1 drochner
476 1.4 drochner scr->pcs.mem = NULL;
477 1.15 drochner
478 1.15 drochner scr->fontset1 = scr->fontset2 = 0;
479 1.12 drochner if (vga_selectfont(vc, scr, 0, 0)) {
480 1.12 drochner if (scr == &vga_console_screen)
481 1.12 drochner panic("vga_init_screen: no font");
482 1.12 drochner else
483 1.12 drochner printf("vga_init_screen: no font\n");
484 1.12 drochner }
485 1.40 drochner if (existing)
486 1.40 drochner vga_setfont(vc, scr);
487 1.15 drochner
488 1.1 drochner vc->nscreens++;
489 1.1 drochner LIST_INSERT_HEAD(&vc->screens, scr, next);
490 1.1 drochner }
491 1.1 drochner
492 1.1 drochner void
493 1.45 junyoung vga_init(struct vga_config *vc, bus_space_tag_t iot, bus_space_tag_t memt)
494 1.1 drochner {
495 1.1 drochner struct vga_handle *vh = &vc->hdl;
496 1.1 drochner u_int8_t mor;
497 1.12 drochner int i;
498 1.1 drochner
499 1.66 tsutsui vh->vh_iot = iot;
500 1.66 tsutsui vh->vh_memt = memt;
501 1.1 drochner
502 1.66 tsutsui if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
503 1.66 tsutsui panic("vga_init: couldn't map vga io");
504 1.1 drochner
505 1.1 drochner /* read "misc output register" */
506 1.67 tsutsui mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
507 1.4 drochner vh->vh_mono = !(mor & 1);
508 1.1 drochner
509 1.4 drochner if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
510 1.66 tsutsui &vh->vh_ioh_6845))
511 1.66 tsutsui panic("vga_init: couldn't map 6845 io");
512 1.1 drochner
513 1.66 tsutsui if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
514 1.66 tsutsui panic("vga_init: couldn't map memory");
515 1.1 drochner
516 1.66 tsutsui if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
517 1.66 tsutsui (vh->vh_mono ? 0x10000 : 0x18000), 0x8000, &vh->vh_memh))
518 1.66 tsutsui panic("vga_init: mem subrange failed");
519 1.5 drochner
520 1.5 drochner /* should only reserve the space (no need to map - save KVM) */
521 1.5 drochner vc->vc_biostag = memt;
522 1.66 tsutsui if (bus_space_map(vc->vc_biostag, 0xc0000, 0x8000, 0, &vc->vc_bioshdl))
523 1.5 drochner vc->vc_biosmapped = 0;
524 1.5 drochner else
525 1.5 drochner vc->vc_biosmapped = 1;
526 1.1 drochner
527 1.1 drochner vc->nscreens = 0;
528 1.1 drochner LIST_INIT(&vc->screens);
529 1.1 drochner vc->active = NULL;
530 1.34 drochner vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen;
531 1.26 thorpej callout_init(&vc->vc_switch_callout);
532 1.12 drochner
533 1.68 tsutsui wsfont_init();
534 1.68 tsutsui if (vga_no_builtinfont) {
535 1.68 tsutsui struct wsdisplay_font *wf;
536 1.68 tsutsui int cookie;
537 1.68 tsutsui
538 1.68 tsutsui cookie = wsfont_find(NULL, 8, 16, 0,
539 1.68 tsutsui WSDISPLAY_FONTORDER_L2R, 0);
540 1.68 tsutsui if (cookie == -1 || wsfont_lock(cookie, &wf))
541 1.68 tsutsui panic("vga_init: can't load console font");
542 1.68 tsutsui vga_loadchars(&vc->hdl, 0, wf->firstchar, wf->numchars,
543 1.68 tsutsui wf->fontheight, wf->data);
544 1.68 tsutsui vga_builtinfont.wsfont = wf;
545 1.68 tsutsui vga_builtinfont.cookie = cookie;
546 1.68 tsutsui vga_builtinfont.slot = 0;
547 1.68 tsutsui }
548 1.12 drochner vc->vc_fonts[0] = &vga_builtinfont;
549 1.23 drochner for (i = 1; i < 8; i++)
550 1.12 drochner vc->vc_fonts[i] = 0;
551 1.37 drochner TAILQ_INIT(&vc->vc_fontlist);
552 1.37 drochner TAILQ_INSERT_HEAD(&vc->vc_fontlist, &vga_builtinfont, next);
553 1.12 drochner
554 1.12 drochner vc->currentfontset1 = vc->currentfontset2 = 0;
555 1.1 drochner }
556 1.1 drochner
557 1.1 drochner void
558 1.45 junyoung vga_common_attach(struct vga_softc *sc, bus_space_tag_t iot,
559 1.56 drochner bus_space_tag_t memt, int type, int quirks,
560 1.56 drochner const struct vga_funcs *vf)
561 1.28 soda {
562 1.1 drochner int console;
563 1.1 drochner struct vga_config *vc;
564 1.1 drochner struct wsemuldisplaydev_attach_args aa;
565 1.1 drochner
566 1.1 drochner console = vga_is_console(iot, type);
567 1.1 drochner
568 1.1 drochner if (console) {
569 1.1 drochner vc = &vga_console_vc;
570 1.1 drochner vga_console_attached = 1;
571 1.1 drochner } else {
572 1.1 drochner vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
573 1.1 drochner vga_init(vc, iot, memt);
574 1.1 drochner }
575 1.1 drochner
576 1.58 drochner if (quirks & VGA_QUIRK_ONEFONT) {
577 1.58 drochner vc->vc_nfontslots = 1;
578 1.58 drochner #ifndef VGA_CONSOLE_ATI_BROKEN_FONTSEL
579 1.58 drochner /*
580 1.58 drochner * XXX maybe invalidate font in slot > 0, but this can
581 1.58 drochner * only be happen with VGA_CONSOLE_SCREENTYPE, and then
582 1.58 drochner * we require VGA_CONSOLE_ATI_BROKEN_FONTSEL anyway.
583 1.58 drochner */
584 1.58 drochner #endif
585 1.58 drochner } else {
586 1.58 drochner vc->vc_nfontslots = 8;
587 1.58 drochner #ifndef VGA_CONSOLE_ATI_BROKEN_FONTSEL
588 1.58 drochner /*
589 1.58 drochner * XXX maybe validate builtin font shifted to slot 1 if
590 1.58 drochner * slot 0 got overwritten because of VGA_CONSOLE_SCREENTYPE,
591 1.58 drochner * but it will be reloaded anyway if needed.
592 1.58 drochner */
593 1.58 drochner #endif
594 1.58 drochner }
595 1.58 drochner
596 1.58 drochner /*
597 1.58 drochner * Save the builtin font to memory. In case it got overwritten
598 1.58 drochner * in console initialization, use the copy in slot 1.
599 1.58 drochner */
600 1.58 drochner #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
601 1.58 drochner #define BUILTINFONTLOC (vga_builtinfont.slot == -1 ? 1 : 0)
602 1.58 drochner #else
603 1.58 drochner KASSERT(vga_builtinfont.slot == 0);
604 1.58 drochner #define BUILTINFONTLOC (0)
605 1.58 drochner #endif
606 1.68 tsutsui if (!vga_no_builtinfont) {
607 1.69 jdolecek char *data =
608 1.68 tsutsui malloc(256 * vga_builtinfont.wsfont->fontheight,
609 1.68 tsutsui M_DEVBUF, M_WAITOK);
610 1.68 tsutsui vga_readoutchars(&vc->hdl, BUILTINFONTLOC, 0, 256,
611 1.69 jdolecek vga_builtinfont.wsfont->fontheight, data);
612 1.69 jdolecek vga_builtinfont.wsfont->data = data;
613 1.68 tsutsui }
614 1.56 drochner
615 1.42 thorpej vc->vc_type = type;
616 1.42 thorpej vc->vc_funcs = vf;
617 1.63 drochner vc->vc_quirks = quirks;
618 1.42 thorpej
619 1.42 thorpej sc->sc_vc = vc;
620 1.42 thorpej vc->softc = sc;
621 1.28 soda
622 1.1 drochner aa.console = console;
623 1.4 drochner aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
624 1.1 drochner aa.accessops = &vga_accessops;
625 1.1 drochner aa.accesscookie = vc;
626 1.1 drochner
627 1.66 tsutsui config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
628 1.1 drochner }
629 1.1 drochner
630 1.1 drochner int
631 1.45 junyoung vga_cnattach(bus_space_tag_t iot, bus_space_tag_t memt, int type, int check)
632 1.1 drochner {
633 1.3 drochner long defattr;
634 1.3 drochner const struct wsscreen_descr *scr;
635 1.3 drochner
636 1.1 drochner if (check && !vga_common_probe(iot, memt))
637 1.1 drochner return (ENXIO);
638 1.1 drochner
639 1.1 drochner /* set up bus-independent VGA configuration */
640 1.1 drochner vga_init(&vga_console_vc, iot, memt);
641 1.34 drochner #ifdef VGA_CONSOLE_SCREENTYPE
642 1.34 drochner scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ?
643 1.66 tsutsui &vga_screenlist_mono : &vga_screenlist, VGA_CONSOLE_SCREENTYPE);
644 1.34 drochner if (!scr)
645 1.34 drochner panic("vga_cnattach: invalid screen type");
646 1.34 drochner #else
647 1.11 drochner scr = vga_console_vc.currenttype;
648 1.34 drochner #endif
649 1.56 drochner #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
650 1.56 drochner /*
651 1.56 drochner * On some (most/all?) ATI cards, only font slot 0 is usable.
652 1.56 drochner * vga_init_screen() might need font slot 0 for a non-default
653 1.58 drochner * console font, so save the builtin VGA font to another font slot.
654 1.58 drochner * The attach() code will take care later.
655 1.56 drochner */
656 1.63 drochner vga_console_vc.vc_quirks |= VGA_QUIRK_ONEFONT; /* redundant */
657 1.56 drochner vga_copyfont01(&vga_console_vc.hdl);
658 1.56 drochner vga_console_vc.vc_nfontslots = 1;
659 1.56 drochner #else
660 1.56 drochner vga_console_vc.vc_nfontslots = 8;
661 1.56 drochner #endif
662 1.63 drochner /* until we know better, assume "fast scrolling" does not work */
663 1.63 drochner vga_console_vc.vc_quirks |= VGA_QUIRK_NOFASTSCROLL;
664 1.63 drochner
665 1.4 drochner vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
666 1.1 drochner
667 1.3 drochner wsdisplay_cnattach(scr, &vga_console_screen,
668 1.66 tsutsui vga_console_screen.pcs.cursorcol,
669 1.66 tsutsui vga_console_screen.pcs.cursorrow, defattr);
670 1.1 drochner
671 1.1 drochner vgaconsole = 1;
672 1.1 drochner vga_console_type = type;
673 1.1 drochner return (0);
674 1.1 drochner }
675 1.1 drochner
676 1.1 drochner int
677 1.45 junyoung vga_is_console(bus_space_tag_t iot, int type)
678 1.1 drochner {
679 1.1 drochner if (vgaconsole &&
680 1.1 drochner !vga_console_attached &&
681 1.1 drochner iot == vga_console_vc.hdl.vh_iot &&
682 1.1 drochner (vga_console_type == -1 || (type == vga_console_type)))
683 1.1 drochner return (1);
684 1.1 drochner return (0);
685 1.1 drochner }
686 1.1 drochner
687 1.46 lukem static int
688 1.46 lukem vga_get_video(struct vga_config *vc)
689 1.46 lukem {
690 1.67 tsutsui
691 1.67 tsutsui return (vga_ts_read(&vc->hdl, mode) & VGA_TS_MODE_BLANK) == 0;
692 1.46 lukem }
693 1.46 lukem
694 1.46 lukem static void
695 1.46 lukem vga_set_video(struct vga_config *vc, int state)
696 1.46 lukem {
697 1.46 lukem int val;
698 1.46 lukem
699 1.46 lukem vga_ts_write(&vc->hdl, syncreset, 0x01);
700 1.46 lukem if (state) { /* unblank screen */
701 1.46 lukem val = vga_ts_read(&vc->hdl, mode);
702 1.67 tsutsui vga_ts_write(&vc->hdl, mode, val & ~VGA_TS_MODE_BLANK);
703 1.46 lukem #ifndef VGA_NO_VBLANK
704 1.46 lukem val = vga_6845_read(&vc->hdl, mode);
705 1.46 lukem vga_6845_write(&vc->hdl, mode, val | 0x80);
706 1.46 lukem #endif
707 1.46 lukem } else { /* blank screen */
708 1.46 lukem val = vga_ts_read(&vc->hdl, mode);
709 1.67 tsutsui vga_ts_write(&vc->hdl, mode, val | VGA_TS_MODE_BLANK);
710 1.46 lukem #ifndef VGA_NO_VBLANK
711 1.46 lukem val = vga_6845_read(&vc->hdl, mode);
712 1.46 lukem vga_6845_write(&vc->hdl, mode, val & ~0x80);
713 1.46 lukem #endif
714 1.46 lukem }
715 1.46 lukem vga_ts_write(&vc->hdl, syncreset, 0x03);
716 1.46 lukem }
717 1.46 lukem
718 1.1 drochner int
719 1.45 junyoung vga_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
720 1.1 drochner {
721 1.1 drochner struct vga_config *vc = v;
722 1.42 thorpej const struct vga_funcs *vf = vc->vc_funcs;
723 1.1 drochner
724 1.1 drochner switch (cmd) {
725 1.1 drochner case WSDISPLAYIO_GTYPE:
726 1.1 drochner *(int *)data = vc->vc_type;
727 1.10 augustss return 0;
728 1.12 drochner
729 1.1 drochner case WSDISPLAYIO_GINFO:
730 1.42 thorpej /* XXX should get detailed hardware information here */
731 1.49 atatat return EPASSTHROUGH;
732 1.42 thorpej
733 1.46 lukem case WSDISPLAYIO_GVIDEO:
734 1.66 tsutsui *(int *)data = (vga_get_video(vc) ?
735 1.66 tsutsui WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF);
736 1.46 lukem return 0;
737 1.46 lukem
738 1.46 lukem case WSDISPLAYIO_SVIDEO:
739 1.46 lukem vga_set_video(vc, *(int *)data == WSDISPLAYIO_VIDEO_ON);
740 1.46 lukem return 0;
741 1.46 lukem
742 1.1 drochner case WSDISPLAYIO_GETCMAP:
743 1.1 drochner case WSDISPLAYIO_PUTCMAP:
744 1.1 drochner case WSDISPLAYIO_GCURPOS:
745 1.1 drochner case WSDISPLAYIO_SCURPOS:
746 1.1 drochner case WSDISPLAYIO_GCURMAX:
747 1.1 drochner case WSDISPLAYIO_GCURSOR:
748 1.1 drochner case WSDISPLAYIO_SCURSOR:
749 1.1 drochner /* NONE of these operations are by the generic VGA driver. */
750 1.49 atatat return EPASSTHROUGH;
751 1.1 drochner }
752 1.12 drochner
753 1.42 thorpej if (vc->vc_funcs == NULL)
754 1.49 atatat return (EPASSTHROUGH);
755 1.42 thorpej
756 1.42 thorpej if (vf->vf_ioctl == NULL)
757 1.49 atatat return (EPASSTHROUGH);
758 1.42 thorpej
759 1.42 thorpej return ((*vf->vf_ioctl)(v, cmd, data, flag, p));
760 1.1 drochner }
761 1.1 drochner
762 1.29 simonb static paddr_t
763 1.45 junyoung vga_mmap(void *v, off_t offset, int prot)
764 1.1 drochner {
765 1.42 thorpej struct vga_config *vc = v;
766 1.42 thorpej const struct vga_funcs *vf = vc->vc_funcs;
767 1.1 drochner
768 1.42 thorpej if (vc->vc_funcs == NULL)
769 1.42 thorpej return (-1);
770 1.28 soda
771 1.42 thorpej if (vf->vf_mmap == NULL)
772 1.42 thorpej return (-1);
773 1.32 thorpej
774 1.42 thorpej return ((*vf->vf_mmap)(v, offset, prot));
775 1.1 drochner }
776 1.1 drochner
777 1.1 drochner int
778 1.45 junyoung vga_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
779 1.45 junyoung int *curxp, int *curyp, long *defattrp)
780 1.1 drochner {
781 1.1 drochner struct vga_config *vc = v;
782 1.1 drochner struct vgascreen *scr;
783 1.1 drochner
784 1.1 drochner if (vc->nscreens == 1) {
785 1.38 drochner struct vgascreen *scr1 = vc->screens.lh_first;
786 1.1 drochner /*
787 1.1 drochner * When allocating the second screen, get backing store
788 1.1 drochner * for the first one too.
789 1.1 drochner * XXX We could be more clever and use video RAM.
790 1.1 drochner */
791 1.38 drochner scr1->pcs.mem =
792 1.66 tsutsui malloc(scr1->pcs.type->ncols * scr1->pcs.type->nrows * 2,
793 1.66 tsutsui M_DEVBUF, M_WAITOK);
794 1.1 drochner }
795 1.1 drochner
796 1.1 drochner scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
797 1.4 drochner vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
798 1.1 drochner
799 1.39 drochner if (vc->nscreens > 1) {
800 1.4 drochner scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
801 1.66 tsutsui M_DEVBUF, M_WAITOK);
802 1.4 drochner pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
803 1.1 drochner }
804 1.1 drochner
805 1.1 drochner *cookiep = scr;
806 1.60 junyoung *curxp = scr->pcs.cursorcol;
807 1.60 junyoung *curyp = scr->pcs.cursorrow;
808 1.1 drochner
809 1.1 drochner return (0);
810 1.1 drochner }
811 1.1 drochner
812 1.1 drochner void
813 1.45 junyoung vga_free_screen(void *v, void *cookie)
814 1.1 drochner {
815 1.1 drochner struct vgascreen *vs = cookie;
816 1.11 drochner struct vga_config *vc = vs->cfg;
817 1.1 drochner
818 1.1 drochner LIST_REMOVE(vs, next);
819 1.38 drochner if (vs->fontset1)
820 1.38 drochner egavga_unreffont(vc, vs->fontset1);
821 1.38 drochner if (vs->fontset2)
822 1.38 drochner egavga_unreffont(vc, vs->fontset2);
823 1.38 drochner
824 1.1 drochner if (vs != &vga_console_screen)
825 1.1 drochner free(vs, M_DEVBUF);
826 1.1 drochner else
827 1.1 drochner panic("vga_free_screen: console");
828 1.11 drochner
829 1.11 drochner if (vc->active == vs)
830 1.11 drochner vc->active = 0;
831 1.1 drochner }
832 1.1 drochner
833 1.40 drochner static void vga_usefont(struct vga_config *, struct egavga_font *);
834 1.37 drochner
835 1.40 drochner static void
836 1.45 junyoung vga_usefont(struct vga_config *vc, struct egavga_font *f)
837 1.37 drochner {
838 1.37 drochner int slot;
839 1.37 drochner struct egavga_font *of;
840 1.37 drochner
841 1.37 drochner if (f->slot != -1)
842 1.37 drochner goto toend;
843 1.37 drochner
844 1.51 drochner for (slot = 0; slot < vc->vc_nfontslots; slot++) {
845 1.37 drochner if (!vc->vc_fonts[slot])
846 1.37 drochner goto loadit;
847 1.37 drochner }
848 1.37 drochner
849 1.37 drochner /* have to kick out another one */
850 1.37 drochner TAILQ_FOREACH(of, &vc->vc_fontlist, next) {
851 1.37 drochner if (of->slot != -1) {
852 1.37 drochner KASSERT(vc->vc_fonts[of->slot] == of);
853 1.37 drochner slot = of->slot;
854 1.37 drochner of->slot = -1;
855 1.37 drochner goto loadit;
856 1.37 drochner }
857 1.37 drochner }
858 1.54 junyoung panic("vga_usefont");
859 1.37 drochner
860 1.37 drochner loadit:
861 1.52 drochner vga_loadchars(&vc->hdl, slot, f->wsfont->firstchar,
862 1.66 tsutsui f->wsfont->numchars, f->wsfont->fontheight, f->wsfont->data);
863 1.37 drochner f->slot = slot;
864 1.37 drochner vc->vc_fonts[slot] = f;
865 1.37 drochner
866 1.37 drochner toend:
867 1.37 drochner TAILQ_REMOVE(&vc->vc_fontlist, f, next);
868 1.37 drochner TAILQ_INSERT_TAIL(&vc->vc_fontlist, f, next);
869 1.37 drochner }
870 1.37 drochner
871 1.12 drochner static void
872 1.45 junyoung vga_setfont(struct vga_config *vc, struct vgascreen *scr)
873 1.12 drochner {
874 1.12 drochner int fontslot1, fontslot2;
875 1.12 drochner
876 1.37 drochner if (scr->fontset1)
877 1.37 drochner vga_usefont(vc, scr->fontset1);
878 1.37 drochner if (scr->fontset2)
879 1.37 drochner vga_usefont(vc, scr->fontset2);
880 1.37 drochner
881 1.12 drochner fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
882 1.12 drochner fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
883 1.12 drochner if (vc->currentfontset1 != fontslot1 ||
884 1.12 drochner vc->currentfontset2 != fontslot2) {
885 1.12 drochner vga_setfontset(&vc->hdl, fontslot1, fontslot2);
886 1.12 drochner vc->currentfontset1 = fontslot1;
887 1.12 drochner vc->currentfontset2 = fontslot2;
888 1.12 drochner }
889 1.12 drochner }
890 1.12 drochner
891 1.22 drochner int
892 1.45 junyoung vga_show_screen(void *v, void *cookie, int waitok,
893 1.45 junyoung void (*cb)(void *, int, int), void *cbarg)
894 1.1 drochner {
895 1.4 drochner struct vgascreen *scr = cookie, *oldscr;
896 1.1 drochner struct vga_config *vc = scr->cfg;
897 1.22 drochner
898 1.22 drochner oldscr = vc->active; /* can be NULL! */
899 1.22 drochner if (scr == oldscr) {
900 1.22 drochner return (0);
901 1.22 drochner }
902 1.22 drochner
903 1.22 drochner vc->wantedscreen = cookie;
904 1.22 drochner vc->switchcb = cb;
905 1.22 drochner vc->switchcbarg = cbarg;
906 1.22 drochner if (cb) {
907 1.26 thorpej callout_reset(&vc->vc_switch_callout, 0,
908 1.26 thorpej (void(*)(void *))vga_doswitch, vc);
909 1.22 drochner return (EAGAIN);
910 1.22 drochner }
911 1.22 drochner
912 1.22 drochner vga_doswitch(vc);
913 1.22 drochner return (0);
914 1.22 drochner }
915 1.22 drochner
916 1.22 drochner void
917 1.45 junyoung vga_doswitch(struct vga_config *vc)
918 1.22 drochner {
919 1.22 drochner struct vgascreen *scr, *oldscr;
920 1.1 drochner struct vga_handle *vh = &vc->hdl;
921 1.22 drochner const struct wsscreen_descr *type;
922 1.1 drochner
923 1.22 drochner scr = vc->wantedscreen;
924 1.22 drochner if (!scr) {
925 1.22 drochner printf("vga_doswitch: disappeared\n");
926 1.22 drochner (*vc->switchcb)(vc->switchcbarg, EIO, 0);
927 1.22 drochner return;
928 1.22 drochner }
929 1.22 drochner type = scr->pcs.type;
930 1.11 drochner oldscr = vc->active; /* can be NULL! */
931 1.4 drochner #ifdef DIAGNOSTIC
932 1.11 drochner if (oldscr) {
933 1.11 drochner if (!oldscr->pcs.active)
934 1.11 drochner panic("vga_show_screen: not active");
935 1.11 drochner if (oldscr->pcs.type != vc->currenttype)
936 1.11 drochner panic("vga_show_screen: bad type");
937 1.11 drochner }
938 1.4 drochner #endif
939 1.4 drochner if (scr == oldscr) {
940 1.1 drochner return;
941 1.4 drochner }
942 1.4 drochner #ifdef DIAGNOSTIC
943 1.4 drochner if (scr->pcs.active)
944 1.4 drochner panic("vga_show_screen: active");
945 1.4 drochner #endif
946 1.4 drochner
947 1.11 drochner if (oldscr) {
948 1.11 drochner const struct wsscreen_descr *oldtype = oldscr->pcs.type;
949 1.1 drochner
950 1.11 drochner oldscr->pcs.active = 0;
951 1.11 drochner bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
952 1.66 tsutsui oldscr->pcs.dispoffset, oldscr->pcs.mem,
953 1.66 tsutsui oldtype->ncols * oldtype->nrows);
954 1.11 drochner }
955 1.1 drochner
956 1.11 drochner if (vc->currenttype != type) {
957 1.4 drochner vga_setscreentype(vh, type);
958 1.11 drochner vc->currenttype = type;
959 1.11 drochner }
960 1.12 drochner
961 1.12 drochner vga_setfont(vc, scr);
962 1.11 drochner /* XXX swich colours! */
963 1.1 drochner
964 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
965 1.11 drochner if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
966 1.8 drochner vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
967 1.8 drochner vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
968 1.8 drochner }
969 1.8 drochner
970 1.11 drochner bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
971 1.66 tsutsui scr->pcs.dispoffset, scr->pcs.mem, type->ncols * type->nrows);
972 1.11 drochner scr->pcs.active = 1;
973 1.1 drochner
974 1.4 drochner vc->active = scr;
975 1.1 drochner
976 1.4 drochner pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
977 1.66 tsutsui scr->pcs.cursorrow, scr->pcs.cursorcol);
978 1.22 drochner
979 1.22 drochner vc->wantedscreen = 0;
980 1.22 drochner if (vc->switchcb)
981 1.22 drochner (*vc->switchcb)(vc->switchcbarg, 0, 0);
982 1.1 drochner }
983 1.1 drochner
984 1.1 drochner static int
985 1.45 junyoung vga_load_font(void *v, void *cookie, struct wsdisplay_font *data)
986 1.1 drochner {
987 1.12 drochner struct vga_config *vc = v;
988 1.1 drochner struct vgascreen *scr = cookie;
989 1.12 drochner char *name2;
990 1.37 drochner int res;
991 1.12 drochner
992 1.12 drochner if (scr) {
993 1.50 hannken name2 = NULL;
994 1.50 hannken if (data->name) {
995 1.50 hannken name2 = strchr(data->name, ',');
996 1.50 hannken if (name2)
997 1.50 hannken *name2++ = '\0';
998 1.50 hannken }
999 1.12 drochner res = vga_selectfont(vc, scr, data->name, name2);
1000 1.52 drochner if (!res && scr->pcs.active)
1001 1.12 drochner vga_setfont(vc, scr);
1002 1.12 drochner return (res);
1003 1.12 drochner }
1004 1.1 drochner
1005 1.1 drochner return (0);
1006 1.1 drochner }
1007 1.1 drochner
1008 1.3 drochner static int
1009 1.59 junyoung vga_allocattr(void *id, int fg, int bg, int flags, long *attrp)
1010 1.3 drochner {
1011 1.3 drochner struct vgascreen *scr = id;
1012 1.3 drochner struct vga_config *vc = scr->cfg;
1013 1.3 drochner
1014 1.4 drochner if (vc->hdl.vh_mono) {
1015 1.3 drochner if (flags & WSATTR_WSCOLORS)
1016 1.3 drochner return (EINVAL);
1017 1.3 drochner if (flags & WSATTR_REVERSE)
1018 1.3 drochner *attrp = 0x70;
1019 1.3 drochner else
1020 1.3 drochner *attrp = 0x07;
1021 1.3 drochner if (flags & WSATTR_UNDERLINE)
1022 1.3 drochner *attrp |= FG_UNDERLINE;
1023 1.3 drochner if (flags & WSATTR_HILIT)
1024 1.3 drochner *attrp |= FG_INTENSE;
1025 1.3 drochner } else {
1026 1.3 drochner if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
1027 1.3 drochner return (EINVAL);
1028 1.3 drochner if (flags & WSATTR_WSCOLORS)
1029 1.3 drochner *attrp = fgansitopc[fg] | bgansitopc[bg];
1030 1.3 drochner else
1031 1.3 drochner *attrp = 7;
1032 1.3 drochner if (flags & WSATTR_HILIT)
1033 1.3 drochner *attrp += 8;
1034 1.3 drochner }
1035 1.3 drochner if (flags & WSATTR_BLINK)
1036 1.3 drochner *attrp |= FG_BLINK;
1037 1.3 drochner return (0);
1038 1.8 drochner }
1039 1.8 drochner
1040 1.45 junyoung static void
1041 1.45 junyoung vga_copyrows(void *id, int srcrow, int dstrow, int nrows)
1042 1.8 drochner {
1043 1.8 drochner struct vgascreen *scr = id;
1044 1.8 drochner bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
1045 1.8 drochner bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
1046 1.8 drochner int ncols = scr->pcs.type->ncols;
1047 1.8 drochner bus_size_t srcoff, dstoff;
1048 1.8 drochner
1049 1.8 drochner srcoff = srcrow * ncols + 0;
1050 1.8 drochner dstoff = dstrow * ncols + 0;
1051 1.8 drochner
1052 1.8 drochner if (scr->pcs.active) {
1053 1.8 drochner if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
1054 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
1055 1.20 ad int cursoron = scr->pcs.cursoron;
1056 1.20 ad
1057 1.21 mycroft if (cursoron)
1058 1.21 mycroft pcdisplay_cursor(&scr->pcs, 0,
1059 1.60 junyoung scr->pcs.cursorrow, scr->pcs.cursorcol);
1060 1.18 ad #endif
1061 1.8 drochner /* scroll up whole screen */
1062 1.8 drochner if ((scr->pcs.dispoffset + srcrow * ncols * 2)
1063 1.8 drochner <= scr->maxdispoffset) {
1064 1.8 drochner scr->pcs.dispoffset += srcrow * ncols * 2;
1065 1.8 drochner } else {
1066 1.8 drochner bus_space_copy_region_2(memt, memh,
1067 1.66 tsutsui scr->pcs.dispoffset + srcoff * 2,
1068 1.66 tsutsui memh, scr->mindispoffset, nrows * ncols);
1069 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
1070 1.8 drochner }
1071 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrh,
1072 1.66 tsutsui scr->pcs.dispoffset >> 9);
1073 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrl,
1074 1.66 tsutsui scr->pcs.dispoffset >> 1);
1075 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
1076 1.21 mycroft if (cursoron)
1077 1.21 mycroft pcdisplay_cursor(&scr->pcs, 1,
1078 1.60 junyoung scr->pcs.cursorrow, scr->pcs.cursorcol);
1079 1.18 ad #endif
1080 1.8 drochner } else {
1081 1.8 drochner bus_space_copy_region_2(memt, memh,
1082 1.66 tsutsui scr->pcs.dispoffset + srcoff * 2,
1083 1.66 tsutsui memh, scr->pcs.dispoffset + dstoff * 2,
1084 1.66 tsutsui nrows * ncols);
1085 1.8 drochner }
1086 1.8 drochner } else
1087 1.36 thorpej memcpy(&scr->pcs.mem[dstoff], &scr->pcs.mem[srcoff],
1088 1.66 tsutsui nrows * ncols * 2);
1089 1.12 drochner }
1090 1.12 drochner
1091 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
1092 1.12 drochner
1093 1.12 drochner #define NOTYET 0xffff
1094 1.35 jdolecek static const u_int16_t pcvt_unichars[0xa0] = {
1095 1.44 bjh21 /* 0 */ _e006U, /* N/L control */
1096 1.14 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1097 1.12 drochner NOTYET,
1098 1.12 drochner 0x2409, /* SYMBOL FOR HORIZONTAL TABULATION */
1099 1.12 drochner 0x240a, /* SYMBOL FOR LINE FEED */
1100 1.12 drochner 0x240b, /* SYMBOL FOR VERTICAL TABULATION */
1101 1.12 drochner 0x240c, /* SYMBOL FOR FORM FEED */
1102 1.12 drochner 0x240d, /* SYMBOL FOR CARRIAGE RETURN */
1103 1.12 drochner NOTYET, NOTYET,
1104 1.14 drochner /* 1 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1105 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1106 1.12 drochner /* 2 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1107 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1108 1.14 drochner /* 3 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1109 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1110 1.12 drochner /* 4 */ 0x03c1, /* GREEK SMALL LETTER RHO */
1111 1.12 drochner 0x03c8, /* GREEK SMALL LETTER PSI */
1112 1.12 drochner 0x2202, /* PARTIAL DIFFERENTIAL */
1113 1.12 drochner 0x03bb, /* GREEK SMALL LETTER LAMDA */
1114 1.12 drochner 0x03b9, /* GREEK SMALL LETTER IOTA */
1115 1.12 drochner 0x03b7, /* GREEK SMALL LETTER ETA */
1116 1.12 drochner 0x03b5, /* GREEK SMALL LETTER EPSILON */
1117 1.12 drochner 0x03c7, /* GREEK SMALL LETTER CHI */
1118 1.12 drochner 0x2228, /* LOGICAL OR */
1119 1.12 drochner 0x2227, /* LOGICAL AND */
1120 1.12 drochner 0x222a, /* UNION */
1121 1.12 drochner 0x2283, /* SUPERSET OF */
1122 1.12 drochner 0x2282, /* SUBSET OF */
1123 1.12 drochner 0x03a5, /* GREEK CAPITAL LETTER UPSILON */
1124 1.12 drochner 0x039e, /* GREEK CAPITAL LETTER XI */
1125 1.12 drochner 0x03a8, /* GREEK CAPITAL LETTER PSI */
1126 1.14 drochner /* 5 */ 0x03a0, /* GREEK CAPITAL LETTER PI */
1127 1.12 drochner 0x21d2, /* RIGHTWARDS DOUBLE ARROW */
1128 1.12 drochner 0x21d4, /* LEFT RIGHT DOUBLE ARROW */
1129 1.12 drochner 0x039b, /* GREEK CAPITAL LETTER LAMDA */
1130 1.12 drochner 0x0398, /* GREEK CAPITAL LETTER THETA */
1131 1.12 drochner 0x2243, /* ASYMPTOTICALLY EQUAL TO */
1132 1.12 drochner 0x2207, /* NABLA */
1133 1.12 drochner 0x2206, /* INCREMENT */
1134 1.12 drochner 0x221d, /* PROPORTIONAL TO */
1135 1.12 drochner 0x2234, /* THEREFORE */
1136 1.12 drochner 0x222b, /* INTEGRAL */
1137 1.12 drochner 0x2215, /* DIVISION SLASH */
1138 1.12 drochner 0x2216, /* SET MINUS */
1139 1.44 bjh21 _e00eU, /* angle? */
1140 1.44 bjh21 _e00dU, /* inverted angle? */
1141 1.44 bjh21 _e00bU, /* braceleftmid */
1142 1.44 bjh21 /* 6 */ _e00cU, /* bracerightmid */
1143 1.44 bjh21 _e007U, /* bracelefttp */
1144 1.44 bjh21 _e008U, /* braceleftbt */
1145 1.44 bjh21 _e009U, /* bracerighttp */
1146 1.44 bjh21 _e00aU, /* bracerightbt */
1147 1.12 drochner 0x221a, /* SQUARE ROOT */
1148 1.12 drochner 0x03c9, /* GREEK SMALL LETTER OMEGA */
1149 1.12 drochner 0x00a5, /* YEN SIGN */
1150 1.12 drochner 0x03be, /* GREEK SMALL LETTER XI */
1151 1.12 drochner 0x00fd, /* LATIN SMALL LETTER Y WITH ACUTE */
1152 1.12 drochner 0x00fe, /* LATIN SMALL LETTER THORN */
1153 1.12 drochner 0x00f0, /* LATIN SMALL LETTER ETH */
1154 1.12 drochner 0x00de, /* LATIN CAPITAL LETTER THORN */
1155 1.12 drochner 0x00dd, /* LATIN CAPITAL LETTER Y WITH ACUTE */
1156 1.12 drochner 0x00d7, /* MULTIPLICATION SIGN */
1157 1.12 drochner 0x00d0, /* LATIN CAPITAL LETTER ETH */
1158 1.14 drochner /* 7 */ 0x00be, /* VULGAR FRACTION THREE QUARTERS */
1159 1.12 drochner 0x00b8, /* CEDILLA */
1160 1.12 drochner 0x00b4, /* ACUTE ACCENT */
1161 1.12 drochner 0x00af, /* MACRON */
1162 1.12 drochner 0x00ae, /* REGISTERED SIGN */
1163 1.12 drochner 0x00ad, /* SOFT HYPHEN */
1164 1.12 drochner 0x00ac, /* NOT SIGN */
1165 1.12 drochner 0x00a8, /* DIAERESIS */
1166 1.12 drochner 0x2260, /* NOT EQUAL TO */
1167 1.44 bjh21 _e005U, /* scan 9 */
1168 1.44 bjh21 _e004U, /* scan 7 */
1169 1.44 bjh21 _e003U, /* scan 5 */
1170 1.44 bjh21 _e002U, /* scan 3 */
1171 1.44 bjh21 _e001U, /* scan 1 */
1172 1.12 drochner 0x03c5, /* GREEK SMALL LETTER UPSILON */
1173 1.12 drochner 0x00f8, /* LATIN SMALL LETTER O WITH STROKE */
1174 1.12 drochner /* 8 */ 0x0153, /* LATIN SMALL LIGATURE OE */
1175 1.12 drochner 0x00f5, /* LATIN SMALL LETTER O WITH TILDE !!!doc bug */
1176 1.12 drochner 0x00e3, /* LATIN SMALL LETTER A WITH TILDE */
1177 1.12 drochner 0x0178, /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
1178 1.12 drochner 0x00db, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
1179 1.12 drochner 0x00da, /* LATIN CAPITAL LETTER U WITH ACUTE */
1180 1.12 drochner 0x00d9, /* LATIN CAPITAL LETTER U WITH GRAVE */
1181 1.12 drochner 0x00d8, /* LATIN CAPITAL LETTER O WITH STROKE */
1182 1.12 drochner 0x0152, /* LATIN CAPITAL LIGATURE OE */
1183 1.12 drochner 0x00d5, /* LATIN CAPITAL LETTER O WITH TILDE */
1184 1.12 drochner 0x00d4, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
1185 1.12 drochner 0x00d3, /* LATIN CAPITAL LETTER O WITH ACUTE */
1186 1.12 drochner 0x00d2, /* LATIN CAPITAL LETTER O WITH GRAVE */
1187 1.12 drochner 0x00cf, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
1188 1.12 drochner 0x00ce, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
1189 1.12 drochner 0x00cd, /* LATIN CAPITAL LETTER I WITH ACUTE */
1190 1.14 drochner /* 9 */ 0x00cc, /* LATIN CAPITAL LETTER I WITH GRAVE */
1191 1.12 drochner 0x00cb, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
1192 1.12 drochner 0x00ca, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
1193 1.12 drochner 0x00c8, /* LATIN CAPITAL LETTER E WITH GRAVE */
1194 1.12 drochner 0x00c3, /* LATIN CAPITAL LETTER A WITH TILDE */
1195 1.12 drochner 0x00c2, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
1196 1.12 drochner 0x00c1, /* LATIN CAPITAL LETTER A WITH ACUTE */
1197 1.12 drochner 0x00c0, /* LATIN CAPITAL LETTER A WITH GRAVE */
1198 1.12 drochner 0x00b9, /* SUPERSCRIPT ONE */
1199 1.12 drochner 0x00b7, /* MIDDLE DOT */
1200 1.12 drochner 0x03b6, /* GREEK SMALL LETTER ZETA */
1201 1.12 drochner 0x00b3, /* SUPERSCRIPT THREE */
1202 1.12 drochner 0x00a9, /* COPYRIGHT SIGN */
1203 1.12 drochner 0x00a4, /* CURRENCY SIGN */
1204 1.12 drochner 0x03ba, /* GREEK SMALL LETTER KAPPA */
1205 1.44 bjh21 _e000U /* mirrored question mark? */
1206 1.12 drochner };
1207 1.12 drochner
1208 1.45 junyoung static int vga_pcvt_mapchar(int, u_int *);
1209 1.12 drochner
1210 1.12 drochner static int
1211 1.45 junyoung vga_pcvt_mapchar(int uni, u_int *index)
1212 1.12 drochner {
1213 1.12 drochner int i;
1214 1.12 drochner
1215 1.12 drochner for (i = 0; i < 0xa0; i++) /* 0xa0..0xff are reserved */
1216 1.13 drochner if (uni == pcvt_unichars[i]) {
1217 1.13 drochner *index = i;
1218 1.13 drochner return (5);
1219 1.13 drochner }
1220 1.13 drochner *index = 0x99; /* middle dot */
1221 1.13 drochner return (0);
1222 1.12 drochner }
1223 1.12 drochner
1224 1.12 drochner #endif /* WSCONS_SUPPORT_PCVTFONTS */
1225 1.12 drochner
1226 1.34 drochner #ifdef WSCONS_SUPPORT_ISO7FONTS
1227 1.34 drochner
1228 1.34 drochner static int
1229 1.45 junyoung vga_iso7_mapchar(int uni, u_int *index)
1230 1.34 drochner {
1231 1.34 drochner
1232 1.34 drochner /*
1233 1.34 drochner * U+0384 (GREEK TONOS) to
1234 1.34 drochner * U+03ce (GREEK SMALL LETTER OMEGA WITH TONOS)
1235 1.34 drochner * map directly to the iso-9 font
1236 1.34 drochner */
1237 1.34 drochner if (uni >= 0x0384 && uni <= 0x03ce) {
1238 1.34 drochner /* U+0384 is at offset 0xb4 in the font */
1239 1.34 drochner *index = uni - 0x0384 + 0xb4;
1240 1.34 drochner return (5);
1241 1.34 drochner }
1242 1.34 drochner
1243 1.34 drochner /* XXX more chars in the iso-9 font */
1244 1.34 drochner
1245 1.34 drochner *index = 0xa4; /* shaded rectangle */
1246 1.34 drochner return (0);
1247 1.34 drochner }
1248 1.34 drochner
1249 1.34 drochner #endif /* WSCONS_SUPPORT_ISO7FONTS */
1250 1.34 drochner
1251 1.45 junyoung static int _vga_mapchar(void *, const struct egavga_font *, int, u_int *);
1252 1.12 drochner
1253 1.12 drochner static int
1254 1.45 junyoung _vga_mapchar(void *id, const struct egavga_font *font, int uni, u_int *index)
1255 1.12 drochner {
1256 1.12 drochner
1257 1.37 drochner switch (font->wsfont->encoding) {
1258 1.12 drochner case WSDISPLAY_FONTENC_ISO:
1259 1.13 drochner if (uni < 256) {
1260 1.13 drochner *index = uni;
1261 1.13 drochner return (5);
1262 1.13 drochner } else {
1263 1.13 drochner *index = ' ';
1264 1.13 drochner return (0);
1265 1.13 drochner }
1266 1.12 drochner case WSDISPLAY_FONTENC_IBM:
1267 1.13 drochner return (pcdisplay_mapchar(id, uni, index));
1268 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
1269 1.12 drochner case WSDISPLAY_FONTENC_PCVT:
1270 1.13 drochner return (vga_pcvt_mapchar(uni, index));
1271 1.34 drochner #endif
1272 1.34 drochner #ifdef WSCONS_SUPPORT_ISO7FONTS
1273 1.34 drochner case WSDISPLAY_FONTENC_ISO7:
1274 1.34 drochner return (vga_iso7_mapchar(uni, index));
1275 1.12 drochner #endif
1276 1.13 drochner default:
1277 1.16 drochner #ifdef VGAFONTDEBUG
1278 1.37 drochner printf("_vga_mapchar: encoding=%d\n", font->wsfont->encoding);
1279 1.16 drochner #endif
1280 1.13 drochner *index = ' ';
1281 1.13 drochner return (0);
1282 1.12 drochner }
1283 1.12 drochner }
1284 1.12 drochner
1285 1.13 drochner static int
1286 1.45 junyoung vga_mapchar(void *id, int uni, u_int *index)
1287 1.12 drochner {
1288 1.12 drochner struct vgascreen *scr = id;
1289 1.45 junyoung u_int idx1, idx2;
1290 1.13 drochner int res1, res2;
1291 1.12 drochner
1292 1.13 drochner res1 = 0;
1293 1.13 drochner idx1 = ' '; /* space */
1294 1.13 drochner if (scr->fontset1)
1295 1.13 drochner res1 = _vga_mapchar(id, scr->fontset1, uni, &idx1);
1296 1.13 drochner res2 = -1;
1297 1.12 drochner if (scr->fontset2) {
1298 1.12 drochner KASSERT(VGA_SCREEN_CANTWOFONTS(scr->pcs.type));
1299 1.13 drochner res2 = _vga_mapchar(id, scr->fontset2, uni, &idx2);
1300 1.12 drochner }
1301 1.13 drochner if (res2 > res1) {
1302 1.14 drochner *index = idx2 | 0x0800; /* attribute bit 3 */
1303 1.14 drochner return (res2);
1304 1.13 drochner }
1305 1.13 drochner *index = idx1;
1306 1.13 drochner return (res1);
1307 1.53 christos }
1308 1.53 christos
1309 1.57 christos #ifdef WSDISPLAY_CHARFUNCS
1310 1.53 christos int
1311 1.53 christos vga_getwschar(void *cookie, struct wsdisplay_char *wschar)
1312 1.53 christos {
1313 1.53 christos struct vgascreen *scr = cookie;
1314 1.53 christos
1315 1.53 christos if (scr == NULL) return 0;
1316 1.53 christos return (pcdisplay_getwschar(&scr->pcs, wschar));
1317 1.53 christos }
1318 1.53 christos
1319 1.53 christos int
1320 1.53 christos vga_putwschar(void *cookie, struct wsdisplay_char *wschar)
1321 1.53 christos {
1322 1.53 christos struct vgascreen *scr = cookie;
1323 1.53 christos
1324 1.53 christos if (scr == NULL) return 0;
1325 1.53 christos return (pcdisplay_putwschar(&scr->pcs, wschar));
1326 1.1 drochner }
1327 1.57 christos #endif /* WSDISPLAY_CHARFUNCS */
1328