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