Home | History | Annotate | Line # | Download | only in dev
ite.c revision 1.2
      1  1.1       mw /*
      2  1.1       mw  * Copyright (c) 1988 University of Utah.
      3  1.1       mw  * Copyright (c) 1990 The Regents of the University of California.
      4  1.1       mw  * All rights reserved.
      5  1.1       mw  *
      6  1.1       mw  * This code is derived from software contributed to Berkeley by
      7  1.1       mw  * the Systems Programming Group of the University of Utah Computer
      8  1.1       mw  * Science Department.
      9  1.1       mw  *
     10  1.1       mw  * Redistribution and use in source and binary forms, with or without
     11  1.1       mw  * modification, are permitted provided that the following conditions
     12  1.1       mw  * are met:
     13  1.1       mw  * 1. Redistributions of source code must retain the above copyright
     14  1.1       mw  *    notice, this list of conditions and the following disclaimer.
     15  1.1       mw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1       mw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1       mw  *    documentation and/or other materials provided with the distribution.
     18  1.1       mw  * 3. All advertising materials mentioning features or use of this software
     19  1.1       mw  *    must display the following acknowledgement:
     20  1.1       mw  *	This product includes software developed by the University of
     21  1.1       mw  *	California, Berkeley and its contributors.
     22  1.1       mw  * 4. Neither the name of the University nor the names of its contributors
     23  1.1       mw  *    may be used to endorse or promote products derived from this software
     24  1.1       mw  *    without specific prior written permission.
     25  1.1       mw  *
     26  1.1       mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1       mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1       mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1       mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1       mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1       mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1       mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1       mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1       mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1       mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1       mw  * SUCH DAMAGE.
     37  1.1       mw  *
     38  1.2  mycroft  *	from: Utah Hdr: ite.c 1.1 90/07/09
     39  1.1       mw  *	from: @(#)ite.c	7.6 (Berkeley) 5/16/91
     40  1.2  mycroft  *	$Id: ite.c,v 1.2 1993/08/01 19:23:09 mycroft Exp $
     41  1.1       mw  */
     42  1.1       mw 
     43  1.1       mw /*
     44  1.1       mw  * Bit-mapped display terminal emulator machine independent code.
     45  1.1       mw  * This is a very rudimentary.  Much more can be abstracted out of
     46  1.1       mw  * the hardware dependent routines.
     47  1.1       mw  */
     48  1.1       mw #include "ite.h"
     49  1.1       mw #if NITE > 0
     50  1.1       mw 
     51  1.1       mw #include "grf.h"
     52  1.1       mw 
     53  1.1       mw #undef NITE
     54  1.1       mw #define NITE	NGRF
     55  1.1       mw 
     56  1.1       mw #include "param.h"
     57  1.1       mw #include "conf.h"
     58  1.1       mw #include "proc.h"
     59  1.1       mw #include "ioctl.h"
     60  1.1       mw #include "tty.h"
     61  1.1       mw #include "systm.h"
     62  1.1       mw #include "malloc.h"
     63  1.1       mw 
     64  1.1       mw #include "itevar.h"
     65  1.1       mw #include "iteioctl.h"
     66  1.1       mw #include "kbdmap.h"
     67  1.1       mw 
     68  1.1       mw #include "machine/cpu.h"
     69  1.1       mw 
     70  1.1       mw #ifdef __STDC__
     71  1.1       mw /* automatically generated, as you might guess:-) */
     72  1.1       mw 
     73  1.1       mw struct consdev;
     74  1.1       mw struct itesw;
     75  1.1       mw 
     76  1.1       mw extern int iteon (dev_t dev, int flag);
     77  1.1       mw extern int iteinit (dev_t dev);
     78  1.1       mw extern int iteoff (dev_t dev, int flag);
     79  1.1       mw extern int iteopen (dev_t dev, int mode, int devtype, struct proc *p);
     80  1.1       mw extern int iteclose (dev_t dev, int flag, int mode, struct proc *p);
     81  1.1       mw extern int iteread (dev_t dev, struct uio *uio, int flag);
     82  1.1       mw extern int itewrite (dev_t dev, struct uio *uio, int flag);
     83  1.1       mw extern int iteioctl (dev_t dev, int cmd, caddr_t addr, int flag);
     84  1.1       mw extern int itestart (register struct tty *tp);
     85  1.1       mw extern int itefilter (register u_char c, enum caller caller);
     86  1.1       mw extern int iteputchar (register int c, dev_t dev);
     87  1.1       mw extern int itecheckwrap (register struct ite_softc *ip, register struct itesw *sp);
     88  1.1       mw extern int itecnprobe (struct consdev *cp);
     89  1.1       mw extern int itecninit (struct consdev *cp);
     90  1.1       mw extern int itecngetc (dev_t dev);
     91  1.1       mw extern int itecnputc (dev_t dev, int c);
     92  1.1       mw static void repeat_handler (int a0, int a1);
     93  1.1       mw static void ite_dnchar (struct ite_softc *ip, struct itesw *sp, int n);
     94  1.1       mw static void ite_inchar (struct ite_softc *ip, struct itesw *sp, int n);
     95  1.1       mw static void ite_clrtoeol (struct ite_softc *ip, struct itesw *sp, int y, int x);
     96  1.1       mw static void ite_clrtobol (struct ite_softc *ip, struct itesw *sp, int y, int x);
     97  1.1       mw static void ite_clrline (struct ite_softc *ip, struct itesw *sp, int y, int x);
     98  1.1       mw static void ite_clrtoeos (struct ite_softc *ip, struct itesw *sp);
     99  1.1       mw static void ite_clrtobos (struct ite_softc *ip, struct itesw *sp);
    100  1.1       mw static void ite_clrscreen (struct ite_softc *ip, struct itesw *sp);
    101  1.1       mw static void ite_dnline (struct ite_softc *ip, struct itesw *sp, int n);
    102  1.1       mw static void ite_inline (struct ite_softc *ip, struct itesw *sp, int n);
    103  1.1       mw static void ite_lf (struct ite_softc *ip, struct itesw *sp);
    104  1.1       mw static void ite_crlf (struct ite_softc *ip, struct itesw *sp);
    105  1.1       mw static void ite_cr (struct ite_softc *ip, struct itesw *sp);
    106  1.1       mw static void ite_rlf (struct ite_softc *ip, struct itesw *sp);
    107  1.1       mw static int atoi (const char *cp);
    108  1.1       mw static char *index (const char *cp, char ch);
    109  1.1       mw static int ite_argnum (struct ite_softc *ip);
    110  1.1       mw static int ite_zargnum (struct ite_softc *ip);
    111  1.1       mw static void ite_sendstr (struct ite_softc *ip, char *str);
    112  1.1       mw static int strncmp (const char *a, const char *b, int l);
    113  1.1       mw #endif
    114  1.1       mw 
    115  1.1       mw 
    116  1.1       mw #define set_attr(ip, attr)	((ip)->attribute |= (attr))
    117  1.1       mw #define clr_attr(ip, attr)	((ip)->attribute &= ~(attr))
    118  1.1       mw 
    119  1.1       mw extern  int nodev();
    120  1.1       mw 
    121  1.1       mw int customc_scroll(),	customc_init(),		customc_deinit();
    122  1.1       mw int customc_clear(),	customc_putc(),		customc_cursor();
    123  1.1       mw 
    124  1.1       mw int tiga_scroll(),	tiga_init(),		tiga_deinit();
    125  1.1       mw int tiga_clear(),	tiga_putc(),		tiga_cursor();
    126  1.1       mw 
    127  1.1       mw 
    128  1.1       mw struct itesw itesw[] =
    129  1.1       mw {
    130  1.1       mw 	customc_init,		customc_deinit,		customc_clear,
    131  1.1       mw 	customc_putc,		customc_cursor,		customc_scroll,
    132  1.1       mw 
    133  1.1       mw 	tiga_init,		tiga_deinit,		tiga_clear,
    134  1.1       mw 	tiga_putc,		tiga_cursor,		tiga_scroll,
    135  1.1       mw };
    136  1.1       mw 
    137  1.1       mw /*
    138  1.1       mw  * # of chars are output in a single itestart() call.
    139  1.1       mw  * If this is too big, user processes will be blocked out for
    140  1.1       mw  * long periods of time while we are emptying the queue in itestart().
    141  1.1       mw  * If it is too small, console output will be very ragged.
    142  1.1       mw  */
    143  1.1       mw int	iteburst = 64;
    144  1.1       mw 
    145  1.1       mw int	nite = NITE;
    146  1.1       mw struct  tty *kbd_tty = NULL;
    147  1.1       mw struct	tty ite_cons;
    148  1.1       mw struct	tty *ite_tty[NITE] = { &ite_cons };
    149  1.1       mw struct  ite_softc ite_softc[NITE];
    150  1.1       mw 
    151  1.1       mw int	itestart();
    152  1.1       mw extern	int ttrstrt();
    153  1.1       mw extern	struct tty *constty;
    154  1.1       mw 
    155  1.1       mw /* These are (later..) settable via an ioctl */
    156  1.1       mw int	start_repeat_timo = 30;	/* /100: initial timeout till pressed key repeats */
    157  1.1       mw int	next_repeat_timo  = 5;  /* /100: timeout when repeating for next char */
    158  1.1       mw 
    159  1.1       mw /*
    160  1.1       mw  * Primary attribute buffer to be used by the first bitmapped console
    161  1.1       mw  * found. Secondary displays alloc the attribute buffer as needed.
    162  1.1       mw  * Size is based on a 68x128 display, which is currently our largest.
    163  1.1       mw  */
    164  1.1       mw u_char  console_attributes[0x2200];
    165  1.1       mw 
    166  1.1       mw /*
    167  1.1       mw  * Perform functions necessary to setup device as a terminal emulator.
    168  1.1       mw  */
    169  1.1       mw iteon(dev, flag)
    170  1.1       mw 	dev_t dev;
    171  1.1       mw {
    172  1.1       mw 	int unit = UNIT(dev);
    173  1.1       mw 	struct tty *tp = ite_tty[unit];
    174  1.1       mw 	struct ite_softc *ip = &ite_softc[unit];
    175  1.1       mw 
    176  1.1       mw 	if (unit < 0 || unit >= NITE || (ip->flags&ITE_ALIVE) == 0)
    177  1.1       mw 		return(ENXIO);
    178  1.1       mw 	/* force ite active, overriding graphics mode */
    179  1.1       mw 	if (flag & 1) {
    180  1.1       mw 		ip->flags |= ITE_ACTIVE;
    181  1.1       mw 		ip->flags &= ~(ITE_INGRF|ITE_INITED);
    182  1.1       mw 	}
    183  1.1       mw 	/* leave graphics mode */
    184  1.1       mw 	if (flag & 2) {
    185  1.1       mw 		ip->flags &= ~ITE_INGRF;
    186  1.1       mw 		if ((ip->flags & ITE_ACTIVE) == 0)
    187  1.1       mw 			return(0);
    188  1.1       mw 	}
    189  1.1       mw 	ip->flags |= ITE_ACTIVE;
    190  1.1       mw 	if (ip->flags & ITE_INGRF)
    191  1.1       mw 		return(0);
    192  1.1       mw 	if (kbd_tty == NULL || kbd_tty == tp) {
    193  1.1       mw 		kbd_tty = tp;
    194  1.1       mw 		kbdenable();
    195  1.1       mw 	}
    196  1.1       mw 	iteinit(dev);
    197  1.1       mw 	return(0);
    198  1.1       mw }
    199  1.1       mw 
    200  1.1       mw /* used by the grf layer to reinitialize ite after changing fb parameters */
    201  1.1       mw itereinit(dev)
    202  1.1       mw      dev_t dev;
    203  1.1       mw {
    204  1.1       mw   int unit = UNIT(dev);
    205  1.1       mw   struct ite_softc *ip = &ite_softc[unit];
    206  1.1       mw 
    207  1.1       mw   ip->flags &= ~ITE_INITED;
    208  1.1       mw   iteinit (dev);
    209  1.1       mw }
    210  1.1       mw 
    211  1.1       mw iteinit(dev)
    212  1.1       mw      dev_t dev;
    213  1.1       mw {
    214  1.1       mw 	int unit = UNIT(dev);
    215  1.1       mw 	struct ite_softc *ip = &ite_softc[unit];
    216  1.1       mw 
    217  1.1       mw 	if (ip->flags & ITE_INITED)
    218  1.1       mw 		return;
    219  1.1       mw 
    220  1.1       mw 	ip->curx = 0;
    221  1.1       mw 	ip->cury = 0;
    222  1.1       mw 	ip->cursorx = 0;
    223  1.1       mw 	ip->cursory = 0;
    224  1.1       mw 	ip->save_curx = 0;
    225  1.1       mw 	ip->save_cury = 0;
    226  1.1       mw 	ip->ap = ip->argbuf;
    227  1.1       mw 	ip->emul_level = EMUL_VT300_7;
    228  1.1       mw 	ip->eightbit_C1 = 0;
    229  1.1       mw 	ip->inside_margins = 0;
    230  1.1       mw 	ip->linefeed_newline = 0;
    231  1.1       mw 
    232  1.1       mw 	(*itesw[ip->type].ite_init)(ip);
    233  1.1       mw 	(*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
    234  1.1       mw 
    235  1.1       mw 	/* ip->rows initialized by ite_init above */
    236  1.1       mw 	ip->top_margin = 0; ip->bottom_margin = ip->rows - 1;
    237  1.1       mw 
    238  1.1       mw 	ip->attribute = 0;
    239  1.1       mw 	if (ip->attrbuf == NULL)
    240  1.1       mw 		ip->attrbuf = (u_char *)
    241  1.1       mw 			malloc(ip->rows * ip->cols, M_DEVBUF, M_WAITOK);
    242  1.1       mw 	bzero(ip->attrbuf, (ip->rows * ip->cols));
    243  1.1       mw 
    244  1.1       mw 	ip->imode = 0;
    245  1.1       mw 	ip->flags |= ITE_INITED;
    246  1.1       mw }
    247  1.1       mw 
    248  1.1       mw /*
    249  1.1       mw  * "Shut down" device as terminal emulator.
    250  1.1       mw  * Note that we do not deinit the console device unless forced.
    251  1.1       mw  * Deinit'ing the console every time leads to a very active
    252  1.1       mw  * screen when processing /etc/rc.
    253  1.1       mw  */
    254  1.1       mw iteoff(dev, flag)
    255  1.1       mw 	dev_t dev;
    256  1.1       mw {
    257  1.1       mw 	register struct ite_softc *ip = &ite_softc[UNIT(dev)];
    258  1.1       mw 
    259  1.1       mw 	if (flag & 2)
    260  1.1       mw 		ip->flags |= ITE_INGRF;
    261  1.1       mw 	if ((ip->flags & ITE_ACTIVE) == 0)
    262  1.1       mw 		return;
    263  1.1       mw 	if ((flag & 1) ||
    264  1.1       mw 	    (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
    265  1.1       mw 		(*itesw[ip->type].ite_deinit)(ip);
    266  1.1       mw 	if ((flag & 2) == 0)
    267  1.1       mw 		ip->flags &= ~ITE_ACTIVE;
    268  1.1       mw }
    269  1.1       mw 
    270  1.1       mw /* ARGSUSED */
    271  1.1       mw #ifdef __STDC__
    272  1.1       mw iteopen(dev_t dev, int mode, int devtype, struct proc *p)
    273  1.1       mw #else
    274  1.1       mw iteopen(dev, mode, devtype, p)
    275  1.1       mw 	dev_t dev;
    276  1.1       mw 	int mode, devtype;
    277  1.1       mw 	struct proc *p;
    278  1.1       mw #endif
    279  1.1       mw {
    280  1.1       mw 	int unit = UNIT(dev);
    281  1.1       mw 	register struct tty *tp;
    282  1.1       mw 	register struct ite_softc *ip = &ite_softc[unit];
    283  1.1       mw 	register int error;
    284  1.1       mw 	int first = 0;
    285  1.1       mw 
    286  1.1       mw 	if(!ite_tty[unit]) {
    287  1.1       mw 		MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK);
    288  1.1       mw 		bzero(tp, sizeof(struct tty));
    289  1.1       mw 		ite_tty[unit] = tp;
    290  1.1       mw 	} else
    291  1.1       mw 		tp = ite_tty[unit];
    292  1.1       mw 
    293  1.1       mw 	if ((tp->t_state&(TS_ISOPEN|TS_XCLUDE)) == (TS_ISOPEN|TS_XCLUDE)
    294  1.1       mw 	    && p->p_ucred->cr_uid != 0)
    295  1.1       mw 		return (EBUSY);
    296  1.1       mw 	if ((ip->flags & ITE_ACTIVE) == 0) {
    297  1.1       mw 		error = iteon(dev, 0);
    298  1.1       mw 		if (error)
    299  1.1       mw 			return (error);
    300  1.1       mw 		first = 1;
    301  1.1       mw 	}
    302  1.1       mw 	tp->t_oproc = itestart;
    303  1.1       mw 	tp->t_param = NULL;
    304  1.1       mw 	tp->t_dev = dev;
    305  1.1       mw 	if ((tp->t_state&TS_ISOPEN) == 0) {
    306  1.1       mw 		ttychars(tp);
    307  1.1       mw 		tp->t_iflag = TTYDEF_IFLAG;
    308  1.1       mw 		tp->t_oflag = TTYDEF_OFLAG;
    309  1.1       mw 		tp->t_cflag = CS8|CREAD;
    310  1.1       mw 		tp->t_lflag = TTYDEF_LFLAG;
    311  1.1       mw 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    312  1.1       mw 		/* don't set TS_ISOPEN  here, or the tty queues won't
    313  1.1       mw 		   be initialized in ttyopen()! */
    314  1.1       mw 		tp->t_state = TS_CARR_ON;
    315  1.1       mw 		ttsetwater(tp);
    316  1.1       mw 	}
    317  1.1       mw 	error = (*linesw[tp->t_line].l_open)(dev, tp);
    318  1.1       mw 	if (error == 0) {
    319  1.1       mw 		tp->t_winsize.ws_row = ip->rows;
    320  1.1       mw 		tp->t_winsize.ws_col = ip->cols;
    321  1.1       mw 	} else if (first)
    322  1.1       mw 		iteoff(dev, 0);
    323  1.1       mw 	return (error);
    324  1.1       mw }
    325  1.1       mw 
    326  1.1       mw /*ARGSUSED*/
    327  1.1       mw iteclose(dev, flag, mode, p)
    328  1.1       mw 	dev_t dev;
    329  1.1       mw 	int flag, mode;
    330  1.1       mw 	struct proc *p;
    331  1.1       mw {
    332  1.1       mw 	register struct tty *tp = ite_tty[UNIT(dev)];
    333  1.1       mw 
    334  1.1       mw 	(*linesw[tp->t_line].l_close)(tp, flag);
    335  1.1       mw 	ttyclose(tp);
    336  1.1       mw 	iteoff(dev, 0);
    337  1.1       mw 	if (tp != &ite_cons)
    338  1.1       mw 	  {
    339  1.1       mw 	    FREE(tp, M_TTYS);
    340  1.1       mw 	    ite_tty[UNIT(dev)] = (struct tty *)NULL;
    341  1.1       mw 	  }
    342  1.1       mw 	return(0);
    343  1.1       mw }
    344  1.1       mw 
    345  1.1       mw iteread(dev, uio, flag)
    346  1.1       mw 	dev_t dev;
    347  1.1       mw 	struct uio *uio;
    348  1.1       mw {
    349  1.1       mw 	register struct tty *tp = ite_tty[UNIT(dev)];
    350  1.1       mw 	int rc;
    351  1.1       mw 
    352  1.1       mw 	rc = ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    353  1.1       mw 	return rc;
    354  1.1       mw }
    355  1.1       mw 
    356  1.1       mw itewrite(dev, uio, flag)
    357  1.1       mw 	dev_t dev;
    358  1.1       mw 	struct uio *uio;
    359  1.1       mw {
    360  1.1       mw 	int unit = UNIT(dev);
    361  1.1       mw 	register struct tty *tp = ite_tty[unit];
    362  1.1       mw 
    363  1.1       mw 	if ((ite_softc[unit].flags & ITE_ISCONS) && constty &&
    364  1.1       mw 	    (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN))
    365  1.1       mw 		tp = constty;
    366  1.1       mw 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    367  1.1       mw }
    368  1.1       mw 
    369  1.1       mw iteioctl(dev, cmd, addr, flag)
    370  1.1       mw 	dev_t dev;
    371  1.1       mw 	caddr_t addr;
    372  1.1       mw {
    373  1.1       mw 	register struct tty *tp = ite_tty[UNIT(dev)];
    374  1.1       mw 	int error;
    375  1.1       mw 
    376  1.1       mw 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag);
    377  1.1       mw 	if (error >= 0)
    378  1.1       mw 		return (error);
    379  1.1       mw 	error = ttioctl(tp, cmd, addr, flag);
    380  1.1       mw 	if (error >= 0)
    381  1.1       mw 		return (error);
    382  1.1       mw 	return (ENOTTY);
    383  1.1       mw }
    384  1.1       mw 
    385  1.1       mw itestart(tp)
    386  1.1       mw 	register struct tty *tp;
    387  1.1       mw {
    388  1.1       mw 	register int cc, s;
    389  1.1       mw 	int hiwat = 0;
    390  1.1       mw 
    391  1.1       mw 	s = spltty();
    392  1.1       mw 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
    393  1.1       mw 		splx(s);
    394  1.1       mw 		return;
    395  1.1       mw 	}
    396  1.1       mw 	tp->t_state |= TS_BUSY;
    397  1.1       mw 	cc = RB_LEN (&tp->t_out);
    398  1.1       mw 	if (cc <= tp->t_lowat) {
    399  1.1       mw 		if (tp->t_state & TS_ASLEEP) {
    400  1.1       mw 			tp->t_state &= ~TS_ASLEEP;
    401  1.1       mw 			wakeup(&tp->t_out);
    402  1.1       mw 		}
    403  1.1       mw 		selwakeup(&tp->t_wsel);
    404  1.1       mw 	}
    405  1.1       mw 	/*
    406  1.1       mw 	 * Limit the amount of output we do in one burst
    407  1.1       mw 	 * to prevent hogging the CPU.
    408  1.1       mw 	 */
    409  1.1       mw 	if (cc > iteburst) {
    410  1.1       mw 		hiwat++;
    411  1.1       mw 		cc = iteburst;
    412  1.1       mw 	}
    413  1.1       mw 	while (--cc >= 0) {
    414  1.1       mw 		register int c;
    415  1.1       mw 
    416  1.1       mw 		c = rbgetc(&tp->t_out);
    417  1.1       mw 		/*
    418  1.1       mw 		 * iteputchar() may take a long time and we don't want to
    419  1.1       mw 		 * block all interrupts for long periods of time.  Since
    420  1.1       mw 		 * there is no need to stay at high priority while outputing
    421  1.1       mw 		 * the character (since we don't have to worry about
    422  1.1       mw 		 * interrupts), we don't.  We just need to make sure that
    423  1.1       mw 		 * we don't reenter iteputchar, which is guarenteed by the
    424  1.1       mw 		 * earlier setting of TS_BUSY.
    425  1.1       mw 		 */
    426  1.1       mw 		splx(s);
    427  1.1       mw 		iteputchar(c, tp->t_dev);
    428  1.1       mw 		spltty();
    429  1.1       mw 	}
    430  1.1       mw 	if (hiwat) {
    431  1.1       mw 		tp->t_state |= TS_TIMEOUT;
    432  1.1       mw 		timeout(ttrstrt, tp, 1);
    433  1.1       mw 	}
    434  1.1       mw 	tp->t_state &= ~TS_BUSY;
    435  1.1       mw 	splx(s);
    436  1.1       mw }
    437  1.1       mw 
    438  1.1       mw /* these are used to implement repeating keys.. */
    439  1.1       mw static u_char last_char = 0;
    440  1.1       mw static u_char tout_pending = 0;
    441  1.1       mw 
    442  1.1       mw static void
    443  1.1       mw repeat_handler (a0, a1)
    444  1.1       mw     int a0, a1;
    445  1.1       mw {
    446  1.1       mw   tout_pending = 0;
    447  1.1       mw   /* leave it up to itefilter() to possible install a new callout entry
    448  1.1       mw      to reinvoke repeat_handler() */
    449  1.1       mw   itefilter (last_char, ITEFILT_REPEATER);
    450  1.1       mw }
    451  1.1       mw 
    452  1.1       mw 
    453  1.1       mw int
    454  1.1       mw itefilter(c, caller)
    455  1.1       mw      register u_char c;
    456  1.1       mw      enum caller caller;
    457  1.1       mw {
    458  1.1       mw   static u_char mod = 0;
    459  1.1       mw   static u_char last_dead = 0;
    460  1.1       mw   register char code, *str;
    461  1.1       mw   u_char up, mask, i;
    462  1.1       mw   struct key key;
    463  1.1       mw 
    464  1.1       mw   if (caller != ITEFILT_CONSOLE && kbd_tty == NULL)
    465  1.1       mw      return;
    466  1.1       mw 
    467  1.1       mw   up = c & 0x80 ? 1 : 0;
    468  1.1       mw   c &= 0x7f;
    469  1.1       mw   code = 0;
    470  1.1       mw 
    471  1.1       mw   mask = 0;
    472  1.1       mw   if (c >= KBD_LEFT_SHIFT)
    473  1.1       mw     {
    474  1.1       mw       switch (c)
    475  1.1       mw         {
    476  1.1       mw         case KBD_LEFT_SHIFT:
    477  1.1       mw           mask = KBD_MOD_LSHIFT;
    478  1.1       mw           break;
    479  1.1       mw 
    480  1.1       mw         case KBD_RIGHT_SHIFT:
    481  1.1       mw           mask = KBD_MOD_RSHIFT;
    482  1.1       mw           break;
    483  1.1       mw 
    484  1.1       mw         case KBD_LEFT_ALT:
    485  1.1       mw           mask = KBD_MOD_LALT;
    486  1.1       mw           break;
    487  1.1       mw 
    488  1.1       mw         case KBD_RIGHT_ALT:
    489  1.1       mw           mask = KBD_MOD_RALT;
    490  1.1       mw           break;
    491  1.1       mw 
    492  1.1       mw         case KBD_LEFT_META:
    493  1.1       mw           mask = KBD_MOD_LMETA;
    494  1.1       mw           break;
    495  1.1       mw 
    496  1.1       mw         case KBD_RIGHT_META:
    497  1.1       mw           mask = KBD_MOD_RMETA;
    498  1.1       mw           break;
    499  1.1       mw 
    500  1.1       mw         case KBD_CAPS_LOCK:
    501  1.1       mw           /* capslock already behaves `right', don't need to keep track of the
    502  1.1       mw              state in here. */
    503  1.1       mw           mask = KBD_MOD_CAPS;
    504  1.1       mw           break;
    505  1.1       mw 
    506  1.1       mw         case KBD_CTRL:
    507  1.1       mw           mask = KBD_MOD_CTRL;
    508  1.1       mw           break;
    509  1.1       mw         }
    510  1.1       mw 
    511  1.1       mw       if (mask)
    512  1.1       mw         {
    513  1.1       mw           if (up)
    514  1.1       mw             mod &= ~mask;
    515  1.1       mw           else
    516  1.1       mw             mod |= mask;
    517  1.1       mw         }
    518  1.1       mw 
    519  1.1       mw       /* these keys should not repeat, so it's the Right Thing dealing with
    520  1.1       mw          repeaters only after this block. */
    521  1.1       mw 
    522  1.1       mw       /* return even if it wasn't a modifier key, the other codes up here
    523  1.1       mw          are either special (like reset warning), or not yet defined */
    524  1.1       mw       return -1;
    525  1.1       mw     }
    526  1.1       mw 
    527  1.1       mw   /* no matter which character we're repeating, stop it if we get a key-up
    528  1.1       mw      event. I think this is the same thing amigados does. */
    529  1.1       mw   if (up)
    530  1.1       mw     {
    531  1.1       mw       if (tout_pending)
    532  1.1       mw         {
    533  1.1       mw           untimeout (repeat_handler, 0);
    534  1.1       mw           tout_pending = 0;
    535  1.1       mw         }
    536  1.1       mw       return -1;
    537  1.1       mw     }
    538  1.1       mw 
    539  1.1       mw 
    540  1.1       mw   switch (mod & (KBD_MOD_ALT | KBD_MOD_SHIFT))
    541  1.1       mw     {
    542  1.1       mw     case 0:
    543  1.1       mw 	key = kbdmap.keys[c];
    544  1.1       mw 	if (!(mod & KBD_MOD_CAPS) || !(key.mode & KBD_MODE_CAPS))
    545  1.1       mw 	  break;
    546  1.1       mw 	/* FALL INTO */
    547  1.1       mw 
    548  1.1       mw     case KBD_MOD_LSHIFT:
    549  1.1       mw     case KBD_MOD_RSHIFT:
    550  1.1       mw     case KBD_MOD_SHIFT:
    551  1.1       mw         key = kbdmap.shift_keys[c];
    552  1.1       mw         break;
    553  1.1       mw 
    554  1.1       mw     case KBD_MOD_LALT:
    555  1.1       mw     case KBD_MOD_RALT:
    556  1.1       mw     case KBD_MOD_ALT:
    557  1.1       mw 	key = kbdmap.alt_keys[c];
    558  1.1       mw 	if (!(mod & KBD_MOD_CAPS) || !(key.mode & KBD_MODE_CAPS))
    559  1.1       mw 	  break;
    560  1.1       mw 	/* FALL INTO */
    561  1.1       mw 
    562  1.1       mw     case KBD_MOD_LALT|KBD_MOD_LSHIFT:
    563  1.1       mw     case KBD_MOD_LALT|KBD_MOD_RSHIFT:
    564  1.1       mw     case KBD_MOD_LALT|KBD_MOD_SHIFT:
    565  1.1       mw     case KBD_MOD_RALT|KBD_MOD_RSHIFT:
    566  1.1       mw     case KBD_MOD_RALT|KBD_MOD_SHIFT:
    567  1.1       mw     case KBD_MOD_ALT|KBD_MOD_RSHIFT:
    568  1.1       mw 	key = kbdmap.alt_shift_keys[c];
    569  1.1       mw 	break;
    570  1.1       mw     }
    571  1.1       mw 
    572  1.1       mw   code = key.code;
    573  1.1       mw 
    574  1.1       mw   /* arrange to repeat the keystroke. By doing this at the level of scan-codes,
    575  1.1       mw      we can have function keys, and keys that send strings, repeat too. This
    576  1.1       mw      also entitles an additional overhead, since we have to do the conversion
    577  1.1       mw      each time, but I guess that's ok. */
    578  1.1       mw   if (!tout_pending && caller == ITEFILT_TTY)
    579  1.1       mw     {
    580  1.1       mw       tout_pending = 1;
    581  1.1       mw       last_char = c;
    582  1.1       mw       timeout (repeat_handler, 0, start_repeat_timo);
    583  1.1       mw     }
    584  1.1       mw   else if (!tout_pending && caller == ITEFILT_REPEATER)
    585  1.1       mw     {
    586  1.1       mw       tout_pending = 1;
    587  1.1       mw       last_char = c;
    588  1.1       mw       timeout (repeat_handler, 0, next_repeat_timo);
    589  1.1       mw     }
    590  1.1       mw 
    591  1.1       mw   /* handle dead keys */
    592  1.1       mw   if (key.mode & KBD_MODE_DEAD)
    593  1.1       mw     {
    594  1.1       mw       /* if entered twice, send accent itself */
    595  1.1       mw       if (last_dead == key.mode & KBD_MODE_ACCMASK)
    596  1.1       mw         last_dead = 0;
    597  1.1       mw       else
    598  1.1       mw 	{
    599  1.1       mw 	  last_dead = key.mode & KBD_MODE_ACCMASK;
    600  1.1       mw 	  return -1;
    601  1.1       mw 	}
    602  1.1       mw     }
    603  1.1       mw   if (last_dead)
    604  1.1       mw     {
    605  1.1       mw       /* can't apply dead flag to string-keys */
    606  1.1       mw       if (! (key.mode & KBD_MODE_STRING) && code >= '@' && code < 0x7f)
    607  1.1       mw         code = acctable[KBD_MODE_ACCENT (last_dead)][code - '@'];
    608  1.1       mw 
    609  1.1       mw       last_dead = 0;
    610  1.1       mw     }
    611  1.1       mw 
    612  1.1       mw   /* if not string, apply META and CTRL modifiers */
    613  1.1       mw   if (! (key.mode & KBD_MODE_STRING))
    614  1.1       mw     {
    615  1.1       mw       if (mod & KBD_MOD_CTRL)
    616  1.1       mw         code &= 0x1f;
    617  1.1       mw 
    618  1.1       mw       if (mod & KBD_MOD_META)
    619  1.1       mw         code |= 0x80;
    620  1.1       mw     }
    621  1.1       mw   else
    622  1.1       mw     {
    623  1.1       mw       /* strings are only supported in normal tty mode, not in console mode */
    624  1.1       mw       if (caller != ITEFILT_CONSOLE)
    625  1.1       mw         {
    626  1.1       mw           str = kbdmap.strings + code;
    627  1.1       mw           /* using a length-byte instead of 0-termination allows to embed \0 into
    628  1.1       mw              strings, although this is not used in the default keymap */
    629  1.1       mw           for (i = *str++; i; i--)
    630  1.1       mw             (*linesw[kbd_tty->t_line].l_rint)(*str++, kbd_tty);
    631  1.1       mw         }
    632  1.1       mw       return -1;
    633  1.1       mw     }
    634  1.1       mw 
    635  1.1       mw   if (caller == ITEFILT_CONSOLE)
    636  1.1       mw     return code;
    637  1.1       mw   else
    638  1.1       mw     (*linesw[kbd_tty->t_line].l_rint)(code, kbd_tty);
    639  1.1       mw 
    640  1.1       mw   return -1;
    641  1.1       mw }
    642  1.1       mw 
    643  1.1       mw 
    644  1.1       mw /* helper functions, makes the code below more readable */
    645  1.1       mw static void inline
    646  1.1       mw ite_dnchar(ip, sp, n)
    647  1.1       mw      struct ite_softc *ip;
    648  1.1       mw      struct itesw *sp;
    649  1.1       mw      int n;
    650  1.1       mw {
    651  1.1       mw   (*sp->ite_scroll)(ip, ip->cury, ip->curx + n, n, SCROLL_LEFT);
    652  1.1       mw   attrmov(ip, ip->cury, ip->curx + n, ip->cury, ip->curx,
    653  1.1       mw 	  1, ip->cols - ip->curx - n);
    654  1.1       mw   attrclr(ip, ip->cury, ip->cols - n, 1, n);
    655  1.1       mw   while (n--)
    656  1.1       mw     (*sp->ite_putc)(ip, ' ', ip->cury, ip->cols - n - 1, ATTR_NOR);
    657  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    658  1.1       mw }
    659  1.1       mw 
    660  1.1       mw static void inline
    661  1.1       mw ite_inchar(ip, sp, n)
    662  1.1       mw      struct ite_softc *ip;
    663  1.1       mw      struct itesw *sp;
    664  1.1       mw      int n;
    665  1.1       mw {
    666  1.1       mw   (*sp->ite_scroll)(ip, ip->cury, ip->curx, n, SCROLL_RIGHT);
    667  1.1       mw   attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + n,
    668  1.1       mw 	  1, ip->cols - ip->curx - n);
    669  1.1       mw   attrclr(ip, ip->cury, ip->curx, 1, n);
    670  1.1       mw   while (n--)
    671  1.1       mw     (*sp->ite_putc)(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
    672  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    673  1.1       mw }
    674  1.1       mw 
    675  1.1       mw static void inline
    676  1.1       mw ite_clrtoeol(ip, sp, y, x)
    677  1.1       mw      struct ite_softc *ip;
    678  1.1       mw      struct itesw *sp;
    679  1.1       mw      int y, x;
    680  1.1       mw {
    681  1.1       mw   (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
    682  1.1       mw   attrclr(ip, y, x, 1, ip->cols - x);
    683  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    684  1.1       mw }
    685  1.1       mw 
    686  1.1       mw static void inline
    687  1.1       mw ite_clrtobol(ip, sp, y, x)
    688  1.1       mw      struct ite_softc *ip;
    689  1.1       mw      struct itesw *sp;
    690  1.1       mw      int y, x;
    691  1.1       mw {
    692  1.1       mw   (*sp->ite_clear)(ip, y, 0, 1, x);
    693  1.1       mw   attrclr(ip, y, 0, 1, x);
    694  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    695  1.1       mw }
    696  1.1       mw 
    697  1.1       mw static void inline
    698  1.1       mw ite_clrline(ip, sp, y, x)
    699  1.1       mw      struct ite_softc *ip;
    700  1.1       mw      struct itesw *sp;
    701  1.1       mw      int y, x;
    702  1.1       mw {
    703  1.1       mw   (*sp->ite_clear)(ip, y, 0, 1, ip->cols);
    704  1.1       mw   attrclr(ip, y, 0, 1, ip->cols);
    705  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    706  1.1       mw }
    707  1.1       mw 
    708  1.1       mw 
    709  1.1       mw 
    710  1.1       mw static void inline
    711  1.1       mw ite_clrtoeos(ip, sp)
    712  1.1       mw      struct ite_softc *ip;
    713  1.1       mw      struct itesw *sp;
    714  1.1       mw {
    715  1.1       mw   (*sp->ite_clear)(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
    716  1.1       mw   attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
    717  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    718  1.1       mw }
    719  1.1       mw 
    720  1.1       mw static void inline
    721  1.1       mw ite_clrtobos(ip, sp)
    722  1.1       mw      struct ite_softc *ip;
    723  1.1       mw      struct itesw *sp;
    724  1.1       mw {
    725  1.1       mw   (*sp->ite_clear)(ip, 0, 0, ip->cury, ip->cols);
    726  1.1       mw   attrclr(ip, 0, 0, ip->cury, ip->cols);
    727  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    728  1.1       mw }
    729  1.1       mw 
    730  1.1       mw static void inline
    731  1.1       mw ite_clrscreen(ip, sp)
    732  1.1       mw      struct ite_softc *ip;
    733  1.1       mw      struct itesw *sp;
    734  1.1       mw {
    735  1.1       mw   (*sp->ite_clear)(ip, 0, 0, ip->rows, ip->cols);
    736  1.1       mw   attrclr(ip, 0, 0, ip->rows, ip->cols);
    737  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    738  1.1       mw }
    739  1.1       mw 
    740  1.1       mw 
    741  1.1       mw 
    742  1.1       mw static void inline
    743  1.1       mw ite_dnline(ip, sp, n)
    744  1.1       mw      struct ite_softc *ip;
    745  1.1       mw      struct itesw *sp;
    746  1.1       mw      int n;
    747  1.1       mw {
    748  1.1       mw   (*sp->ite_scroll)(ip, ip->cury + n, 0, n, SCROLL_UP);
    749  1.1       mw   attrmov(ip, ip->cury + n, 0, ip->cury, 0,
    750  1.1       mw 	  ip->bottom_margin + 1 - ip->cury - n, ip->cols);
    751  1.1       mw   (*sp->ite_clear)(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
    752  1.1       mw   attrclr(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
    753  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    754  1.1       mw }
    755  1.1       mw 
    756  1.1       mw static void inline
    757  1.1       mw ite_inline(ip, sp, n)
    758  1.1       mw      struct ite_softc *ip;
    759  1.1       mw      struct itesw *sp;
    760  1.1       mw      int n;
    761  1.1       mw {
    762  1.1       mw   (*sp->ite_scroll)(ip, ip->cury, 0, n, SCROLL_DOWN);
    763  1.1       mw   attrmov(ip, ip->cury, 0, ip->cury + n, 0,
    764  1.1       mw 	  ip->bottom_margin + 1 - ip->cury - n, ip->cols);
    765  1.1       mw   (*sp->ite_clear)(ip, ip->cury, 0, n, ip->cols);
    766  1.1       mw   attrclr(ip, ip->cury, 0, n, ip->cols);
    767  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    768  1.1       mw }
    769  1.1       mw 
    770  1.1       mw static void inline
    771  1.1       mw ite_lf (ip, sp)
    772  1.1       mw      struct ite_softc *ip;
    773  1.1       mw      struct itesw *sp;
    774  1.1       mw {
    775  1.1       mw #if 0
    776  1.1       mw   if (ip->inside_margins)
    777  1.1       mw     {
    778  1.1       mw #endif
    779  1.1       mw       if (++ip->cury >= ip->bottom_margin + 1)
    780  1.1       mw         {
    781  1.1       mw           ip->cury = ip->bottom_margin;
    782  1.1       mw           (*sp->ite_scroll)(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
    783  1.1       mw           ite_clrtoeol(ip, sp, ip->cury, 0);
    784  1.1       mw         }
    785  1.1       mw       else
    786  1.1       mw         (*sp->ite_cursor)(ip, MOVE_CURSOR);
    787  1.1       mw #if 0
    788  1.1       mw     }
    789  1.1       mw   else
    790  1.1       mw     {
    791  1.1       mw       if (++ip->cury == ip->rows)
    792  1.1       mw         {
    793  1.1       mw           --ip->cury;
    794  1.1       mw           (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
    795  1.1       mw           ite_clrtoeol(ip, sp, ip->cury, 0);
    796  1.1       mw         }
    797  1.1       mw       else
    798  1.1       mw         (*sp->ite_cursor)(ip, MOVE_CURSOR);
    799  1.1       mw     }
    800  1.1       mw #endif
    801  1.1       mw   clr_attr(ip, ATTR_INV);
    802  1.1       mw }
    803  1.1       mw 
    804  1.1       mw static void inline
    805  1.1       mw ite_crlf (ip, sp)
    806  1.1       mw      struct ite_softc *ip;
    807  1.1       mw      struct itesw *sp;
    808  1.1       mw {
    809  1.1       mw   ip->curx = 0;
    810  1.1       mw   ite_lf (ip, sp);
    811  1.1       mw }
    812  1.1       mw 
    813  1.1       mw static void inline
    814  1.1       mw ite_cr (ip, sp)
    815  1.1       mw      struct ite_softc *ip;
    816  1.1       mw      struct itesw *sp;
    817  1.1       mw {
    818  1.1       mw   if (ip->curx)
    819  1.1       mw     {
    820  1.1       mw       ip->curx = 0;
    821  1.1       mw       (*sp->ite_cursor)(ip, MOVE_CURSOR);
    822  1.1       mw     }
    823  1.1       mw }
    824  1.1       mw 
    825  1.1       mw static void inline
    826  1.1       mw ite_rlf (ip, sp)
    827  1.1       mw      struct ite_softc *ip;
    828  1.1       mw      struct itesw *sp;
    829  1.1       mw {
    830  1.1       mw   if (ip->cury > 0)
    831  1.1       mw     {
    832  1.1       mw       ip->cury--;
    833  1.1       mw       (*sp->ite_cursor)(ip, MOVE_CURSOR);
    834  1.1       mw     }
    835  1.1       mw   else
    836  1.1       mw     ite_inline (ip, sp, 1);
    837  1.1       mw   clr_attr(ip, ATTR_INV);
    838  1.1       mw }
    839  1.1       mw 
    840  1.1       mw static int inline
    841  1.1       mw atoi (cp)
    842  1.1       mw     const char *cp;
    843  1.1       mw {
    844  1.1       mw   int n;
    845  1.1       mw 
    846  1.1       mw   for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++)
    847  1.1       mw     n = n * 10 + *cp - '0';
    848  1.1       mw 
    849  1.1       mw   return n;
    850  1.1       mw }
    851  1.1       mw 
    852  1.1       mw static char *
    853  1.1       mw index (cp, ch)
    854  1.1       mw     const char *cp;
    855  1.1       mw     char ch;
    856  1.1       mw {
    857  1.1       mw   while (*cp && *cp != ch) cp++;
    858  1.1       mw   return *cp ? cp : 0;
    859  1.1       mw }
    860  1.1       mw 
    861  1.1       mw 
    862  1.1       mw 
    863  1.1       mw static int inline
    864  1.1       mw ite_argnum (ip)
    865  1.1       mw     struct ite_softc *ip;
    866  1.1       mw {
    867  1.1       mw   char ch;
    868  1.1       mw   int n;
    869  1.1       mw 
    870  1.1       mw   /* convert argument string into number */
    871  1.1       mw   if (ip->ap == ip->argbuf)
    872  1.1       mw     return 1;
    873  1.1       mw   ch = *ip->ap;
    874  1.1       mw   *ip->ap = 0;
    875  1.1       mw   n = atoi (ip->argbuf);
    876  1.1       mw   *ip->ap = ch;
    877  1.1       mw 
    878  1.1       mw   return n;
    879  1.1       mw }
    880  1.1       mw 
    881  1.1       mw static int inline
    882  1.1       mw ite_zargnum (ip)
    883  1.1       mw     struct ite_softc *ip;
    884  1.1       mw {
    885  1.1       mw   char ch, *cp;
    886  1.1       mw   int n;
    887  1.1       mw 
    888  1.1       mw   /* convert argument string into number */
    889  1.1       mw   if (ip->ap == ip->argbuf)
    890  1.1       mw     return 0;
    891  1.1       mw   ch = *ip->ap;
    892  1.1       mw   *ip->ap = 0;
    893  1.1       mw   n = atoi (ip->argbuf);
    894  1.1       mw   *ip->ap = ch;
    895  1.1       mw 
    896  1.1       mw   return n;
    897  1.1       mw }
    898  1.1       mw 
    899  1.1       mw static void inline
    900  1.1       mw ite_sendstr (ip, str)
    901  1.1       mw     struct ite_softc *ip;
    902  1.1       mw     char *str;
    903  1.1       mw {
    904  1.1       mw   while (*str)
    905  1.1       mw     (*linesw[kbd_tty->t_line].l_rint)(*str++, kbd_tty);
    906  1.1       mw }
    907  1.1       mw 
    908  1.1       mw static int inline
    909  1.1       mw strncmp (a, b, l)
    910  1.1       mw     const char *a, *b;
    911  1.1       mw     int l;
    912  1.1       mw {
    913  1.1       mw   for (;l--; a++, b++)
    914  1.1       mw     if (*a != *b)
    915  1.1       mw       return *a - *b;
    916  1.1       mw   return 0;
    917  1.1       mw }
    918  1.1       mw 
    919  1.1       mw static void inline
    920  1.1       mw ite_reinit(ip)
    921  1.1       mw     struct ite_softc *ip;
    922  1.1       mw {
    923  1.1       mw   ip->curx = 0;
    924  1.1       mw   ip->cury = 0;
    925  1.1       mw   ip->cursorx = 0;
    926  1.1       mw   ip->cursory = 0;
    927  1.1       mw   ip->save_curx = 0;
    928  1.1       mw   ip->save_cury = 0;
    929  1.1       mw   ip->ap = ip->argbuf;
    930  1.1       mw   ip->emul_level = EMUL_VT300_7;
    931  1.1       mw   ip->eightbit_C1 = 0;
    932  1.1       mw   ip->top_margin = 0; ip->bottom_margin = 23;
    933  1.1       mw   ip->inside_margins = 0;
    934  1.1       mw   ip->linefeed_newline = 0;
    935  1.1       mw 
    936  1.1       mw   (*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
    937  1.1       mw 
    938  1.1       mw   ip->attribute = 0;
    939  1.1       mw   bzero(ip->attrbuf, (ip->rows * ip->cols));
    940  1.1       mw 
    941  1.1       mw   ip->imode = 0;
    942  1.1       mw }
    943  1.1       mw 
    944  1.1       mw 
    945  1.1       mw 
    946  1.1       mw iteputchar(c, dev)
    947  1.1       mw 	register int c;
    948  1.1       mw 	dev_t dev;
    949  1.1       mw {
    950  1.1       mw 	int unit = UNIT(dev);
    951  1.1       mw 	register struct ite_softc *ip = &ite_softc[unit];
    952  1.1       mw 	register struct itesw *sp = &itesw[ip->type];
    953  1.1       mw 	register int n;
    954  1.1       mw 	int x, y;
    955  1.1       mw 	char *cp;
    956  1.1       mw 
    957  1.1       mw 	if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
    958  1.1       mw 	  	return;
    959  1.1       mw 
    960  1.1       mw 	if ((ite_tty[unit]->t_cflag & CSIZE) == CS7
    961  1.1       mw 	    || (ite_tty[unit]->t_cflag & PARENB))
    962  1.1       mw 	  c &= 0x7f;
    963  1.1       mw 
    964  1.1       mw 	if (ip->escape)
    965  1.1       mw 	  {
    966  1.1       mw doesc:
    967  1.1       mw 	    switch (ip->escape)
    968  1.1       mw 	      {
    969  1.1       mw 	      case ESC:
    970  1.1       mw 	        switch (c)
    971  1.1       mw 	          {
    972  1.1       mw 		  /* first 7bit equivalents for the 8bit control characters */
    973  1.1       mw 
    974  1.1       mw 	          case 'D':
    975  1.1       mw 		    c = IND;
    976  1.1       mw 		    ip->escape = 0;
    977  1.1       mw 		    break;
    978  1.1       mw 
    979  1.1       mw 		  case 'E':
    980  1.1       mw 		    c = NEL;
    981  1.1       mw 		    ip->escape = 0;
    982  1.1       mw 		    break;
    983  1.1       mw 
    984  1.1       mw 		  case 'H':
    985  1.1       mw 		    c = HTS;
    986  1.1       mw 		    ip->escape = 0;
    987  1.1       mw 		    break;
    988  1.1       mw 
    989  1.1       mw 		  case 'M':
    990  1.1       mw 		    c = RI;
    991  1.1       mw 		    ip->escape = 0;
    992  1.1       mw 		    break;
    993  1.1       mw 
    994  1.1       mw 		  case 'N':
    995  1.1       mw 		    c = SS2;
    996  1.1       mw 		    ip->escape = 0;
    997  1.1       mw 		    break;
    998  1.1       mw 
    999  1.1       mw 		  case 'O':
   1000  1.1       mw 		    c = SS3;
   1001  1.1       mw 		    ip->escape = 0;
   1002  1.1       mw 		    break;
   1003  1.1       mw 
   1004  1.1       mw 		  case 'P':
   1005  1.1       mw 		    c = DCS;
   1006  1.1       mw 		    ip->escape = 0;
   1007  1.1       mw 		    break;
   1008  1.1       mw 
   1009  1.1       mw 		  case '[':
   1010  1.1       mw 		    c = CSI;
   1011  1.1       mw 		    ip->escape = 0;
   1012  1.1       mw 		    break;
   1013  1.1       mw 
   1014  1.1       mw 		  case '\\':
   1015  1.1       mw 		    c = ST;
   1016  1.1       mw 		    ip->escape = 0;
   1017  1.1       mw 		    break;
   1018  1.1       mw 
   1019  1.1       mw 		  case ']':
   1020  1.1       mw 		    c = OSC;
   1021  1.1       mw 		    ip->escape = 0;
   1022  1.1       mw 		    break;
   1023  1.1       mw 
   1024  1.1       mw 		  case '^':
   1025  1.1       mw 		    c = PM;
   1026  1.1       mw 		    ip->escape = 0;
   1027  1.1       mw 		    break;
   1028  1.1       mw 
   1029  1.1       mw 		  case '_':
   1030  1.1       mw 		    c = APC;
   1031  1.1       mw 		    ip->escape = 0;
   1032  1.1       mw 		    break;
   1033  1.1       mw 
   1034  1.1       mw 
   1035  1.1       mw 		  /* introduces 7/8bit control */
   1036  1.1       mw 		  case ' ':
   1037  1.1       mw 		     /* can be followed by either F or G */
   1038  1.1       mw 		     ip->escape = ' ';
   1039  1.1       mw 		     break;
   1040  1.1       mw 
   1041  1.1       mw 
   1042  1.1       mw 		  /* a lot of character set selections, not yet used...
   1043  1.1       mw 		     94-character sets: */
   1044  1.1       mw 		  case '(':	/* G0 */
   1045  1.1       mw 		  case ')':	/* G1 */
   1046  1.1       mw 		  case '*':	/* G2 */
   1047  1.1       mw 		  case '+':	/* G3 */
   1048  1.1       mw 		  case 'B':	/* ASCII */
   1049  1.1       mw 		  case 'A':	/* ISO latin 1 */
   1050  1.1       mw 		  case '<':	/* user preferred suplemental */
   1051  1.1       mw 		  case '0':	/* dec special graphics */
   1052  1.1       mw 
   1053  1.1       mw 		  /* 96-character sets: */
   1054  1.1       mw 		  case '-':	/* G1 */
   1055  1.1       mw 		  case '.':	/* G2 */
   1056  1.1       mw 		  case '/':	/* G3 */
   1057  1.1       mw 
   1058  1.1       mw 		  /* national character sets: */
   1059  1.1       mw 		  case '4':	/* dutch */
   1060  1.1       mw 		  case '5':
   1061  1.1       mw 		  case 'C':	/* finnish */
   1062  1.1       mw 		  case 'R':	/* french */
   1063  1.1       mw 		  case 'Q':	/* french canadian */
   1064  1.1       mw 		  case 'K':	/* german */
   1065  1.1       mw 		  case 'Y':	/* italian */
   1066  1.1       mw 		  case '6':	/* norwegian/danish */
   1067  1.1       mw 		  case 'Z':	/* spanish */
   1068  1.1       mw 		  case '=':	/* swiss */
   1069  1.1       mw 		  /* note: %5 and %6 are not supported (two chars..) */
   1070  1.1       mw 
   1071  1.1       mw 		    ip->escape = 0;
   1072  1.1       mw 		    /* just ignore for now */
   1073  1.1       mw 		    return -1;
   1074  1.1       mw 
   1075  1.1       mw 
   1076  1.1       mw 		  /* locking shift modes (as you might guess, not yet supported..) */
   1077  1.1       mw 		  case '`':
   1078  1.1       mw 		    ip->GR = ip->G1;
   1079  1.1       mw 		    ip->escape = 0;
   1080  1.1       mw 		    return -1;
   1081  1.1       mw 
   1082  1.1       mw 		  case 'n':
   1083  1.1       mw 		    ip->GL = ip->G2;
   1084  1.1       mw 		    ip->escape = 0;
   1085  1.1       mw 		    return -1;
   1086  1.1       mw 
   1087  1.1       mw 		  case '}':
   1088  1.1       mw 		    ip->GR = ip->G2;
   1089  1.1       mw 		    ip->escape = 0;
   1090  1.1       mw 		    return -1;
   1091  1.1       mw 
   1092  1.1       mw 		  case 'o':
   1093  1.1       mw 		    ip->GL = ip->G3;
   1094  1.1       mw 		    ip->escape = 0;
   1095  1.1       mw 		    return -1;
   1096  1.1       mw 
   1097  1.1       mw 		  case '|':
   1098  1.1       mw 		    ip->GR = ip->G3;
   1099  1.1       mw 		    ip->escape = 0;
   1100  1.1       mw 		    return -1;
   1101  1.1       mw 
   1102  1.1       mw 
   1103  1.1       mw 		  /* font width/height control */
   1104  1.1       mw 		  case '#':
   1105  1.1       mw 		    ip->escape = '#';
   1106  1.1       mw 		    return -1;
   1107  1.1       mw 
   1108  1.1       mw 
   1109  1.1       mw 		  /* hard terminal reset .. */
   1110  1.1       mw 		  case 'c':
   1111  1.1       mw 		    ite_reinit (ip);
   1112  1.1       mw 		    ip->escape = 0;
   1113  1.1       mw 		    return -1;
   1114  1.1       mw 
   1115  1.1       mw 
   1116  1.1       mw 		  case '7':
   1117  1.1       mw 		    ip->save_curx = ip->curx;
   1118  1.1       mw 		    ip->save_cury = ip->cury;
   1119  1.1       mw 		    ip->escape = 0;
   1120  1.1       mw 		    return -1;
   1121  1.1       mw 
   1122  1.1       mw 		  case '8':
   1123  1.1       mw 		    ip->curx = ip->save_curx;
   1124  1.1       mw 		    ip->cury = ip->save_cury;
   1125  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1126  1.1       mw 		    ip->escape = 0;
   1127  1.1       mw 		    return -1;
   1128  1.1       mw 
   1129  1.1       mw 
   1130  1.1       mw 		  /* default catch all for not recognized ESC sequences */
   1131  1.1       mw 		  default:
   1132  1.1       mw 		    ip->escape = 0;
   1133  1.1       mw 		    return -1;
   1134  1.1       mw 		  }
   1135  1.1       mw 		break;
   1136  1.1       mw 
   1137  1.1       mw 
   1138  1.1       mw 	      case ' ':
   1139  1.1       mw 	        switch (c)
   1140  1.1       mw 	          {
   1141  1.1       mw 	          case 'F':
   1142  1.1       mw 		    ip->eightbit_C1 = 0;
   1143  1.1       mw 		    ip->escape = 0;
   1144  1.1       mw 		    return -1;
   1145  1.1       mw 
   1146  1.1       mw 		  case 'G':
   1147  1.1       mw 		    ip->eightbit_C1 = 1;
   1148  1.1       mw 		    ip->escape = 0;
   1149  1.1       mw 		    return -1;
   1150  1.1       mw 
   1151  1.1       mw 		  default:
   1152  1.1       mw 		    /* not supported */
   1153  1.1       mw 		    ip->escape = 0;
   1154  1.1       mw 		    return -1;
   1155  1.1       mw 		  }
   1156  1.1       mw 		break;
   1157  1.1       mw 
   1158  1.1       mw 
   1159  1.1       mw 	      case '#':
   1160  1.1       mw 		switch (c)
   1161  1.1       mw 		  {
   1162  1.1       mw 		  case '5':
   1163  1.1       mw 		    /* single height, single width */
   1164  1.1       mw 		    ip->escape = 0;
   1165  1.1       mw 		    return -1;
   1166  1.1       mw 
   1167  1.1       mw 		  case '6':
   1168  1.1       mw 		    /* double width, single height */
   1169  1.1       mw 		    ip->escape = 0;
   1170  1.1       mw 		    return -1;
   1171  1.1       mw 
   1172  1.1       mw 		  case '3':
   1173  1.1       mw 		    /* top half */
   1174  1.1       mw 		    ip->escape = 0;
   1175  1.1       mw 		    return -1;
   1176  1.1       mw 
   1177  1.1       mw 		  case '4':
   1178  1.1       mw 		    /* bottom half */
   1179  1.1       mw 		    ip->escape = 0;
   1180  1.1       mw 		    return -1;
   1181  1.1       mw 
   1182  1.1       mw 		  case '8':
   1183  1.1       mw 		    /* screen alignment pattern... */
   1184  1.1       mw 		    ip->escape = 0;
   1185  1.1       mw 		    return -1;
   1186  1.1       mw 
   1187  1.1       mw 		  default:
   1188  1.1       mw 		    ip->escape = 0;
   1189  1.1       mw 		    return -1;
   1190  1.1       mw 		  }
   1191  1.1       mw 		break;
   1192  1.1       mw 
   1193  1.1       mw 
   1194  1.1       mw 
   1195  1.1       mw #if 0
   1196  1.1       mw 	      case DCS:
   1197  1.1       mw 	      case PM:
   1198  1.1       mw 	      case APC:
   1199  1.1       mw 	      case OSC:
   1200  1.1       mw 		switch (c)
   1201  1.1       mw 		  {
   1202  1.1       mw 		  case ST:
   1203  1.1       mw 		    ip->escape = 0;
   1204  1.1       mw 		    return -1;
   1205  1.1       mw 
   1206  1.1       mw 		  default:
   1207  1.1       mw 		    return -1;
   1208  1.1       mw 		  }
   1209  1.1       mw 		break;
   1210  1.1       mw #endif
   1211  1.1       mw 
   1212  1.1       mw 
   1213  1.1       mw 	      case CSI:
   1214  1.1       mw 	        /* the biggie... */
   1215  1.1       mw 	        switch (c)
   1216  1.1       mw 	          {
   1217  1.1       mw 	          case '0': case '1': case '2': case '3': case '4':
   1218  1.1       mw 	          case '5': case '6': case '7': case '8': case '9':
   1219  1.1       mw 	          case ';': case '\"': case '$': case '>':
   1220  1.1       mw 	            if (ip->ap < ip->argbuf + ARGBUF_SIZE)
   1221  1.1       mw 	              *ip->ap++ = c;
   1222  1.1       mw 	            return -1;
   1223  1.1       mw 
   1224  1.1       mw 		  case CAN:
   1225  1.1       mw     		    ip->escape = 0;
   1226  1.1       mw 		    return -1;
   1227  1.1       mw 
   1228  1.1       mw 
   1229  1.1       mw 	          case 'p':
   1230  1.1       mw 		    *ip->ap = 0;
   1231  1.1       mw 	            if (! strncmp (ip->argbuf, "61\"", 3))
   1232  1.1       mw 	              ip->emul_level = EMUL_VT100;
   1233  1.1       mw 	            else if (! strncmp (ip->argbuf, "63;1\"", 5)
   1234  1.1       mw 	            	     || ! strncmp (ip->argbuf, "62;1\"", 5))
   1235  1.1       mw 	              ip->emul_level = EMUL_VT300_7;
   1236  1.1       mw 	            else
   1237  1.1       mw 	              ip->emul_level = EMUL_VT300_8;
   1238  1.1       mw 	            ip->escape = 0;
   1239  1.1       mw 	            return -1;
   1240  1.1       mw 
   1241  1.1       mw 
   1242  1.1       mw 	          case '?':
   1243  1.1       mw 		    *ip->ap = 0;
   1244  1.1       mw 	            ip->escape = '?';
   1245  1.1       mw 	            ip->ap = ip->argbuf;
   1246  1.1       mw 	            return -1;
   1247  1.1       mw 
   1248  1.1       mw 
   1249  1.1       mw 		  case 'c':
   1250  1.1       mw 		    *ip->ap = 0;
   1251  1.1       mw 		    if (ip->ap == ip->argbuf
   1252  1.1       mw 		        || (ip->ap == &ip->argbuf[1] && ip->argbuf[0] == '0'))
   1253  1.1       mw 		      {
   1254  1.1       mw 			/* primary DA request, send primary DA response */
   1255  1.1       mw 			if (ip->emul_level == EMUL_VT100)
   1256  1.1       mw 		          ite_sendstr (ip, "\033[61;0c");
   1257  1.1       mw 		        else
   1258  1.1       mw 		          ite_sendstr (ip, "\033[63;0c");
   1259  1.1       mw 		      }
   1260  1.1       mw 
   1261  1.1       mw 		    else if ((ip->ap == &ip->argbuf[1] && ip->argbuf[0] == '>')
   1262  1.1       mw 		        || (ip->ap == &ip->argbuf[2]
   1263  1.1       mw 			    && !strncmp (ip->argbuf, ">0", 2)))
   1264  1.1       mw 		      {
   1265  1.1       mw 		        ite_sendstr (ip, "\033[>24;0;0;0c");
   1266  1.1       mw 		      }
   1267  1.1       mw 
   1268  1.1       mw 		    ip->escape = 0;
   1269  1.1       mw 		    return -1;
   1270  1.1       mw 
   1271  1.1       mw 
   1272  1.1       mw 		  case 'n':
   1273  1.1       mw 		    *ip->ap = 0;
   1274  1.1       mw 		    if (ip->ap == &ip->argbuf[1])
   1275  1.1       mw 		      {
   1276  1.1       mw 		        if (ip->argbuf[0] == '5')
   1277  1.1       mw 		          ite_sendstr (ip, "\033[0n");	/* no malfunction */
   1278  1.1       mw 
   1279  1.1       mw 		        else if (ip->argbuf[0] == '6')
   1280  1.1       mw 		          {
   1281  1.1       mw 		            sprintf (ip->argbuf, "\033[%d;%dR",
   1282  1.1       mw 				     ip->cury + 1, ip->curx + 1);
   1283  1.1       mw 			    /* cursor position report */
   1284  1.1       mw 			    ite_sendstr (ip, ip->argbuf);
   1285  1.1       mw 		          }
   1286  1.1       mw 
   1287  1.1       mw 		      }
   1288  1.1       mw 		    ip->escape = 0;
   1289  1.1       mw 		    return -1;
   1290  1.1       mw 
   1291  1.1       mw 
   1292  1.1       mw 	          case 'h': case 'l':
   1293  1.1       mw 		    *ip->ap = 0;
   1294  1.1       mw 		    if (ip->ap == &ip->argbuf[1] && ip->argbuf[0] == '4')
   1295  1.1       mw 		      ip->imode = (c == 'h');	/* insert/replace mode */
   1296  1.1       mw 
   1297  1.1       mw 		    else if (ip->ap == &ip->argbuf[2]
   1298  1.1       mw 			     && !strncmp (ip->argbuf, "20", 2))
   1299  1.1       mw 		      ip->linefeed_newline = (c == 'h');
   1300  1.1       mw 
   1301  1.1       mw 
   1302  1.1       mw 	            /* various not supported commands */
   1303  1.1       mw 	            ip->escape = 0;
   1304  1.1       mw 	            return -1;
   1305  1.1       mw 
   1306  1.1       mw 
   1307  1.1       mw 		  case 'M':
   1308  1.1       mw 		    *ip->ap = 0;
   1309  1.1       mw 		    ite_dnline (ip, sp, ite_argnum (ip));
   1310  1.1       mw 	            ip->escape = 0;
   1311  1.1       mw 	            return -1;
   1312  1.1       mw 
   1313  1.1       mw 
   1314  1.1       mw 		  case 'L':
   1315  1.1       mw 		    *ip->ap = 0;
   1316  1.1       mw 		    ite_inline (ip, sp, ite_argnum (ip));
   1317  1.1       mw 	            ip->escape = 0;
   1318  1.1       mw 	            return -1;
   1319  1.1       mw 
   1320  1.1       mw 
   1321  1.1       mw 		  case 'P':
   1322  1.1       mw 		    *ip->ap = 0;
   1323  1.1       mw 		    ite_dnchar (ip, sp, ite_argnum (ip));
   1324  1.1       mw 	            ip->escape = 0;
   1325  1.1       mw 	            return -1;
   1326  1.1       mw 
   1327  1.1       mw 
   1328  1.1       mw 		  case '@':
   1329  1.1       mw 		    *ip->ap = 0;
   1330  1.1       mw 		    ite_inchar (ip, sp, ite_argnum (ip));
   1331  1.1       mw 	            ip->escape = 0;
   1332  1.1       mw 	            return -1;
   1333  1.1       mw 
   1334  1.1       mw 
   1335  1.1       mw 		  case 'H':
   1336  1.1       mw 		  case 'f':
   1337  1.1       mw 		    *ip->ap = 0;
   1338  1.1       mw 		    y = atoi (ip->argbuf);
   1339  1.1       mw 		    x = 0;
   1340  1.1       mw 		    cp = index (ip->argbuf, ';');
   1341  1.1       mw 		    if (cp)
   1342  1.1       mw 		      x = atoi (cp + 1);
   1343  1.1       mw 		    if (x) x--;
   1344  1.1       mw 		    if (y) y--;
   1345  1.1       mw 		    if (ip->inside_margins)
   1346  1.1       mw 		      {
   1347  1.1       mw 			y += ip->top_margin;
   1348  1.1       mw 			ip->cury = MIN(y, ip->bottom_margin);
   1349  1.1       mw 		      }
   1350  1.1       mw 		    else
   1351  1.1       mw 		      {
   1352  1.1       mw 			ip->cury = MIN(y, ip->rows - 1);
   1353  1.1       mw 		      }
   1354  1.1       mw 		    ip->curx = MIN(x, ip->cols - 1);
   1355  1.1       mw 		    ip->escape = 0;
   1356  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1357  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1358  1.1       mw 		    return -1;
   1359  1.1       mw 
   1360  1.1       mw 		  case 'A':
   1361  1.1       mw 		    *ip->ap = 0;
   1362  1.1       mw 		    n = ip->cury - ite_argnum (ip);
   1363  1.1       mw 		    ip->cury = n >= 0 ? n : 0;
   1364  1.1       mw 		    ip->escape = 0;
   1365  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1366  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1367  1.1       mw 		    return -1;
   1368  1.1       mw 
   1369  1.1       mw 		  case 'B':
   1370  1.1       mw 		    *ip->ap = 0;
   1371  1.1       mw 		    n = ite_argnum (ip) + ip->cury;
   1372  1.1       mw 		    ip->cury = MIN(n, ip->rows - 1);
   1373  1.1       mw 		    ip->escape = 0;
   1374  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1375  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1376  1.1       mw 		    return -1;
   1377  1.1       mw 
   1378  1.1       mw 		  case 'C':
   1379  1.1       mw 		    *ip->ap = 0;
   1380  1.1       mw 		    n = ite_argnum (ip) + ip->curx;
   1381  1.1       mw 		    ip->curx = MIN(n, ip->cols - 1);
   1382  1.1       mw 		    ip->escape = 0;
   1383  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1384  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1385  1.1       mw 		    return -1;
   1386  1.1       mw 
   1387  1.1       mw 		  case 'D':
   1388  1.1       mw 		    *ip->ap = 0;
   1389  1.1       mw 		    n = ip->curx - ite_argnum (ip);
   1390  1.1       mw 		    ip->curx = n >= 0 ? n : 0;
   1391  1.1       mw 		    ip->escape = 0;
   1392  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1393  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1394  1.1       mw 		    return -1;
   1395  1.1       mw 
   1396  1.1       mw 
   1397  1.1       mw 
   1398  1.1       mw 
   1399  1.1       mw 		  case 'J':
   1400  1.1       mw 		    *ip->ap = 0;
   1401  1.1       mw 		    n = ite_zargnum (ip);
   1402  1.1       mw 		    if (n == 0)
   1403  1.1       mw 	              ite_clrtoeos(ip, sp);
   1404  1.1       mw 		    else if (n == 1)
   1405  1.1       mw 		      ite_clrtobos(ip, sp);
   1406  1.1       mw 		    else if (n == 2)
   1407  1.1       mw 		      ite_clrscreen(ip, sp);
   1408  1.1       mw 	            ip->escape = 0;
   1409  1.1       mw 	            return -1;
   1410  1.1       mw 
   1411  1.1       mw 
   1412  1.1       mw 		  case 'K':
   1413  1.1       mw 		    *ip->ap = 0;
   1414  1.1       mw 		    n = ite_zargnum (ip);
   1415  1.1       mw 		    if (n == 0)
   1416  1.1       mw 		      ite_clrtoeol(ip, sp, ip->cury, ip->curx);
   1417  1.1       mw 		    else if (n == 1)
   1418  1.1       mw 		      ite_clrtobol(ip, sp, ip->cury, ip->curx);
   1419  1.1       mw 		    else if (n == 2)
   1420  1.1       mw 		      ite_clrline(ip, sp, ip->cury, ip->curx);
   1421  1.1       mw 		    ip->escape = 0;
   1422  1.1       mw 		    return -1;
   1423  1.1       mw 
   1424  1.1       mw 
   1425  1.1       mw 		  case 'X':
   1426  1.1       mw 		    *ip->ap = 0;
   1427  1.1       mw 		    for (n = ite_argnum (ip); n > 0; n--)
   1428  1.1       mw 		      {
   1429  1.1       mw 			attrclr(ip, ip->cury, ip->curx + n - 1, 1, 1);
   1430  1.1       mw 			(*sp->ite_putc)(ip, ' ', ip->cury, ip->curx + n - 1, ATTR_NOR);
   1431  1.1       mw 		      }
   1432  1.1       mw 		    ip->escape = 0;
   1433  1.1       mw 		    return -1;
   1434  1.1       mw 
   1435  1.1       mw 
   1436  1.1       mw 	          case '}': case '`':
   1437  1.1       mw 	            /* status line control */
   1438  1.1       mw 	            ip->escape = 0;
   1439  1.1       mw 	            return -1;
   1440  1.1       mw 
   1441  1.1       mw 
   1442  1.1       mw 		  case 'r':
   1443  1.1       mw 		    *ip->ap = 0;
   1444  1.1       mw 		    x = atoi (ip->argbuf);
   1445  1.1       mw 		    y = 0;
   1446  1.1       mw 		    cp = index (ip->argbuf, ';');
   1447  1.1       mw 		    if (cp)
   1448  1.1       mw 		      y = atoi (cp + 1);
   1449  1.1       mw 		    if (x) x--;
   1450  1.1       mw 		    if (y) y--;
   1451  1.1       mw 		    ip->top_margin = MIN(x, ip->rows - 1);
   1452  1.1       mw 		    ip->bottom_margin = MIN(y, ip->rows - 1);
   1453  1.1       mw 		    ip->escape = 0;
   1454  1.1       mw 		    return -1;
   1455  1.1       mw 
   1456  1.1       mw 
   1457  1.1       mw 		  case 'm':
   1458  1.1       mw 		    /* big attribute setter/resetter */
   1459  1.1       mw 		    {
   1460  1.1       mw 		      char *cp;
   1461  1.1       mw 		      *ip->ap = 0;
   1462  1.1       mw 		      for (cp = ip->argbuf; cp < ip->ap; )
   1463  1.1       mw 		        {
   1464  1.1       mw 			  switch (*cp)
   1465  1.1       mw 			    {
   1466  1.1       mw 			    case '0':
   1467  1.1       mw 			      clr_attr (ip, ATTR_ALL);
   1468  1.1       mw 			      cp++;
   1469  1.1       mw 			      break;
   1470  1.1       mw 
   1471  1.1       mw 			    case '1':
   1472  1.1       mw 			      set_attr (ip, ATTR_BOLD);
   1473  1.1       mw 			      cp++;
   1474  1.1       mw 			      break;
   1475  1.1       mw 
   1476  1.1       mw 			    case '2':
   1477  1.1       mw 			      switch (cp[1])
   1478  1.1       mw 			        {
   1479  1.1       mw 			        case '2':
   1480  1.1       mw 			          clr_attr (ip, ATTR_BOLD);
   1481  1.1       mw 			          cp += 2;
   1482  1.1       mw 			          break;
   1483  1.1       mw 
   1484  1.1       mw 			        case '4':
   1485  1.1       mw 			          clr_attr (ip, ATTR_UL);
   1486  1.1       mw 			          cp += 2;
   1487  1.1       mw 			          break;
   1488  1.1       mw 
   1489  1.1       mw 			        case '5':
   1490  1.1       mw 			          clr_attr (ip, ATTR_BLINK);
   1491  1.1       mw 			          cp += 2;
   1492  1.1       mw 			          break;
   1493  1.1       mw 
   1494  1.1       mw 			        case '7':
   1495  1.1       mw 			          clr_attr (ip, ATTR_INV);
   1496  1.1       mw 			          cp += 2;
   1497  1.1       mw 			          break;
   1498  1.1       mw 
   1499  1.1       mw 		        	default:
   1500  1.1       mw 		        	  cp++;
   1501  1.1       mw 		        	  break;
   1502  1.1       mw 		        	}
   1503  1.1       mw 			      break;
   1504  1.1       mw 
   1505  1.1       mw 			    case '4':
   1506  1.1       mw 			      set_attr (ip, ATTR_UL);
   1507  1.1       mw 			      cp++;
   1508  1.1       mw 			      break;
   1509  1.1       mw 
   1510  1.1       mw 			    case '5':
   1511  1.1       mw 			      set_attr (ip, ATTR_BLINK);
   1512  1.1       mw 			      cp++;
   1513  1.1       mw 			      break;
   1514  1.1       mw 
   1515  1.1       mw 			    case '7':
   1516  1.1       mw 			      set_attr (ip, ATTR_INV);
   1517  1.1       mw 			      cp++;
   1518  1.1       mw 			      break;
   1519  1.1       mw 
   1520  1.1       mw 			    default:
   1521  1.1       mw 			      cp++;
   1522  1.1       mw 			      break;
   1523  1.1       mw 			    }
   1524  1.1       mw 		        }
   1525  1.1       mw 
   1526  1.1       mw 		    }
   1527  1.1       mw 		    ip->escape = 0;
   1528  1.1       mw 		    return -1;
   1529  1.1       mw 
   1530  1.1       mw 
   1531  1.1       mw 		  case 'u':
   1532  1.1       mw 		    /* DECRQTSR */
   1533  1.1       mw 		    ite_sendstr (ip, "\033P\033\\");
   1534  1.1       mw 		    ip->escape = 0;
   1535  1.1       mw 		    return -1;
   1536  1.1       mw 
   1537  1.1       mw 
   1538  1.1       mw 
   1539  1.1       mw 		  default:
   1540  1.1       mw 		    ip->escape = 0;
   1541  1.1       mw 		    return -1;
   1542  1.1       mw 		  }
   1543  1.1       mw 		break;
   1544  1.1       mw 
   1545  1.1       mw 
   1546  1.1       mw 
   1547  1.1       mw 	      case '?':	/* CSI ? */
   1548  1.1       mw 	      	switch (c)
   1549  1.1       mw 	      	  {
   1550  1.1       mw 	          case '0': case '1': case '2': case '3': case '4':
   1551  1.1       mw 	          case '5': case '6': case '7': case '8': case '9':
   1552  1.1       mw 	          case ';': case '\"': case '$':
   1553  1.1       mw 	            if (ip->ap < ip->argbuf + ARGBUF_SIZE)
   1554  1.1       mw 	              *ip->ap++ = c;
   1555  1.1       mw 	            return -1;
   1556  1.1       mw 
   1557  1.1       mw 
   1558  1.1       mw 		  case CAN:
   1559  1.1       mw     		    ip->escape = 0;
   1560  1.1       mw 		    return -1;
   1561  1.1       mw 
   1562  1.1       mw 
   1563  1.1       mw 		  case 'n':
   1564  1.1       mw 		    *ip->ap = 0;
   1565  1.1       mw 		    if (ip->ap == &ip->argbuf[2])
   1566  1.1       mw 		      {
   1567  1.1       mw 		        if (! strncmp (ip->argbuf, "15", 2))
   1568  1.1       mw 		          /* printer status: no printer */
   1569  1.1       mw 		          ite_sendstr (ip, "\033[13n");
   1570  1.1       mw 
   1571  1.1       mw 		        else if (! strncmp (ip->argbuf, "25", 2))
   1572  1.1       mw 		          /* udk status */
   1573  1.1       mw 		          ite_sendstr (ip, "\033[20n");
   1574  1.1       mw 
   1575  1.1       mw 		        else if (! strncmp (ip->argbuf, "26", 2))
   1576  1.1       mw 		          /* keyboard dialect: US */
   1577  1.1       mw 		          ite_sendstr (ip, "\033[27;1n");
   1578  1.1       mw 		      }
   1579  1.1       mw 		    ip->escape = 0;
   1580  1.1       mw 		    return -1;
   1581  1.1       mw 
   1582  1.1       mw 
   1583  1.1       mw 		  case 'h': case 'l':
   1584  1.1       mw 		    *ip->ap = 0;
   1585  1.1       mw 		    if (ip->ap[0] == '6')
   1586  1.1       mw 		      ip->inside_margins = (c == 'h');
   1587  1.1       mw 
   1588  1.1       mw 		    else if (! strncmp (ip->ap, "25", 2))
   1589  1.1       mw 		      (*itesw[ip->type].ite_cursor)(ip,
   1590  1.1       mw 						    (c == 'h') ? DRAW_CURSOR : ERASE_CURSOR);
   1591  1.1       mw 
   1592  1.1       mw 		    /* others.. */
   1593  1.1       mw 
   1594  1.1       mw 		  default:
   1595  1.1       mw 		    ip->escape = 0;
   1596  1.1       mw 		    return -1;
   1597  1.1       mw 		  }
   1598  1.1       mw 		break;
   1599  1.1       mw 
   1600  1.1       mw 
   1601  1.1       mw 	      default:
   1602  1.1       mw 	        ip->escape = 0;
   1603  1.1       mw 	        return -1;
   1604  1.1       mw 	      }
   1605  1.1       mw           }
   1606  1.1       mw 
   1607  1.1       mw 
   1608  1.1       mw 	switch (c) {
   1609  1.1       mw 
   1610  1.1       mw 	case VT:	/* VT is treated like LF */
   1611  1.1       mw 	case FF:	/* so is FF */
   1612  1.1       mw 	case LF:
   1613  1.1       mw 		if (ip->linefeed_newline)
   1614  1.1       mw 		  ite_crlf (ip, sp);
   1615  1.1       mw 		else
   1616  1.1       mw 		  ite_lf (ip, sp);
   1617  1.1       mw 		break;
   1618  1.1       mw 
   1619  1.1       mw 	case CR:
   1620  1.1       mw 		ite_cr (ip, sp);
   1621  1.1       mw 		break;
   1622  1.1       mw 
   1623  1.1       mw 	case BS:
   1624  1.1       mw 		if (--ip->curx < 0)
   1625  1.1       mw 			ip->curx = 0;
   1626  1.1       mw 		else
   1627  1.1       mw 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
   1628  1.1       mw 		break;
   1629  1.1       mw 
   1630  1.1       mw 	case HT:
   1631  1.1       mw 		if (ip->curx < TABEND(unit)) {
   1632  1.1       mw 			n = TABSIZE - (ip->curx & (TABSIZE - 1));
   1633  1.1       mw 			ip->curx += n;
   1634  1.1       mw 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
   1635  1.1       mw 		} else
   1636  1.1       mw 			itecheckwrap(ip, sp);
   1637  1.1       mw 		break;
   1638  1.1       mw 
   1639  1.1       mw 	case BEL:
   1640  1.1       mw 		if (ite_tty[unit] == kbd_tty)
   1641  1.1       mw 			kbdbell();
   1642  1.1       mw 		break;
   1643  1.1       mw 
   1644  1.1       mw 	case SO:
   1645  1.1       mw 		ip->GL = ip->G1;
   1646  1.1       mw 		break;
   1647  1.1       mw 
   1648  1.1       mw 	case SI:
   1649  1.1       mw 		ip->GL = ip->G0;
   1650  1.1       mw 		break;
   1651  1.1       mw 
   1652  1.1       mw 	case ENQ:
   1653  1.1       mw 		/* send answer-back message !! */
   1654  1.1       mw 		break;
   1655  1.1       mw 
   1656  1.1       mw 	case CAN:
   1657  1.1       mw 		ip->escape = 0;	/* cancel any escape sequence in progress */
   1658  1.1       mw 		break;
   1659  1.1       mw 
   1660  1.1       mw 	case SUB:
   1661  1.1       mw 		ip->escape = 0;	/* dito, but see below */
   1662  1.1       mw 		/* should also display a reverse question mark!! */
   1663  1.1       mw 		break;
   1664  1.1       mw 
   1665  1.1       mw 	case ESC:
   1666  1.1       mw 		ip->escape = ESC;
   1667  1.1       mw 		break;
   1668  1.1       mw 
   1669  1.1       mw 
   1670  1.1       mw 	/* now it gets weird.. 8bit control sequences.. */
   1671  1.1       mw 	case IND:	/* index: move cursor down, scroll */
   1672  1.1       mw 		ite_lf (ip, sp);
   1673  1.1       mw 		break;
   1674  1.1       mw 
   1675  1.1       mw 	case NEL:	/* next line. next line, first pos. */
   1676  1.1       mw 		ite_crlf (ip, sp);
   1677  1.1       mw 		break;
   1678  1.1       mw 
   1679  1.1       mw 	case HTS:	/* set horizontal tab */
   1680  1.1       mw 		/* not yet supported */
   1681  1.1       mw 		break;
   1682  1.1       mw 
   1683  1.1       mw 	case RI:	/* reverse index */
   1684  1.1       mw 		ite_rlf (ip, sp);
   1685  1.1       mw 		break;
   1686  1.1       mw 
   1687  1.1       mw 	case SS2:	/* go into G2 for one character */
   1688  1.1       mw 		/* not yet supported */
   1689  1.1       mw 		break;
   1690  1.1       mw 
   1691  1.1       mw 	case SS3:	/* go into G3 for one character */
   1692  1.1       mw 		break;
   1693  1.1       mw 
   1694  1.1       mw 	case DCS:	/* device control string introducer */
   1695  1.1       mw 		ip->escape = DCS;
   1696  1.1       mw 		ip->ap = ip->argbuf;
   1697  1.1       mw 		break;
   1698  1.1       mw 
   1699  1.1       mw 	case CSI:	/* control sequence introducer */
   1700  1.1       mw 		ip->escape = CSI;
   1701  1.1       mw 		ip->ap = ip->argbuf;
   1702  1.1       mw 		break;
   1703  1.1       mw 
   1704  1.1       mw 	case ST:	/* string terminator */
   1705  1.1       mw 		/* ignore, if not used as terminator */
   1706  1.1       mw 		break;
   1707  1.1       mw 
   1708  1.1       mw 	case OSC:	/* introduces OS command. Ignore everything upto ST */
   1709  1.1       mw 		ip->escape = OSC;
   1710  1.1       mw 		break;
   1711  1.1       mw 
   1712  1.1       mw 	case PM:	/* privacy message, ignore everything upto ST */
   1713  1.1       mw 		ip->escape = PM;
   1714  1.1       mw 		break;
   1715  1.1       mw 
   1716  1.1       mw 	case APC:	/* application program command, ignore everything upto ST */
   1717  1.1       mw 		ip->escape = APC;
   1718  1.1       mw 		break;
   1719  1.1       mw 
   1720  1.1       mw 	default:
   1721  1.1       mw 		if (c < ' ' || c == DEL)
   1722  1.1       mw 			break;
   1723  1.1       mw 		if (ip->imode)
   1724  1.1       mw 			ite_inchar(ip, sp, 1);
   1725  1.1       mw 		if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
   1726  1.1       mw 			attrset(ip, ATTR_INV);
   1727  1.1       mw 			(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_INV);
   1728  1.1       mw 		}
   1729  1.1       mw 		else
   1730  1.1       mw 			(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
   1731  1.1       mw 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
   1732  1.1       mw 		itecheckwrap(ip, sp);
   1733  1.1       mw 		break;
   1734  1.1       mw 	}
   1735  1.1       mw }
   1736  1.1       mw 
   1737  1.1       mw itecheckwrap(ip, sp)
   1738  1.1       mw      register struct ite_softc *ip;
   1739  1.1       mw      register struct itesw *sp;
   1740  1.1       mw {
   1741  1.1       mw 	if (++ip->curx == ip->cols) {
   1742  1.1       mw 		ip->curx = 0;
   1743  1.1       mw 		clr_attr(ip, ATTR_INV);
   1744  1.1       mw 		if (++ip->cury >= ip->bottom_margin + 1) {
   1745  1.1       mw 			ip->cury = ip->bottom_margin;
   1746  1.1       mw 			(*sp->ite_scroll)(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
   1747  1.1       mw 			ite_clrtoeol(ip, sp, ip->cury, 0);
   1748  1.1       mw 			return;
   1749  1.1       mw 		}
   1750  1.1       mw 	}
   1751  1.1       mw 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
   1752  1.1       mw }
   1753  1.1       mw 
   1754  1.1       mw /*
   1755  1.1       mw  * Console functions
   1756  1.1       mw  */
   1757  1.1       mw #include "../amiga/cons.h"
   1758  1.1       mw #include "grfioctl.h"
   1759  1.1       mw #include "grfvar.h"
   1760  1.1       mw 
   1761  1.1       mw #ifdef DEBUG
   1762  1.1       mw /*
   1763  1.1       mw  * Minimum ITE number at which to start looking for a console.
   1764  1.1       mw  * Setting to 0 will do normal search, 1 will skip first ITE device,
   1765  1.1       mw  * NITE will skip ITEs and use serial port.
   1766  1.1       mw  */
   1767  1.1       mw int	whichconsole = 0;
   1768  1.1       mw #endif
   1769  1.1       mw 
   1770  1.1       mw itecnprobe(cp)
   1771  1.1       mw 	struct consdev *cp;
   1772  1.1       mw {
   1773  1.1       mw 	register struct ite_softc *ip;
   1774  1.1       mw 	int i, maj, unit, pri;
   1775  1.1       mw 
   1776  1.1       mw 	/* locate the major number */
   1777  1.1       mw 	for (maj = 0; maj < nchrdev; maj++)
   1778  1.1       mw 		if (cdevsw[maj].d_open == iteopen)
   1779  1.1       mw 			break;
   1780  1.1       mw 
   1781  1.1       mw 	/* urk! */
   1782  1.1       mw 	grfconfig();
   1783  1.1       mw 
   1784  1.1       mw 	/* check all the individual displays and find the best */
   1785  1.1       mw 	unit = -1;
   1786  1.1       mw 	pri = CN_DEAD;
   1787  1.1       mw 	for (i = 0; i < NITE; i++) {
   1788  1.1       mw 		struct grf_softc *gp = &grf_softc[i];
   1789  1.1       mw 
   1790  1.1       mw 		ip = &ite_softc[i];
   1791  1.1       mw 		if ((gp->g_flags & GF_ALIVE) == 0)
   1792  1.1       mw 			continue;
   1793  1.1       mw 		ip->flags = (ITE_ALIVE|ITE_CONSOLE);
   1794  1.1       mw 
   1795  1.1       mw 		/* XXX - we need to do something about mapping these */
   1796  1.1       mw 		switch (gp->g_type) {
   1797  1.1       mw 		case GT_CUSTOMCHIPS:
   1798  1.1       mw 		        ip->type = ITE_CUSTOMCHIPS;
   1799  1.1       mw 		        break;
   1800  1.1       mw 
   1801  1.1       mw 		case GT_TIGA_A2410:
   1802  1.1       mw 		        ip->type = ITE_TIGA_A2410;
   1803  1.1       mw 		        break;
   1804  1.1       mw 		}
   1805  1.1       mw #ifdef DEBUG
   1806  1.1       mw 		if (i < whichconsole)
   1807  1.1       mw 			continue;
   1808  1.1       mw #endif
   1809  1.1       mw 		if ((int)gp->g_type == GT_CUSTOMCHIPS) {
   1810  1.1       mw 			pri = CN_INTERNAL;
   1811  1.1       mw 			unit = i;
   1812  1.1       mw 		} else if (unit < 0) {
   1813  1.1       mw 			pri = CN_NORMAL;
   1814  1.1       mw 			unit = i;
   1815  1.1       mw 		}
   1816  1.1       mw 	}
   1817  1.1       mw 
   1818  1.1       mw 	/* initialize required fields */
   1819  1.1       mw 	cp->cn_dev = makedev(maj, unit);
   1820  1.1       mw 	cp->cn_tp = ite_tty[unit];
   1821  1.1       mw 	cp->cn_pri = pri;
   1822  1.1       mw }
   1823  1.1       mw 
   1824  1.1       mw itecninit(cp)
   1825  1.1       mw 	struct consdev *cp;
   1826  1.1       mw {
   1827  1.1       mw 	int unit = UNIT(cp->cn_dev);
   1828  1.1       mw 	struct ite_softc *ip = &ite_softc[unit];
   1829  1.1       mw 	ip->attrbuf = console_attributes;
   1830  1.1       mw 	iteinit(cp->cn_dev);
   1831  1.1       mw 	ip->flags |= (ITE_ACTIVE|ITE_ISCONS);
   1832  1.1       mw 	kbd_tty = ite_tty[unit];
   1833  1.1       mw 	kbdenable();
   1834  1.1       mw }
   1835  1.1       mw 
   1836  1.1       mw /*ARGSUSED*/
   1837  1.1       mw itecngetc(dev)
   1838  1.1       mw 	dev_t dev;
   1839  1.1       mw {
   1840  1.1       mw 	register int c;
   1841  1.1       mw 
   1842  1.1       mw         do
   1843  1.1       mw           {
   1844  1.1       mw             c = kbdgetcn ();
   1845  1.1       mw             c = itefilter (c, ITEFILT_CONSOLE);
   1846  1.1       mw           }
   1847  1.1       mw         while (c == -1);
   1848  1.1       mw 
   1849  1.1       mw 	return(c);
   1850  1.1       mw }
   1851  1.1       mw 
   1852  1.1       mw itecnputc(dev, c)
   1853  1.1       mw 	dev_t dev;
   1854  1.1       mw 	int c;
   1855  1.1       mw {
   1856  1.1       mw 	static int paniced = 0;
   1857  1.1       mw 	struct ite_softc *ip = &ite_softc[UNIT(dev)];
   1858  1.1       mw 	extern char *panicstr;
   1859  1.1       mw 
   1860  1.1       mw 	if (panicstr && !paniced &&
   1861  1.1       mw 	    (ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) {
   1862  1.1       mw 		(void) iteon(dev, 3);
   1863  1.1       mw 		paniced = 1;
   1864  1.1       mw 	}
   1865  1.1       mw 	iteputchar(c, dev);
   1866  1.1       mw }
   1867  1.1       mw #endif
   1868