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