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