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