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