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