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