Home | History | Annotate | Line # | Download | only in common
ite.c revision 1.8
      1  1.8  christos /*	$NetBSD: ite.c,v 1.8 2007/03/04 05:59:50 christos 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.2       agc  *
      7  1.2       agc  * This code is derived from software contributed to Berkeley by
      8  1.2       agc  * the Systems Programming Group of the University of Utah Computer
      9  1.2       agc  * Science Department.
     10  1.2       agc  *
     11  1.2       agc  * Redistribution and use in source and binary forms, with or without
     12  1.2       agc  * modification, are permitted provided that the following conditions
     13  1.2       agc  * are met:
     14  1.2       agc  * 1. Redistributions of source code must retain the above copyright
     15  1.2       agc  *    notice, this list of conditions and the following disclaimer.
     16  1.2       agc  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.2       agc  *    notice, this list of conditions and the following disclaimer in the
     18  1.2       agc  *    documentation and/or other materials provided with the distribution.
     19  1.2       agc  * 3. Neither the name of the University nor the names of its contributors
     20  1.2       agc  *    may be used to endorse or promote products derived from this software
     21  1.2       agc  *    without specific prior written permission.
     22  1.2       agc  *
     23  1.2       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.2       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.2       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.2       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.2       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.2       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.2       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.2       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.2       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.2       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.2       agc  * SUCH DAMAGE.
     34  1.2       agc  *
     35  1.2       agc  * from: Utah $Hdr: ite.c 1.24 93/06/25$
     36  1.2       agc  *
     37  1.2       agc  *	@(#)ite.c	8.1 (Berkeley) 7/8/93
     38  1.2       agc  */
     39  1.2       agc /*
     40  1.2       agc  * Copyright (c) 1988 University of Utah.
     41  1.1   thorpej  *
     42  1.1   thorpej  * This code is derived from software contributed to Berkeley by
     43  1.1   thorpej  * the Systems Programming Group of the University of Utah Computer
     44  1.1   thorpej  * Science Department.
     45  1.1   thorpej  *
     46  1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     47  1.1   thorpej  * modification, are permitted provided that the following conditions
     48  1.1   thorpej  * are met:
     49  1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     50  1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     51  1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     53  1.1   thorpej  *    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.7   tsutsui #include <hp300/dev/intioreg.h>
     90  1.1   thorpej 
     91  1.1   thorpej #include <hp300/stand/common/device.h>
     92  1.1   thorpej #include <hp300/stand/common/itevar.h>
     93  1.3   tsutsui #include <hp300/stand/common/kbdvar.h>
     94  1.1   thorpej #include <hp300/stand/common/consdefs.h>
     95  1.1   thorpej #include <hp300/stand/common/samachdep.h>
     96  1.1   thorpej 
     97  1.3   tsutsui static void iteconfig(void);
     98  1.3   tsutsui static void ite_deinit_noop(struct ite_data *);
     99  1.3   tsutsui static void ite_clrtoeol(struct ite_data *, struct itesw *, int, int);
    100  1.3   tsutsui static void itecheckwrap(struct ite_data *, struct itesw *);
    101  1.1   thorpej 
    102  1.1   thorpej struct itesw itesw[] = {
    103  1.1   thorpej 	{ GID_TOPCAT,
    104  1.1   thorpej 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
    105  1.1   thorpej 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
    106  1.1   thorpej 
    107  1.1   thorpej 	{ GID_GATORBOX,
    108  1.1   thorpej 	gbox_init,	ite_deinit_noop, gbox_clear,	gbox_putc,
    109  1.1   thorpej 	gbox_cursor,	gbox_scroll,	ite_readbyte,	ite_writeglyph },
    110  1.1   thorpej 
    111  1.1   thorpej 	{ GID_RENAISSANCE,
    112  1.1   thorpej 	rbox_init,	ite_deinit_noop, rbox_clear,	rbox_putc,
    113  1.1   thorpej 	rbox_cursor,	rbox_scroll,	ite_readbyte,	ite_writeglyph },
    114  1.1   thorpej 
    115  1.1   thorpej 	{ GID_LRCATSEYE,
    116  1.1   thorpej 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
    117  1.1   thorpej 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
    118  1.1   thorpej 
    119  1.1   thorpej 	{ GID_HRCCATSEYE,
    120  1.1   thorpej 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
    121  1.1   thorpej 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
    122  1.1   thorpej 
    123  1.1   thorpej 	{ GID_HRMCATSEYE,
    124  1.1   thorpej 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
    125  1.1   thorpej 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
    126  1.1   thorpej 
    127  1.1   thorpej 	{ GID_DAVINCI,
    128  1.1   thorpej       	dvbox_init,	ite_deinit_noop, dvbox_clear,	dvbox_putc,
    129  1.1   thorpej 	dvbox_cursor,	dvbox_scroll,	ite_readbyte,	ite_writeglyph },
    130  1.1   thorpej 
    131  1.1   thorpej 	{ GID_HYPERION,
    132  1.1   thorpej 	hyper_init,	ite_deinit_noop, hyper_clear,	hyper_putc,
    133  1.1   thorpej 	hyper_cursor,	hyper_scroll,	ite_readbyte,	ite_writeglyph },
    134  1.1   thorpej };
    135  1.1   thorpej int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
    136  1.1   thorpej 
    137  1.1   thorpej /* these guys need to be in initialized data */
    138  1.1   thorpej int itecons = -1;
    139  1.3   tsutsui struct  ite_data ite_data[NITE] = { { 0 } };
    140  1.1   thorpej int	ite_scode[NITE] = { 0 };
    141  1.1   thorpej 
    142  1.1   thorpej /*
    143  1.1   thorpej  * Locate all bitmapped displays
    144  1.1   thorpej  */
    145  1.3   tsutsui static void
    146  1.4   tsutsui iteconfig(void)
    147  1.1   thorpej {
    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.8  christos 		if (badaddr((void *)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.8  christos 		ip->regbase = (void *) gr;
    172  1.1   thorpej 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
    173  1.8  christos 		ip->fbbase = (void *)(*((u_char *)ip->regbase + fboff) << 16);
    174  1.1   thorpej 		/* DIO II: FB offset is relative to select code space */
    175  1.8  christos 		if (ip->regbase >= (void *)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.4   tsutsui iteprobe(struct consdev *cp)
    207  1.1   thorpej {
    208  1.3   tsutsui 	int ite;
    209  1.3   tsutsui 	struct ite_data *ip;
    210  1.1   thorpej 	int unit, pri;
    211  1.1   thorpej 
    212  1.1   thorpej #ifdef CONSDEBUG
    213  1.1   thorpej 	whichconsole = ++whichconsole % (NITE+1);
    214  1.1   thorpej #endif
    215  1.1   thorpej 
    216  1.1   thorpej 	if (itecons != -1)
    217  1.1   thorpej 		return;
    218  1.1   thorpej 
    219  1.1   thorpej 	iteconfig();
    220  1.1   thorpej 	unit = -1;
    221  1.1   thorpej 	pri = CN_DEAD;
    222  1.1   thorpej 	for (ite = 0; ite < NITE; ite++) {
    223  1.1   thorpej #ifdef CONSDEBUG
    224  1.1   thorpej 		if (ite < whichconsole)
    225  1.1   thorpej 			continue;
    226  1.1   thorpej #endif
    227  1.1   thorpej 		ip = &ite_data[ite];
    228  1.1   thorpej 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
    229  1.1   thorpej 		    != (ITE_ALIVE|ITE_CONSOLE))
    230  1.1   thorpej 			continue;
    231  1.7   tsutsui 		if ((int)ip->regbase == INTIOBASE + FB_BASE) {
    232  1.1   thorpej 			pri = CN_INTERNAL;
    233  1.1   thorpej 			unit = ite;
    234  1.1   thorpej 		} else if (unit < 0) {
    235  1.1   thorpej 			pri = CN_NORMAL;
    236  1.1   thorpej 			unit = ite;
    237  1.1   thorpej 		}
    238  1.1   thorpej 	}
    239  1.1   thorpej 	curcons_scode = ite_scode[unit];
    240  1.1   thorpej 	cp->cn_dev = unit;
    241  1.1   thorpej 	cp->cn_pri = pri;
    242  1.1   thorpej }
    243  1.1   thorpej 
    244  1.1   thorpej void
    245  1.4   tsutsui iteinit(struct consdev *cp)
    246  1.1   thorpej {
    247  1.1   thorpej 	int ite = cp->cn_dev;
    248  1.1   thorpej 	struct ite_data *ip;
    249  1.1   thorpej 
    250  1.1   thorpej 	if (itecons != -1)
    251  1.1   thorpej 		return;
    252  1.1   thorpej 
    253  1.1   thorpej 	ip = &ite_data[ite];
    254  1.1   thorpej 
    255  1.1   thorpej 	ip->curx = 0;
    256  1.1   thorpej 	ip->cury = 0;
    257  1.1   thorpej 	ip->cursorx = 0;
    258  1.1   thorpej 	ip->cursory = 0;
    259  1.1   thorpej 
    260  1.1   thorpej 	(*ip->isw->ite_init)(ip);
    261  1.1   thorpej 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
    262  1.1   thorpej 
    263  1.1   thorpej 	itecons = ite;
    264  1.1   thorpej 	kbdinit();
    265  1.1   thorpej }
    266  1.1   thorpej 
    267  1.1   thorpej /* ARGSUSED */
    268  1.1   thorpej void
    269  1.4   tsutsui iteputchar(dev_t dev, int c)
    270  1.1   thorpej {
    271  1.3   tsutsui 	struct ite_data *ip = &ite_data[itecons];
    272  1.3   tsutsui 	struct itesw *sp = ip->isw;
    273  1.1   thorpej 
    274  1.1   thorpej 	c &= 0x7F;
    275  1.1   thorpej 	switch (c) {
    276  1.1   thorpej 
    277  1.1   thorpej 	case '\n':
    278  1.1   thorpej 		if (++ip->cury == ip->rows) {
    279  1.1   thorpej 			ip->cury--;
    280  1.1   thorpej 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
    281  1.1   thorpej 			ite_clrtoeol(ip, sp, ip->cury, 0);
    282  1.1   thorpej 		}
    283  1.1   thorpej 		else
    284  1.1   thorpej 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    285  1.1   thorpej 		break;
    286  1.1   thorpej 
    287  1.1   thorpej 	case '\r':
    288  1.1   thorpej 		ip->curx = 0;
    289  1.1   thorpej 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
    290  1.1   thorpej 		break;
    291  1.1   thorpej 
    292  1.1   thorpej 	case '\b':
    293  1.1   thorpej 		if (--ip->curx < 0)
    294  1.1   thorpej 			ip->curx = 0;
    295  1.1   thorpej 		else
    296  1.1   thorpej 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
    297  1.1   thorpej 		break;
    298  1.1   thorpej 
    299  1.1   thorpej 	default:
    300  1.1   thorpej 		if (c < ' ' || c == 0177)
    301  1.1   thorpej 			break;
    302  1.1   thorpej 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
    303  1.1   thorpej 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
    304  1.1   thorpej 		itecheckwrap(ip, sp);
    305  1.1   thorpej 		break;
    306  1.1   thorpej 	}
    307  1.1   thorpej }
    308  1.1   thorpej 
    309  1.3   tsutsui static void
    310  1.4   tsutsui itecheckwrap(struct ite_data *ip, struct itesw *sp)
    311  1.1   thorpej {
    312  1.1   thorpej 	if (++ip->curx == ip->cols) {
    313  1.1   thorpej 		ip->curx = 0;
    314  1.1   thorpej 		if (++ip->cury == ip->rows) {
    315  1.1   thorpej 			--ip->cury;
    316  1.1   thorpej 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
    317  1.1   thorpej 			ite_clrtoeol(ip, sp, ip->cury, 0);
    318  1.1   thorpej 			return;
    319  1.1   thorpej 		}
    320  1.1   thorpej 	}
    321  1.1   thorpej 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
    322  1.1   thorpej }
    323  1.1   thorpej 
    324  1.3   tsutsui static void
    325  1.4   tsutsui ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
    326  1.1   thorpej {
    327  1.4   tsutsui 
    328  1.1   thorpej 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
    329  1.1   thorpej 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
    330  1.1   thorpej }
    331  1.1   thorpej 
    332  1.1   thorpej /* ARGSUSED */
    333  1.1   thorpej int
    334  1.4   tsutsui itegetchar(dev_t dev)
    335  1.1   thorpej {
    336  1.3   tsutsui 
    337  1.1   thorpej #ifdef SMALL
    338  1.3   tsutsui 	return 0;
    339  1.1   thorpej #else
    340  1.3   tsutsui 	return kbdgetc();
    341  1.1   thorpej #endif
    342  1.1   thorpej }
    343  1.1   thorpej #endif
    344  1.1   thorpej 
    345  1.1   thorpej /* ARGSUSED */
    346  1.3   tsutsui static void
    347  1.4   tsutsui ite_deinit_noop(struct ite_data *ip)
    348  1.1   thorpej {
    349  1.1   thorpej }
    350