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