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