Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.6
      1 /*	$NetBSD: ite_et.c,v 1.6 1997/07/09 14:38:02 leo Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Leo Weppelman.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Leo Weppelman.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/conf.h>
     35 #include <sys/ioctl.h>
     36 #include <sys/malloc.h>
     37 #include <sys/device.h>
     38 #include <dev/cons.h>
     39 
     40 #include <machine/cpu.h>
     41 
     42 #include <atari/atari/device.h>
     43 
     44 #include <atari/dev/itevar.h>
     45 #include <atari/dev/iteioctl.h>
     46 #include <atari/dev/grfioctl.h>
     47 #include <atari/dev/grf_etreg.h>
     48 #include <atari/dev/grfabs_reg.h>
     49 #include <atari/dev/grfabs_et.h>
     50 #include <atari/dev/grfvar.h>
     51 #include <atari/dev/font.h>
     52 #include <atari/dev/viewioctl.h>
     53 #include <atari/dev/viewvar.h>
     54 
     55 #include "grfet.h"
     56 
     57 /*
     58  * This is what ip->priv points to;
     59  * it contains local variables for custom-chip ites.
     60  */
     61 struct ite_priv {
     62 	volatile u_char	*regkva;
     63 };
     64 
     65 typedef struct ite_priv ipriv_t;
     66 
     67 static ipriv_t	con_ipriv;
     68 
     69 /* Console colors */
     70 static u_char etconscolors[3][3] = {	/* background, foreground, hilite */
     71 	{0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f,  0x3f,  0x3f}
     72 };
     73 
     74 /* XXX: Shouldn't these be in font.h???? */
     75 extern font_info	font_info_8x8;
     76 extern font_info	font_info_8x16;
     77 
     78 static void grfet_iteinit __P((struct grf_softc *));
     79 static void view_init __P((struct ite_softc *));
     80 static void view_deinit __P((struct ite_softc *));
     81 static int  iteet_ioctl __P((struct ite_softc *, u_long, caddr_t, int,
     82 							struct proc *));
     83 static int  ite_newsize __P((struct ite_softc *, struct itewinsize *));
     84 static void et_inittextmode __P((struct ite_softc *, et_sv_reg_t *, int));
     85 void et_cursor __P((struct ite_softc *ip, int flag));
     86 void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
     87 void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
     88 void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
     89     int dir));
     90 
     91 /* XXX: move to ite.c */
     92 extern int ite_default_x;
     93 extern int ite_default_y;
     94 extern int ite_default_width;
     95 extern int ite_default_depth;
     96 extern int ite_default_height;
     97 
     98 /*
     99  * grfet config stuff
    100  */
    101 void grfetattach __P((struct device *, struct device *, void *));
    102 int  grfetmatch __P((struct device *, struct cfdata *, void *));
    103 int  grfetprint __P((void *, const char *));
    104 
    105 struct cfattach grfet_ca = {
    106 	sizeof(struct grf_softc), grfetmatch, grfetattach
    107 };
    108 
    109 struct cfdriver grfet_cd = {
    110 	NULL, "grfet", DV_DULL
    111 };
    112 
    113 /*
    114  * only used in console init.
    115  */
    116 static struct cfdata *cfdata_grf   = NULL;
    117 
    118 int
    119 grfetmatch(pdp, cfp, auxp)
    120 struct device	*pdp;
    121 struct cfdata	*cfp;
    122 void		*auxp;
    123 {
    124 	static int	card_probed = -1;
    125 	grf_auxp_t	*grf_auxp = auxp;
    126 
    127 	if (card_probed <= 0) {
    128 		if (card_probed == 0) /* Probed but failed */
    129 			return 0;
    130 		card_probed = 0;
    131 
    132 		/*
    133 		 * Check if the layers we depend on exist
    134 		 */
    135 		if(!(machineid & ATARI_HADES))
    136 			return 0;
    137 		if (!et_probe_card())
    138 			return 0;
    139 		if (grfabs_probe(&et_probe_video) == 0)
    140 			return 0;
    141 		viewprobe();
    142 		card_probed = 1; /* Probed and found */
    143 	}
    144 
    145 	if (atari_realconfig == 0) {
    146 		/*
    147 		 * Early console init. Only match unit 0.
    148 		 */
    149 		if (cfp->cf_unit != 0)
    150 			return 0;
    151 		if (viewopen(0, 0, 0, NULL))
    152 			return 0;
    153 		cfdata_grf = cfp;
    154 		return 1;
    155 	}
    156 
    157 	/*
    158 	 * Normal config. When we are called directly from the grfbus,
    159 	 * we only match unit 0. The attach function will call us for
    160 	 * the other configured units.
    161 	 */
    162 	if (grf_auxp->from_bus_match
    163 	    && ((cfp->cf_unit != 0) || !et_probe_card()))
    164 		return 0;
    165 
    166 	if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
    167 		return 0;
    168 
    169 	/*
    170 	 * Final constraint: each grf needs a view....
    171 	 */
    172 	if((cfdata_grf == NULL) || (cfp->cf_unit != 0)) {
    173 	    if(viewopen(cfp->cf_unit, 0, 0, NULL))
    174 		return 0;
    175 	}
    176 	return 1;
    177 }
    178 
    179 /*
    180  * attach: initialize the grf-structure and try to attach an ite to us.
    181  * note  : dp is NULL during early console init.
    182  */
    183 void
    184 grfetattach(pdp, dp, auxp)
    185 struct device	*pdp, *dp;
    186 void		*auxp;
    187 {
    188 	static struct grf_softc		congrf;
    189 	       grf_auxp_t		*grf_bus_auxp = auxp;
    190 	       grf_auxp_t		grf_auxp;
    191 	       struct grf_softc		*gp;
    192 	       int			maj;
    193 
    194 	/*
    195 	 * find our major device number
    196 	 */
    197 	for(maj = 0; maj < nchrdev; maj++)
    198 		if (cdevsw[maj].d_open == grfopen)
    199 			break;
    200 
    201 	/*
    202 	 * Handle exeption case: early console init
    203 	 */
    204 	if(dp == NULL) {
    205 		congrf.g_unit    = 0;
    206 		congrf.g_grfdev  = makedev(maj, 0);
    207 		congrf.g_itedev  = (dev_t)-1;
    208 		congrf.g_flags   = GF_ALIVE;
    209 		congrf.g_mode    = grf_mode;
    210 		congrf.g_conpri  = CN_INTERNAL;
    211 		congrf.g_viewdev = congrf.g_unit;
    212 		grfet_iteinit(&congrf);
    213 		grf_viewsync(&congrf);
    214 
    215 		/* Attach console ite */
    216 		atari_config_found(cfdata_grf, NULL, &congrf, grfetprint);
    217 		return;
    218 	}
    219 
    220 	gp = (struct grf_softc *)dp;
    221 	gp->g_unit = gp->g_device.dv_unit;
    222 	grfsp[gp->g_unit] = gp;
    223 
    224 	if((cfdata_grf != NULL) && (gp->g_unit == 0)) {
    225 		/*
    226 		 * We inited earlier just copy the info, take care
    227 		 * not to copy the device struct though.
    228 		 */
    229 		bcopy(&congrf.g_display, &gp->g_display,
    230 			(char *)&gp[1] - (char *)&gp->g_display);
    231 	}
    232 	else {
    233 		gp->g_grfdev  = makedev(maj, gp->g_unit);
    234 		gp->g_itedev  = (dev_t)-1;
    235 		gp->g_flags   = GF_ALIVE;
    236 		gp->g_mode    = grf_mode;
    237 		gp->g_conpri  = 0;
    238 		gp->g_viewdev = gp->g_unit;
    239 		grfet_iteinit(gp);
    240 		grf_viewsync(gp);
    241 	}
    242 
    243 	printf(": %dx%d", gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
    244 	if(gp->g_display.gd_colors == 2)
    245 		printf(" monochrome\n");
    246 	else printf(" colors %d\n", gp->g_display.gd_colors);
    247 
    248 	/*
    249 	 * try and attach an ite
    250 	 */
    251 	config_found(dp, gp, grfetprint);
    252 
    253 	/*
    254 	 * If attaching unit 0, go ahead and 'find' the rest of us
    255 	 */
    256 	if (gp->g_unit == 0) {
    257 		grf_auxp.from_bus_match = 0;
    258 		for (grf_auxp.unit=0; grf_auxp.unit < NGRFET; grf_auxp.unit++) {
    259 		    config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
    260 		}
    261 	}
    262 }
    263 
    264 int
    265 grfetprint(auxp, pnp)
    266 void *auxp;
    267 const char *pnp;
    268 {
    269 	if(pnp) /* XXX */
    270 		printf("ite at %s", pnp);
    271 	return(UNCONF);
    272 }
    273 
    274 /*
    275  * Init ite portion of grf_softc struct
    276  */
    277 static void
    278 grfet_iteinit(gp)
    279 struct grf_softc *gp;
    280 {
    281 
    282 	gp->g_itecursor = et_cursor;
    283 	gp->g_iteputc   = et_putc;
    284 	gp->g_iteclear  = et_clear;
    285 	gp->g_itescroll = et_scroll;
    286 	gp->g_iteinit   = view_init;
    287 	gp->g_itedeinit = view_deinit;
    288 }
    289 
    290 static void
    291 view_deinit(ip)
    292 struct ite_softc	*ip;
    293 {
    294 	ip->flags &= ~ITE_INITED;
    295 }
    296 
    297 static void
    298 view_init(ip)
    299 register struct ite_softc *ip;
    300 {
    301 	struct itewinsize	wsz;
    302 	ipriv_t			*cci;
    303 	view_t			*view;
    304 	save_area_t		*et_save;
    305 
    306 	if((cci = ip->priv) != NULL)
    307 		return;
    308 
    309 	ip->itexx_ioctl = iteet_ioctl;
    310 
    311 #if defined(KFONT_8X8)
    312 	ip->font = font_info_8x8;
    313 #else
    314 	ip->font = font_info_8x16;
    315 #endif
    316 
    317 	/* Find the correct set of rendering routines for this font.  */
    318 	if(ip->font.width != 8)
    319 		panic("kernel font size not supported");
    320 
    321 	if(!atari_realconfig)
    322 		ip->priv = cci = &con_ipriv;
    323 	else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
    324 	if(cci == NULL)
    325 		panic("No memory for ite-view");
    326 	bzero(cci, sizeof(*cci));
    327 
    328 	wsz.x      = ite_default_x;
    329 	wsz.y      = ite_default_y;
    330 	wsz.width  = ite_default_width;
    331 	wsz.height = ite_default_height;
    332 	wsz.depth  = ite_default_depth;
    333 
    334 	ite_newsize (ip, &wsz);
    335 
    336 	view  = viewview(ip->grf->g_viewdev);
    337 	cci->regkva = view->bitmap->regs;
    338 
    339 	/*
    340 	 * Only console will be turned on by default..
    341 	 */
    342 	if(ip->flags & ITE_ISCONS)
    343 		ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
    344 
    345 	/*
    346 	 * Activate text-mode settings
    347 	 */
    348 	et_save = (save_area_t *)view->save_area;
    349 	if (et_save == NULL)
    350 		et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    351 	else {
    352 		et_inittextmode(ip, &et_save->sv_regs, view->flags&VF_DISPLAY);
    353 		et_save->fb_size = ip->cols * ip->rows;
    354 	}
    355 }
    356 
    357 static int
    358 ite_newsize(ip, winsz)
    359 struct ite_softc	*ip;
    360 struct itewinsize	*winsz;
    361 {
    362 	struct view_size	vs;
    363 	int			error = 0;
    364 	save_area_t		*et_save;
    365 	view_t			*view;
    366 
    367 	vs.x      = winsz->x;
    368 	vs.y      = winsz->y;
    369 	vs.width  = winsz->width;
    370 	vs.height = winsz->height;
    371 	vs.depth  = winsz->depth;
    372 
    373 	error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, (caddr_t)&vs, 0,
    374 								NOPROC);
    375 	view  = viewview(ip->grf->g_viewdev);
    376 
    377 	/*
    378 	 * Reinitialize our structs
    379 	 */
    380 	ip->cols = view->display.width  / ip->font.width;
    381 	ip->rows = view->display.height / ip->font.height;
    382 
    383 	/*
    384 	 * save new values so that future opens use them
    385 	 * this may not be correct when we implement Virtual Consoles
    386 	 */
    387 	ite_default_height = view->display.height;
    388 	ite_default_width  = view->display.width;
    389 	ite_default_x      = view->display.x;
    390 	ite_default_y      = view->display.y;
    391 	ite_default_depth  = view->bitmap->depth;
    392 
    393 	et_save = (save_area_t *)view->save_area;
    394 	if (et_save == NULL)
    395 	    et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    396 	else {
    397 	    et_inittextmode(ip, &et_save->sv_regs, view->flags & VF_DISPLAY);
    398 	    et_save->fb_size = ip->cols * ip->rows;
    399 	}
    400 	et_clear(ip, 0, 0, ip->rows, ip->cols);
    401 
    402 	return(error);
    403 }
    404 
    405 int
    406 iteet_ioctl(ip, cmd, addr, flag, p)
    407 struct ite_softc	*ip;
    408 u_long			cmd;
    409 caddr_t			addr;
    410 int			flag;
    411 struct proc		*p;
    412 {
    413 	struct winsize		ws;
    414 	struct itewinsize	*is;
    415 	int			error = 0;
    416 	view_t			*view = viewview(ip->grf->g_viewdev);
    417 #if 0 /* LWP: notyet */
    418 	struct itebell		*ib;
    419 #endif
    420 
    421 	switch (cmd) {
    422 	case ITEIOCSWINSZ:
    423 		is = (struct itewinsize *)addr;
    424 
    425 		if(ite_newsize(ip, is))
    426 			error = ENOMEM;
    427 		else {
    428 			view         = viewview(ip->grf->g_viewdev);
    429 			ws.ws_row    = ip->rows;
    430 			ws.ws_col    = ip->cols;
    431 			ws.ws_xpixel = view->display.width;
    432 			ws.ws_ypixel = view->display.height;
    433 			ite_reset(ip);
    434 			/*
    435 			 * XXX tell tty about the change
    436 			 * XXX this is messy, but works
    437 			 */
    438 			iteioctl(ip->grf->g_itedev,TIOCSWINSZ,(caddr_t)&ws,0,p);
    439 		}
    440 		break;
    441 	case ITEIOCGBELL:
    442 #if 0 /* LWP */
    443 		/* XXX This won't work now			*/
    444 		/* XXX Should the bell be device dependent?	*/
    445 		ib         = (struct itebell *)addr;
    446 		ib->volume = bvolume;
    447 		ib->pitch  = bpitch;
    448 		ib->msec   = bmsec;
    449 #endif
    450 		break;
    451 	case ITEIOCSBELL:
    452 #if 0 /* LWP */
    453 		/* XXX See above				*/
    454 		ib = (struct itebell *)addr;
    455 		/* bounds check */
    456 		if(ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH ||
    457 		    ib->volume > MAXBVOLUME || ib->msec > MAXBTIME)
    458 			error = EINVAL;
    459 		else {
    460 			bvolume = ib->volume;
    461 			bpitch  = ib->pitch;
    462 			bmsec   = ib->msec;
    463 		}
    464 #endif
    465 		break;
    466 	case VIOCSCMAP:
    467 	case VIOCGCMAP:
    468 		/*
    469 		 * XXX watchout for that NOPROC. its not really the kernel
    470 		 * XXX talking these two commands don't use the proc pointer
    471 		 * XXX though.
    472 		 */
    473 		error = viewioctl(ip->grf->g_viewdev, cmd, addr, flag, NOPROC);
    474 		break;
    475 	default:
    476 		error = -1;
    477 		break;
    478 	}
    479 	return (error);
    480 }
    481 
    482 void
    483 et_cursor(ip, flag)
    484 	struct ite_softc *ip;
    485 	int flag;
    486 {
    487 	volatile u_char	*ba;
    488 		 view_t	*v;
    489 		 u_long cpos;
    490 
    491 	ba = ((ipriv_t*)ip->priv)->regkva;
    492 	v  = viewview(ip->grf->g_viewdev);
    493 
    494 	/*
    495 	 * Don't update the cursor when not on display
    496 	 */
    497 	if (!(v->flags & VF_DISPLAY))
    498 		return;
    499 
    500 	switch (flag) {
    501  	    case DRAW_CURSOR:
    502 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    503 	    case MOVE_CURSOR:
    504 		cpos  =  RCrt(ba, CRT_ID_START_ADDR_LOW) & 0xff;
    505 		cpos |= (RCrt(ba, CRT_ID_START_ADDR_HIGH) & 0xff) << 8;
    506 		cpos += ip->curx + ip->cury * ip->cols;
    507 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, cpos & 0xff);
    508 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (cpos >> 8) & 0xff);
    509 		WCrt(ba, CTR_ID_EXT_START, (cpos >> (16-2)) & 0x0c);
    510 
    511 		ip->cursorx = ip->curx;
    512 		ip->cursory = ip->cury;
    513 		break;
    514 	    case ERASE_CURSOR:
    515 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    516 	    case START_CURSOROPT:
    517 	    case END_CURSOROPT:
    518 	    default:
    519 		break;
    520     	}
    521 }
    522 
    523 void
    524 et_putc(ip, c, dy, dx, mode)
    525 	struct ite_softc *ip;
    526 	int c;
    527 	int dy;
    528 	int dx;
    529 	int mode;
    530 {
    531 	view_t	*v   = viewview(ip->grf->g_viewdev);
    532 	u_char	attr;
    533 	u_short	*cp;
    534 
    535 	attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    536 	if (mode & ATTR_UL)     attr |= 0x01;
    537 	if (mode & ATTR_BOLD)   attr |= 0x08;
    538 	if (mode & ATTR_BLINK)  attr |= 0x80;
    539 
    540 	cp  = (u_short*)v->bitmap->plane;
    541 	cp[(dy * ip->cols) + dx] = (c << 8) | attr;
    542 }
    543 
    544 void
    545 et_clear(ip, sy, sx, h, w)
    546 	struct ite_softc *ip;
    547 	int sy;
    548 	int sx;
    549 	int h;
    550 	int w;
    551 {
    552 	/* cl_clear and cl_scroll both rely on ite passing arguments
    553 	 * which describe continuous regions.  For a VT200 terminal,
    554 	 * this is safe behavior.
    555 	 */
    556 	view_t		*v   = viewview(ip->grf->g_viewdev);
    557 	u_short		*dest;
    558 	int		len;
    559 
    560 	dest = (u_short *)v->bitmap->plane + (sy * ip->cols) + sx;
    561 	for(len = w * h; len-- ;)
    562 		*dest++ = 0x2007;
    563 }
    564 
    565 void
    566 et_scroll(ip, sy, sx, count, dir)
    567 	struct ite_softc *ip;
    568 	int	sy;
    569 	int	sx;
    570 	int	count;
    571 	int	dir;
    572 {
    573 	view_t	*v   = viewview(ip->grf->g_viewdev);
    574 	u_short	*fb;
    575 	u_short	*src, *dst;
    576 	int	len;
    577 
    578 	fb = (u_short*)v->bitmap->plane + sy * ip->cols;
    579 	switch (dir) {
    580 	    case SCROLL_UP:
    581 			src = fb;
    582 			dst = fb - count * ip->cols;
    583 			len = (ip->bottom_margin + 1 - sy) * ip->cols;
    584 			break;
    585 	    case SCROLL_DOWN:
    586 			src = fb;
    587 			dst = fb + count * ip->cols;
    588 			len = (ip->bottom_margin + 1 - (sy + count)) * ip->cols;
    589 			break;
    590 	    case SCROLL_RIGHT:
    591 			src = fb + sx;
    592 			dst = fb + sx + count;
    593 			len = ip->cols - sx + count;
    594 			break;
    595 	    case SCROLL_LEFT:
    596 			src = fb + sx;
    597 			dst = fb + sx - count;
    598 			len = ip->cols - sx;
    599 			break;
    600 	    default:
    601 			return;
    602 	}
    603 	if (src > dst) {
    604 		while (len--)
    605 			*dst++ = *src++;
    606 	}
    607 	else {
    608 		src = &src[len];
    609 		dst = &dst[len];
    610 		while (len--)
    611 			*--dst = *--src;
    612 	}
    613 }
    614 
    615 static void
    616 et_inittextmode(ip, etregs, loadfont)
    617 	struct ite_softc *ip;
    618 	et_sv_reg_t	 *etregs;
    619 	int		 loadfont;
    620 {
    621 	volatile u_char *ba;
    622 	font_info	*fd;
    623 	u_char		*fb;
    624 	u_char		*c, *f, tmp;
    625 	u_short		z, y;
    626 	int		s;
    627 	view_t		*v   = viewview(ip->grf->g_viewdev);
    628 	et_sv_reg_t	loc_regs;
    629 
    630 	if (etregs == NULL) {
    631 		etregs = &loc_regs;
    632 		et_hwsave(etregs);
    633 	}
    634 
    635 	ba = ((ipriv_t*)ip->priv)->regkva;
    636 	fb = v->bitmap->plane;
    637 
    638 #if defined(KFONT_8X8)
    639 	fd = &font_info_8x8;
    640 #else
    641 	fd = &font_info_8x16;
    642 #endif
    643 
    644 	if (loadfont) { /* XXX: We should set the colormap */
    645 		/*
    646 		 * set colors (B&W)
    647 		 */
    648 		vgaw(ba, VDAC_ADDRESS_W, 0);
    649 		for (z = 0; z < 256; z++) {
    650 			y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
    651 
    652 			vgaw(ba, VDAC_DATA, etconscolors[y][0]);
    653 			vgaw(ba, VDAC_DATA, etconscolors[y][1]);
    654 			vgaw(ba, VDAC_DATA, etconscolors[y][2]);
    655 		}
    656 
    657 		/*
    658 		 * Enter a suitable mode to download the font. This
    659 		 * basically means sequential addressing mode
    660 		 */
    661 		s = splhigh();
    662 
    663 		WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
    664 		WSeq(ba, SEQ_ID_MAP_MASK,	 0x04);
    665 		WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x06);
    666 		WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
    667 		WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x00);
    668 		WGfx(ba, GCT_ID_MISC,		 0x04);
    669 		splx(s);
    670 
    671 		/*
    672 		 * load text font into beginning of display memory. Each
    673 		 * character cell is 32 bytes long (enough for 4 planes)
    674 		 */
    675 		for (z = 0, c = fb; z < 256 * 32; z++)
    676 			*c++ = 0;
    677 
    678 		c = (unsigned char *) (fb) + (32 * fd->font_lo);
    679 		f = fd->font_p;
    680 		z = fd->font_lo;
    681 		for (; z <= fd->font_hi; z++, c += (32 - fd->height))
    682 			for (y = 0; y < fd->height; y++) {
    683 				*c++ = *f++;
    684 			}
    685 	}
    686 
    687 	/*
    688 	 * Odd/Even addressing
    689 	 */
    690 	etregs->seq[SEQ_ID_MAP_MASK]        = 0x03;
    691 	etregs->seq[SEQ_ID_MEMORY_MODE]     = 0x03;
    692 	etregs->grf[GCT_ID_READ_MAP_SELECT] = 0x00;
    693 	etregs->grf[GCT_ID_GRAPHICS_MODE]   = 0x10;
    694 	etregs->grf[GCT_ID_MISC]            = 0x06;
    695 
    696 	/*
    697 	 * Font height + underline location
    698 	 */
    699 	tmp = etregs->crt[CRT_ID_MAX_ROW_ADDRESS] & 0xe0;
    700 	etregs->crt[CRT_ID_MAX_ROW_ADDRESS] = tmp | (fd->height - 1);
    701 	tmp = etregs->crt[CRT_ID_UNDERLINE_LOC] & 0xe0;
    702 	etregs->crt[CRT_ID_UNDERLINE_LOC] = tmp | (fd->height - 1);
    703 
    704 	/*
    705 	 * Cursor setup
    706 	 */
    707 	etregs->crt[CRT_ID_CURSOR_START]    = 0x00;
    708 	etregs->crt[CRT_ID_CURSOR_END]      = fd->height - 1;
    709 	etregs->crt[CRT_ID_CURSOR_LOC_HIGH] = 0x00;
    710 	etregs->crt[CRT_ID_CURSOR_LOC_LOW]  = 0x00;
    711 
    712 	/*
    713 	 * Enter text mode
    714 	 */
    715 	etregs->crt[CRT_ID_MODE_CONTROL]    = 0xa3;
    716 	etregs->attr[ACT_ID_ATTR_MODE_CNTL] = 0x0a;
    717 
    718 #if 1
    719 	if (loadfont || (etregs == &loc_regs))
    720 #else
    721 	if (etregs == &loc_regs)
    722 #endif
    723 		et_hwrest(etregs);
    724 }
    725