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