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