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