xref: /csrg-svn/sys/hp300/stand/ite.c (revision 54073)
141488Smckusick /*
241488Smckusick  * Copyright (c) 1988 University of Utah.
341488Smckusick  * Copyright (c) 1990 The Regents of the University of California.
441488Smckusick  * All rights reserved.
541488Smckusick  *
641488Smckusick  * This code is derived from software contributed to Berkeley by
741488Smckusick  * the Systems Programming Group of the University of Utah Computer
841488Smckusick  * Science Department.
941488Smckusick  *
1041488Smckusick  * %sccs.include.redist.c%
1141488Smckusick  *
12*54073Shibler  * from: Utah $Hdr: ite.c 1.23 92/02/28$
1341488Smckusick  *
14*54073Shibler  *	@(#)ite.c	7.4 (Berkeley) 06/18/92
1541488Smckusick  */
1641488Smckusick 
1741488Smckusick /*
1841488Smckusick  * Standalone Internal Terminal Emulator (CRT and keyboard)
1941488Smckusick  */
2041488Smckusick #include "samachdep.h"
2141488Smckusick 
2241488Smckusick #ifdef ITECONSOLE
2341488Smckusick 
2445790Sbostic #include "sys/param.h"
25*54073Shibler #include "hp/dev/cons.h"
26*54073Shibler #include "hp/dev/device.h"
27*54073Shibler #include "hp/dev/itevar.h"
28*54073Shibler #include "hp/dev/grfreg.h"
2941488Smckusick 
30*54073Shibler extern int nodev();
31*54073Shibler extern u_char ite_readbyte();
32*54073Shibler extern int ite_writeglyph();
3341488Smckusick 
34*54073Shibler extern int topcat_init(), topcat_putc();
35*54073Shibler extern int topcat_clear(), topcat_cursor(), topcat_scroll();
36*54073Shibler extern int gbox_init(), gbox_clear();
37*54073Shibler extern int gbox_putc(), gbox_cursor(), gbox_scroll();
38*54073Shibler extern int rbox_init(), rbox_clear();
39*54073Shibler extern int rbox_putc(), rbox_cursor(), rbox_scroll();
40*54073Shibler extern int dvbox_init(), dvbox_clear();
41*54073Shibler extern int dvbox_putc(), dvbox_cursor(), dvbox_scroll();
42*54073Shibler extern int hyper_init(), hyper_clear();
43*54073Shibler extern int hyper_putc(), hyper_cursor(), hyper_scroll();
4441488Smckusick 
4541488Smckusick struct itesw itesw[] = {
46*54073Shibler 	GID_TOPCAT,
47*54073Shibler 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
48*54073Shibler 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
49*54073Shibler 	GID_GATORBOX,
50*54073Shibler 	gbox_init,	nodev,		gbox_clear,	gbox_putc,
51*54073Shibler 	gbox_cursor,	gbox_scroll,	ite_readbyte,	ite_writeglyph,
52*54073Shibler 	GID_RENAISSANCE,
53*54073Shibler 	rbox_init,	nodev,		rbox_clear,	rbox_putc,
54*54073Shibler 	rbox_cursor,	rbox_scroll,	ite_readbyte,	ite_writeglyph,
55*54073Shibler 	GID_LRCATSEYE,
56*54073Shibler 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
57*54073Shibler 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
58*54073Shibler 	GID_HRCCATSEYE,
59*54073Shibler 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
60*54073Shibler 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
61*54073Shibler 	GID_HRMCATSEYE,
62*54073Shibler 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
63*54073Shibler 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
64*54073Shibler 	GID_DAVINCI,
65*54073Shibler       	dvbox_init,	nodev,		dvbox_clear,	dvbox_putc,
66*54073Shibler 	dvbox_cursor,	dvbox_scroll,	ite_readbyte,	ite_writeglyph,
67*54073Shibler 	GID_HYPERION,
68*54073Shibler 	hyper_init,	nodev,		hyper_clear,	hyper_putc,
69*54073Shibler 	hyper_cursor,	hyper_scroll,	ite_readbyte,	ite_writeglyph,
7041488Smckusick };
71*54073Shibler int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
7241488Smckusick 
7341488Smckusick /* these guys need to be in initialized data */
7441488Smckusick int itecons = -1;
7541488Smckusick struct  ite_softc ite_softc[NITE] = { 0 };
7641488Smckusick 
7741488Smckusick /*
7841488Smckusick  * Locate all bitmapped displays
7941488Smckusick  */
8041488Smckusick iteconfig()
8141488Smckusick {
8241488Smckusick 	extern struct hp_hw sc_table[];
8341488Smckusick 	int dtype, fboff, i;
8441488Smckusick 	struct hp_hw *hw;
8541488Smckusick 	struct grfreg *gr;
8641488Smckusick 	struct ite_softc *ip;
8741488Smckusick 
8841488Smckusick 	i = 0;
8949334Shibler 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
9049334Shibler 	        if (!HW_ISDEV(hw, D_BITMAP))
9141488Smckusick 			continue;
9249334Shibler 		gr = (struct grfreg *) hw->hw_kva;
9341488Smckusick 		/* XXX: redundent but safe */
9441488Smckusick 		if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
9541488Smckusick 			continue;
96*54073Shibler 		for (dtype = 0; dtype < nitesw; dtype++)
97*54073Shibler 			if (itesw[dtype].ite_hwid == gr->gr_id2)
98*54073Shibler 				break;
99*54073Shibler 		if (dtype == nitesw)
10041488Smckusick 			continue;
10141488Smckusick 		if (i >= NITE)
10241488Smckusick 			break;
10341488Smckusick 		ip = &ite_softc[i];
104*54073Shibler 		ip->isw = &itesw[dtype];
10541488Smckusick 		ip->regbase = (caddr_t) gr;
10641488Smckusick 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
10741488Smckusick 		ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16);
10841488Smckusick 		/* DIO II: FB offset is relative to select code space */
10949334Shibler 		if (ip->regbase >= (caddr_t)DIOIIBASE)
11041488Smckusick 			ip->fbbase += (int)ip->regbase;
111*54073Shibler 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
112*54073Shibler 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
113*54073Shibler 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
114*54073Shibler 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
11541488Smckusick 		ip->flags = ITE_ALIVE|ITE_CONSOLE;
11641488Smckusick 		i++;
11741488Smckusick 	}
11841488Smckusick }
11941488Smckusick 
12041488Smckusick #ifdef CONSDEBUG
12141488Smckusick /*
12241488Smckusick  * Allows us to cycle through all possible consoles (NITE ites and serial port)
12341488Smckusick  * by using SHIFT-RESET on the keyboard.
12441488Smckusick  */
12541488Smckusick int	whichconsole = -1;
12641488Smckusick #endif
12741488Smckusick 
12841488Smckusick iteprobe(cp)
12941488Smckusick 	struct consdev *cp;
13041488Smckusick {
13141488Smckusick 	register int ite;
13241488Smckusick 	register struct ite_softc *ip;
13341488Smckusick 	int unit, pri;
13441488Smckusick 
13541488Smckusick #ifdef CONSDEBUG
13641488Smckusick 	whichconsole = ++whichconsole % (NITE+1);
13741488Smckusick #endif
13841488Smckusick 
13941488Smckusick 	if (itecons != -1)
14041488Smckusick 		return(1);
14141488Smckusick 
14241488Smckusick 	iteconfig();
14341488Smckusick 	unit = -1;
14441488Smckusick 	pri = CN_DEAD;
14541488Smckusick 	for (ite = 0; ite < NITE; ite++) {
14641488Smckusick #ifdef CONSDEBUG
14741488Smckusick 		if (ite < whichconsole)
14841488Smckusick 			continue;
14941488Smckusick #endif
15041488Smckusick 		ip = &ite_softc[ite];
15141488Smckusick 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
15241488Smckusick 		    != (ITE_ALIVE|ITE_CONSOLE))
15341488Smckusick 			continue;
15441488Smckusick 		if ((int)ip->regbase == GRFIADDR) {
15541488Smckusick 			pri = CN_INTERNAL;
15641488Smckusick 			unit = ite;
15741488Smckusick 		} else if (unit < 0) {
15841488Smckusick 			pri = CN_NORMAL;
15941488Smckusick 			unit = ite;
16041488Smckusick 		}
16141488Smckusick 	}
16241488Smckusick 	cp->cn_dev = unit;
16341488Smckusick 	cp->cn_pri = pri;
16441488Smckusick }
16541488Smckusick 
16641488Smckusick iteinit(cp)
16741488Smckusick 	struct consdev *cp;
16841488Smckusick {
16941488Smckusick 	int ite = cp->cn_dev;
17041488Smckusick 	struct ite_softc *ip;
17141488Smckusick 
17241488Smckusick 	if (itecons != -1)
17341488Smckusick 		return(1);
17441488Smckusick 
17541488Smckusick 	ip = &ite_softc[ite];
17641488Smckusick 
17741488Smckusick 	ip->curx = 0;
17841488Smckusick 	ip->cury = 0;
17941488Smckusick 	ip->cursorx = 0;
18041488Smckusick 	ip->cursory = 0;
18141488Smckusick 
182*54073Shibler 	(*ip->isw->ite_init)(ip);
183*54073Shibler 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
18441488Smckusick 
18541488Smckusick 	itecons = ite;
18641488Smckusick 	kbdinit();
18741488Smckusick }
18841488Smckusick 
18941488Smckusick iteputchar(c)
19041488Smckusick 	register int c;
19141488Smckusick {
19241488Smckusick 	register struct ite_softc *ip = &ite_softc[itecons];
193*54073Shibler 	register struct itesw *sp = ip->isw;
19441488Smckusick 
19541488Smckusick 	c &= 0x7F;
19641488Smckusick 	switch (c) {
19741488Smckusick 
19841488Smckusick 	case '\n':
19941488Smckusick 		if (++ip->cury == ip->rows) {
20041488Smckusick 			ip->cury--;
20141488Smckusick 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
20241488Smckusick 			ite_clrtoeol(ip, sp, ip->cury, 0);
20341488Smckusick 		}
20441488Smckusick 		else
20541488Smckusick 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
20641488Smckusick 		break;
20741488Smckusick 
20841488Smckusick 	case '\r':
20941488Smckusick 		ip->curx = 0;
21041488Smckusick 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
21141488Smckusick 		break;
21241488Smckusick 
21341488Smckusick 	case '\b':
21441488Smckusick 		if (--ip->curx < 0)
21541488Smckusick 			ip->curx = 0;
21641488Smckusick 		else
21741488Smckusick 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
21841488Smckusick 		break;
21941488Smckusick 
22041488Smckusick 	default:
22141488Smckusick 		if (c < ' ' || c == 0177)
22241488Smckusick 			break;
22341488Smckusick 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
22441488Smckusick 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
22541488Smckusick 		itecheckwrap(ip, sp);
22641488Smckusick 		break;
22741488Smckusick 	}
22841488Smckusick }
22941488Smckusick 
23041488Smckusick itecheckwrap(ip, sp)
23141488Smckusick      register struct ite_softc *ip;
23241488Smckusick      register struct itesw *sp;
23341488Smckusick {
23441488Smckusick 	if (++ip->curx == ip->cols) {
23541488Smckusick 		ip->curx = 0;
23641488Smckusick 		if (++ip->cury == ip->rows) {
23741488Smckusick 			--ip->cury;
23841488Smckusick 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
23941488Smckusick 			ite_clrtoeol(ip, sp, ip->cury, 0);
24041488Smckusick 			return;
24141488Smckusick 		}
24241488Smckusick 	}
24341488Smckusick 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
24441488Smckusick }
24541488Smckusick 
24641488Smckusick ite_clrtoeol(ip, sp, y, x)
24741488Smckusick      register struct ite_softc *ip;
24841488Smckusick      register struct itesw *sp;
24941488Smckusick      register int y, x;
25041488Smckusick {
25141488Smckusick 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
25241488Smckusick 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
25341488Smckusick }
25441488Smckusick 
25541488Smckusick itegetchar()
25641488Smckusick {
25741488Smckusick #ifdef SMALL
25841488Smckusick 	return (0);
25941488Smckusick #else
26041488Smckusick 	return (kbdgetc());
26141488Smckusick #endif
26241488Smckusick }
26341488Smckusick #endif
264