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