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