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