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