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