Home | History | Annotate | Line # | Download | only in dev
ite.c revision 1.3
      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.3       mw <<<<<<< ite.c
     41  1.3       mw  *	$Id: ite.c,v 1.3 1993/09/02 18:08:02 mw Exp $
     42  1.3       mw ||||||| 1.1.1.2
     43  1.3       mw  *	$Id: ite.c,v 1.3 1993/09/02 18:08:02 mw Exp $
     44  1.3       mw =======
     45  1.3       mw  *	$Id: ite.c,v 1.3 1993/09/02 18:08:02 mw Exp $
     46  1.3       mw  *
     47  1.3       mw  * Original author: unknown
     48  1.3       mw  * Amiga author:: Markus Wild
     49  1.3       mw  * Other contributors: Bryan Ford (improved vt100 compability)
     50  1.3       mw >>>>>>> /tmp/T4009622
     51  1.1       mw  */
     52  1.1       mw 
     53  1.1       mw /*
     54  1.1       mw  * Bit-mapped display terminal emulator machine independent code.
     55  1.1       mw  * This is a very rudimentary.  Much more can be abstracted out of
     56  1.1       mw  * the hardware dependent routines.
     57  1.1       mw  */
     58  1.1       mw #include "ite.h"
     59  1.1       mw #if NITE > 0
     60  1.1       mw 
     61  1.1       mw #include "grf.h"
     62  1.1       mw 
     63  1.1       mw #undef NITE
     64  1.1       mw #define NITE	NGRF
     65  1.1       mw 
     66  1.1       mw #include "param.h"
     67  1.1       mw #include "conf.h"
     68  1.1       mw #include "proc.h"
     69  1.1       mw #include "ioctl.h"
     70  1.1       mw #include "tty.h"
     71  1.1       mw #include "systm.h"
     72  1.1       mw #include "malloc.h"
     73  1.1       mw 
     74  1.1       mw #include "itevar.h"
     75  1.1       mw #include "iteioctl.h"
     76  1.1       mw #include "kbdmap.h"
     77  1.1       mw 
     78  1.1       mw #include "machine/cpu.h"
     79  1.3       mw #include "../amiga/cons.h"
     80  1.1       mw 
     81  1.1       mw #ifdef __STDC__
     82  1.1       mw /* automatically generated, as you might guess:-) */
     83  1.1       mw 
     84  1.1       mw struct consdev;
     85  1.1       mw struct itesw;
     86  1.1       mw 
     87  1.1       mw extern int iteon (dev_t dev, int flag);
     88  1.1       mw extern int iteinit (dev_t dev);
     89  1.1       mw extern int iteoff (dev_t dev, int flag);
     90  1.1       mw extern int iteopen (dev_t dev, int mode, int devtype, struct proc *p);
     91  1.1       mw extern int iteclose (dev_t dev, int flag, int mode, struct proc *p);
     92  1.1       mw extern int iteread (dev_t dev, struct uio *uio, int flag);
     93  1.1       mw extern int itewrite (dev_t dev, struct uio *uio, int flag);
     94  1.1       mw extern int iteioctl (dev_t dev, int cmd, caddr_t addr, int flag);
     95  1.1       mw extern int itestart (register struct tty *tp);
     96  1.1       mw extern int itefilter (register u_char c, enum caller caller);
     97  1.3       mw extern void iteputchar (register int c, dev_t dev);
     98  1.3       mw extern int iteprecheckwrap (register struct ite_softc *ip, register struct itesw *sp);
     99  1.1       mw extern int itecheckwrap (register struct ite_softc *ip, register struct itesw *sp);
    100  1.1       mw extern int itecnprobe (struct consdev *cp);
    101  1.1       mw extern int itecninit (struct consdev *cp);
    102  1.1       mw extern int itecngetc (dev_t dev);
    103  1.1       mw extern int itecnputc (dev_t dev, int c);
    104  1.1       mw static void repeat_handler (int a0, int a1);
    105  1.3       mw static void inline ite_reset(struct ite_softc *ip);
    106  1.1       mw static void ite_dnchar (struct ite_softc *ip, struct itesw *sp, int n);
    107  1.1       mw static void ite_inchar (struct ite_softc *ip, struct itesw *sp, int n);
    108  1.3       mw static void ite_clrtoeol (struct ite_softc *ip, struct itesw *sp);
    109  1.3       mw static void ite_clrtobol (struct ite_softc *ip, struct itesw *sp);
    110  1.3       mw static void ite_clrline (struct ite_softc *ip, struct itesw *sp);
    111  1.1       mw static void ite_clrtoeos (struct ite_softc *ip, struct itesw *sp);
    112  1.1       mw static void ite_clrtobos (struct ite_softc *ip, struct itesw *sp);
    113  1.1       mw static void ite_clrscreen (struct ite_softc *ip, struct itesw *sp);
    114  1.1       mw static void ite_dnline (struct ite_softc *ip, struct itesw *sp, int n);
    115  1.1       mw static void ite_inline (struct ite_softc *ip, struct itesw *sp, int n);
    116  1.1       mw static void ite_lf (struct ite_softc *ip, struct itesw *sp);
    117  1.1       mw static void ite_crlf (struct ite_softc *ip, struct itesw *sp);
    118  1.1       mw static void ite_cr (struct ite_softc *ip, struct itesw *sp);
    119  1.1       mw static void ite_rlf (struct ite_softc *ip, struct itesw *sp);
    120  1.1       mw static int atoi (const char *cp);
    121  1.1       mw static char *index (const char *cp, char ch);
    122  1.1       mw static int ite_argnum (struct ite_softc *ip);
    123  1.1       mw static int ite_zargnum (struct ite_softc *ip);
    124  1.1       mw static void ite_sendstr (struct ite_softc *ip, char *str);
    125  1.1       mw static int strncmp (const char *a, const char *b, int l);
    126  1.1       mw #endif
    127  1.1       mw 
    128  1.1       mw 
    129  1.1       mw #define set_attr(ip, attr)	((ip)->attribute |= (attr))
    130  1.1       mw #define clr_attr(ip, attr)	((ip)->attribute &= ~(attr))
    131  1.1       mw 
    132  1.1       mw extern  int nodev();
    133  1.1       mw 
    134  1.1       mw int customc_scroll(),	customc_init(),		customc_deinit();
    135  1.1       mw int customc_clear(),	customc_putc(),		customc_cursor();
    136  1.1       mw 
    137  1.1       mw int tiga_scroll(),	tiga_init(),		tiga_deinit();
    138  1.1       mw int tiga_clear(),	tiga_putc(),		tiga_cursor();
    139  1.1       mw 
    140  1.3       mw int retina_scroll(),	retina_init(),		retina_deinit();
    141  1.3       mw int retina_clear(),	retina_putc(),		retina_cursor();
    142  1.1       mw 
    143  1.1       mw struct itesw itesw[] =
    144  1.1       mw {
    145  1.3       mw 	customc_init,		customc_deinit,		0,
    146  1.3       mw 	0,			0,			0,
    147  1.1       mw 
    148  1.1       mw 	tiga_init,		tiga_deinit,		tiga_clear,
    149  1.1       mw 	tiga_putc,		tiga_cursor,		tiga_scroll,
    150  1.3       mw 
    151  1.3       mw 	retina_init,		retina_deinit,		retina_clear,
    152  1.3       mw 	retina_putc,		retina_cursor,		retina_scroll,
    153  1.1       mw };
    154  1.1       mw 
    155  1.1       mw /*
    156  1.1       mw  * # of chars are output in a single itestart() call.
    157  1.1       mw  * If this is too big, user processes will be blocked out for
    158  1.1       mw  * long periods of time while we are emptying the queue in itestart().
    159  1.1       mw  * If it is too small, console output will be very ragged.
    160  1.1       mw  */
    161  1.1       mw int	iteburst = 64;
    162  1.1       mw 
    163  1.1       mw int	nite = NITE;
    164  1.3       mw 
    165  1.1       mw struct  tty *kbd_tty = NULL;
    166  1.3       mw struct	ite_softc *kbd_ip = NULL;
    167  1.3       mw 
    168  1.3       mw struct	tty ite_cons1, ite_cons2;
    169  1.3       mw #if 0
    170  1.3       mw struct	tty *ite_tty[NITE] = { &ite_cons1, &ite_cons2 };
    171  1.3       mw #else
    172  1.3       mw struct	tty *ite_tty[NITE];
    173  1.3       mw /* ugh.. */
    174  1.3       mw static int delayed_con_tty = -1;  /* if >= 0 set cn_tp later to that tty.. */
    175  1.3       mw #endif
    176  1.1       mw struct  ite_softc ite_softc[NITE];
    177  1.1       mw 
    178  1.1       mw int	itestart();
    179  1.1       mw extern	int ttrstrt();
    180  1.1       mw extern	struct tty *constty;
    181  1.1       mw 
    182  1.1       mw /* These are (later..) settable via an ioctl */
    183  1.3       mw int	start_repeat_timo = 20;	/* /100: initial timeout till pressed key repeats */
    184  1.3       mw int	next_repeat_timo  = 3;  /* /100: timeout when repeating for next char */
    185  1.1       mw 
    186  1.3       mw #ifdef DO_WEIRD_ATTRIBUTES
    187  1.1       mw /*
    188  1.1       mw  * Primary attribute buffer to be used by the first bitmapped console
    189  1.1       mw  * found. Secondary displays alloc the attribute buffer as needed.
    190  1.1       mw  * Size is based on a 68x128 display, which is currently our largest.
    191  1.1       mw  */
    192  1.1       mw u_char  console_attributes[0x2200];
    193  1.3       mw #endif
    194  1.3       mw u_char	console_tabs[256 * NITE];
    195  1.1       mw 
    196  1.1       mw /*
    197  1.1       mw  * Perform functions necessary to setup device as a terminal emulator.
    198  1.1       mw  */
    199  1.1       mw iteon(dev, flag)
    200  1.1       mw 	dev_t dev;
    201  1.1       mw {
    202  1.1       mw 	int unit = UNIT(dev);
    203  1.1       mw 	struct tty *tp = ite_tty[unit];
    204  1.1       mw 	struct ite_softc *ip = &ite_softc[unit];
    205  1.1       mw 
    206  1.1       mw 	if (unit < 0 || unit >= NITE || (ip->flags&ITE_ALIVE) == 0)
    207  1.1       mw 		return(ENXIO);
    208  1.1       mw 	/* force ite active, overriding graphics mode */
    209  1.1       mw 	if (flag & 1) {
    210  1.1       mw 		ip->flags |= ITE_ACTIVE;
    211  1.1       mw 		ip->flags &= ~(ITE_INGRF|ITE_INITED);
    212  1.1       mw 	}
    213  1.1       mw 	/* leave graphics mode */
    214  1.1       mw 	if (flag & 2) {
    215  1.1       mw 		ip->flags &= ~ITE_INGRF;
    216  1.1       mw 		if ((ip->flags & ITE_ACTIVE) == 0)
    217  1.1       mw 			return(0);
    218  1.1       mw 	}
    219  1.1       mw 	ip->flags |= ITE_ACTIVE;
    220  1.1       mw 	if (ip->flags & ITE_INGRF)
    221  1.1       mw 		return(0);
    222  1.3       mw 	if (tp && (kbd_tty == NULL || kbd_tty == tp)) {
    223  1.1       mw 		kbd_tty = tp;
    224  1.3       mw 		kbd_ip = ip;
    225  1.1       mw 		kbdenable();
    226  1.1       mw 	}
    227  1.1       mw 	iteinit(dev);
    228  1.1       mw 	return(0);
    229  1.1       mw }
    230  1.1       mw 
    231  1.1       mw /* used by the grf layer to reinitialize ite after changing fb parameters */
    232  1.1       mw itereinit(dev)
    233  1.1       mw      dev_t dev;
    234  1.1       mw {
    235  1.1       mw   int unit = UNIT(dev);
    236  1.1       mw   struct ite_softc *ip = &ite_softc[unit];
    237  1.1       mw 
    238  1.1       mw   ip->flags &= ~ITE_INITED;
    239  1.1       mw   iteinit (dev);
    240  1.1       mw }
    241  1.1       mw 
    242  1.1       mw iteinit(dev)
    243  1.1       mw      dev_t dev;
    244  1.1       mw {
    245  1.1       mw 	int unit = UNIT(dev);
    246  1.1       mw 	struct ite_softc *ip = &ite_softc[unit];
    247  1.1       mw 
    248  1.1       mw 	if (ip->flags & ITE_INITED)
    249  1.1       mw 		return;
    250  1.3       mw 
    251  1.3       mw 	bcopy (&ascii_kbdmap, &kbdmap, sizeof (struct kbdmap));
    252  1.1       mw 
    253  1.1       mw 	ip->cursorx = 0;
    254  1.1       mw 	ip->cursory = 0;
    255  1.1       mw 	(*itesw[ip->type].ite_init)(ip);
    256  1.3       mw <<<<<<< ite.c
    257  1.3       mw 	(*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
    258  1.3       mw ||||||| 1.1.1.2
    259  1.1       mw 	(*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
    260  1.1       mw 
    261  1.1       mw 	/* ip->rows initialized by ite_init above */
    262  1.1       mw 	ip->top_margin = 0; ip->bottom_margin = ip->rows - 1;
    263  1.3       mw =======
    264  1.3       mw >>>>>>> /tmp/T4009622
    265  1.1       mw 
    266  1.3       mw <<<<<<< ite.c
    267  1.3       mw 	/* ip->rows initialized by ite_init above */
    268  1.3       mw 	ip->top_margin = 0; ip->bottom_margin = ip->rows - 1;
    269  1.3       mw 
    270  1.1       mw 	ip->attribute = 0;
    271  1.3       mw ||||||| 1.1.1.2
    272  1.3       mw 	ip->attribute = 0;
    273  1.3       mw =======
    274  1.3       mw #ifdef DO_WEIRD_ATTRIBUTES
    275  1.3       mw >>>>>>> /tmp/T4009622
    276  1.1       mw 	if (ip->attrbuf == NULL)
    277  1.1       mw 		ip->attrbuf = (u_char *)
    278  1.1       mw 			malloc(ip->rows * ip->cols, M_DEVBUF, M_WAITOK);
    279  1.1       mw 	bzero(ip->attrbuf, (ip->rows * ip->cols));
    280  1.3       mw #endif
    281  1.3       mw 	if (! ip->tabs)
    282  1.3       mw 	  {
    283  1.3       mw 	    /* can't use malloc, as this buffer might be used before
    284  1.3       mw 	       the allocators are initialized (console!) */
    285  1.3       mw 	    ip->tabs = &console_tabs[unit * 256];
    286  1.3       mw 	  }
    287  1.3       mw 
    288  1.3       mw 	ite_reset (ip);
    289  1.1       mw 
    290  1.3       mw 	(*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
    291  1.1       mw 	ip->flags |= ITE_INITED;
    292  1.1       mw }
    293  1.1       mw 
    294  1.1       mw /*
    295  1.1       mw  * "Shut down" device as terminal emulator.
    296  1.1       mw  * Note that we do not deinit the console device unless forced.
    297  1.1       mw  * Deinit'ing the console every time leads to a very active
    298  1.1       mw  * screen when processing /etc/rc.
    299  1.1       mw  */
    300  1.1       mw iteoff(dev, flag)
    301  1.1       mw 	dev_t dev;
    302  1.1       mw {
    303  1.1       mw 	register struct ite_softc *ip = &ite_softc[UNIT(dev)];
    304  1.1       mw 
    305  1.1       mw 	if (flag & 2)
    306  1.1       mw 		ip->flags |= ITE_INGRF;
    307  1.1       mw 	if ((ip->flags & ITE_ACTIVE) == 0)
    308  1.1       mw 		return;
    309  1.1       mw 	if ((flag & 1) ||
    310  1.1       mw 	    (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
    311  1.1       mw 		(*itesw[ip->type].ite_deinit)(ip);
    312  1.1       mw 	if ((flag & 2) == 0)
    313  1.1       mw 		ip->flags &= ~ITE_ACTIVE;
    314  1.1       mw }
    315  1.1       mw 
    316  1.1       mw /* ARGSUSED */
    317  1.1       mw #ifdef __STDC__
    318  1.1       mw iteopen(dev_t dev, int mode, int devtype, struct proc *p)
    319  1.1       mw #else
    320  1.1       mw iteopen(dev, mode, devtype, p)
    321  1.1       mw 	dev_t dev;
    322  1.1       mw 	int mode, devtype;
    323  1.1       mw 	struct proc *p;
    324  1.1       mw #endif
    325  1.1       mw {
    326  1.1       mw 	int unit = UNIT(dev);
    327  1.1       mw 	register struct tty *tp;
    328  1.1       mw 	register struct ite_softc *ip = &ite_softc[unit];
    329  1.1       mw 	register int error;
    330  1.1       mw 	int first = 0;
    331  1.1       mw 
    332  1.3       mw 	if (unit >= NITE)
    333  1.3       mw 	  return ENXIO;
    334  1.3       mw 
    335  1.1       mw 	if(!ite_tty[unit]) {
    336  1.3       mw #if 0
    337  1.1       mw 		MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK);
    338  1.1       mw 		bzero(tp, sizeof(struct tty));
    339  1.1       mw 		ite_tty[unit] = tp;
    340  1.3       mw #else
    341  1.3       mw 		tp = ite_tty[unit] = ttymalloc();
    342  1.3       mw 		/* HA! caught it finally... */
    343  1.3       mw 		if (unit == delayed_con_tty)
    344  1.3       mw 		  {
    345  1.3       mw 		    extern struct consdev *cn_tab;
    346  1.3       mw 		    extern struct tty *cn_tty;
    347  1.3       mw 
    348  1.3       mw 		    kbd_tty = tp;
    349  1.3       mw 		    kbd_ip = ip;
    350  1.3       mw 		    kbdenable ();
    351  1.3       mw 		    cn_tty = cn_tab->cn_tp = tp;
    352  1.3       mw 		    delayed_con_tty = -1;
    353  1.3       mw 		  }
    354  1.3       mw #endif
    355  1.1       mw 	} else
    356  1.1       mw 		tp = ite_tty[unit];
    357  1.1       mw 
    358  1.1       mw 	if ((tp->t_state&(TS_ISOPEN|TS_XCLUDE)) == (TS_ISOPEN|TS_XCLUDE)
    359  1.1       mw 	    && p->p_ucred->cr_uid != 0)
    360  1.1       mw 		return (EBUSY);
    361  1.1       mw 	if ((ip->flags & ITE_ACTIVE) == 0) {
    362  1.1       mw 		error = iteon(dev, 0);
    363  1.1       mw 		if (error)
    364  1.1       mw 			return (error);
    365  1.1       mw 		first = 1;
    366  1.1       mw 	}
    367  1.1       mw 	tp->t_oproc = itestart;
    368  1.1       mw 	tp->t_param = NULL;
    369  1.1       mw 	tp->t_dev = dev;
    370  1.1       mw 	if ((tp->t_state&TS_ISOPEN) == 0) {
    371  1.1       mw 		ttychars(tp);
    372  1.1       mw 		tp->t_iflag = TTYDEF_IFLAG;
    373  1.1       mw 		tp->t_oflag = TTYDEF_OFLAG;
    374  1.1       mw 		tp->t_cflag = CS8|CREAD;
    375  1.1       mw 		tp->t_lflag = TTYDEF_LFLAG;
    376  1.1       mw 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    377  1.1       mw 		/* don't set TS_ISOPEN  here, or the tty queues won't
    378  1.1       mw 		   be initialized in ttyopen()! */
    379  1.1       mw 		tp->t_state = TS_CARR_ON;
    380  1.1       mw 		ttsetwater(tp);
    381  1.1       mw 	}
    382  1.1       mw 	error = (*linesw[tp->t_line].l_open)(dev, tp);
    383  1.1       mw 	if (error == 0) {
    384  1.1       mw 		tp->t_winsize.ws_row = ip->rows;
    385  1.1       mw 		tp->t_winsize.ws_col = ip->cols;
    386  1.3       mw 		ip->open_cnt++;
    387  1.1       mw 	} else if (first)
    388  1.1       mw 		iteoff(dev, 0);
    389  1.1       mw 	return (error);
    390  1.1       mw }
    391  1.1       mw 
    392  1.1       mw /*ARGSUSED*/
    393  1.1       mw iteclose(dev, flag, mode, p)
    394  1.1       mw 	dev_t dev;
    395  1.1       mw 	int flag, mode;
    396  1.1       mw 	struct proc *p;
    397  1.1       mw {
    398  1.3       mw 	int unit = UNIT(dev);
    399  1.3       mw 	register struct tty *tp = ite_tty[unit];
    400  1.3       mw 	register struct ite_softc *ip = &ite_softc[unit];
    401  1.3       mw 
    402  1.3       mw #if 0
    403  1.3       mw 	/* aliasing with /dev/console can lead to such weird problems... */
    404  1.3       mw 	if (ip->open_cnt-- > 0)
    405  1.3       mw 	  return 0;
    406  1.3       mw #endif
    407  1.1       mw 
    408  1.3       mw 	if (tp)
    409  1.3       mw 	  {
    410  1.3       mw 	    (*linesw[tp->t_line].l_close)(tp, flag);
    411  1.3       mw 	    ttyclose(tp);
    412  1.3       mw 	  }
    413  1.1       mw 	iteoff(dev, 0);
    414  1.3       mw #if 0
    415  1.1       mw 	if (tp != &ite_cons)
    416  1.1       mw 	  {
    417  1.3       mw #if 0
    418  1.1       mw 	    FREE(tp, M_TTYS);
    419  1.3       mw #else
    420  1.3       mw 	    ttyfree (tp);
    421  1.3       mw #endif
    422  1.1       mw 	    ite_tty[UNIT(dev)] = (struct tty *)NULL;
    423  1.1       mw 	  }
    424  1.3       mw #endif
    425  1.1       mw 	return(0);
    426  1.1       mw }
    427  1.1       mw 
    428  1.1       mw iteread(dev, uio, flag)
    429  1.1       mw 	dev_t dev;
    430  1.1       mw 	struct uio *uio;
    431  1.1       mw {
    432  1.1       mw 	register struct tty *tp = ite_tty[UNIT(dev)];
    433  1.1       mw 	int rc;
    434  1.1       mw 
    435  1.3       mw 	if (! tp)
    436  1.3       mw 	  return ENXIO;
    437  1.3       mw 
    438  1.1       mw 	rc = ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    439  1.1       mw 	return rc;
    440  1.1       mw }
    441  1.1       mw 
    442  1.1       mw itewrite(dev, uio, flag)
    443  1.1       mw 	dev_t dev;
    444  1.1       mw 	struct uio *uio;
    445  1.1       mw {
    446  1.1       mw 	int unit = UNIT(dev);
    447  1.1       mw 	register struct tty *tp = ite_tty[unit];
    448  1.1       mw 
    449  1.3       mw 	if (! tp)
    450  1.3       mw 	  return ENXIO;
    451  1.3       mw 
    452  1.1       mw 	if ((ite_softc[unit].flags & ITE_ISCONS) && constty &&
    453  1.1       mw 	    (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN))
    454  1.1       mw 		tp = constty;
    455  1.1       mw 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    456  1.1       mw }
    457  1.1       mw 
    458  1.1       mw iteioctl(dev, cmd, addr, flag)
    459  1.1       mw 	dev_t dev;
    460  1.1       mw 	caddr_t addr;
    461  1.1       mw {
    462  1.1       mw 	register struct tty *tp = ite_tty[UNIT(dev)];
    463  1.1       mw 	int error;
    464  1.1       mw 
    465  1.3       mw 	if (! tp)
    466  1.3       mw 	  return ENXIO;
    467  1.3       mw 
    468  1.3       mw 
    469  1.1       mw 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag);
    470  1.1       mw 	if (error >= 0)
    471  1.1       mw 		return (error);
    472  1.1       mw 	error = ttioctl(tp, cmd, addr, flag);
    473  1.1       mw 	if (error >= 0)
    474  1.1       mw 		return (error);
    475  1.3       mw 
    476  1.3       mw 	switch (cmd)
    477  1.3       mw 	  {
    478  1.3       mw 	  case ITELOADKMAP:
    479  1.3       mw 	    if (addr)
    480  1.3       mw 	      {
    481  1.3       mw 		bcopy (addr, &kbdmap, sizeof (struct kbdmap));
    482  1.3       mw 		return 0;
    483  1.3       mw 	      }
    484  1.3       mw 	    else
    485  1.3       mw 	      return EFAULT;
    486  1.3       mw 
    487  1.3       mw 	  case ITEGETKMAP:
    488  1.3       mw 	    if (addr)
    489  1.3       mw 	      {
    490  1.3       mw 		bcopy (&kbdmap, addr, sizeof (struct kbdmap));
    491  1.3       mw 		return 0;
    492  1.3       mw 	      }
    493  1.3       mw 	    else
    494  1.3       mw 	      return EFAULT;
    495  1.3       mw 	  }
    496  1.3       mw 
    497  1.3       mw 
    498  1.1       mw 	return (ENOTTY);
    499  1.1       mw }
    500  1.1       mw 
    501  1.1       mw itestart(tp)
    502  1.1       mw 	register struct tty *tp;
    503  1.1       mw {
    504  1.1       mw 	register int cc, s;
    505  1.3       mw 	int unit = UNIT(tp->t_dev);
    506  1.3       mw 	register struct ite_softc *ip = &ite_softc[unit];
    507  1.1       mw 	int hiwat = 0;
    508  1.1       mw 
    509  1.1       mw 	s = spltty();
    510  1.1       mw 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
    511  1.1       mw 		splx(s);
    512  1.1       mw 		return;
    513  1.1       mw 	}
    514  1.1       mw 	tp->t_state |= TS_BUSY;
    515  1.3       mw 	cc = tp->t_outq.c_cc;
    516  1.1       mw 	if (cc <= tp->t_lowat) {
    517  1.1       mw 		if (tp->t_state & TS_ASLEEP) {
    518  1.1       mw 			tp->t_state &= ~TS_ASLEEP;
    519  1.3       mw 			wakeup((caddr_t) &tp->t_outq);
    520  1.1       mw 		}
    521  1.1       mw 		selwakeup(&tp->t_wsel);
    522  1.1       mw 	}
    523  1.1       mw 	/*
    524  1.1       mw 	 * Limit the amount of output we do in one burst
    525  1.1       mw 	 * to prevent hogging the CPU.
    526  1.1       mw 	 */
    527  1.1       mw 	if (cc > iteburst) {
    528  1.1       mw 		hiwat++;
    529  1.1       mw 		cc = iteburst;
    530  1.1       mw 	}
    531  1.3       mw 	(*itesw[ip->type].ite_cursor)(ip, START_CURSOROPT);
    532  1.1       mw 	while (--cc >= 0) {
    533  1.1       mw 		register int c;
    534  1.1       mw 
    535  1.3       mw 		c = getc(&tp->t_outq);
    536  1.1       mw 		/*
    537  1.1       mw 		 * iteputchar() may take a long time and we don't want to
    538  1.1       mw 		 * block all interrupts for long periods of time.  Since
    539  1.1       mw 		 * there is no need to stay at high priority while outputing
    540  1.1       mw 		 * the character (since we don't have to worry about
    541  1.1       mw 		 * interrupts), we don't.  We just need to make sure that
    542  1.1       mw 		 * we don't reenter iteputchar, which is guarenteed by the
    543  1.1       mw 		 * earlier setting of TS_BUSY.
    544  1.1       mw 		 */
    545  1.1       mw 		splx(s);
    546  1.1       mw 		iteputchar(c, tp->t_dev);
    547  1.1       mw 		spltty();
    548  1.1       mw 	}
    549  1.3       mw 	(*itesw[ip->type].ite_cursor)(ip, END_CURSOROPT);
    550  1.1       mw 	if (hiwat) {
    551  1.1       mw 		tp->t_state |= TS_TIMEOUT;
    552  1.3       mw 		timeout((timeout_t) ttrstrt, (caddr_t) tp, 1);
    553  1.1       mw 	}
    554  1.1       mw 	tp->t_state &= ~TS_BUSY;
    555  1.1       mw 	splx(s);
    556  1.1       mw }
    557  1.1       mw 
    558  1.1       mw /* these are used to implement repeating keys.. */
    559  1.1       mw static u_char last_char = 0;
    560  1.1       mw static u_char tout_pending = 0;
    561  1.1       mw 
    562  1.1       mw static void
    563  1.1       mw repeat_handler (a0, a1)
    564  1.1       mw     int a0, a1;
    565  1.1       mw {
    566  1.1       mw   tout_pending = 0;
    567  1.3       mw   /* leave it up to itefilter() to possibly install a new callout entry
    568  1.1       mw      to reinvoke repeat_handler() */
    569  1.3       mw   if (last_char)
    570  1.3       mw     {
    571  1.3       mw       /* don't call itefilter directly, we're at spl6 here, and have
    572  1.3       mw 	 blocked out way too much stuff. Besides, the keyboard wouldn't
    573  1.3       mw 	 even have a chance to tell us about key-up events if we
    574  1.3       mw 	 did.. */
    575  1.3       mw       add_sicallback (itefilter, last_char, ITEFILT_REPEATER);
    576  1.3       mw 
    577  1.3       mw       /* itefilter (last_char, ITEFILT_REPEATER); */
    578  1.3       mw     }
    579  1.3       mw }
    580  1.3       mw 
    581  1.3       mw static void inline
    582  1.3       mw itesendch (int ch)
    583  1.3       mw {
    584  1.3       mw   (*linesw[kbd_tty->t_line].l_rint)(ch, kbd_tty);
    585  1.1       mw }
    586  1.1       mw 
    587  1.1       mw 
    588  1.1       mw int
    589  1.1       mw itefilter(c, caller)
    590  1.1       mw      register u_char c;
    591  1.1       mw      enum caller caller;
    592  1.1       mw {
    593  1.1       mw   static u_char mod = 0;
    594  1.1       mw   static u_char last_dead = 0;
    595  1.3       mw   register unsigned char code, *str;
    596  1.1       mw   u_char up, mask, i;
    597  1.1       mw   struct key key;
    598  1.3       mw   int s;
    599  1.1       mw 
    600  1.1       mw   if (caller != ITEFILT_CONSOLE && kbd_tty == NULL)
    601  1.1       mw      return;
    602  1.1       mw 
    603  1.3       mw   /* have to make sure we're at spltty in here */
    604  1.3       mw   s = spltty ();
    605  1.3       mw 
    606  1.3       mw   /* keyboard interrupts come at priority 2, while softint-
    607  1.3       mw      generated keyboard-repeat interrupts come at level 1.
    608  1.3       mw      So, to not allow a key-up event to get thru before
    609  1.3       mw      a repeat for the key-down, we remove any outstanding
    610  1.3       mw      callout requests.. */
    611  1.3       mw   rem_sicallback (itefilter);
    612  1.3       mw 
    613  1.1       mw   up = c & 0x80 ? 1 : 0;
    614  1.1       mw   c &= 0x7f;
    615  1.1       mw   code = 0;
    616  1.1       mw 
    617  1.1       mw   mask = 0;
    618  1.1       mw   if (c >= KBD_LEFT_SHIFT)
    619  1.1       mw     {
    620  1.1       mw       switch (c)
    621  1.1       mw         {
    622  1.1       mw         case KBD_LEFT_SHIFT:
    623  1.1       mw           mask = KBD_MOD_LSHIFT;
    624  1.1       mw           break;
    625  1.1       mw 
    626  1.1       mw         case KBD_RIGHT_SHIFT:
    627  1.1       mw           mask = KBD_MOD_RSHIFT;
    628  1.1       mw           break;
    629  1.1       mw 
    630  1.1       mw         case KBD_LEFT_ALT:
    631  1.1       mw           mask = KBD_MOD_LALT;
    632  1.1       mw           break;
    633  1.1       mw 
    634  1.1       mw         case KBD_RIGHT_ALT:
    635  1.1       mw           mask = KBD_MOD_RALT;
    636  1.1       mw           break;
    637  1.1       mw 
    638  1.1       mw         case KBD_LEFT_META:
    639  1.1       mw           mask = KBD_MOD_LMETA;
    640  1.1       mw           break;
    641  1.1       mw 
    642  1.1       mw         case KBD_RIGHT_META:
    643  1.1       mw           mask = KBD_MOD_RMETA;
    644  1.1       mw           break;
    645  1.1       mw 
    646  1.1       mw         case KBD_CAPS_LOCK:
    647  1.1       mw           /* capslock already behaves `right', don't need to keep track of the
    648  1.1       mw              state in here. */
    649  1.1       mw           mask = KBD_MOD_CAPS;
    650  1.1       mw           break;
    651  1.1       mw 
    652  1.1       mw         case KBD_CTRL:
    653  1.1       mw           mask = KBD_MOD_CTRL;
    654  1.1       mw           break;
    655  1.1       mw         }
    656  1.1       mw 
    657  1.1       mw       if (mask)
    658  1.1       mw         {
    659  1.1       mw           if (up)
    660  1.1       mw             mod &= ~mask;
    661  1.1       mw           else
    662  1.1       mw             mod |= mask;
    663  1.1       mw         }
    664  1.1       mw 
    665  1.1       mw       /* these keys should not repeat, so it's the Right Thing dealing with
    666  1.1       mw          repeaters only after this block. */
    667  1.1       mw 
    668  1.1       mw       /* return even if it wasn't a modifier key, the other codes up here
    669  1.1       mw          are either special (like reset warning), or not yet defined */
    670  1.3       mw       splx (s);
    671  1.1       mw       return -1;
    672  1.1       mw     }
    673  1.1       mw 
    674  1.1       mw   /* no matter which character we're repeating, stop it if we get a key-up
    675  1.1       mw      event. I think this is the same thing amigados does. */
    676  1.1       mw   if (up)
    677  1.1       mw     {
    678  1.1       mw       if (tout_pending)
    679  1.1       mw         {
    680  1.3       mw           untimeout ((timeout_t) repeat_handler, 0);
    681  1.1       mw           tout_pending = 0;
    682  1.3       mw 	  last_char = 0;
    683  1.1       mw         }
    684  1.3       mw       splx (s);
    685  1.3       mw       return -1;
    686  1.3       mw     }
    687  1.3       mw 
    688  1.3       mw 
    689  1.3       mw   /* intercept Ctrl-LAlt-F1 here to switch back to original ascii-keymap.
    690  1.3       mw      this should probably be configurable.. */
    691  1.3       mw   if (mod == (KBD_MOD_LALT|KBD_MOD_SHIFT) && code == 0x50)
    692  1.3       mw     {
    693  1.3       mw       bcopy (&ascii_kbdmap, &kbdmap, sizeof (struct kbdmap));
    694  1.3       mw       splx (s);
    695  1.1       mw       return -1;
    696  1.1       mw     }
    697  1.1       mw 
    698  1.1       mw 
    699  1.1       mw   switch (mod & (KBD_MOD_ALT | KBD_MOD_SHIFT))
    700  1.1       mw     {
    701  1.1       mw     case 0:
    702  1.1       mw 	key = kbdmap.keys[c];
    703  1.1       mw 	if (!(mod & KBD_MOD_CAPS) || !(key.mode & KBD_MODE_CAPS))
    704  1.1       mw 	  break;
    705  1.1       mw 	/* FALL INTO */
    706  1.1       mw 
    707  1.1       mw     case KBD_MOD_LSHIFT:
    708  1.1       mw     case KBD_MOD_RSHIFT:
    709  1.1       mw     case KBD_MOD_SHIFT:
    710  1.1       mw         key = kbdmap.shift_keys[c];
    711  1.1       mw         break;
    712  1.1       mw 
    713  1.1       mw     case KBD_MOD_LALT:
    714  1.1       mw     case KBD_MOD_RALT:
    715  1.1       mw     case KBD_MOD_ALT:
    716  1.1       mw 	key = kbdmap.alt_keys[c];
    717  1.1       mw 	if (!(mod & KBD_MOD_CAPS) || !(key.mode & KBD_MODE_CAPS))
    718  1.1       mw 	  break;
    719  1.1       mw 	/* FALL INTO */
    720  1.1       mw 
    721  1.1       mw     case KBD_MOD_LALT|KBD_MOD_LSHIFT:
    722  1.1       mw     case KBD_MOD_LALT|KBD_MOD_RSHIFT:
    723  1.1       mw     case KBD_MOD_LALT|KBD_MOD_SHIFT:
    724  1.1       mw     case KBD_MOD_RALT|KBD_MOD_RSHIFT:
    725  1.1       mw     case KBD_MOD_RALT|KBD_MOD_SHIFT:
    726  1.1       mw     case KBD_MOD_ALT|KBD_MOD_RSHIFT:
    727  1.1       mw 	key = kbdmap.alt_shift_keys[c];
    728  1.1       mw 	break;
    729  1.1       mw     }
    730  1.1       mw 
    731  1.1       mw   code = key.code;
    732  1.1       mw 
    733  1.1       mw   /* arrange to repeat the keystroke. By doing this at the level of scan-codes,
    734  1.1       mw      we can have function keys, and keys that send strings, repeat too. This
    735  1.1       mw      also entitles an additional overhead, since we have to do the conversion
    736  1.1       mw      each time, but I guess that's ok. */
    737  1.3       mw   if (!tout_pending && caller == ITEFILT_TTY && kbd_ip->key_repeat)
    738  1.1       mw     {
    739  1.1       mw       tout_pending = 1;
    740  1.1       mw       last_char = c;
    741  1.3       mw       timeout ((timeout_t) repeat_handler, 0, start_repeat_timo);
    742  1.1       mw     }
    743  1.3       mw   else if (!tout_pending && caller == ITEFILT_REPEATER && kbd_ip->key_repeat)
    744  1.1       mw     {
    745  1.1       mw       tout_pending = 1;
    746  1.1       mw       last_char = c;
    747  1.3       mw       timeout ((timeout_t) repeat_handler, 0, next_repeat_timo);
    748  1.1       mw     }
    749  1.1       mw 
    750  1.1       mw   /* handle dead keys */
    751  1.1       mw   if (key.mode & KBD_MODE_DEAD)
    752  1.1       mw     {
    753  1.1       mw       /* if entered twice, send accent itself */
    754  1.1       mw       if (last_dead == key.mode & KBD_MODE_ACCMASK)
    755  1.1       mw         last_dead = 0;
    756  1.1       mw       else
    757  1.1       mw 	{
    758  1.1       mw 	  last_dead = key.mode & KBD_MODE_ACCMASK;
    759  1.3       mw 	  splx (s);
    760  1.1       mw 	  return -1;
    761  1.1       mw 	}
    762  1.1       mw     }
    763  1.1       mw   if (last_dead)
    764  1.1       mw     {
    765  1.1       mw       /* can't apply dead flag to string-keys */
    766  1.1       mw       if (! (key.mode & KBD_MODE_STRING) && code >= '@' && code < 0x7f)
    767  1.1       mw         code = acctable[KBD_MODE_ACCENT (last_dead)][code - '@'];
    768  1.1       mw 
    769  1.1       mw       last_dead = 0;
    770  1.1       mw     }
    771  1.1       mw 
    772  1.1       mw   /* if not string, apply META and CTRL modifiers */
    773  1.1       mw   if (! (key.mode & KBD_MODE_STRING))
    774  1.1       mw     {
    775  1.1       mw       if (mod & KBD_MOD_CTRL)
    776  1.1       mw         code &= 0x1f;
    777  1.1       mw 
    778  1.1       mw       if (mod & KBD_MOD_META)
    779  1.1       mw         code |= 0x80;
    780  1.1       mw     }
    781  1.1       mw   else
    782  1.1       mw     {
    783  1.1       mw       /* strings are only supported in normal tty mode, not in console mode */
    784  1.1       mw       if (caller != ITEFILT_CONSOLE)
    785  1.1       mw         {
    786  1.1       mw           str = kbdmap.strings + code;
    787  1.1       mw           /* using a length-byte instead of 0-termination allows to embed \0 into
    788  1.1       mw              strings, although this is not used in the default keymap */
    789  1.1       mw           for (i = *str++; i; i--)
    790  1.3       mw             itesendch(*str++);
    791  1.1       mw         }
    792  1.3       mw       splx (s);
    793  1.1       mw       return -1;
    794  1.1       mw     }
    795  1.1       mw 
    796  1.1       mw   if (caller == ITEFILT_CONSOLE)
    797  1.3       mw     {
    798  1.3       mw       /* do the conversion here because raw console input doesn't go thru
    799  1.3       mw 	 tty conversions */
    800  1.3       mw       code = code == '\r' ? '\n' : code;
    801  1.3       mw       splx (s);
    802  1.3       mw       return code;
    803  1.3       mw     }
    804  1.1       mw   else
    805  1.3       mw     /* NOTE: *don't* do any cr->crlf conversion here, this is input
    806  1.3       mw 	     processing, the mentioned conversion should only be
    807  1.3       mw 	     done for output processing (for input, it is not
    808  1.3       mw 	     terminal-specific but depends on tty-settings!) */
    809  1.1       mw     (*linesw[kbd_tty->t_line].l_rint)(code, kbd_tty);
    810  1.1       mw 
    811  1.3       mw   splx (s);
    812  1.1       mw   return -1;
    813  1.1       mw }
    814  1.1       mw 
    815  1.1       mw 
    816  1.1       mw /* helper functions, makes the code below more readable */
    817  1.1       mw static void inline
    818  1.3       mw ite_sendstr (ip, str)
    819  1.3       mw     struct ite_softc *ip;
    820  1.3       mw     char *str;
    821  1.3       mw {
    822  1.3       mw   while (*str)
    823  1.3       mw     itesendch (*str++);
    824  1.3       mw }
    825  1.3       mw 
    826  1.3       mw static void
    827  1.3       mw alignment_display(struct ite_softc *ip, struct itesw *sp)
    828  1.3       mw {
    829  1.3       mw   int i, j;
    830  1.3       mw 
    831  1.3       mw   for (j = 0; j < ip->rows; j++)
    832  1.3       mw     for (i = 0; i < ip->cols; i++)
    833  1.3       mw       (*sp->ite_putc)(ip, 'E', j, i, ATTR_NOR);
    834  1.3       mw   attrclr(ip, 0, 0, ip->rows, ip->cols);
    835  1.3       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    836  1.3       mw }
    837  1.3       mw 
    838  1.3       mw static void inline
    839  1.3       mw snap_cury(struct ite_softc *ip, struct itesw *sp)
    840  1.3       mw {
    841  1.3       mw   if (ip->inside_margins)
    842  1.3       mw     {
    843  1.3       mw       if (ip->cury < ip->top_margin)
    844  1.3       mw 	ip->cury = ip->top_margin;
    845  1.3       mw       if (ip->cury > ip->bottom_margin)
    846  1.3       mw 	ip->cury = ip->bottom_margin;
    847  1.3       mw     }
    848  1.3       mw }
    849  1.3       mw 
    850  1.3       mw static void inline
    851  1.1       mw ite_dnchar(ip, sp, n)
    852  1.1       mw      struct ite_softc *ip;
    853  1.1       mw      struct itesw *sp;
    854  1.1       mw      int n;
    855  1.1       mw {
    856  1.3       mw   n = MIN(n, ip->cols - ip->curx);
    857  1.3       mw   if (n < ip->cols - ip->curx)
    858  1.3       mw     {
    859  1.3       mw       (*sp->ite_scroll)(ip, ip->cury, ip->curx + n, n, SCROLL_LEFT);
    860  1.3       mw       attrmov(ip, ip->cury, ip->curx + n, ip->cury, ip->curx,
    861  1.3       mw 	      1, ip->cols - ip->curx - n);
    862  1.3       mw       attrclr(ip, ip->cury, ip->cols - n, 1, n);
    863  1.3       mw     }
    864  1.3       mw   while (n-- > 0)
    865  1.1       mw     (*sp->ite_putc)(ip, ' ', ip->cury, ip->cols - n - 1, ATTR_NOR);
    866  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    867  1.1       mw }
    868  1.1       mw 
    869  1.1       mw static void inline
    870  1.1       mw ite_inchar(ip, sp, n)
    871  1.1       mw      struct ite_softc *ip;
    872  1.1       mw      struct itesw *sp;
    873  1.1       mw      int n;
    874  1.1       mw {
    875  1.3       mw   n = MIN(n, ip->cols - ip->curx);
    876  1.3       mw   if (n < ip->cols - ip->curx)
    877  1.3       mw     {
    878  1.3       mw       (*sp->ite_scroll)(ip, ip->cury, ip->curx, n, SCROLL_RIGHT);
    879  1.3       mw       attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + n,
    880  1.3       mw 	      1, ip->cols - ip->curx - n);
    881  1.3       mw       attrclr(ip, ip->cury, ip->curx, 1, n);
    882  1.3       mw     }
    883  1.1       mw   while (n--)
    884  1.1       mw     (*sp->ite_putc)(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
    885  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    886  1.1       mw }
    887  1.1       mw 
    888  1.1       mw static void inline
    889  1.3       mw ite_clrtoeol(ip, sp)
    890  1.1       mw      struct ite_softc *ip;
    891  1.1       mw      struct itesw *sp;
    892  1.1       mw {
    893  1.3       mw   int y = ip->cury, x = ip->curx;
    894  1.3       mw   if (ip->cols - x > 0)
    895  1.3       mw     {
    896  1.3       mw       (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
    897  1.3       mw       attrclr(ip, y, x, 1, ip->cols - x);
    898  1.3       mw       (*sp->ite_cursor)(ip, DRAW_CURSOR);
    899  1.3       mw     }
    900  1.1       mw }
    901  1.1       mw 
    902  1.1       mw static void inline
    903  1.3       mw ite_clrtobol(ip, sp)
    904  1.1       mw      struct ite_softc *ip;
    905  1.1       mw      struct itesw *sp;
    906  1.1       mw {
    907  1.3       mw   int y = ip->cury, x = MIN(ip->curx + 1, ip->cols);
    908  1.1       mw   (*sp->ite_clear)(ip, y, 0, 1, x);
    909  1.1       mw   attrclr(ip, y, 0, 1, x);
    910  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    911  1.1       mw }
    912  1.1       mw 
    913  1.1       mw static void inline
    914  1.3       mw ite_clrline(ip, sp)
    915  1.1       mw      struct ite_softc *ip;
    916  1.1       mw      struct itesw *sp;
    917  1.1       mw {
    918  1.3       mw   int y = ip->cury;
    919  1.1       mw   (*sp->ite_clear)(ip, y, 0, 1, ip->cols);
    920  1.1       mw   attrclr(ip, y, 0, 1, ip->cols);
    921  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    922  1.1       mw }
    923  1.1       mw 
    924  1.1       mw 
    925  1.1       mw 
    926  1.1       mw static void inline
    927  1.1       mw ite_clrtoeos(ip, sp)
    928  1.1       mw      struct ite_softc *ip;
    929  1.1       mw      struct itesw *sp;
    930  1.1       mw {
    931  1.3       mw   ite_clrtoeol(ip, sp);
    932  1.3       mw   if (ip->cury < ip->rows - 1)
    933  1.3       mw     {
    934  1.3       mw       (*sp->ite_clear)(ip, ip->cury + 1, 0, ip->rows - 1 - ip->cury, ip->cols);
    935  1.3       mw       attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
    936  1.3       mw       (*sp->ite_cursor)(ip, DRAW_CURSOR);
    937  1.3       mw     }
    938  1.1       mw }
    939  1.1       mw 
    940  1.1       mw static void inline
    941  1.1       mw ite_clrtobos(ip, sp)
    942  1.1       mw      struct ite_softc *ip;
    943  1.1       mw      struct itesw *sp;
    944  1.1       mw {
    945  1.3       mw   ite_clrtobol(ip, sp);
    946  1.3       mw   if (ip->cury > 0)
    947  1.3       mw     {
    948  1.3       mw       (*sp->ite_clear)(ip, 0, 0, ip->cury, ip->cols);
    949  1.3       mw       attrclr(ip, 0, 0, ip->cury, ip->cols);
    950  1.3       mw       (*sp->ite_cursor)(ip, DRAW_CURSOR);
    951  1.3       mw     }
    952  1.1       mw }
    953  1.1       mw 
    954  1.1       mw static void inline
    955  1.1       mw ite_clrscreen(ip, sp)
    956  1.1       mw      struct ite_softc *ip;
    957  1.1       mw      struct itesw *sp;
    958  1.1       mw {
    959  1.1       mw   (*sp->ite_clear)(ip, 0, 0, ip->rows, ip->cols);
    960  1.1       mw   attrclr(ip, 0, 0, ip->rows, ip->cols);
    961  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    962  1.1       mw }
    963  1.1       mw 
    964  1.1       mw 
    965  1.1       mw 
    966  1.1       mw static void inline
    967  1.1       mw ite_dnline(ip, sp, n)
    968  1.1       mw      struct ite_softc *ip;
    969  1.1       mw      struct itesw *sp;
    970  1.1       mw      int n;
    971  1.1       mw {
    972  1.3       mw   n = MIN(n, ip->bottom_margin + 1 - ip->cury);
    973  1.3       mw   if (n <= ip->bottom_margin - ip->cury)
    974  1.3       mw     {
    975  1.3       mw       (*sp->ite_scroll)(ip, ip->cury + n, 0, n, SCROLL_UP);
    976  1.3       mw       attrmov(ip, ip->cury + n, 0, ip->cury, 0,
    977  1.3       mw 	      ip->bottom_margin + 1 - ip->cury - n, ip->cols);
    978  1.3       mw     }
    979  1.1       mw   (*sp->ite_clear)(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
    980  1.1       mw   attrclr(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
    981  1.1       mw   (*sp->ite_cursor)(ip, DRAW_CURSOR);
    982  1.1       mw }
    983  1.1       mw 
    984  1.1       mw static void inline
    985  1.1       mw ite_inline(ip, sp, n)
    986  1.1       mw      struct ite_softc *ip;
    987  1.1       mw      struct itesw *sp;
    988  1.1       mw      int n;
    989  1.1       mw {
    990  1.3       mw   if ((ip->cury >= ip->top_margin) && (ip->cury <= ip->bottom_margin))
    991  1.3       mw     {
    992  1.3       mw       n = MIN(n, ip->bottom_margin + 1 - ip->cury);
    993  1.3       mw       if (n <= ip->bottom_margin - ip->cury)
    994  1.3       mw 	{
    995  1.3       mw 	  (*sp->ite_scroll)(ip, ip->cury, 0, n, SCROLL_DOWN);
    996  1.3       mw 	  attrmov(ip, ip->cury, 0, ip->cury + n, 0,
    997  1.3       mw 		  ip->bottom_margin + 1 - ip->cury - n, ip->cols);
    998  1.3       mw 	}
    999  1.3       mw       (*sp->ite_clear)(ip, ip->cury, 0, n, ip->cols);
   1000  1.3       mw       attrclr(ip, ip->cury, 0, n, ip->cols);
   1001  1.3       mw       (*sp->ite_cursor)(ip, DRAW_CURSOR);
   1002  1.3       mw     }
   1003  1.1       mw }
   1004  1.1       mw 
   1005  1.1       mw static void inline
   1006  1.1       mw ite_lf (ip, sp)
   1007  1.1       mw      struct ite_softc *ip;
   1008  1.1       mw      struct itesw *sp;
   1009  1.1       mw {
   1010  1.1       mw   if (ip->inside_margins)
   1011  1.1       mw     {
   1012  1.3       mw       ++ip->cury;
   1013  1.3       mw       if ((ip->cury == ip->bottom_margin+1) || (ip->cury == ip->rows))
   1014  1.1       mw         {
   1015  1.3       mw           ip->cury--;
   1016  1.1       mw           (*sp->ite_scroll)(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
   1017  1.3       mw           ite_clrline(ip, sp);
   1018  1.1       mw         }
   1019  1.3       mw       (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1020  1.1       mw     }
   1021  1.1       mw   else
   1022  1.1       mw     {
   1023  1.3       mw       if (++ip->cury >= ip->rows)
   1024  1.1       mw         {
   1025  1.3       mw           ip->cury = ip->rows - 1;
   1026  1.1       mw           (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
   1027  1.3       mw           ite_clrline(ip, sp);
   1028  1.1       mw         }
   1029  1.3       mw       (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1030  1.1       mw     }
   1031  1.1       mw   clr_attr(ip, ATTR_INV);
   1032  1.1       mw }
   1033  1.1       mw 
   1034  1.1       mw static void inline
   1035  1.1       mw ite_crlf (ip, sp)
   1036  1.1       mw      struct ite_softc *ip;
   1037  1.1       mw      struct itesw *sp;
   1038  1.1       mw {
   1039  1.1       mw   ip->curx = 0;
   1040  1.1       mw   ite_lf (ip, sp);
   1041  1.1       mw }
   1042  1.1       mw 
   1043  1.1       mw static void inline
   1044  1.1       mw ite_cr (ip, sp)
   1045  1.1       mw      struct ite_softc *ip;
   1046  1.1       mw      struct itesw *sp;
   1047  1.1       mw {
   1048  1.3       mw   if (ip->curx)
   1049  1.1       mw     {
   1050  1.1       mw       ip->curx = 0;
   1051  1.1       mw       (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1052  1.1       mw     }
   1053  1.1       mw }
   1054  1.1       mw 
   1055  1.1       mw static void inline
   1056  1.1       mw ite_rlf (ip, sp)
   1057  1.1       mw      struct ite_softc *ip;
   1058  1.1       mw      struct itesw *sp;
   1059  1.1       mw {
   1060  1.3       mw   int top = ip->inside_margins ? ip->top_margin : 0;
   1061  1.3       mw 
   1062  1.3       mw   ip->cury--;
   1063  1.3       mw   if ((ip->cury < 0) || (ip->cury == top-1))
   1064  1.1       mw     {
   1065  1.3       mw       ip->cury++;
   1066  1.3       mw       (*sp->ite_scroll)(ip, top, 0, 1, SCROLL_DOWN);
   1067  1.3       mw       ite_clrline(ip, sp);
   1068  1.1       mw     }
   1069  1.3       mw   (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1070  1.1       mw   clr_attr(ip, ATTR_INV);
   1071  1.1       mw }
   1072  1.1       mw 
   1073  1.1       mw static int inline
   1074  1.1       mw atoi (cp)
   1075  1.1       mw     const char *cp;
   1076  1.1       mw {
   1077  1.1       mw   int n;
   1078  1.1       mw 
   1079  1.1       mw   for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++)
   1080  1.1       mw     n = n * 10 + *cp - '0';
   1081  1.1       mw 
   1082  1.1       mw   return n;
   1083  1.1       mw }
   1084  1.1       mw 
   1085  1.1       mw static char *
   1086  1.1       mw index (cp, ch)
   1087  1.1       mw     const char *cp;
   1088  1.1       mw     char ch;
   1089  1.1       mw {
   1090  1.1       mw   while (*cp && *cp != ch) cp++;
   1091  1.3       mw   return *cp ? (char *) cp : 0;
   1092  1.1       mw }
   1093  1.1       mw 
   1094  1.1       mw 
   1095  1.1       mw 
   1096  1.1       mw static int inline
   1097  1.1       mw ite_argnum (ip)
   1098  1.1       mw     struct ite_softc *ip;
   1099  1.1       mw {
   1100  1.1       mw   char ch;
   1101  1.1       mw   int n;
   1102  1.1       mw 
   1103  1.1       mw   /* convert argument string into number */
   1104  1.1       mw   if (ip->ap == ip->argbuf)
   1105  1.1       mw     return 1;
   1106  1.1       mw   ch = *ip->ap;
   1107  1.1       mw   *ip->ap = 0;
   1108  1.1       mw   n = atoi (ip->argbuf);
   1109  1.1       mw   *ip->ap = ch;
   1110  1.1       mw 
   1111  1.1       mw   return n;
   1112  1.1       mw }
   1113  1.1       mw 
   1114  1.1       mw static int inline
   1115  1.1       mw ite_zargnum (ip)
   1116  1.1       mw     struct ite_softc *ip;
   1117  1.1       mw {
   1118  1.1       mw   char ch, *cp;
   1119  1.1       mw   int n;
   1120  1.1       mw 
   1121  1.1       mw   /* convert argument string into number */
   1122  1.1       mw   if (ip->ap == ip->argbuf)
   1123  1.1       mw     return 0;
   1124  1.1       mw   ch = *ip->ap;
   1125  1.1       mw   *ip->ap = 0;
   1126  1.1       mw   n = atoi (ip->argbuf);
   1127  1.1       mw   *ip->ap = ch;
   1128  1.1       mw 
   1129  1.3       mw   return n;	/* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
   1130  1.1       mw }
   1131  1.1       mw 
   1132  1.1       mw static int inline
   1133  1.1       mw strncmp (a, b, l)
   1134  1.1       mw     const char *a, *b;
   1135  1.1       mw     int l;
   1136  1.1       mw {
   1137  1.1       mw   for (;l--; a++, b++)
   1138  1.1       mw     if (*a != *b)
   1139  1.1       mw       return *a - *b;
   1140  1.1       mw   return 0;
   1141  1.1       mw }
   1142  1.1       mw 
   1143  1.1       mw static void inline
   1144  1.3       mw ite_reset(ip)
   1145  1.1       mw     struct ite_softc *ip;
   1146  1.1       mw {
   1147  1.3       mw   int i;
   1148  1.3       mw 
   1149  1.1       mw   ip->curx = 0;
   1150  1.1       mw   ip->cury = 0;
   1151  1.3       mw   ip->attribute = 0;
   1152  1.1       mw   ip->save_curx = 0;
   1153  1.1       mw   ip->save_cury = 0;
   1154  1.3       mw   ip->save_attribute = 0;
   1155  1.1       mw   ip->ap = ip->argbuf;
   1156  1.1       mw   ip->emul_level = EMUL_VT300_7;
   1157  1.1       mw   ip->eightbit_C1 = 0;
   1158  1.3       mw   ip->top_margin = 0; ip->bottom_margin = ip->rows - 1;
   1159  1.3       mw   ip->inside_margins = 1;
   1160  1.1       mw   ip->linefeed_newline = 0;
   1161  1.3       mw   ip->auto_wrap = 0;
   1162  1.3       mw   ip->cursor_appmode = 0;
   1163  1.3       mw   ip->keypad_appmode = 0;
   1164  1.3       mw   ip->imode = 0;
   1165  1.3       mw   ip->key_repeat = 1;
   1166  1.1       mw 
   1167  1.3       mw #ifdef DO_WEIRD_ATTRIBUTES
   1168  1.1       mw   bzero(ip->attrbuf, (ip->rows * ip->cols));
   1169  1.3       mw #endif
   1170  1.3       mw   bzero (ip->tabs, ip->cols);
   1171  1.3       mw   for (i = 0; i < ip->cols; i++)
   1172  1.3       mw     ip->tabs[i] = (i & 7) == 0;
   1173  1.1       mw }
   1174  1.1       mw 
   1175  1.1       mw 
   1176  1.3       mw void
   1177  1.1       mw iteputchar(c, dev)
   1178  1.1       mw 	register int c;
   1179  1.1       mw 	dev_t dev;
   1180  1.1       mw {
   1181  1.1       mw 	int unit = UNIT(dev);
   1182  1.1       mw 	register struct ite_softc *ip = &ite_softc[unit];
   1183  1.1       mw 	register struct itesw *sp = &itesw[ip->type];
   1184  1.1       mw 	register int n;
   1185  1.1       mw 	int x, y;
   1186  1.1       mw 	char *cp;
   1187  1.1       mw 
   1188  1.1       mw 	if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
   1189  1.1       mw 	  	return;
   1190  1.1       mw 
   1191  1.3       mw #if 0
   1192  1.3       mw 	if (ite_tty[unit])
   1193  1.3       mw 	  if ((ite_tty[unit]->t_cflag & CSIZE) == CS7
   1194  1.3       mw 	      || (ite_tty[unit]->t_cflag & PARENB))
   1195  1.3       mw 	    c &= 0x7f;
   1196  1.3       mw #endif
   1197  1.1       mw 
   1198  1.1       mw 	if (ip->escape)
   1199  1.1       mw 	  {
   1200  1.1       mw doesc:
   1201  1.1       mw 	    switch (ip->escape)
   1202  1.1       mw 	      {
   1203  1.1       mw 	      case ESC:
   1204  1.1       mw 	        switch (c)
   1205  1.1       mw 	          {
   1206  1.1       mw 		  /* first 7bit equivalents for the 8bit control characters */
   1207  1.1       mw 
   1208  1.1       mw 	          case 'D':
   1209  1.1       mw 		    c = IND;
   1210  1.1       mw 		    ip->escape = 0;
   1211  1.3       mw 		    break; /* and fall into the next switch below (same for all `break') */
   1212  1.1       mw 
   1213  1.1       mw 		  case 'E':
   1214  1.1       mw 		    c = NEL;
   1215  1.1       mw 		    ip->escape = 0;
   1216  1.1       mw 		    break;
   1217  1.1       mw 
   1218  1.1       mw 		  case 'H':
   1219  1.1       mw 		    c = HTS;
   1220  1.1       mw 		    ip->escape = 0;
   1221  1.1       mw 		    break;
   1222  1.1       mw 
   1223  1.1       mw 		  case 'M':
   1224  1.1       mw 		    c = RI;
   1225  1.1       mw 		    ip->escape = 0;
   1226  1.1       mw 		    break;
   1227  1.1       mw 
   1228  1.1       mw 		  case 'N':
   1229  1.1       mw 		    c = SS2;
   1230  1.1       mw 		    ip->escape = 0;
   1231  1.1       mw 		    break;
   1232  1.1       mw 
   1233  1.1       mw 		  case 'O':
   1234  1.1       mw 		    c = SS3;
   1235  1.1       mw 		    ip->escape = 0;
   1236  1.1       mw 		    break;
   1237  1.1       mw 
   1238  1.1       mw 		  case 'P':
   1239  1.1       mw 		    c = DCS;
   1240  1.1       mw 		    ip->escape = 0;
   1241  1.1       mw 		    break;
   1242  1.1       mw 
   1243  1.1       mw 		  case '[':
   1244  1.1       mw 		    c = CSI;
   1245  1.1       mw 		    ip->escape = 0;
   1246  1.1       mw 		    break;
   1247  1.1       mw 
   1248  1.1       mw 		  case '\\':
   1249  1.1       mw 		    c = ST;
   1250  1.1       mw 		    ip->escape = 0;
   1251  1.1       mw 		    break;
   1252  1.1       mw 
   1253  1.1       mw 		  case ']':
   1254  1.1       mw 		    c = OSC;
   1255  1.1       mw 		    ip->escape = 0;
   1256  1.1       mw 		    break;
   1257  1.1       mw 
   1258  1.1       mw 		  case '^':
   1259  1.1       mw 		    c = PM;
   1260  1.1       mw 		    ip->escape = 0;
   1261  1.1       mw 		    break;
   1262  1.1       mw 
   1263  1.1       mw 		  case '_':
   1264  1.1       mw 		    c = APC;
   1265  1.1       mw 		    ip->escape = 0;
   1266  1.1       mw 		    break;
   1267  1.1       mw 
   1268  1.1       mw 
   1269  1.1       mw 		  /* introduces 7/8bit control */
   1270  1.1       mw 		  case ' ':
   1271  1.1       mw 		     /* can be followed by either F or G */
   1272  1.1       mw 		     ip->escape = ' ';
   1273  1.1       mw 		     break;
   1274  1.1       mw 
   1275  1.1       mw 
   1276  1.1       mw 		  /* a lot of character set selections, not yet used...
   1277  1.1       mw 		     94-character sets: */
   1278  1.1       mw 		  case '(':	/* G0 */
   1279  1.1       mw 		  case ')':	/* G1 */
   1280  1.3       mw 		    ip->escape = c;
   1281  1.3       mw 		    return;
   1282  1.3       mw 
   1283  1.1       mw 		  case '*':	/* G2 */
   1284  1.1       mw 		  case '+':	/* G3 */
   1285  1.1       mw 		  case 'B':	/* ASCII */
   1286  1.1       mw 		  case 'A':	/* ISO latin 1 */
   1287  1.1       mw 		  case '<':	/* user preferred suplemental */
   1288  1.1       mw 		  case '0':	/* dec special graphics */
   1289  1.1       mw 
   1290  1.1       mw 		  /* 96-character sets: */
   1291  1.1       mw 		  case '-':	/* G1 */
   1292  1.1       mw 		  case '.':	/* G2 */
   1293  1.1       mw 		  case '/':	/* G3 */
   1294  1.1       mw 
   1295  1.1       mw 		  /* national character sets: */
   1296  1.1       mw 		  case '4':	/* dutch */
   1297  1.1       mw 		  case '5':
   1298  1.1       mw 		  case 'C':	/* finnish */
   1299  1.1       mw 		  case 'R':	/* french */
   1300  1.1       mw 		  case 'Q':	/* french canadian */
   1301  1.1       mw 		  case 'K':	/* german */
   1302  1.1       mw 		  case 'Y':	/* italian */
   1303  1.1       mw 		  case '6':	/* norwegian/danish */
   1304  1.1       mw 		  /* note: %5 and %6 are not supported (two chars..) */
   1305  1.1       mw 
   1306  1.1       mw 		    ip->escape = 0;
   1307  1.1       mw 		    /* just ignore for now */
   1308  1.3       mw 		    return;
   1309  1.1       mw 
   1310  1.1       mw 
   1311  1.1       mw 		  /* locking shift modes (as you might guess, not yet supported..) */
   1312  1.1       mw 		  case '`':
   1313  1.1       mw 		    ip->GR = ip->G1;
   1314  1.1       mw 		    ip->escape = 0;
   1315  1.3       mw 		    return;
   1316  1.1       mw 
   1317  1.1       mw 		  case 'n':
   1318  1.1       mw 		    ip->GL = ip->G2;
   1319  1.1       mw 		    ip->escape = 0;
   1320  1.3       mw 		    return;
   1321  1.1       mw 
   1322  1.1       mw 		  case '}':
   1323  1.1       mw 		    ip->GR = ip->G2;
   1324  1.1       mw 		    ip->escape = 0;
   1325  1.3       mw 		    return;
   1326  1.1       mw 
   1327  1.1       mw 		  case 'o':
   1328  1.1       mw 		    ip->GL = ip->G3;
   1329  1.1       mw 		    ip->escape = 0;
   1330  1.3       mw 		    return;
   1331  1.1       mw 
   1332  1.1       mw 		  case '|':
   1333  1.1       mw 		    ip->GR = ip->G3;
   1334  1.1       mw 		    ip->escape = 0;
   1335  1.3       mw 		    return;
   1336  1.1       mw 
   1337  1.1       mw 
   1338  1.1       mw 		  /* font width/height control */
   1339  1.1       mw 		  case '#':
   1340  1.1       mw 		    ip->escape = '#';
   1341  1.3       mw 		    return;
   1342  1.1       mw 
   1343  1.1       mw 
   1344  1.1       mw 		  /* hard terminal reset .. */
   1345  1.1       mw 		  case 'c':
   1346  1.3       mw 		    ite_reset (ip);
   1347  1.3       mw 		    (*itesw[ip->type].ite_cursor)(ip, MOVE_CURSOR);
   1348  1.1       mw 		    ip->escape = 0;
   1349  1.3       mw 		    return;
   1350  1.1       mw 
   1351  1.1       mw 
   1352  1.1       mw 		  case '7':
   1353  1.1       mw 		    ip->save_curx = ip->curx;
   1354  1.1       mw 		    ip->save_cury = ip->cury;
   1355  1.3       mw 		    ip->save_attribute = ip->attribute;
   1356  1.1       mw 		    ip->escape = 0;
   1357  1.3       mw 		    return;
   1358  1.1       mw 
   1359  1.1       mw 		  case '8':
   1360  1.1       mw 		    ip->curx = ip->save_curx;
   1361  1.1       mw 		    ip->cury = ip->save_cury;
   1362  1.3       mw 		    ip->attribute = ip->save_attribute;
   1363  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1364  1.1       mw 		    ip->escape = 0;
   1365  1.3       mw 		    return;
   1366  1.3       mw 
   1367  1.3       mw 		  case '=':
   1368  1.3       mw 		    ip->keypad_appmode = 1;
   1369  1.3       mw 		    ip->escape = 0;
   1370  1.3       mw 		    return;
   1371  1.1       mw 
   1372  1.3       mw 		  case '>':
   1373  1.3       mw 		    ip->keypad_appmode = 0;
   1374  1.3       mw 		    ip->escape = 0;
   1375  1.3       mw 		    return;
   1376  1.1       mw 
   1377  1.3       mw 		  case 'Z':	/* request ID */
   1378  1.3       mw 		    if (ip->emul_level == EMUL_VT100)
   1379  1.3       mw 		      ite_sendstr (ip, "\033[61;0c");
   1380  1.3       mw 		    else
   1381  1.3       mw 		      ite_sendstr (ip, "\033[63;0c");
   1382  1.3       mw 		    ip->escape = 0;
   1383  1.3       mw 		    return;
   1384  1.3       mw 
   1385  1.1       mw 		  /* default catch all for not recognized ESC sequences */
   1386  1.1       mw 		  default:
   1387  1.1       mw 		    ip->escape = 0;
   1388  1.3       mw 		    return;
   1389  1.1       mw 		  }
   1390  1.1       mw 		break;
   1391  1.1       mw 
   1392  1.1       mw 
   1393  1.3       mw 	      case '(':
   1394  1.3       mw 	      case ')':
   1395  1.3       mw 		ip->escape = 0;
   1396  1.3       mw 		return;
   1397  1.3       mw 
   1398  1.3       mw 
   1399  1.1       mw 	      case ' ':
   1400  1.1       mw 	        switch (c)
   1401  1.1       mw 	          {
   1402  1.1       mw 	          case 'F':
   1403  1.1       mw 		    ip->eightbit_C1 = 0;
   1404  1.1       mw 		    ip->escape = 0;
   1405  1.3       mw 		    return;
   1406  1.1       mw 
   1407  1.1       mw 		  case 'G':
   1408  1.1       mw 		    ip->eightbit_C1 = 1;
   1409  1.1       mw 		    ip->escape = 0;
   1410  1.3       mw 		    return;
   1411  1.1       mw 
   1412  1.1       mw 		  default:
   1413  1.1       mw 		    /* not supported */
   1414  1.1       mw 		    ip->escape = 0;
   1415  1.3       mw 		    return;
   1416  1.1       mw 		  }
   1417  1.1       mw 		break;
   1418  1.1       mw 
   1419  1.1       mw 
   1420  1.1       mw 	      case '#':
   1421  1.1       mw 		switch (c)
   1422  1.1       mw 		  {
   1423  1.1       mw 		  case '5':
   1424  1.1       mw 		    /* single height, single width */
   1425  1.1       mw 		    ip->escape = 0;
   1426  1.3       mw 		    return;
   1427  1.1       mw 
   1428  1.1       mw 		  case '6':
   1429  1.1       mw 		    /* double width, single height */
   1430  1.1       mw 		    ip->escape = 0;
   1431  1.3       mw 		    return;
   1432  1.1       mw 
   1433  1.1       mw 		  case '3':
   1434  1.1       mw 		    /* top half */
   1435  1.1       mw 		    ip->escape = 0;
   1436  1.3       mw 		    return;
   1437  1.1       mw 
   1438  1.1       mw 		  case '4':
   1439  1.1       mw 		    /* bottom half */
   1440  1.1       mw 		    ip->escape = 0;
   1441  1.3       mw 		    return;
   1442  1.1       mw 
   1443  1.1       mw 		  case '8':
   1444  1.1       mw 		    /* screen alignment pattern... */
   1445  1.1       mw 		    ip->escape = 0;
   1446  1.3       mw 		    return;
   1447  1.1       mw 
   1448  1.1       mw 		  default:
   1449  1.1       mw 		    ip->escape = 0;
   1450  1.3       mw 		    return;
   1451  1.1       mw 		  }
   1452  1.1       mw 		break;
   1453  1.1       mw 
   1454  1.1       mw 
   1455  1.1       mw 
   1456  1.1       mw 	      case CSI:
   1457  1.1       mw 	        /* the biggie... */
   1458  1.1       mw 	        switch (c)
   1459  1.1       mw 	          {
   1460  1.1       mw 	          case '0': case '1': case '2': case '3': case '4':
   1461  1.1       mw 	          case '5': case '6': case '7': case '8': case '9':
   1462  1.1       mw 	          case ';': case '\"': case '$': case '>':
   1463  1.1       mw 	            if (ip->ap < ip->argbuf + ARGBUF_SIZE)
   1464  1.1       mw 	              *ip->ap++ = c;
   1465  1.3       mw 	            return;
   1466  1.1       mw 
   1467  1.1       mw 	          case 'p':
   1468  1.1       mw 		    *ip->ap = 0;
   1469  1.1       mw 	            if (! strncmp (ip->argbuf, "61\"", 3))
   1470  1.1       mw 	              ip->emul_level = EMUL_VT100;
   1471  1.1       mw 	            else if (! strncmp (ip->argbuf, "63;1\"", 5)
   1472  1.1       mw 	            	     || ! strncmp (ip->argbuf, "62;1\"", 5))
   1473  1.1       mw 	              ip->emul_level = EMUL_VT300_7;
   1474  1.1       mw 	            else
   1475  1.1       mw 	              ip->emul_level = EMUL_VT300_8;
   1476  1.1       mw 	            ip->escape = 0;
   1477  1.3       mw 	            return;
   1478  1.1       mw 
   1479  1.1       mw 
   1480  1.1       mw 	          case '?':
   1481  1.1       mw 		    *ip->ap = 0;
   1482  1.1       mw 	            ip->escape = '?';
   1483  1.1       mw 	            ip->ap = ip->argbuf;
   1484  1.3       mw 	            return;
   1485  1.1       mw 
   1486  1.1       mw 
   1487  1.1       mw 		  case 'c':
   1488  1.3       mw   		    *ip->ap = 0;
   1489  1.3       mw 		    if (ip->argbuf[0] == '>')
   1490  1.3       mw 		      {
   1491  1.3       mw 		        ite_sendstr (ip, "\033[>24;0;0;0c");
   1492  1.3       mw 		      }
   1493  1.3       mw 		    else switch (ite_zargnum(ip))
   1494  1.1       mw 		      {
   1495  1.3       mw 		      case 0:
   1496  1.1       mw 			/* primary DA request, send primary DA response */
   1497  1.1       mw 			if (ip->emul_level == EMUL_VT100)
   1498  1.3       mw 		          ite_sendstr (ip, "\033[?1;1c");
   1499  1.1       mw 		        else
   1500  1.1       mw 		          ite_sendstr (ip, "\033[63;0c");
   1501  1.3       mw 			break;
   1502  1.1       mw 		      }
   1503  1.1       mw 		    ip->escape = 0;
   1504  1.3       mw <<<<<<< ite.c
   1505  1.1       mw 		    return -1;
   1506  1.3       mw ||||||| 1.1.1.2
   1507  1.3       mw 		    return -1;
   1508  1.3       mw 
   1509  1.3       mw =======
   1510  1.3       mw 		    return;
   1511  1.3       mw >>>>>>> /tmp/T4009622
   1512  1.1       mw 
   1513  1.1       mw 
   1514  1.1       mw 		  case 'n':
   1515  1.3       mw 		    switch (ite_zargnum(ip))
   1516  1.1       mw 		      {
   1517  1.3       mw 		      case 5:
   1518  1.3       mw 		        ite_sendstr (ip, "\033[0n");	/* no malfunction */
   1519  1.3       mw 			break;
   1520  1.3       mw 		      case 6:
   1521  1.3       mw 			/* cursor position report */
   1522  1.3       mw 		        sprintf (ip->argbuf, "\033[%d;%dR",
   1523  1.3       mw 				 ip->cury + 1, ip->curx + 1);
   1524  1.3       mw 			ite_sendstr (ip, ip->argbuf);
   1525  1.3       mw 			break;
   1526  1.1       mw 		      }
   1527  1.1       mw 		    ip->escape = 0;
   1528  1.3       mw <<<<<<< ite.c
   1529  1.3       mw 		    return -1;
   1530  1.3       mw 
   1531  1.3       mw ||||||| 1.1.1.2
   1532  1.1       mw 		    return -1;
   1533  1.3       mw =======
   1534  1.3       mw 		    return;
   1535  1.3       mw >>>>>>> /tmp/T4009622
   1536  1.1       mw 
   1537  1.3       mw <<<<<<< ite.c
   1538  1.3       mw 	          case 'h': case 'l':
   1539  1.3       mw 		    *ip->ap = 0;
   1540  1.3       mw 		    if (ip->ap == &ip->argbuf[1] && ip->argbuf[0] == '4')
   1541  1.3       mw 		      ip->imode = (c == 'h');	/* insert/replace mode */
   1542  1.3       mw ||||||| 1.1.1.2
   1543  1.1       mw 
   1544  1.1       mw 	          case 'h': case 'l':
   1545  1.1       mw 		    *ip->ap = 0;
   1546  1.1       mw 		    if (ip->ap == &ip->argbuf[1] && ip->argbuf[0] == '4')
   1547  1.1       mw 		      ip->imode = (c == 'h');	/* insert/replace mode */
   1548  1.3       mw =======
   1549  1.3       mw 
   1550  1.3       mw 		  case 'x':
   1551  1.3       mw 		    switch (ite_zargnum(ip))
   1552  1.3       mw 		      {
   1553  1.3       mw 		      case 0:
   1554  1.3       mw 			/* Fake some terminal parameters.  */
   1555  1.3       mw 		        ite_sendstr (ip, "\033[2;1;1;112;112;1;0x");
   1556  1.3       mw 			break;
   1557  1.3       mw 		      case 1:
   1558  1.3       mw 		        ite_sendstr (ip, "\033[3;1;1;112;112;1;0x");
   1559  1.3       mw 			break;
   1560  1.3       mw 		      }
   1561  1.3       mw 		    ip->escape = 0;
   1562  1.3       mw 		    return;
   1563  1.3       mw >>>>>>> /tmp/T4009622
   1564  1.1       mw 
   1565  1.1       mw 
   1566  1.3       mw 		  case 'g':
   1567  1.3       mw 		    switch (ite_zargnum(ip))
   1568  1.3       mw 		      {
   1569  1.3       mw 		      case 0:
   1570  1.3       mw 			if (ip->curx < ip->cols)
   1571  1.3       mw 			  ip->tabs[ip->curx] = 0;
   1572  1.3       mw 			break;
   1573  1.3       mw 		      case 3:
   1574  1.3       mw 		        for (n = 0; n < ip->cols; n++)
   1575  1.3       mw 		          ip->tabs[n] = 0;
   1576  1.3       mw 			break;
   1577  1.3       mw 		      }
   1578  1.3       mw 		    ip->escape = 0;
   1579  1.3       mw 		    return;
   1580  1.1       mw 
   1581  1.3       mw 
   1582  1.3       mw   	          case 'h': case 'l':
   1583  1.3       mw 		    n = ite_zargnum (ip);
   1584  1.3       mw 		    switch (n)
   1585  1.3       mw 		      {
   1586  1.3       mw 		      case 4:
   1587  1.3       mw 		        ip->imode = (c == 'h');	/* insert/replace mode */
   1588  1.3       mw 			break;
   1589  1.3       mw 		      case 20:
   1590  1.3       mw 			ip->linefeed_newline = (c == 'h');
   1591  1.3       mw 			break;
   1592  1.3       mw 		      }
   1593  1.3       mw 		    ip->escape = 0;
   1594  1.3       mw 		    return;
   1595  1.1       mw 
   1596  1.1       mw 
   1597  1.1       mw 		  case 'M':
   1598  1.1       mw 		    ite_dnline (ip, sp, ite_argnum (ip));
   1599  1.1       mw 	            ip->escape = 0;
   1600  1.3       mw 	            return;
   1601  1.1       mw 
   1602  1.1       mw 
   1603  1.1       mw 		  case 'L':
   1604  1.1       mw 		    ite_inline (ip, sp, ite_argnum (ip));
   1605  1.1       mw 	            ip->escape = 0;
   1606  1.3       mw 	            return;
   1607  1.1       mw 
   1608  1.1       mw 
   1609  1.1       mw 		  case 'P':
   1610  1.1       mw 		    ite_dnchar (ip, sp, ite_argnum (ip));
   1611  1.1       mw 	            ip->escape = 0;
   1612  1.3       mw 	            return;
   1613  1.1       mw 
   1614  1.1       mw 
   1615  1.1       mw 		  case '@':
   1616  1.1       mw 		    ite_inchar (ip, sp, ite_argnum (ip));
   1617  1.1       mw 	            ip->escape = 0;
   1618  1.3       mw 	            return;
   1619  1.1       mw 
   1620  1.1       mw 
   1621  1.1       mw 		  case 'H':
   1622  1.1       mw 		  case 'f':
   1623  1.1       mw 		    *ip->ap = 0;
   1624  1.1       mw 		    y = atoi (ip->argbuf);
   1625  1.1       mw 		    x = 0;
   1626  1.1       mw 		    cp = index (ip->argbuf, ';');
   1627  1.1       mw 		    if (cp)
   1628  1.1       mw 		      x = atoi (cp + 1);
   1629  1.1       mw 		    if (x) x--;
   1630  1.1       mw 		    if (y) y--;
   1631  1.3       mw 		    ip->cury = MIN(y, ip->rows - 1);
   1632  1.1       mw 		    ip->curx = MIN(x, ip->cols - 1);
   1633  1.1       mw 		    ip->escape = 0;
   1634  1.3       mw 		    snap_cury(ip, sp);
   1635  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1636  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1637  1.3       mw 		    return;
   1638  1.1       mw 
   1639  1.1       mw 		  case 'A':
   1640  1.1       mw 		    n = ip->cury - ite_argnum (ip);
   1641  1.3       mw 		    if (n < 0) n = 0;
   1642  1.3       mw 		    ip->cury = MAX(n, ip->inside_margins ? ip->top_margin : 0);
   1643  1.1       mw 		    ip->escape = 0;
   1644  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1645  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1646  1.3       mw 		    return;
   1647  1.1       mw 
   1648  1.1       mw 		  case 'B':
   1649  1.1       mw 		    n = ite_argnum (ip) + ip->cury;
   1650  1.3       mw 		    ip->cury = MIN(n, ip->inside_margins ? ip->bottom_margin : ip->rows - 1);
   1651  1.1       mw 		    ip->escape = 0;
   1652  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1653  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1654  1.3       mw 		    return;
   1655  1.1       mw 
   1656  1.1       mw 		  case 'C':
   1657  1.3       mw 		    n = ite_argnum (ip);
   1658  1.3       mw 		    ip->curx = MIN(ip->curx + n, ip->cols - 1);
   1659  1.1       mw 		    ip->escape = 0;
   1660  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1661  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1662  1.3       mw 		    return;
   1663  1.1       mw 
   1664  1.1       mw 		  case 'D':
   1665  1.3       mw 		    n = ite_argnum (ip);
   1666  1.3       mw 		    n = ip->curx - n;
   1667  1.1       mw 		    ip->curx = n >= 0 ? n : 0;
   1668  1.1       mw 		    ip->escape = 0;
   1669  1.1       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1670  1.1       mw 		    clr_attr (ip, ATTR_INV);
   1671  1.3       mw 		    return;
   1672  1.1       mw 
   1673  1.1       mw 
   1674  1.1       mw 
   1675  1.1       mw 
   1676  1.1       mw 		  case 'J':
   1677  1.1       mw 		    *ip->ap = 0;
   1678  1.1       mw 		    n = ite_zargnum (ip);
   1679  1.1       mw 		    if (n == 0)
   1680  1.1       mw 	              ite_clrtoeos(ip, sp);
   1681  1.1       mw 		    else if (n == 1)
   1682  1.1       mw 		      ite_clrtobos(ip, sp);
   1683  1.1       mw 		    else if (n == 2)
   1684  1.1       mw 		      ite_clrscreen(ip, sp);
   1685  1.1       mw 	            ip->escape = 0;
   1686  1.3       mw 	            return;
   1687  1.1       mw 
   1688  1.1       mw 
   1689  1.1       mw 		  case 'K':
   1690  1.1       mw 		    n = ite_zargnum (ip);
   1691  1.1       mw 		    if (n == 0)
   1692  1.3       mw 		      ite_clrtoeol(ip, sp);
   1693  1.1       mw 		    else if (n == 1)
   1694  1.3       mw 		      ite_clrtobol(ip, sp);
   1695  1.1       mw 		    else if (n == 2)
   1696  1.3       mw 		      ite_clrline(ip, sp);
   1697  1.1       mw 		    ip->escape = 0;
   1698  1.3       mw 		    return;
   1699  1.1       mw 
   1700  1.1       mw 
   1701  1.1       mw 		  case 'X':
   1702  1.3       mw 		    n = ite_argnum(ip) - 1;
   1703  1.3       mw 		    n = MIN(n, ip->cols - 1 - ip->curx);
   1704  1.3       mw 		    for (; n >= 0; n--)
   1705  1.1       mw 		      {
   1706  1.3       mw 			attrclr(ip, ip->cury, ip->curx + n, 1, 1);
   1707  1.3       mw 			(*sp->ite_putc)(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
   1708  1.1       mw 		      }
   1709  1.1       mw 		    ip->escape = 0;
   1710  1.3       mw 		    return;
   1711  1.1       mw 
   1712  1.1       mw 
   1713  1.1       mw 	          case '}': case '`':
   1714  1.1       mw 	            /* status line control */
   1715  1.1       mw 	            ip->escape = 0;
   1716  1.3       mw 	            return;
   1717  1.1       mw 
   1718  1.1       mw 
   1719  1.1       mw 		  case 'r':
   1720  1.1       mw 		    *ip->ap = 0;
   1721  1.1       mw 		    x = atoi (ip->argbuf);
   1722  1.1       mw 		    y = 0;
   1723  1.1       mw 		    cp = index (ip->argbuf, ';');
   1724  1.1       mw 		    if (cp)
   1725  1.1       mw 		      y = atoi (cp + 1);
   1726  1.3       mw 		    if ((x > 0) || (y > 1))
   1727  1.3       mw 		      {
   1728  1.3       mw 		        if (x) x--;
   1729  1.3       mw 		        if (y) y--;
   1730  1.3       mw 		        ip->top_margin = MIN(x, ip->rows - 1);
   1731  1.3       mw 		        ip->bottom_margin = MIN(y, ip->rows - 1);
   1732  1.3       mw 			if (ip->bottom_margin < ip->top_margin)
   1733  1.3       mw 			  ip->bottom_margin = ip->top_margin;
   1734  1.3       mw 		      }
   1735  1.3       mw 		    else
   1736  1.3       mw 		      {
   1737  1.3       mw 			ip->top_margin = 0;
   1738  1.3       mw 			ip->bottom_margin = ip->rows - 1;
   1739  1.3       mw 		      }
   1740  1.3       mw 		    ip->cury = ip->top_margin;
   1741  1.3       mw 		    ip->curx = 0;
   1742  1.3       mw 		    (*sp->ite_cursor)(ip, MOVE_CURSOR);
   1743  1.1       mw 		    ip->escape = 0;
   1744  1.3       mw 		    return;
   1745  1.1       mw 
   1746  1.1       mw 
   1747  1.1       mw 		  case 'm':
   1748  1.1       mw 		    /* big attribute setter/resetter */
   1749  1.1       mw 		    {
   1750  1.1       mw 		      char *cp;
   1751  1.1       mw 		      *ip->ap = 0;
   1752  1.3       mw 		      /* kludge to make CSIm work (== CSI0m) */
   1753  1.3       mw 		      if (ip->ap == ip->argbuf)
   1754  1.3       mw 		        ip->ap++;
   1755  1.1       mw 		      for (cp = ip->argbuf; cp < ip->ap; )
   1756  1.1       mw 		        {
   1757  1.1       mw 			  switch (*cp)
   1758  1.1       mw 			    {
   1759  1.3       mw 			    case 0:
   1760  1.1       mw 			    case '0':
   1761  1.1       mw 			      clr_attr (ip, ATTR_ALL);
   1762  1.1       mw 			      cp++;
   1763  1.1       mw 			      break;
   1764  1.1       mw 
   1765  1.1       mw 			    case '1':
   1766  1.1       mw 			      set_attr (ip, ATTR_BOLD);
   1767  1.1       mw 			      cp++;
   1768  1.1       mw 			      break;
   1769  1.1       mw 
   1770  1.1       mw 			    case '2':
   1771  1.1       mw 			      switch (cp[1])
   1772  1.1       mw 			        {
   1773  1.1       mw 			        case '2':
   1774  1.1       mw 			          clr_attr (ip, ATTR_BOLD);
   1775  1.1       mw 			          cp += 2;
   1776  1.1       mw 			          break;
   1777  1.1       mw 
   1778  1.1       mw 			        case '4':
   1779  1.1       mw 			          clr_attr (ip, ATTR_UL);
   1780  1.1       mw 			          cp += 2;
   1781  1.1       mw 			          break;
   1782  1.1       mw 
   1783  1.1       mw 			        case '5':
   1784  1.1       mw 			          clr_attr (ip, ATTR_BLINK);
   1785  1.1       mw 			          cp += 2;
   1786  1.1       mw 			          break;
   1787  1.1       mw 
   1788  1.1       mw 			        case '7':
   1789  1.1       mw 			          clr_attr (ip, ATTR_INV);
   1790  1.1       mw 			          cp += 2;
   1791  1.1       mw 			          break;
   1792  1.1       mw 
   1793  1.1       mw 		        	default:
   1794  1.1       mw 		        	  cp++;
   1795  1.1       mw 		        	  break;
   1796  1.1       mw 		        	}
   1797  1.1       mw 			      break;
   1798  1.1       mw 
   1799  1.1       mw 			    case '4':
   1800  1.1       mw 			      set_attr (ip, ATTR_UL);
   1801  1.1       mw 			      cp++;
   1802  1.1       mw 			      break;
   1803  1.1       mw 
   1804  1.1       mw 			    case '5':
   1805  1.1       mw 			      set_attr (ip, ATTR_BLINK);
   1806  1.1       mw 			      cp++;
   1807  1.1       mw 			      break;
   1808  1.1       mw 
   1809  1.1       mw 			    case '7':
   1810  1.1       mw 			      set_attr (ip, ATTR_INV);
   1811  1.1       mw 			      cp++;
   1812  1.1       mw 			      break;
   1813  1.1       mw 
   1814  1.1       mw 			    default:
   1815  1.1       mw 			      cp++;
   1816  1.1       mw 			      break;
   1817  1.1       mw 			    }
   1818  1.1       mw 		        }
   1819  1.1       mw 
   1820  1.1       mw 		    }
   1821  1.1       mw 		    ip->escape = 0;
   1822  1.3       mw 		    return;
   1823  1.1       mw 
   1824  1.1       mw 
   1825  1.1       mw 		  case 'u':
   1826  1.1       mw 		    /* DECRQTSR */
   1827  1.1       mw 		    ite_sendstr (ip, "\033P\033\\");
   1828  1.1       mw 		    ip->escape = 0;
   1829  1.3       mw 		    return;
   1830  1.1       mw 
   1831  1.1       mw 
   1832  1.1       mw 
   1833  1.1       mw 		  default:
   1834  1.1       mw 		    ip->escape = 0;
   1835  1.3       mw 		    return;
   1836  1.1       mw 		  }
   1837  1.1       mw 		break;
   1838  1.1       mw 
   1839  1.1       mw 
   1840  1.1       mw 
   1841  1.1       mw 	      case '?':	/* CSI ? */
   1842  1.1       mw 	      	switch (c)
   1843  1.1       mw 	      	  {
   1844  1.1       mw 	          case '0': case '1': case '2': case '3': case '4':
   1845  1.1       mw 	          case '5': case '6': case '7': case '8': case '9':
   1846  1.1       mw 	          case ';': case '\"': case '$':
   1847  1.3       mw 		    /* Don't fill the last character; it's needed.  */
   1848  1.3       mw 		    /* XXX yeah, where ?? */
   1849  1.3       mw 	            if (ip->ap < ip->argbuf + ARGBUF_SIZE - 1)
   1850  1.1       mw 	              *ip->ap++ = c;
   1851  1.3       mw 	            return;
   1852  1.1       mw 
   1853  1.1       mw 
   1854  1.1       mw 		  case 'n':
   1855  1.1       mw 		    *ip->ap = 0;
   1856  1.1       mw 		    if (ip->ap == &ip->argbuf[2])
   1857  1.1       mw 		      {
   1858  1.1       mw 		        if (! strncmp (ip->argbuf, "15", 2))
   1859  1.1       mw 		          /* printer status: no printer */
   1860  1.1       mw 		          ite_sendstr (ip, "\033[13n");
   1861  1.1       mw 
   1862  1.1       mw 		        else if (! strncmp (ip->argbuf, "25", 2))
   1863  1.1       mw 		          /* udk status */
   1864  1.1       mw 		          ite_sendstr (ip, "\033[20n");
   1865  1.1       mw 
   1866  1.1       mw 		        else if (! strncmp (ip->argbuf, "26", 2))
   1867  1.1       mw 		          /* keyboard dialect: US */
   1868  1.1       mw 		          ite_sendstr (ip, "\033[27;1n");
   1869  1.1       mw 		      }
   1870  1.1       mw 		    ip->escape = 0;
   1871  1.3       mw 		    return;
   1872  1.3       mw 
   1873  1.3       mw 
   1874  1.3       mw   		  case 'h': case 'l':
   1875  1.3       mw 		    n = ite_zargnum (ip);
   1876  1.3       mw 		    switch (n)
   1877  1.3       mw 		      {
   1878  1.3       mw 		      case 1:
   1879  1.3       mw 		        ip->cursor_appmode = (c == 'h');
   1880  1.3       mw 		        break;
   1881  1.3       mw 
   1882  1.3       mw 		      case 3:
   1883  1.3       mw 		        /* 132/80 columns (132 == 'h') */
   1884  1.3       mw 		        break;
   1885  1.3       mw 
   1886  1.3       mw 		      case 4: /* smooth scroll */
   1887  1.3       mw 			break;
   1888  1.3       mw 
   1889  1.3       mw 		      case 5:
   1890  1.3       mw 		        /* light background (=='h') /dark background(=='l') */
   1891  1.3       mw 		        break;
   1892  1.3       mw 
   1893  1.3       mw 		      case 6: /* origin mode */
   1894  1.3       mw 			ip->inside_margins = (c == 'h');
   1895  1.3       mw 			break;
   1896  1.1       mw 
   1897  1.3       mw 		      case 7: /* auto wraparound */
   1898  1.3       mw 			ip->auto_wrap = (c == 'h');
   1899  1.3       mw 			break;
   1900  1.1       mw 
   1901  1.3       mw 		      case 8: /* keyboard repeat */
   1902  1.3       mw 			ip->key_repeat = (c == 'h');
   1903  1.3       mw 			break;
   1904  1.1       mw 
   1905  1.3       mw 		      case 20: /* newline mode */
   1906  1.3       mw 			ip->linefeed_newline = (c == 'h');
   1907  1.3       mw 			break;
   1908  1.1       mw 
   1909  1.3       mw 		      case 25: /* cursor on/off */
   1910  1.3       mw 			(*itesw[ip->type].ite_cursor)(ip, (c == 'h') ? DRAW_CURSOR : ERASE_CURSOR);
   1911  1.3       mw 			break;
   1912  1.3       mw 		      }
   1913  1.3       mw 		    ip->escape = 0;
   1914  1.3       mw 		    return;
   1915  1.1       mw 
   1916  1.1       mw 		  default:
   1917  1.1       mw 		    ip->escape = 0;
   1918  1.3       mw 		    return;
   1919  1.1       mw 		  }
   1920  1.1       mw 		break;
   1921  1.1       mw 
   1922  1.1       mw 
   1923  1.1       mw 	      default:
   1924  1.1       mw 	        ip->escape = 0;
   1925  1.3       mw 	        return;
   1926  1.1       mw 	      }
   1927  1.1       mw           }
   1928  1.1       mw 
   1929  1.1       mw 
   1930  1.1       mw 	switch (c) {
   1931  1.1       mw 
   1932  1.1       mw 	case VT:	/* VT is treated like LF */
   1933  1.1       mw 	case FF:	/* so is FF */
   1934  1.1       mw 	case LF:
   1935  1.3       mw 		/* cr->crlf distinction is done here, on output,
   1936  1.3       mw 		   not on input! */
   1937  1.1       mw 		if (ip->linefeed_newline)
   1938  1.1       mw 		  ite_crlf (ip, sp);
   1939  1.1       mw 		else
   1940  1.1       mw 		  ite_lf (ip, sp);
   1941  1.1       mw 		break;
   1942  1.1       mw 
   1943  1.1       mw 	case CR:
   1944  1.1       mw 		ite_cr (ip, sp);
   1945  1.1       mw 		break;
   1946  1.1       mw 
   1947  1.1       mw 	case BS:
   1948  1.1       mw 		if (--ip->curx < 0)
   1949  1.1       mw 			ip->curx = 0;
   1950  1.1       mw 		else
   1951  1.1       mw 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
   1952  1.1       mw 		break;
   1953  1.1       mw 
   1954  1.1       mw 	case HT:
   1955  1.3       mw 		for (n = ip->curx + 1; n < ip->cols; n++) {
   1956  1.3       mw 			if (ip->tabs[n]) {
   1957  1.3       mw 				ip->curx = n;
   1958  1.3       mw 				(*sp->ite_cursor)(ip, MOVE_CURSOR);
   1959  1.3       mw 				break;
   1960  1.3       mw 			}
   1961  1.3       mw 		}
   1962  1.1       mw 		break;
   1963  1.1       mw 
   1964  1.1       mw 	case BEL:
   1965  1.3       mw 		if (kbd_tty && ite_tty[unit] == kbd_tty)
   1966  1.1       mw 			kbdbell();
   1967  1.1       mw 		break;
   1968  1.1       mw 
   1969  1.1       mw 	case SO:
   1970  1.1       mw 		ip->GL = ip->G1;
   1971  1.1       mw 		break;
   1972  1.1       mw 
   1973  1.1       mw 	case SI:
   1974  1.1       mw 		ip->GL = ip->G0;
   1975  1.1       mw 		break;
   1976  1.1       mw 
   1977  1.1       mw 	case ENQ:
   1978  1.1       mw 		/* send answer-back message !! */
   1979  1.1       mw 		break;
   1980  1.1       mw 
   1981  1.1       mw 	case CAN:
   1982  1.1       mw 		ip->escape = 0;	/* cancel any escape sequence in progress */
   1983  1.1       mw 		break;
   1984  1.1       mw 
   1985  1.1       mw 	case SUB:
   1986  1.1       mw 		ip->escape = 0;	/* dito, but see below */
   1987  1.1       mw 		/* should also display a reverse question mark!! */
   1988  1.1       mw 		break;
   1989  1.1       mw 
   1990  1.1       mw 	case ESC:
   1991  1.1       mw 		ip->escape = ESC;
   1992  1.1       mw 		break;
   1993  1.1       mw 
   1994  1.1       mw 
   1995  1.1       mw 	/* now it gets weird.. 8bit control sequences.. */
   1996  1.1       mw 	case IND:	/* index: move cursor down, scroll */
   1997  1.1       mw 		ite_lf (ip, sp);
   1998  1.1       mw 		break;
   1999  1.1       mw 
   2000  1.1       mw 	case NEL:	/* next line. next line, first pos. */
   2001  1.1       mw 		ite_crlf (ip, sp);
   2002  1.1       mw 		break;
   2003  1.1       mw 
   2004  1.1       mw 	case HTS:	/* set horizontal tab */
   2005  1.3       mw 		if (ip->curx < ip->cols)
   2006  1.3       mw 		  ip->tabs[ip->curx] = 1;
   2007  1.1       mw 		break;
   2008  1.1       mw 
   2009  1.1       mw 	case RI:	/* reverse index */
   2010  1.1       mw 		ite_rlf (ip, sp);
   2011  1.1       mw 		break;
   2012  1.1       mw 
   2013  1.1       mw 	case SS2:	/* go into G2 for one character */
   2014  1.1       mw 		/* not yet supported */
   2015  1.1       mw 		break;
   2016  1.1       mw 
   2017  1.1       mw 	case SS3:	/* go into G3 for one character */
   2018  1.1       mw 		break;
   2019  1.1       mw 
   2020  1.1       mw 	case DCS:	/* device control string introducer */
   2021  1.1       mw 		ip->escape = DCS;
   2022  1.1       mw 		ip->ap = ip->argbuf;
   2023  1.1       mw 		break;
   2024  1.1       mw 
   2025  1.1       mw 	case CSI:	/* control sequence introducer */
   2026  1.1       mw 		ip->escape = CSI;
   2027  1.1       mw 		ip->ap = ip->argbuf;
   2028  1.1       mw 		break;
   2029  1.1       mw 
   2030  1.1       mw 	case ST:	/* string terminator */
   2031  1.1       mw 		/* ignore, if not used as terminator */
   2032  1.1       mw 		break;
   2033  1.1       mw 
   2034  1.1       mw 	case OSC:	/* introduces OS command. Ignore everything upto ST */
   2035  1.1       mw 		ip->escape = OSC;
   2036  1.1       mw 		break;
   2037  1.1       mw 
   2038  1.1       mw 	case PM:	/* privacy message, ignore everything upto ST */
   2039  1.1       mw 		ip->escape = PM;
   2040  1.1       mw 		break;
   2041  1.1       mw 
   2042  1.1       mw 	case APC:	/* application program command, ignore everything upto ST */
   2043  1.1       mw 		ip->escape = APC;
   2044  1.1       mw 		break;
   2045  1.1       mw 
   2046  1.1       mw 	default:
   2047  1.1       mw 		if (c < ' ' || c == DEL)
   2048  1.1       mw 			break;
   2049  1.1       mw 		if (ip->imode)
   2050  1.1       mw 			ite_inchar(ip, sp, 1);
   2051  1.3       mw 		iteprecheckwrap(ip, sp);
   2052  1.3       mw #ifdef DO_WEIRD_ATTRIBUTES
   2053  1.1       mw 		if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
   2054  1.1       mw 			attrset(ip, ATTR_INV);
   2055  1.1       mw 			(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_INV);
   2056  1.1       mw 		}
   2057  1.1       mw 		else
   2058  1.1       mw 			(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
   2059  1.3       mw #else
   2060  1.3       mw 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ip->attribute);
   2061  1.3       mw #endif
   2062  1.1       mw 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
   2063  1.1       mw 		itecheckwrap(ip, sp);
   2064  1.1       mw 		break;
   2065  1.1       mw 	}
   2066  1.1       mw }
   2067  1.1       mw 
   2068  1.3       mw iteprecheckwrap(ip, sp)
   2069  1.1       mw      register struct ite_softc *ip;
   2070  1.1       mw      register struct itesw *sp;
   2071  1.1       mw {
   2072  1.3       mw 	if (ip->auto_wrap && ip->curx == ip->cols) {
   2073  1.1       mw 		ip->curx = 0;
   2074  1.1       mw 		clr_attr(ip, ATTR_INV);
   2075  1.1       mw 		if (++ip->cury >= ip->bottom_margin + 1) {
   2076  1.1       mw 			ip->cury = ip->bottom_margin;
   2077  1.3       mw 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
   2078  1.1       mw 			(*sp->ite_scroll)(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
   2079  1.3       mw 			ite_clrtoeol(ip, sp);
   2080  1.3       mw 		} else
   2081  1.3       mw 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
   2082  1.3       mw 	}
   2083  1.3       mw }
   2084  1.3       mw 
   2085  1.3       mw itecheckwrap(ip, sp)
   2086  1.3       mw      register struct ite_softc *ip;
   2087  1.3       mw      register struct itesw *sp;
   2088  1.3       mw {
   2089  1.3       mw #if 0
   2090  1.3       mw 	if (++ip->curx == ip->cols) {
   2091  1.3       mw 		if (ip->auto_wrap) {
   2092  1.3       mw 			ip->curx = 0;
   2093  1.3       mw 			clr_attr(ip, ATTR_INV);
   2094  1.3       mw 			if (++ip->cury >= ip->bottom_margin + 1) {
   2095  1.3       mw 				ip->cury = ip->bottom_margin;
   2096  1.3       mw 				(*sp->ite_cursor)(ip, MOVE_CURSOR);
   2097  1.3       mw 				(*sp->ite_scroll)(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
   2098  1.3       mw 				ite_clrtoeol(ip, sp);
   2099  1.3       mw 				return;
   2100  1.3       mw 			}
   2101  1.3       mw 		} else
   2102  1.3       mw 			/* stay there if no autowrap.. */
   2103  1.3       mw 			ip->curx--;
   2104  1.3       mw 	}
   2105  1.3       mw #else
   2106  1.3       mw 	if (ip->curx < ip->cols) {
   2107  1.3       mw 		ip->curx++;
   2108  1.3       mw 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
   2109  1.1       mw 	}
   2110  1.3       mw #endif
   2111  1.1       mw }
   2112  1.1       mw 
   2113  1.1       mw /*
   2114  1.1       mw  * Console functions
   2115  1.1       mw  */
   2116  1.1       mw #include "grfioctl.h"
   2117  1.1       mw #include "grfvar.h"
   2118  1.1       mw 
   2119  1.1       mw #ifdef DEBUG
   2120  1.1       mw /*
   2121  1.1       mw  * Minimum ITE number at which to start looking for a console.
   2122  1.1       mw  * Setting to 0 will do normal search, 1 will skip first ITE device,
   2123  1.1       mw  * NITE will skip ITEs and use serial port.
   2124  1.1       mw  */
   2125  1.1       mw int	whichconsole = 0;
   2126  1.1       mw #endif
   2127  1.1       mw 
   2128  1.1       mw itecnprobe(cp)
   2129  1.1       mw 	struct consdev *cp;
   2130  1.1       mw {
   2131  1.1       mw 	register struct ite_softc *ip;
   2132  1.1       mw 	int i, maj, unit, pri;
   2133  1.1       mw 
   2134  1.1       mw 	/* locate the major number */
   2135  1.1       mw 	for (maj = 0; maj < nchrdev; maj++)
   2136  1.1       mw 		if (cdevsw[maj].d_open == iteopen)
   2137  1.1       mw 			break;
   2138  1.1       mw 
   2139  1.1       mw 	/* urk! */
   2140  1.1       mw 	grfconfig();
   2141  1.1       mw 
   2142  1.1       mw 	/* check all the individual displays and find the best */
   2143  1.1       mw 	unit = -1;
   2144  1.1       mw 	pri = CN_DEAD;
   2145  1.1       mw 	for (i = 0; i < NITE; i++) {
   2146  1.1       mw 		struct grf_softc *gp = &grf_softc[i];
   2147  1.1       mw 
   2148  1.1       mw 		ip = &ite_softc[i];
   2149  1.1       mw 		if ((gp->g_flags & GF_ALIVE) == 0)
   2150  1.1       mw 			continue;
   2151  1.1       mw 		ip->flags = (ITE_ALIVE|ITE_CONSOLE);
   2152  1.1       mw 
   2153  1.1       mw 		/* XXX - we need to do something about mapping these */
   2154  1.1       mw 		switch (gp->g_type) {
   2155  1.1       mw 		case GT_CUSTOMCHIPS:
   2156  1.1       mw 		        ip->type = ITE_CUSTOMCHIPS;
   2157  1.1       mw 		        break;
   2158  1.1       mw 
   2159  1.1       mw 		case GT_TIGA_A2410:
   2160  1.1       mw 		        ip->type = ITE_TIGA_A2410;
   2161  1.1       mw 		        break;
   2162  1.3       mw 
   2163  1.3       mw 		case GT_RETINA:
   2164  1.3       mw 			ip->type = ITE_RETINA;
   2165  1.3       mw 			break;
   2166  1.1       mw 		}
   2167  1.1       mw #ifdef DEBUG
   2168  1.1       mw 		if (i < whichconsole)
   2169  1.1       mw 			continue;
   2170  1.1       mw #endif
   2171  1.1       mw 		if ((int)gp->g_type == GT_CUSTOMCHIPS) {
   2172  1.1       mw 			pri = CN_INTERNAL;
   2173  1.1       mw 			unit = i;
   2174  1.3       mw 		} else /* if (unit < 0) */ {
   2175  1.1       mw 			pri = CN_NORMAL;
   2176  1.1       mw 			unit = i;
   2177  1.1       mw 		}
   2178  1.3       mw 
   2179  1.1       mw 	}
   2180  1.1       mw 
   2181  1.1       mw 	/* initialize required fields */
   2182  1.1       mw 	cp->cn_dev = makedev(maj, unit);
   2183  1.3       mw #if 0
   2184  1.1       mw 	cp->cn_tp = ite_tty[unit];
   2185  1.3       mw #else
   2186  1.3       mw 	delayed_con_tty = unit;
   2187  1.3       mw #endif
   2188  1.1       mw 	cp->cn_pri = pri;
   2189  1.1       mw }
   2190  1.1       mw 
   2191  1.1       mw itecninit(cp)
   2192  1.1       mw 	struct consdev *cp;
   2193  1.1       mw {
   2194  1.3       mw 	int unit;
   2195  1.3       mw 	struct ite_softc *ip;
   2196  1.3       mw 
   2197  1.3       mw 	iteinit(cp->cn_dev);
   2198  1.3       mw 	unit = UNIT(cp->cn_dev);
   2199  1.3       mw 	ip = &ite_softc[unit];
   2200  1.3       mw 
   2201  1.3       mw #ifdef DO_WEIRD_ATTRIBUTES
   2202  1.1       mw 	ip->attrbuf = console_attributes;
   2203  1.3       mw #endif
   2204  1.1       mw 	ip->flags |= (ITE_ACTIVE|ITE_ISCONS);
   2205  1.3       mw 	/* if this is the console, NEVER close the device! */
   2206  1.3       mw 	ip->open_cnt++;
   2207  1.3       mw #if 0
   2208  1.3       mw 	/* have to delay this too.. sigh.. */
   2209  1.1       mw 	kbd_tty = ite_tty[unit];
   2210  1.3       mw 	kbd_ip = ip;
   2211  1.1       mw 	kbdenable();
   2212  1.3       mw #endif
   2213  1.1       mw }
   2214  1.1       mw 
   2215  1.1       mw /*ARGSUSED*/
   2216  1.1       mw itecngetc(dev)
   2217  1.1       mw 	dev_t dev;
   2218  1.1       mw {
   2219  1.1       mw 	register int c;
   2220  1.1       mw 
   2221  1.1       mw         do
   2222  1.1       mw           {
   2223  1.1       mw             c = kbdgetcn ();
   2224  1.1       mw             c = itefilter (c, ITEFILT_CONSOLE);
   2225  1.1       mw           }
   2226  1.1       mw         while (c == -1);
   2227  1.1       mw 
   2228  1.1       mw 	return(c);
   2229  1.1       mw }
   2230  1.1       mw 
   2231  1.1       mw itecnputc(dev, c)
   2232  1.1       mw 	dev_t dev;
   2233  1.1       mw 	int c;
   2234  1.1       mw {
   2235  1.1       mw 	static int paniced = 0;
   2236  1.1       mw 	struct ite_softc *ip = &ite_softc[UNIT(dev)];
   2237  1.1       mw 
   2238  1.1       mw 	if (panicstr && !paniced &&
   2239  1.1       mw 	    (ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) {
   2240  1.1       mw 		(void) iteon(dev, 3);
   2241  1.1       mw 		paniced = 1;
   2242  1.1       mw 	}
   2243  1.1       mw 	iteputchar(c, dev);
   2244  1.1       mw }
   2245  1.1       mw #endif
   2246