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