Home | History | Annotate | Line # | Download | only in common
ite.c revision 1.1
      1 /*	$NetBSD: ite.c,v 1.1 1997/02/04 03:52:30 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1990, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  * from: Utah $Hdr: ite.c 1.24 93/06/25$
     41  *
     42  *	@(#)ite.c	8.1 (Berkeley) 7/8/93
     43  */
     44 
     45 /*
     46  * Standalone Internal Terminal Emulator (CRT and keyboard)
     47  */
     48 
     49 #ifdef ITECONSOLE
     50 
     51 #include <sys/param.h>
     52 #include <dev/cons.h>
     53 
     54 #include <hp300/dev/grfreg.h>
     55 
     56 #include <hp300/stand/common/device.h>
     57 #include <hp300/stand/common/itevar.h>
     58 #include <hp300/stand/common/consdefs.h>
     59 #include <hp300/stand/common/samachdep.h>
     60 
     61 void	ite_deinit_noop __P((struct ite_data *));
     62 
     63 struct itesw itesw[] = {
     64 	{ GID_TOPCAT,
     65 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
     66 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
     67 
     68 	{ GID_GATORBOX,
     69 	gbox_init,	ite_deinit_noop, gbox_clear,	gbox_putc,
     70 	gbox_cursor,	gbox_scroll,	ite_readbyte,	ite_writeglyph },
     71 
     72 	{ GID_RENAISSANCE,
     73 	rbox_init,	ite_deinit_noop, rbox_clear,	rbox_putc,
     74 	rbox_cursor,	rbox_scroll,	ite_readbyte,	ite_writeglyph },
     75 
     76 	{ GID_LRCATSEYE,
     77 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
     78 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
     79 
     80 	{ GID_HRCCATSEYE,
     81 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
     82 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
     83 
     84 	{ GID_HRMCATSEYE,
     85 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
     86 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
     87 
     88 	{ GID_DAVINCI,
     89       	dvbox_init,	ite_deinit_noop, dvbox_clear,	dvbox_putc,
     90 	dvbox_cursor,	dvbox_scroll,	ite_readbyte,	ite_writeglyph },
     91 
     92 	{ GID_HYPERION,
     93 	hyper_init,	ite_deinit_noop, hyper_clear,	hyper_putc,
     94 	hyper_cursor,	hyper_scroll,	ite_readbyte,	ite_writeglyph },
     95 };
     96 int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
     97 
     98 /* these guys need to be in initialized data */
     99 int itecons = -1;
    100 struct  ite_data ite_data[NITE] = { 0 };
    101 int	ite_scode[NITE] = { 0 };
    102 
    103 /*
    104  * Locate all bitmapped displays
    105  */
    106 iteconfig()
    107 {
    108 	extern struct hp_hw sc_table[];
    109 	int dtype, fboff, i;
    110 	struct hp_hw *hw;
    111 	struct grfreg *gr;
    112 	struct ite_data *ip;
    113 
    114 	i = 0;
    115 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
    116 	        if (!HW_ISDEV(hw, D_BITMAP))
    117 			continue;
    118 		gr = (struct grfreg *) hw->hw_kva;
    119 		/* XXX: redundent but safe */
    120 		if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
    121 			continue;
    122 		for (dtype = 0; dtype < nitesw; dtype++)
    123 			if (itesw[dtype].ite_hwid == gr->gr_id2)
    124 				break;
    125 		if (dtype == nitesw)
    126 			continue;
    127 		if (i >= NITE)
    128 			break;
    129 		ite_scode[i] = hw->hw_sc;
    130 		ip = &ite_data[i];
    131 		ip->isw = &itesw[dtype];
    132 		ip->regbase = (caddr_t) gr;
    133 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
    134 		ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16);
    135 		/* DIO II: FB offset is relative to select code space */
    136 		if (ip->regbase >= (caddr_t)DIOIIBASE)
    137 			ip->fbbase += (int)ip->regbase;
    138 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
    139 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
    140 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
    141 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
    142 		/*
    143 		 * XXX some displays (e.g. the davinci) appear
    144 		 * to return a display height greater than the
    145 		 * returned FB height.  Guess we should go back
    146 		 * to getting the display dimensions from the
    147 		 * fontrom...
    148 		 */
    149 		if (ip->dwidth > ip->fbwidth)
    150 			ip->dwidth = ip->fbwidth;
    151 		if (ip->dheight > ip->fbheight)
    152 			ip->dheight = ip->fbheight;
    153 		ip->flags = ITE_ALIVE|ITE_CONSOLE;
    154 		i++;
    155 	}
    156 }
    157 
    158 #ifdef CONSDEBUG
    159 /*
    160  * Allows us to cycle through all possible consoles (NITE ites and serial port)
    161  * by using SHIFT-RESET on the keyboard.
    162  */
    163 int	whichconsole = -1;
    164 #endif
    165 
    166 void
    167 iteprobe(cp)
    168 	struct consdev *cp;
    169 {
    170 	register int ite;
    171 	register struct ite_data *ip;
    172 	int unit, pri;
    173 
    174 #ifdef CONSDEBUG
    175 	whichconsole = ++whichconsole % (NITE+1);
    176 #endif
    177 
    178 	if (itecons != -1)
    179 		return;
    180 
    181 	iteconfig();
    182 	unit = -1;
    183 	pri = CN_DEAD;
    184 	for (ite = 0; ite < NITE; ite++) {
    185 #ifdef CONSDEBUG
    186 		if (ite < whichconsole)
    187 			continue;
    188 #endif
    189 		ip = &ite_data[ite];
    190 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
    191 		    != (ITE_ALIVE|ITE_CONSOLE))
    192 			continue;
    193 		if ((int)ip->regbase == GRFIADDR) {
    194 			pri = CN_INTERNAL;
    195 			unit = ite;
    196 		} else if (unit < 0) {
    197 			pri = CN_NORMAL;
    198 			unit = ite;
    199 		}
    200 	}
    201 	curcons_scode = ite_scode[unit];
    202 	cp->cn_dev = unit;
    203 	cp->cn_pri = pri;
    204 }
    205 
    206 void
    207 iteinit(cp)
    208 	struct consdev *cp;
    209 {
    210 	int ite = cp->cn_dev;
    211 	struct ite_data *ip;
    212 
    213 	if (itecons != -1)
    214 		return;
    215 
    216 	ip = &ite_data[ite];
    217 
    218 	ip->curx = 0;
    219 	ip->cury = 0;
    220 	ip->cursorx = 0;
    221 	ip->cursory = 0;
    222 
    223 	(*ip->isw->ite_init)(ip);
    224 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
    225 
    226 	itecons = ite;
    227 	kbdinit();
    228 }
    229 
    230 /* ARGSUSED */
    231 void
    232 iteputchar(dev, c)
    233 	dev_t dev;
    234 	register int c;
    235 {
    236 	register struct ite_data *ip = &ite_data[itecons];
    237 	register struct itesw *sp = ip->isw;
    238 
    239 	c &= 0x7F;
    240 	switch (c) {
    241 
    242 	case '\n':
    243 		if (++ip->cury == ip->rows) {
    244 			ip->cury--;
    245 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
    246 			ite_clrtoeol(ip, sp, ip->cury, 0);
    247 		}
    248 		else
    249 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    250 		break;
    251 
    252 	case '\r':
    253 		ip->curx = 0;
    254 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
    255 		break;
    256 
    257 	case '\b':
    258 		if (--ip->curx < 0)
    259 			ip->curx = 0;
    260 		else
    261 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    262 		break;
    263 
    264 	default:
    265 		if (c < ' ' || c == 0177)
    266 			break;
    267 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
    268 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
    269 		itecheckwrap(ip, sp);
    270 		break;
    271 	}
    272 }
    273 
    274 itecheckwrap(ip, sp)
    275      register struct ite_data *ip;
    276      register struct itesw *sp;
    277 {
    278 	if (++ip->curx == ip->cols) {
    279 		ip->curx = 0;
    280 		if (++ip->cury == ip->rows) {
    281 			--ip->cury;
    282 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
    283 			ite_clrtoeol(ip, sp, ip->cury, 0);
    284 			return;
    285 		}
    286 	}
    287 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
    288 }
    289 
    290 ite_clrtoeol(ip, sp, y, x)
    291      register struct ite_data *ip;
    292      register struct itesw *sp;
    293      register int y, x;
    294 {
    295 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
    296 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
    297 }
    298 
    299 /* ARGSUSED */
    300 int
    301 itegetchar(dev)
    302 	dev_t dev;
    303 {
    304 #ifdef SMALL
    305 	return (0);
    306 #else
    307 	return (kbdgetc());
    308 #endif
    309 }
    310 #endif
    311 
    312 /* ARGSUSED */
    313 void
    314 ite_deinit_noop(ip)
    315 	struct ite_data *ip;
    316 {
    317 }
    318