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