ite.c revision 1.9 1 /* $NetBSD: ite.c,v 1.9 1998/01/12 21:13:45 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah $Hdr: ite.c 1.1 90/07/09$
41 *
42 * @(#)ite.c 7.6 (Berkeley) 5/16/91
43 */
44
45 /*
46 * ite - bitmaped terminal.
47 * Supports VT200, a few terminal features will be unavailable until
48 * the system actually probes the device (i.e. not after consinit())
49 */
50
51 #include "ite.h"
52 #if NITE > 0
53
54 #include "bell.h"
55
56 #include <sys/param.h>
57 #include <sys/conf.h>
58 #include <sys/proc.h>
59 #include <sys/ioctl.h>
60 #include <sys/tty.h>
61 #include <sys/systm.h>
62 #include <sys/device.h>
63 #include <sys/malloc.h>
64 #include <machine/kbio.h>
65
66 #include <x68k/dev/grfioctl.h>
67 #include <x68k/dev/grfvar.h>
68 #include <x68k/dev/itevar.h>
69 #include <x68k/dev/kbdmap.h>
70
71 #include <x68k/x68k/iodevice.h>
72 #include <x68k/dev/iteioctl.h>
73
74 #define SUBR_CNPROBE(min) itesw[min].ite_cnprobe(min)
75 #define SUBR_INIT(ip) ip->isw->ite_init(ip)
76 #define SUBR_DEINIT(ip) ip->isw->ite_deinit(ip)
77 #define SUBR_PUTC(ip,c,dy,dx,m) ip->isw->ite_putc(ip,c,dy,dx,m)
78 #define SUBR_CURSOR(ip,flg) ip->isw->ite_cursor(ip,flg)
79 #define SUBR_CLEAR(ip,sy,sx,h,w) ip->isw->ite_clear(ip,sy,sx,h,w)
80 #define SUBR_SCROLL(ip,sy,sx,count,dir) \
81 ip->isw->ite_scroll(ip,sy,sx,count,dir)
82
83 struct consdev;
84
85 __inline static void itesendch __P((int));
86 __inline static void alignment_display __P((struct ite_softc *));
87 __inline static void snap_cury __P((struct ite_softc *));
88 __inline static void ite_dnchar __P((struct ite_softc *, int));
89 static void ite_inchar __P((struct ite_softc *, int));
90 __inline static void ite_clrtoeol __P((struct ite_softc *));
91 __inline static void ite_clrtobol __P((struct ite_softc *));
92 __inline static void ite_clrline __P((struct ite_softc *));
93 __inline static void ite_clrtoeos __P((struct ite_softc *));
94 __inline static void ite_clrtobos __P((struct ite_softc *));
95 __inline static void ite_clrscreen __P((struct ite_softc *));
96 __inline static void ite_dnline __P((struct ite_softc *, int));
97 __inline static void ite_inline __P((struct ite_softc *, int));
98 __inline static void ite_index __P((struct ite_softc *));
99 __inline static void ite_lf __P((struct ite_softc *));
100 __inline static void ite_crlf __P((struct ite_softc *));
101 __inline static void ite_cr __P((struct ite_softc *));
102 __inline static void ite_rlf __P((struct ite_softc *));
103 static void iteprecheckwrap __P((struct ite_softc *ip));
104 static void itecheckwrap __P((struct ite_softc *ip));
105 static void repeat_handler __P((void *arg));
106 static int ite_argnum __P((struct ite_softc *ip));
107 static int ite_zargnum __P((struct ite_softc *ip));
108 static void ite_sendstr __P((struct ite_softc *ip, char *str));
109 __inline static int atoi __P((const char *cp));
110 __inline static char *index __P((const char *cp, char ch));
111 void ite_reset __P((struct ite_softc *ip));
112 struct ite_softc *getitesp __P((dev_t));
113 int iteon __P((dev_t, int));
114 void iteoff __P((dev_t, int));
115
116 struct itesw itesw[] = {
117 0, tv_init, tv_deinit, 0,
118 0, 0, 0,
119 };
120 int nitesw = sizeof(itesw) / sizeof(itesw[0]);
121
122 /*
123 * # of chars are output in a single itestart() call.
124 * If this is too big, user processes will be blocked out for
125 * long periods of time while we are emptying the queue in itestart().
126 * If it is too small, console output will be very ragged.
127 */
128 #define ITEBURST 64
129
130 int nite = NITE;
131 struct tty *ite_tty[NITE];
132 struct ite_softc *kbd_ite = NULL;
133 struct ite_softc con_itesoftc;
134
135 struct tty *kbd_tty = NULL;
136
137 int start_repeat_timeo = 20; /* /100: initial timeout till pressed key repeats */
138 int next_repeat_timeo = 3; /* /100: timeout when repeating for next char */
139
140 u_char cons_tabs[MAX_TABS];
141
142 int kbd_init;
143
144 cdev_decl(ite);
145
146 void itestart __P((struct tty *tp));
147
148 void iteputchar __P((int c, struct ite_softc *ip));
149 void ite_putstr __P((const u_char * s, int len, dev_t dev));
150
151 void iteattach __P((struct device *, struct device *, void *));
152 int itematch __P((struct device *, void *, void *));
153
154 struct cfattach ite_ca = {
155 sizeof(struct ite_softc), itematch, iteattach
156 };
157
158 extern struct cfdriver ite_cd;
159
160 int
161 itematch(pdp, match, auxp)
162 struct device *pdp;
163 void *match, *auxp;
164 {
165 struct cfdata *cdp = match;
166 struct grf_softc *gp;
167 int maj;
168
169 gp = auxp;
170
171 /* ite0 should be at grf0 XXX */
172 if(cdp->cf_unit != gp->g_device.dv_unit)
173 return(0);
174
175 #if 0
176 /*
177 * all that our mask allows (more than enough no one
178 * has > 32 monitors for text consoles on one machine)
179 */
180 if (cdp->cf_unit >= sizeof(ite_confunits) * NBBY)
181 return(0);
182 /*
183 * XXX
184 * normally this would be done in attach, however
185 * during early init we do not have a device pointer
186 * and thus no unit number.
187 */
188 for(maj = 0; maj < nchrdev; maj++)
189 if (cdevsw[maj].d_open == iteopen)
190 break;
191 gp->g_itedev = makedev(maj, cdp->cf_unit);
192 #endif
193 return(1);
194 }
195
196 /*
197 * iteinit() is the standard entry point for initialization of
198 * an ite device, it is also called from ite_cninit().
199 */
200 void
201 iteattach(pdp, dp, auxp)
202 struct device *pdp, *dp;
203 void *auxp;
204 {
205 struct ite_softc *ip;
206 struct grf_softc *gp;
207
208 gp = (struct grf_softc *)auxp;
209 if (dp) {
210 ip = (struct ite_softc *)dp;
211 if(con_itesoftc.grf != NULL
212 /*&& con_itesoftc.grf->g_unit == gp->g_unit*/) {
213 /*
214 * console reinit copy params over.
215 * and console always gets keyboard
216 */
217 bcopy(&con_itesoftc.grf, &ip->grf,
218 (char *)&ip[1] - (char *)&ip->grf);
219 con_itesoftc.grf = NULL;
220 kbd_ite = ip;
221 }
222 ip->grf = gp;
223 iteinit(ip->device.dv_unit); /* XXX */
224 printf(": rows %d cols %d", ip->rows, ip->cols);
225 if (kbd_ite == NULL)
226 kbd_ite = ip;
227 printf("\n");
228 } else {
229 if (con_itesoftc.grf != NULL)
230 return;
231 con_itesoftc.grf = gp;
232 con_itesoftc.tabs = cons_tabs;
233 }
234 }
235
236 struct ite_softc *
237 getitesp(dev)
238 dev_t dev;
239 {
240 extern int x68k_realconfig;
241
242 if (x68k_realconfig && con_itesoftc.grf == NULL)
243 return(ite_cd.cd_devs[UNIT(dev)]);
244
245 if (con_itesoftc.grf == NULL)
246 panic("no ite_softc for console");
247 return(&con_itesoftc);
248 }
249
250 void
251 iteinit(dev)
252 dev_t dev;
253 {
254 struct ite_softc *ip;
255
256 ip = getitesp(dev);
257
258 if (ip->flags & ITE_INITED)
259 return;
260 bcopy(&ascii_kbdmap, &kbdmap, sizeof(struct kbdmap));
261
262 ip->curx = 0;
263 ip->cury = 0;
264 ip->cursorx = 0;
265 ip->cursory = 0;
266
267 ip->isw = &itesw[ip->device.dv_unit]; /* XXX */
268 SUBR_INIT(ip);
269 SUBR_CURSOR(ip, DRAW_CURSOR);
270 if (!ip->tabs)
271 ip->tabs = malloc(MAX_TABS*sizeof(u_char), M_DEVBUF, M_WAITOK);
272 ite_reset(ip);
273 ip->flags |= ITE_INITED;
274 }
275
276 /*
277 * Perform functions necessary to setup device as a terminal emulator.
278 */
279 int
280 iteon(dev, flag)
281 dev_t dev;
282 int flag;
283 {
284 int unit = UNIT(dev);
285 struct ite_softc *ip = getitesp(unit);
286
287 if (unit < 0 || unit >= ite_cd.cd_ndevs || (ip->flags&ITE_ALIVE) == 0)
288 return(ENXIO);
289 /* force ite active, overriding graphics mode */
290 if (flag & 1) {
291 ip->flags |= ITE_ACTIVE;
292 ip->flags &= ~(ITE_INGRF|ITE_INITED);
293 }
294 /* leave graphics mode */
295 if (flag & 2) {
296 ip->flags &= ~ITE_INGRF;
297 if ((ip->flags & ITE_ACTIVE) == 0)
298 return(0);
299 }
300 ip->flags |= ITE_ACTIVE;
301 if (ip->flags & ITE_INGRF)
302 return(0);
303 iteinit(dev);
304 return(0);
305 }
306
307 /*
308 * "Shut down" device as terminal emulator.
309 * Note that we do not deinit the console device unless forced.
310 * Deinit'ing the console every time leads to a very active
311 * screen when processing /etc/rc.
312 */
313 void
314 iteoff(dev, flag)
315 dev_t dev;
316 int flag;
317 {
318 int unit = UNIT(dev);
319 register struct ite_softc *ip = getitesp(unit);
320
321 /* XXX check whether when call from grf.c */
322 if (unit < 0 || unit >= ite_cd.cd_ndevs || (ip->flags&ITE_ALIVE) == 0)
323 return;
324 if (flag & 2)
325 ip->flags |= ITE_INGRF;
326
327 if ((ip->flags & ITE_ACTIVE) == 0)
328 return;
329 if ((flag & 1) ||
330 (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
331 SUBR_DEINIT(ip);
332
333 /*
334 * XXX When the system is rebooted with "reboot", init(8)
335 * kills the last process to have the console open.
336 * If we don't revent the the ITE_ACTIVE bit from being
337 * cleared, we will never see messages printed during
338 * the process of rebooting.
339 */
340 if ((flag & 2) == 0 && (ip->flags & ITE_ISCONS) == 0)
341 ip->flags &= ~ITE_ACTIVE;
342 }
343
344 /*
345 * standard entry points to the device.
346 */
347
348 /* ARGSUSED */
349 int
350 iteopen(dev, mode, devtype, p)
351 dev_t dev;
352 int mode, devtype;
353 struct proc *p;
354 {
355 int unit = UNIT(dev);
356 register struct tty *tp;
357 register struct ite_softc *ip;
358 register int error;
359 int first = 0;
360
361 ip = getitesp(dev);
362 if (!ite_tty[unit]) {
363 tp = ite_tty[unit] = ttymalloc();
364 tty_attach(tp);
365 } else
366 tp = ite_tty[unit];
367 if ((tp->t_state&(TS_ISOPEN|TS_XCLUDE)) == (TS_ISOPEN|TS_XCLUDE)
368 && p->p_ucred->cr_uid != 0)
369 return (EBUSY);
370 if ((ip->flags & ITE_ACTIVE) == 0) {
371 error = iteon(dev, 0);
372 if (error)
373 return (error);
374 first = 1;
375 }
376 tp->t_oproc = itestart;
377 tp->t_param = NULL;
378 tp->t_dev = dev;
379 if ((tp->t_state&TS_ISOPEN) == 0) {
380 ttychars(tp);
381 tp->t_iflag = TTYDEF_IFLAG;
382 tp->t_oflag = TTYDEF_OFLAG;
383 tp->t_cflag = TTYDEF_CFLAG;
384 tp->t_lflag = TTYDEF_LFLAG;
385 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
386 tp->t_state = TS_ISOPEN|TS_CARR_ON;
387 ttsetwater(tp);
388 }
389 error = (*linesw[tp->t_line].l_open)(dev, tp);
390 if (error == 0) {
391 tp->t_winsize.ws_row = ip->rows;
392 tp->t_winsize.ws_col = ip->cols;
393 if (!kbd_init) {
394 kbd_init = 1;
395 kbdenable();
396 }
397 } else if (first)
398 iteoff(dev, 0);
399 return (error);
400 }
401
402 /*ARGSUSED*/
403 int
404 iteclose(dev, flag, mode, p)
405 dev_t dev;
406 int flag, mode;
407 struct proc *p;
408 {
409 register struct tty *tp = ite_tty[UNIT(dev)];
410
411 (*linesw[tp->t_line].l_close)(tp, flag);
412 ttyclose(tp);
413 iteoff(dev, 0);
414 #if 0
415 ttyfree(tp);
416 ite_tty[UNIT(dev)] = (struct tty *)0;
417 #endif
418 return(0);
419 }
420
421 int
422 iteread(dev, uio, flag)
423 dev_t dev;
424 struct uio *uio;
425 int flag;
426 {
427 register struct tty *tp = ite_tty[UNIT(dev)];
428
429 return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
430 }
431
432 int
433 itewrite(dev, uio, flag)
434 dev_t dev;
435 struct uio *uio;
436 int flag;
437 {
438 register struct tty *tp = ite_tty[UNIT(dev)];
439
440 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
441 }
442
443 struct tty *
444 itetty(dev)
445 dev_t dev;
446 {
447
448 return (ite_tty[UNIT(dev)]);
449 }
450
451 int
452 iteioctl(dev, cmd, addr, flag, p)
453 dev_t dev;
454 u_long cmd;
455 caddr_t addr;
456 int flag;
457 struct proc *p;
458 {
459 struct iterepeat *irp;
460 register struct tty *tp = ite_tty[UNIT(dev)];
461 int error;
462
463 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag, p);
464 if (error >= 0)
465 return (error);
466 error = ttioctl(tp, cmd, addr, flag, p);
467 if (error >= 0)
468 return (error);
469
470 switch (cmd) {
471 case ITEIOCSKMAP:
472 if (addr == 0)
473 return(EFAULT);
474 bcopy(addr, &kbdmap, sizeof(struct kbdmap));
475 return(0);
476
477 case ITEIOCGKMAP:
478 if (addr == NULL)
479 return(EFAULT);
480 bcopy(&kbdmap, addr, sizeof(struct kbdmap));
481 return(0);
482
483 case ITEIOCGREPT:
484 irp = (struct iterepeat *)addr;
485 irp->start = start_repeat_timeo;
486 irp->next = next_repeat_timeo;
487
488 case ITEIOCSREPT:
489 irp = (struct iterepeat *)addr;
490 if (irp->start < ITEMINREPEAT && irp->next < ITEMINREPEAT)
491 return(EINVAL);
492 start_repeat_timeo = irp->start;
493 next_repeat_timeo = irp->next;
494 #if x68k
495 case ITELOADFONT:
496 if (addr) {
497 bcopy(addr, kern_font, 4096 /*sizeof (kernel_font)*/);
498 return 0;
499 } else
500 return EFAULT;
501
502 case ITETVCTRL:
503 if (addr && *(u_char *)addr < 0x40) {
504 while(!(mfp.tsr & 0x80)) ;
505 mfp.udr = *(u_char *)addr;
506 return 0;
507 } else
508 return EFAULT;
509 #endif
510 }
511 return (ENOTTY);
512 }
513
514 void
515 itestart(tp)
516 register struct tty *tp;
517 {
518 struct clist *rbp;
519 struct ite_softc *ip;
520 u_char buf[ITEBURST];
521 int s, len, n;
522
523 ip = getitesp(tp->t_dev);
524 /*
525 * (Potentially) lower priority. We only need to protect ourselves
526 * from keyboard interrupts since that is all that can affect the
527 * state of our tty (kernel printf doesn't go through this routine).
528 */
529 s = spltty();
530 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
531 goto out;
532 tp->t_state |= TS_BUSY;
533 rbp = &tp->t_outq;
534 len = q_to_b(rbp, buf, ITEBURST);
535 /*splx(s);*/
536
537 /* Here is a really good place to implement pre/jumpscroll() */
538 ite_putstr(buf, len, tp->t_dev);
539
540 /*s = spltty();*/
541 tp->t_state &= ~TS_BUSY;
542 /* we have characters remaining. */
543 if (rbp->c_cc) {
544 tp->t_state |= TS_TIMEOUT;
545 timeout(ttrstrt, (caddr_t)tp, 1);
546 }
547 /* wakeup we are below */
548 if (rbp->c_cc <= tp->t_lowat) {
549 if (tp->t_state & TS_ASLEEP) {
550 tp->t_state &= ~TS_ASLEEP;
551 wakeup((caddr_t)rbp);
552 }
553 selwakeup(&tp->t_wsel);
554 }
555 out:
556 splx(s);
557 }
558
559 /* XXX called after changes made in underlying grf layer. */
560 /* I want to nuke this */
561 void
562 ite_reinit(dev)
563 dev_t dev;
564 {
565 struct ite_softc *ip;
566 int unit = UNIT(dev);
567
568 /* XXX check whether when call from grf.c */
569 if (unit < 0 || unit >= ite_cd.cd_ndevs)
570 return;
571
572 ip = getitesp(dev);
573 ip->flags &= ~ITE_INITED;
574 iteinit(dev);
575 }
576
577 void
578 ite_reset(ip)
579 struct ite_softc *ip;
580 {
581 int i;
582
583 ip->curx = 0;
584 ip->cury = 0;
585 ip->attribute = 0;
586 ip->save_curx = 0;
587 ip->save_cury = 0;
588 ip->save_attribute = 0;
589 ip->ap = ip->argbuf;
590 ip->emul_level = EMUL_VT300_8;
591 ip->eightbit_C1 = 0;
592 ip->top_margin = 0;
593 ip->bottom_margin = ip->rows - 1;
594 ip->inside_margins = 0; /* origin mode == absolute */
595 ip->linefeed_newline = 0;
596 ip->auto_wrap = 1;
597 ip->cursor_appmode = 0;
598 ip->keypad_appmode = 0;
599 ip->imode = 0;
600 ip->key_repeat = 1;
601 ip->G0 = CSET_ASCII;
602 ip->G1 = CSET_JIS1983;
603 ip->G2 = CSET_JISKANA;
604 ip->G3 = CSET_JIS1990;
605 ip->GL = &ip->G0;
606 ip->GR = &ip->G1;
607 ip->save_GL = 0;
608 ip->save_char = 0;
609 ip->fgcolor = 7;
610 ip->bgcolor = 0;
611 for (i = 0; i < ip->cols; i++)
612 ip->tabs[i] = ((i & 7) == 0);
613 /* XXX clear screen */
614 SUBR_CLEAR(ip, 0, 0, ip->rows, ip->cols);
615 attrclr(ip, 0, 0, ip->rows, ip->cols);
616 }
617
618 /* Used in console at startup only */
619 int
620 ite_cnfilter(c, caller)
621 u_char c;
622 enum caller caller;
623 {
624 struct tty *kbd_tty;
625 static u_char mod = 0;
626 struct key key;
627 u_char code, up, mask;
628 int s, i;
629
630 up = c & 0x80 ? 1 : 0;
631 c &= 0x7f;
632 code = 0;
633
634 s = spltty();
635
636 mask = 0;
637 if (c >= KBD_LEFT_ALT && !(c >= 0x63 && c <= 0x6c)) { /* 0x63: F1, 0x6c:F10 */
638 switch (c) {
639 case KBD_LEFT_SHIFT:
640 mask = KBD_MOD_SHIFT;
641 break;
642
643 case KBD_LEFT_ALT:
644 mask = KBD_MOD_LALT;
645 break;
646
647 case KBD_RIGHT_ALT:
648 mask = KBD_MOD_RALT;
649 break;
650
651 case KBD_LEFT_META:
652 mask = KBD_MOD_LMETA;
653 break;
654
655 case KBD_RIGHT_META:
656 mask = KBD_MOD_RMETA;
657 break;
658
659 case KBD_CAPS_LOCK:
660 /*
661 * capslock already behaves `right', don't need to
662 * keep track of the state in here.
663 */
664 mask = KBD_MOD_CAPS;
665 break;
666
667 case KBD_CTRL:
668 mask = KBD_MOD_CTRL;
669 break;
670
671 case KBD_RECONNECT:
672 /* ite got 0xff */
673 if (up)
674 kbd_setLED();
675 break;
676 }
677 if (mask & KBD_MOD_CAPS) {
678 if (!up) {
679 mod ^= KBD_MOD_CAPS;
680 kbdled ^= LED_CAPS_LOCK;
681 kbd_setLED();
682 }
683 } else if (up)
684 mod &= ~mask;
685 else mod |= mask;
686 splx (s);
687 return -1;
688 }
689
690 if (up) {
691 splx(s);
692 return -1;
693 }
694
695 /* translate modifiers */
696 if (mod & KBD_MOD_SHIFT) {
697 if (mod & KBD_MOD_ALT)
698 key = kbdmap.alt_shift_keys[c];
699 else
700 key = kbdmap.shift_keys[c];
701 } else if (mod & KBD_MOD_ALT)
702 key = kbdmap.alt_keys[c];
703 else {
704 key = kbdmap.keys[c];
705 /* if CAPS and key is CAPable (no pun intended) */
706 if ((mod & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
707 key = kbdmap.shift_keys[c];
708 }
709 code = key.code;
710
711 /* if string return */
712 if (key.mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) {
713 splx(s);
714 return -1;
715 }
716 /* handle dead keys */
717 if (key.mode & KBD_MODE_DEAD) {
718 splx(s);
719 return -1;
720 }
721 if (mod & KBD_MOD_CTRL)
722 code &= 0x1f;
723 if (mod & KBD_MOD_META)
724 code |= 0x80;
725
726 /* do console mapping. */
727 code = code == '\r' ? '\n' : code;
728
729 splx(s);
730 return (code);
731 }
732
733 /* And now the old stuff. */
734
735 /* these are used to implement repeating keys.. */
736 static u_char last_char = 0;
737 static u_char tout_pending = 0;
738
739 /*ARGSUSED*/
740 static void
741 repeat_handler (arg)
742 void *arg;
743 {
744 tout_pending = 0;
745 if (last_char)
746 add_sicallback(ite_filter, last_char, ITEFILT_REPEATER);
747 }
748
749 __inline static void
750 itesendch (ch)
751 int ch;
752 {
753 (*linesw[kbd_tty->t_line].l_rint)(ch, kbd_tty);
754 }
755
756
757 void
758 ite_filter(c, caller)
759 u_char c;
760 enum caller caller;
761 {
762 static u_short mod = 0;
763 register unsigned char code, *str;
764 u_short up, mask;
765 struct key key;
766 int s, i;
767
768 if (!kbd_ite)
769 return;
770 kbd_tty = ite_tty[kbd_ite->device.dv_unit];
771
772 /* have to make sure we're at spltty in here */
773 s = spltty ();
774
775 #if 0 /* XXX? x68k */
776 /* keyboard interrupts come at priority 2, while softint-
777 generated keyboard-repeat interrupts come at level 1.
778 So, to not allow a key-up event to get thru before
779 a repeat for the key-down, we remove any outstanding
780 callout requests.. */
781 rem_sicallback (ite_filter);
782 #endif
783
784 up = c & 0x80 ? 1 : 0;
785 c &= 0x7f;
786 code = 0;
787
788 mask = 0;
789 if (c >= KBD_LEFT_ALT &&
790 !(c >= 0x63 && c <= 0x6c)) { /* 0x63: F1, 0x6c:F10 */
791 switch (c) {
792 case KBD_LEFT_SHIFT:
793 mask = KBD_MOD_SHIFT;
794 break;
795
796 case KBD_LEFT_ALT:
797 mask = KBD_MOD_LALT;
798 break;
799
800 case KBD_RIGHT_ALT:
801 mask = KBD_MOD_RALT;
802 break;
803
804 case KBD_LEFT_META:
805 mask = KBD_MOD_LMETA;
806 break;
807
808 case KBD_RIGHT_META:
809 mask = KBD_MOD_RMETA;
810 break;
811
812 case KBD_CAPS_LOCK:
813 /*
814 * capslock already behaves `right', don't need to keep
815 * track of the state in here.
816 */
817 mask = KBD_MOD_CAPS;
818 break;
819
820 case KBD_CTRL:
821 mask = KBD_MOD_CTRL;
822 break;
823
824 case KBD_OPT1:
825 mask = KBD_MOD_OPT1;
826 break;
827
828 case KBD_OPT2:
829 mask = KBD_MOD_OPT2;
830 break;
831
832 case KBD_RECONNECT:
833 if (up) { /* ite got 0xff */
834 kbd_setLED();
835 }
836 break;
837 }
838
839 if (mask & KBD_MOD_CAPS) {
840 if (!up) {
841 mod ^= KBD_MOD_CAPS;
842 kbdled ^= LED_CAPS_LOCK;
843 kbd_setLED();
844 }
845 } else if (up) {
846 mod &= ~mask;
847 } else mod |= mask;
848
849 /*
850 * these keys should not repeat, so it's the Right Thing
851 * dealing with repeaters only after this block.
852 */
853
854 /*
855 * return even if it wasn't a modifier key, the other
856 * codes up here are either special (like reset warning),
857 * or not yet defined
858 */
859 splx (s);
860 return;
861 }
862
863 /*
864 * no matter which character we're repeating, stop it if we
865 * get a key-up event. I think this is the same thing amigados does.
866 */
867 if (up) {
868 if (tout_pending) {
869 untimeout (repeat_handler, 0);
870 tout_pending = 0;
871 last_char = 0;
872 }
873 splx (s);
874 return;
875 } else if (tout_pending && last_char != c) {
876 /*
877 * not the same character remove the repeater and continue
878 * to process this key. -ch
879 */
880 untimeout (repeat_handler, 0);
881 tout_pending = 0;
882 last_char = 0;
883 }
884
885 /*
886 * intercept LAlt-LMeta-F1 here to switch back to original ascii-keymap.
887 * this should probably be configurable..
888 */
889 if (mod == (KBD_MOD_LALT|KBD_MOD_LMETA) && c == 0x50) {
890 bcopy (&ascii_kbdmap, &kbdmap, sizeof (struct kbdmap));
891 splx (s);
892 return;
893 }
894
895 /* translate modifiers */
896 if (mod & KBD_MOD_SHIFT) {
897 if (mod & KBD_MOD_ALT)
898 key = kbdmap.alt_shift_keys[c];
899 else
900 key = kbdmap.shift_keys[c];
901 } else if (mod & KBD_MOD_ALT)
902 key = kbdmap.alt_keys[c];
903 else {
904 key = kbdmap.keys[c];
905 /* if CAPS and key is CAPable (no pun intended) */
906 if ((mod & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
907 key = kbdmap.shift_keys[c];
908 else if ((mod & KBD_MOD_OPT2) && (key.mode & KBD_MODE_KPAD))
909 key = kbdmap.shift_keys[c];
910 }
911 code = key.code;
912
913 /*
914 * arrange to repeat the keystroke. By doing this at the level of scan-codes,
915 * we can have function keys, and keys that send strings, repeat too. This
916 * also entitles an additional overhead, since we have to do the conversion
917 * each time, but I guess that's ok.
918 */
919 if (!tout_pending && caller == ITEFILT_TTY && kbd_ite->key_repeat) {
920 tout_pending = 1;
921 last_char = c;
922 timeout (repeat_handler, 0, start_repeat_timeo);
923 } else if (!tout_pending && caller == ITEFILT_REPEATER &&
924 kbd_ite->key_repeat) {
925 tout_pending = 1;
926 last_char = c;
927 timeout (repeat_handler, 0, next_repeat_timeo);
928 }
929
930 /* handle dead keys */
931 if (key.mode & KBD_MODE_DEAD) {
932 splx (s);
933 return;
934 }
935 /* if not string, apply META and CTRL modifiers */
936 if (! (key.mode & KBD_MODE_STRING)
937 && (!(key.mode & KBD_MODE_KPAD) ||
938 (kbd_ite && !kbd_ite->keypad_appmode))) {
939 if ((mod & KBD_MOD_CTRL) &&
940 (code == ' ' || (code >= '@' && code <= 'z')))
941 code &= 0x1f;
942 if (mod & KBD_MOD_META)
943 code |= 0x80;
944 } else if ((key.mode & KBD_MODE_KPAD) &&
945 (kbd_ite && kbd_ite->keypad_appmode)) {
946 static char *in = "0123456789-+.\r()/*";
947 static char *out = "pqrstuvwxymlnMPQRS";
948 char *cp = index (in, code);
949
950 /*
951 * keypad-appmode sends SS3 followed by the above
952 * translated character
953 */
954 (*linesw[kbd_tty->t_line].l_rint) (27, kbd_tty);
955 (*linesw[kbd_tty->t_line].l_rint) ('O', kbd_tty);
956 (*linesw[kbd_tty->t_line].l_rint) (out[cp - in], kbd_tty);
957 splx(s);
958 return;
959 } else {
960 /* *NO* I don't like this.... */
961 static u_char app_cursor[] =
962 {
963 3, 27, 'O', 'A',
964 3, 27, 'O', 'B',
965 3, 27, 'O', 'C',
966 3, 27, 'O', 'D'};
967
968 str = kbdmap.strings + code;
969 /*
970 * if this is a cursor key, AND it has the default
971 * keymap setting, AND we're in app-cursor mode, switch
972 * to the above table. This is *nasty* !
973 */
974 if (c >= 0x3b && c <= 0x3e && kbd_ite->cursor_appmode
975 && !bcmp(str, "\x03\x1b[", 3) &&
976 index("ABCD", str[3]))
977 str = app_cursor + 4 * (str[3] - 'A');
978
979 /*
980 * using a length-byte instead of 0-termination allows
981 * to embed \0 into strings, although this is not used
982 * in the default keymap
983 */
984 for (i = *str++; i; i--)
985 (*linesw[kbd_tty->t_line].l_rint) (*str++, kbd_tty);
986 splx(s);
987 return;
988 }
989 (*linesw[kbd_tty->t_line].l_rint)(code, kbd_tty);
990
991 splx(s);
992 return;
993 }
994
995 /* helper functions, makes the code below more readable */
996 __inline static void
997 ite_sendstr (ip, str)
998 struct ite_softc *ip;
999 char *str;
1000 {
1001 while (*str)
1002 itesendch (*str++);
1003 }
1004
1005 __inline static void
1006 alignment_display(ip)
1007 struct ite_softc *ip;
1008 {
1009 int i, j;
1010
1011 for (j = 0; j < ip->rows; j++)
1012 for (i = 0; i < ip->cols; i++)
1013 SUBR_PUTC(ip, 'E', j, i, ATTR_NOR);
1014 attrclr(ip, 0, 0, ip->rows, ip->cols);
1015 }
1016
1017 __inline static void
1018 snap_cury(ip)
1019 struct ite_softc *ip;
1020 {
1021 if (ip->inside_margins) {
1022 if (ip->cury < ip->top_margin)
1023 ip->cury = ip->top_margin;
1024 if (ip->cury > ip->bottom_margin)
1025 ip->cury = ip->bottom_margin;
1026 }
1027 }
1028
1029 __inline static void
1030 ite_dnchar(ip, n)
1031 struct ite_softc *ip;
1032 int n;
1033 {
1034 n = min(n, ip->cols - ip->curx);
1035 if (n < ip->cols - ip->curx) {
1036 SUBR_SCROLL(ip, ip->cury, ip->curx + n, n, SCROLL_LEFT);
1037 attrmov(ip, ip->cury, ip->curx + n, ip->cury, ip->curx,
1038 1, ip->cols - ip->curx - n);
1039 attrclr(ip, ip->cury, ip->cols - n, 1, n);
1040 }
1041 while (n-- > 0)
1042 SUBR_PUTC(ip, ' ', ip->cury, ip->cols - n - 1, ATTR_NOR);
1043 }
1044
1045 static void
1046 ite_inchar(ip, n)
1047 struct ite_softc *ip;
1048 int n;
1049 {
1050 int c = ip->save_char;
1051 ip->save_char = 0;
1052 n = min(n, ip->cols - ip->curx);
1053 if (n < ip->cols - ip->curx) {
1054 SUBR_SCROLL(ip, ip->cury, ip->curx, n, SCROLL_RIGHT);
1055 attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + n,
1056 1, ip->cols - ip->curx - n);
1057 attrclr(ip, ip->cury, ip->curx, 1, n);
1058 }
1059 while (n--)
1060 SUBR_PUTC(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
1061 ip->save_char = c;
1062 }
1063
1064 __inline static void
1065 ite_clrtoeol(ip)
1066 struct ite_softc *ip;
1067 {
1068 int y = ip->cury, x = ip->curx;
1069 if (ip->cols - x > 0) {
1070 SUBR_CLEAR(ip, y, x, 1, ip->cols - x);
1071 attrclr(ip, y, x, 1, ip->cols - x);
1072 }
1073 }
1074
1075 __inline static void
1076 ite_clrtobol(ip)
1077 struct ite_softc *ip;
1078 {
1079 int y = ip->cury, x = min(ip->curx + 1, ip->cols);
1080 SUBR_CLEAR(ip, y, 0, 1, x);
1081 attrclr(ip, y, 0, 1, x);
1082 }
1083
1084 __inline static void
1085 ite_clrline(ip)
1086 struct ite_softc *ip;
1087 {
1088 int y = ip->cury;
1089 SUBR_CLEAR(ip, y, 0, 1, ip->cols);
1090 attrclr(ip, y, 0, 1, ip->cols);
1091 }
1092
1093 __inline static void
1094 ite_clrtoeos(ip)
1095 struct ite_softc *ip;
1096 {
1097 ite_clrtoeol(ip);
1098 if (ip->cury < ip->rows - 1) {
1099 SUBR_CLEAR(ip, ip->cury + 1, 0, ip->rows - 1 - ip->cury, ip->cols);
1100 attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
1101 }
1102 }
1103
1104 __inline static void
1105 ite_clrtobos(ip)
1106 struct ite_softc *ip;
1107 {
1108 ite_clrtobol(ip);
1109 if (ip->cury > 0) {
1110 SUBR_CLEAR(ip, 0, 0, ip->cury, ip->cols);
1111 attrclr(ip, 0, 0, ip->cury, ip->cols);
1112 }
1113 }
1114
1115 __inline static void
1116 ite_clrscreen(ip)
1117 struct ite_softc *ip;
1118 {
1119 SUBR_CLEAR(ip, 0, 0, ip->rows, ip->cols);
1120 attrclr(ip, 0, 0, ip->rows, ip->cols);
1121 }
1122
1123
1124
1125 __inline static void
1126 ite_dnline(ip, n)
1127 struct ite_softc *ip;
1128 int n;
1129 {
1130 /*
1131 * interesting.. if the cursor is outside the scrolling
1132 * region, this command is simply ignored..
1133 */
1134 if (ip->cury < ip->top_margin || ip->cury > ip->bottom_margin)
1135 return;
1136
1137 n = min(n, ip->bottom_margin + 1 - ip->cury);
1138 if (n <= ip->bottom_margin - ip->cury) {
1139 SUBR_SCROLL(ip, ip->cury + n, 0, n, SCROLL_UP);
1140 attrmov(ip, ip->cury + n, 0, ip->cury, 0,
1141 ip->bottom_margin + 1 - ip->cury - n, ip->cols);
1142 }
1143 SUBR_CLEAR(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
1144 attrclr(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
1145 }
1146
1147 __inline static void
1148 ite_inline(ip, n)
1149 struct ite_softc *ip;
1150 int n;
1151 {
1152 /*
1153 * interesting.. if the cursor is outside the scrolling
1154 * region, this command is simply ignored..
1155 */
1156 if (ip->cury < ip->top_margin || ip->cury > ip->bottom_margin)
1157 return;
1158
1159 if (n <= 0)
1160 n = 1;
1161 else n = min(n, ip->bottom_margin + 1 - ip->cury);
1162 if (n <= ip->bottom_margin - ip->cury) {
1163 SUBR_SCROLL(ip, ip->cury, 0, n, SCROLL_DOWN);
1164 attrmov(ip, ip->cury, 0, ip->cury + n, 0,
1165 ip->bottom_margin + 1 - ip->cury - n, ip->cols);
1166 }
1167 SUBR_CLEAR(ip, ip->cury, 0, n, ip->cols);
1168 attrclr(ip, ip->cury, 0, n, ip->cols);
1169 ip->curx = 0;
1170 }
1171
1172 __inline static void
1173 ite_index (ip)
1174 struct ite_softc *ip;
1175 {
1176 ++ip->cury;
1177 if ((ip->cury == ip->bottom_margin+1) || (ip->cury == ip->rows)) {
1178 ip->cury--;
1179 SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
1180 ite_clrline(ip);
1181 }
1182 /*clr_attr(ip, ATTR_INV);*/
1183 }
1184
1185 __inline static void
1186 ite_lf (ip)
1187 struct ite_softc *ip;
1188 {
1189 ++ip->cury;
1190 if (ip->cury > ip->bottom_margin) {
1191 ip->cury--;
1192 SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
1193 ite_clrline(ip);
1194 }
1195 /* SUBR_CURSOR(ip, MOVE_CURSOR);*/
1196 /*clr_attr(ip, ATTR_INV);*/
1197 /* reset character set ... thanks for mohta. */
1198 ip->G0 = CSET_ASCII;
1199 ip->G1 = CSET_JIS1983;
1200 ip->G2 = CSET_JISKANA;
1201 ip->G3 = CSET_JIS1990;
1202 ip->GL = &ip->G0;
1203 ip->GR = &ip->G1;
1204 ip->save_GL = 0;
1205 ip->save_char = 0;
1206 }
1207
1208 __inline static void
1209 ite_crlf (ip)
1210 struct ite_softc *ip;
1211 {
1212 ip->curx = 0;
1213 ite_lf (ip);
1214 }
1215
1216 __inline static void
1217 ite_cr (ip)
1218 struct ite_softc *ip;
1219 {
1220 if (ip->curx) {
1221 ip->curx = 0;
1222 }
1223 }
1224
1225 __inline static void
1226 ite_rlf (ip)
1227 struct ite_softc *ip;
1228 {
1229 ip->cury--;
1230 if ((ip->cury < 0) || (ip->cury == ip->top_margin - 1)) {
1231 ip->cury++;
1232 SUBR_SCROLL(ip, ip->top_margin, 0, 1, SCROLL_DOWN);
1233 ite_clrline(ip);
1234 }
1235 clr_attr(ip, ATTR_INV);
1236 }
1237
1238 __inline static int
1239 atoi (cp)
1240 const char *cp;
1241 {
1242 int n;
1243
1244 for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++)
1245 n = n * 10 + *cp - '0';
1246 return n;
1247 }
1248
1249 __inline static char *
1250 index(cp, ch)
1251 const char *cp;
1252 char ch;
1253 {
1254 while (*cp && *cp != ch)
1255 cp++;
1256 return *cp ? (char *) cp : 0;
1257 }
1258
1259 __inline static int
1260 ite_argnum (ip)
1261 struct ite_softc *ip;
1262 {
1263 char ch;
1264 int n;
1265
1266 /* convert argument string into number */
1267 if (ip->ap == ip->argbuf)
1268 return 1;
1269 ch = *ip->ap;
1270 *ip->ap = 0;
1271 n = atoi (ip->argbuf);
1272 *ip->ap = ch;
1273
1274 return n;
1275 }
1276
1277 __inline static int
1278 ite_zargnum (ip)
1279 struct ite_softc *ip;
1280 {
1281 char ch;
1282 int n;
1283
1284 /* convert argument string into number */
1285 if (ip->ap == ip->argbuf)
1286 return 0;
1287 ch = *ip->ap;
1288 *ip->ap = 0; /* terminate string */
1289 n = atoi (ip->argbuf);
1290 *ip->ap = ch;
1291
1292 return n; /* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
1293 }
1294
1295 void
1296 ite_putstr(s, len, dev)
1297 const u_char *s;
1298 int len;
1299 dev_t dev;
1300 {
1301 struct ite_softc *ip;
1302 int i;
1303
1304 ip = getitesp(dev);
1305
1306 /* XXX avoid problems */
1307 if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
1308 return;
1309
1310 SUBR_CURSOR(ip, START_CURSOROPT);
1311 for (i = 0; i < len; i++)
1312 if (s[i])
1313 iteputchar(s[i], ip);
1314 SUBR_CURSOR(ip, END_CURSOROPT);
1315 }
1316
1317 void
1318 iteputchar(c, ip)
1319 register int c;
1320 struct ite_softc *ip;
1321 {
1322 struct tty *kbd_tty;
1323 int n, x, y;
1324 char *cp;
1325
1326 kbd_tty = ite_tty[kbd_ite->device.dv_unit];
1327
1328 if (c >= 0x20 && ip->escape) {
1329 switch (ip->escape) {
1330
1331 case ESC:
1332 switch (c) {
1333 /* first 7bit equivalents for the 8bit control characters */
1334
1335 case 'D':
1336 c = IND;
1337 ip->escape = 0;
1338 break; /* and fall into the next switch below (same for all `break') */
1339
1340 case 'E':
1341 /* next line */
1342 c = NEL;
1343 ip->escape = 0;
1344 break;
1345
1346 case 'H':
1347 /* set TAB at current col */
1348 c = HTS;
1349 ip->escape = 0;
1350 break;
1351
1352 case 'M':
1353 /* reverse index */
1354 c = RI;
1355 ip->escape = 0;
1356 break;
1357
1358 case 'N':
1359 /* single shift G2 */
1360 c = SS2;
1361 ip->escape = 0;
1362 break;
1363
1364 case 'O':
1365 /* single shift G3 */
1366 c = SS3;
1367 ip->escape = 0;
1368 break;
1369
1370 case 'P':
1371 /* DCS detected */
1372 c = DCS;
1373 ip->escape = 0;
1374 break;
1375
1376 case '[':
1377 c = CSI;
1378 ip->escape = 0;
1379 break;
1380
1381 case '\\':
1382 /* String Terminator */
1383 c = ST;
1384 ip->escape = 0;
1385 break;
1386
1387 case ']':
1388 c = OSC;
1389 ip->escape = 0;
1390 break;
1391
1392 case '^':
1393 c = PM;
1394 ip->escape = 0;
1395 break;
1396
1397 case '_':
1398 c = APC;
1399 ip->escape = 0;
1400 break;
1401
1402
1403 /* introduces 7/8bit control */
1404 case ' ':
1405 /* can be followed by either F or G */
1406 ip->escape = ' ';
1407 break;
1408
1409
1410 /* a lot of character set selections, not yet used...
1411 94-character sets: */
1412 case '(': /* G0 */
1413 case ')': /* G1 */
1414 ip->escape = c;
1415 return;
1416
1417 case '*': /* G2 */
1418 case '+': /* G3 */
1419 case 'B': /* ASCII */
1420 case 'A': /* ISO latin 1 */
1421 case '<': /* user preferred suplemental */
1422 case '0': /* dec special graphics */
1423
1424 /* 96-character sets: */
1425 case '-': /* G1 */
1426 case '.': /* G2 */
1427 case '/': /* G3 */
1428
1429 /* national character sets: */
1430 case '4': /* dutch */
1431 case '5':
1432 case 'C': /* finnish */
1433 case 'R': /* french */
1434 case 'Q': /* french canadian */
1435 case 'K': /* german */
1436 case 'Y': /* italian */
1437 case '6': /* norwegian/danish */
1438 /* note: %5 and %6 are not supported (two chars..) */
1439
1440 ip->escape = 0;
1441 /* just ignore for now */
1442 return;
1443
1444 /* 94-multibyte character sets designate */
1445 case '$':
1446 ip->escape = '$';
1447 return;
1448
1449 /* locking shift modes */
1450 case '`':
1451 ip->GR = &ip->G1;
1452 ip->escape = 0;
1453 return;
1454
1455 case 'n':
1456 ip->GL = &ip->G2;
1457 ip->escape = 0;
1458 return;
1459
1460 case '}':
1461 ip->GR = &ip->G2;
1462 ip->escape = 0;
1463 return;
1464
1465 case 'o':
1466 ip->GL = &ip->G3;
1467 ip->escape = 0;
1468 return;
1469
1470 case '|':
1471 ip->GR = &ip->G3;
1472 ip->escape = 0;
1473 return;
1474
1475 case '~':
1476 ip->GR = &ip->G1;
1477 ip->escape = 0;
1478 return;
1479
1480 /* font width/height control */
1481 case '#':
1482 ip->escape = '#';
1483 return;
1484
1485 case 'c':
1486 /* hard terminal reset .. */
1487 ite_reset (ip);
1488 SUBR_CURSOR(ip, MOVE_CURSOR);
1489 ip->escape = 0;
1490 return;
1491
1492
1493 case '7':
1494 /* save cursor */
1495 ip->save_curx = ip->curx;
1496 ip->save_cury = ip->cury;
1497 ip->save_attribute = ip->attribute;
1498 ip->sc_om = ip->inside_margins;
1499 ip->sc_G0 = ip->G0;
1500 ip->sc_G1 = ip->G1;
1501 ip->sc_G2 = ip->G2;
1502 ip->sc_G3 = ip->G3;
1503 ip->sc_GL = ip->GL;
1504 ip->sc_GR = ip->GR;
1505 ip->escape = 0;
1506 return;
1507
1508 case '8':
1509 /* restore cursor */
1510 ip->curx = ip->save_curx;
1511 ip->cury = ip->save_cury;
1512 ip->attribute = ip->save_attribute;
1513 ip->inside_margins = ip->sc_om;
1514 ip->G0 = ip->sc_G0;
1515 ip->G1 = ip->sc_G1;
1516 ip->G2 = ip->sc_G2;
1517 ip->G3 = ip->sc_G3;
1518 ip->GL = ip->sc_GL;
1519 ip->GR = ip->sc_GR;
1520 SUBR_CURSOR(ip, MOVE_CURSOR);
1521 ip->escape = 0;
1522 return;
1523
1524 case '=':
1525 /* keypad application mode */
1526 ip->keypad_appmode = 1;
1527 ip->escape = 0;
1528 return;
1529
1530 case '>':
1531 /* keypad numeric mode */
1532 ip->keypad_appmode = 0;
1533 ip->escape = 0;
1534 return;
1535
1536 case 'Z': /* request ID */
1537 if (ip->emul_level == EMUL_VT100)
1538 ite_sendstr (ip, "\033[61;0c"); /* XXX not clean */
1539 else
1540 ite_sendstr (ip, "\033[63;0c"); /* XXX not clean */
1541 ip->escape = 0;
1542 return;
1543
1544 /* default catch all for not recognized ESC sequences */
1545 default:
1546 ip->escape = 0;
1547 return;
1548 }
1549 break;
1550
1551
1552 case '(': /* designate G0 */
1553 switch (c) {
1554 case 'B': /* USASCII */
1555 ip->G0 = CSET_ASCII;
1556 ip->escape = 0;
1557 return;
1558 case 'I':
1559 ip->G0 = CSET_JISKANA;
1560 ip->escape = 0;
1561 return;
1562 case 'J':
1563 ip->G0 = CSET_JISROMA;
1564 ip->escape = 0;
1565 return;
1566 case 'A': /* British or ISO-Latin-1 */
1567 case 'H': /* Swedish */
1568 case 'K': /* German */
1569 case 'R': /* French */
1570 case 'Y': /* Italian */
1571 case 'Z': /* Spanish */
1572 default:
1573 /* not supported */
1574 ip->escape = 0;
1575 return;
1576 }
1577
1578 case ')': /* designate G1 */
1579 ip->escape = 0;
1580 return;
1581
1582 case '$': /* 94-multibyte character set */
1583 switch (c) {
1584 case '@':
1585 ip->G0 = CSET_JIS1978;
1586 ip->escape = 0;
1587 return;
1588 case 'B':
1589 ip->G0 = CSET_JIS1983;
1590 ip->escape = 0;
1591 return;
1592 case 'D':
1593 ip->G0 = CSET_JIS1990;
1594 ip->escape = 0;
1595 return;
1596 default:
1597 /* not supported */
1598 ip->escape = 0;
1599 return;
1600 }
1601
1602 case ' ':
1603 switch (c) {
1604 case 'F':
1605 ip->eightbit_C1 = 0;
1606 ip->escape = 0;
1607 return;
1608
1609 case 'G':
1610 ip->eightbit_C1 = 1;
1611 ip->escape = 0;
1612 return;
1613
1614 default:
1615 /* not supported */
1616 ip->escape = 0;
1617 return;
1618 }
1619 break;
1620
1621 case '#':
1622 switch (c) {
1623 case '5':
1624 /* single height, single width */
1625 ip->escape = 0;
1626 return;
1627
1628 case '6':
1629 /* double width, single height */
1630 ip->escape = 0;
1631 return;
1632
1633 case '3':
1634 /* top half */
1635 ip->escape = 0;
1636 return;
1637
1638 case '4':
1639 /* bottom half */
1640 ip->escape = 0;
1641 return;
1642
1643 case '8':
1644 /* screen alignment pattern... */
1645 alignment_display (ip);
1646 ip->escape = 0;
1647 return;
1648
1649 default:
1650 ip->escape = 0;
1651 return;
1652 }
1653 break;
1654
1655
1656
1657 case CSI:
1658 /* the biggie... */
1659 switch (c) {
1660 case '0': case '1': case '2': case '3': case '4':
1661 case '5': case '6': case '7': case '8': case '9':
1662 case ';': case '\"': case '$': case '>':
1663 if (ip->ap < ip->argbuf + MAX_ARGSIZE)
1664 *ip->ap++ = c;
1665 return;
1666
1667 case 'p':
1668 *ip->ap = 0;
1669 if (!strncmp(ip->argbuf, "61\"", 3))
1670 ip->emul_level = EMUL_VT100;
1671 else if (!strncmp(ip->argbuf, "63;1\"", 5)
1672 || !strncmp(ip->argbuf, "62;1\"", 5))
1673 ip->emul_level = EMUL_VT300_7;
1674 else
1675 ip->emul_level = EMUL_VT300_8;
1676 ip->escape = 0;
1677 return;
1678
1679
1680 case '?':
1681 *ip->ap = 0;
1682 ip->escape = '?';
1683 ip->ap = ip->argbuf;
1684 return;
1685
1686
1687 case 'c':
1688 /* device attributes */
1689 *ip->ap = 0;
1690 if (ip->argbuf[0] == '>') {
1691 ite_sendstr (ip, "\033[>24;0;0;0c");
1692 } else
1693 switch (ite_zargnum(ip)) {
1694 case 0:
1695 /* primary DA request, send primary DA response */
1696 if (ip->emul_level == EMUL_VT100)
1697 ite_sendstr (ip, "\033[?1;1c");
1698 else
1699 ite_sendstr (ip, "\033[63;0c");
1700 break;
1701 }
1702 ip->escape = 0;
1703 return;
1704
1705 case 'n':
1706 switch (ite_zargnum(ip)) {
1707 case 5:
1708 ite_sendstr (ip, "\033[0n"); /* no malfunction */
1709 break;
1710 case 6:
1711 /* cursor position report */
1712 sprintf (ip->argbuf, "\033[%d;%dR",
1713 ip->cury + 1, ip->curx + 1);
1714 ite_sendstr (ip, ip->argbuf);
1715 break;
1716 }
1717 ip->escape = 0;
1718 return;
1719
1720
1721 case 'x':
1722 switch (ite_zargnum(ip)) {
1723 case 0:
1724 /* Fake some terminal parameters. */
1725 ite_sendstr (ip, "\033[2;1;1;112;112;1;0x");
1726 break;
1727 case 1:
1728 ite_sendstr (ip, "\033[3;1;1;112;112;1;0x");
1729 break;
1730 }
1731 ip->escape = 0;
1732 return;
1733
1734
1735 case 'g':
1736 /* clear tabs */
1737 switch (ite_zargnum(ip)) {
1738 case 0:
1739 if (ip->curx < ip->cols)
1740 ip->tabs[ip->curx] = 0;
1741 break;
1742 case 3:
1743 for (n = 0; n < ip->cols; n++)
1744 ip->tabs[n] = 0;
1745 break;
1746
1747 default:
1748 /* ignore */
1749 break;
1750 }
1751 ip->escape = 0;
1752 return;
1753
1754
1755 case 'h': /* set mode */
1756 case 'l': /* reset mode */
1757 n = ite_zargnum (ip);
1758 switch (n) {
1759 case 4:
1760 ip->imode = (c == 'h'); /* insert/replace mode */
1761 break;
1762 case 20:
1763 ip->linefeed_newline = (c == 'h');
1764 break;
1765 }
1766 ip->escape = 0;
1767 return;
1768
1769
1770 case 'M':
1771 /* delete line */
1772 ite_dnline (ip, ite_argnum (ip));
1773 ip->escape = 0;
1774 return;
1775
1776
1777 case 'L':
1778 /* insert line */
1779 ite_inline (ip, ite_argnum (ip));
1780 ip->escape = 0;
1781 return;
1782
1783
1784 case 'P':
1785 /* delete char */
1786 ite_dnchar (ip, ite_argnum (ip));
1787 ip->escape = 0;
1788 return;
1789
1790
1791 case '@':
1792 /* insert char(s) */
1793 ite_inchar (ip, ite_argnum (ip));
1794 ip->escape = 0;
1795 return;
1796
1797 case '!':
1798 /* soft terminal reset */
1799 ip->escape = 0; /* XXX */
1800 return;
1801
1802 case 'G':
1803 /* this one was *not* in my vt320 manual but in
1804 a vt320 termcap entry.. who is right?
1805 It's supposed to set the horizontal cursor position. */
1806 *ip->ap = 0;
1807 x = atoi (ip->argbuf);
1808 if (x) x--;
1809 ip->curx = min(x, ip->cols - 1);
1810 ip->escape = 0;
1811 SUBR_CURSOR(ip, MOVE_CURSOR);
1812 clr_attr (ip, ATTR_INV);
1813 return;
1814
1815
1816 case 'd':
1817 /* same thing here, this one's for setting the absolute
1818 vertical cursor position. Not documented... */
1819 *ip->ap = 0;
1820 y = atoi (ip->argbuf);
1821 if (y) y--;
1822 if (ip->inside_margins)
1823 y += ip->top_margin;
1824 ip->cury = min(y, ip->rows - 1);
1825 ip->escape = 0;
1826 snap_cury(ip);
1827 SUBR_CURSOR(ip, MOVE_CURSOR);
1828 clr_attr (ip, ATTR_INV);
1829 return;
1830
1831
1832 case 'H':
1833 case 'f':
1834 *ip->ap = 0;
1835 y = atoi (ip->argbuf);
1836 x = 0;
1837 cp = index (ip->argbuf, ';');
1838 if (cp)
1839 x = atoi (cp + 1);
1840 if (x) x--;
1841 if (y) y--;
1842 if (ip->inside_margins)
1843 y += ip->top_margin;
1844 ip->cury = min(y, ip->rows - 1);
1845 ip->curx = min(x, ip->cols - 1);
1846 ip->escape = 0;
1847 snap_cury(ip);
1848 SUBR_CURSOR(ip, MOVE_CURSOR);
1849 /*clr_attr (ip, ATTR_INV);*/
1850 return;
1851
1852 case 'A':
1853 /* cursor up */
1854 n = ite_argnum (ip);
1855 n = ip->cury - (n ? n : 1);
1856 if (n < 0) n = 0;
1857 if (ip->inside_margins)
1858 n = max(ip->top_margin, n);
1859 else if (n == ip->top_margin - 1)
1860 /* allow scrolling outside region, but don't scroll out
1861 of active region without explicit CUP */
1862 n = ip->top_margin;
1863 ip->cury = n;
1864 ip->escape = 0;
1865 SUBR_CURSOR(ip, MOVE_CURSOR);
1866 clr_attr (ip, ATTR_INV);
1867 return;
1868
1869 case 'B':
1870 /* cursor down */
1871 n = ite_argnum (ip);
1872 n = ip->cury + (n ? n : 1);
1873 n = min(ip->rows - 1, n);
1874 #if 0
1875 if (ip->inside_margins)
1876 #endif
1877 n = min(ip->bottom_margin, n);
1878 #if 0
1879 else if (n == ip->bottom_margin + 1)
1880 /* allow scrolling outside region, but don't scroll out
1881 of active region without explicit CUP */
1882 n = ip->bottom_margin;
1883 #endif
1884 ip->cury = n;
1885 ip->escape = 0;
1886 SUBR_CURSOR(ip, MOVE_CURSOR);
1887 clr_attr (ip, ATTR_INV);
1888 return;
1889
1890 case 'C':
1891 /* cursor forward */
1892 n = ite_argnum (ip);
1893 n = n ? n : 1;
1894 ip->curx = min(ip->curx + n, ip->cols - 1);
1895 ip->escape = 0;
1896 SUBR_CURSOR(ip, MOVE_CURSOR);
1897 clr_attr (ip, ATTR_INV);
1898 return;
1899
1900 case 'D':
1901 /* cursor backward */
1902 n = ite_argnum (ip);
1903 n = n ? n : 1;
1904 n = ip->curx - n;
1905 ip->curx = n >= 0 ? n : 0;
1906 ip->escape = 0;
1907 SUBR_CURSOR(ip, MOVE_CURSOR);
1908 clr_attr (ip, ATTR_INV);
1909 return;
1910
1911
1912 case 'J':
1913 /* erase screen */
1914 *ip->ap = 0;
1915 n = ite_zargnum (ip);
1916 if (n == 0)
1917 ite_clrtoeos(ip);
1918 else if (n == 1)
1919 ite_clrtobos(ip);
1920 else if (n == 2)
1921 ite_clrscreen(ip);
1922 ip->escape = 0;
1923 return;
1924
1925
1926 case 'K':
1927 /* erase line */
1928 n = ite_zargnum (ip);
1929 if (n == 0)
1930 ite_clrtoeol(ip);
1931 else if (n == 1)
1932 ite_clrtobol(ip);
1933 else if (n == 2)
1934 ite_clrline(ip);
1935 ip->escape = 0;
1936 return;
1937
1938 case 'S':
1939 /* scroll up */
1940 n = ite_zargnum (ip);
1941 if (n <= 0)
1942 n = 1;
1943 else if (n > ip->rows-1)
1944 n = ip->rows-1;
1945 SUBR_SCROLL(ip, ip->rows-1, 0, n, SCROLL_UP);
1946 ip->escape = 0;
1947 return;
1948
1949 case 'T':
1950 /* scroll down */
1951 n = ite_zargnum (ip);
1952 if (n <= 0)
1953 n = 1;
1954 else if (n > ip->rows-1)
1955 n = ip->rows-1;
1956 SUBR_SCROLL(ip, 0, 0, n, SCROLL_DOWN);
1957 ip->escape = 0;
1958 return;
1959
1960 case 'X':
1961 /* erase character */
1962 n = ite_argnum(ip) - 1;
1963 n = min(n, ip->cols - 1 - ip->curx);
1964 for (; n >= 0; n--) {
1965 attrclr(ip, ip->cury, ip->curx + n, 1, 1);
1966 SUBR_PUTC(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
1967 }
1968 ip->escape = 0;
1969 return;
1970
1971
1972 case '}': case '`':
1973 /* status line control */
1974 ip->escape = 0;
1975 return;
1976
1977 case 'r':
1978 /* set scrolling region */
1979 ip->escape = 0;
1980 *ip->ap = 0;
1981 x = atoi (ip->argbuf);
1982 x = x ? x : 1;
1983 y = ip->rows;
1984 cp = index (ip->argbuf, ';');
1985 if (cp) {
1986 y = atoi (cp + 1);
1987 y = y ? y : ip->rows;
1988 }
1989 if (y <= x)
1990 return;
1991 x--;
1992 y--;
1993 ip->top_margin = min(x, ip->rows - 2);
1994 ip->bottom_margin = min(y, ip->rows - 1);
1995 if (ip->inside_margins) {
1996 ip->cury = ip->top_margin;
1997 } else
1998 ip->cury = 0;
1999 ip->curx = 0;
2000 return;
2001
2002
2003 case 'm':
2004 /* big attribute setter/resetter */
2005 {
2006 char *cp;
2007 *ip->ap = 0;
2008 /* kludge to make CSIm work (== CSI0m) */
2009 if (ip->ap == ip->argbuf)
2010 ip->ap++;
2011 for (cp = ip->argbuf; cp < ip->ap; ) {
2012 switch (*cp) {
2013 case 0:
2014 case '0':
2015 clr_attr (ip, ATTR_ALL);
2016 ip->fgcolor = 7;
2017 ip->bgcolor = 0;
2018 cp++;
2019 break;
2020
2021 case '1':
2022 set_attr (ip, ATTR_BOLD);
2023 cp++;
2024 break;
2025
2026 case '2':
2027 switch (cp[1]) {
2028 case '2':
2029 clr_attr (ip, ATTR_BOLD);
2030 cp += 2;
2031 break;
2032
2033 case '4':
2034 clr_attr (ip, ATTR_UL);
2035 cp += 2;
2036 break;
2037
2038 case '5':
2039 clr_attr (ip, ATTR_BLINK);
2040 cp += 2;
2041 break;
2042
2043 case '7':
2044 clr_attr (ip, ATTR_INV);
2045 cp += 2;
2046 break;
2047
2048 default:
2049 cp++;
2050 break;
2051 }
2052 break;
2053
2054 case '3':
2055 switch (cp[1]) {
2056 case '0': case '1': case '2': case '3':
2057 case '4': case '5': case '6': case '7':
2058 /* foreground colors */
2059 ip->fgcolor = cp[1] - '0';
2060 cp += 2;
2061 break;
2062 default:
2063 cp++;
2064 break;
2065 }
2066 break;
2067
2068 case '4':
2069 switch (cp[1]) {
2070 case '0': case '1': case '2': case '3':
2071 case '4': case '5': case '6': case '7':
2072 /* background colors */
2073 ip->bgcolor = cp[1] - '0';
2074 cp += 2;
2075 break;
2076 default:
2077 set_attr (ip, ATTR_UL);
2078 cp++;
2079 break;
2080 }
2081 break;
2082
2083 case '5':
2084 set_attr (ip, ATTR_BLINK);
2085 cp++;
2086 break;
2087
2088 case '7':
2089 set_attr (ip, ATTR_INV);
2090 cp++;
2091 break;
2092
2093 default:
2094 cp++;
2095 break;
2096 }
2097 }
2098
2099 }
2100 ip->escape = 0;
2101 return;
2102
2103
2104 case 'u':
2105 /* DECRQTSR */
2106 ite_sendstr (ip, "\033P\033\\");
2107 ip->escape = 0;
2108 return;
2109
2110 default:
2111 ip->escape = 0;
2112 return;
2113 }
2114 break;
2115
2116
2117
2118 case '?': /* CSI ? */
2119 switch (c) {
2120 case '0': case '1': case '2': case '3': case '4':
2121 case '5': case '6': case '7': case '8': case '9':
2122 case ';': case '\"': case '$':
2123 /* Don't fill the last character; it's needed. */
2124 /* XXX yeah, where ?? */
2125 if (ip->ap < ip->argbuf + MAX_ARGSIZE - 1)
2126 *ip->ap++ = c;
2127 return;
2128
2129
2130 case 'n':
2131 /* Terminal Reports */
2132 *ip->ap = 0;
2133 if (ip->ap == &ip->argbuf[2]) {
2134 if (!strncmp(ip->argbuf, "15", 2))
2135 /* printer status: no printer */
2136 ite_sendstr (ip, "\033[13n");
2137
2138 else if (!strncmp(ip->argbuf, "25", 2))
2139 /* udk status */
2140 ite_sendstr (ip, "\033[20n");
2141
2142 else if (!strncmp(ip->argbuf, "26", 2))
2143 /* keyboard dialect: US */
2144 ite_sendstr (ip, "\033[27;1n");
2145 }
2146 ip->escape = 0;
2147 return;
2148
2149
2150 case 'h': /* set dec private modes */
2151 case 'l': /* reset dec private modes */
2152 n = ite_zargnum (ip);
2153 switch (n) {
2154 case 1:
2155 /* CKM - cursor key mode */
2156 ip->cursor_appmode = (c == 'h');
2157 break;
2158
2159 case 3:
2160 /* 132/80 columns (132 == 'h') */
2161 break;
2162
2163 case 4: /* smooth scroll */
2164 break;
2165
2166 case 5:
2167 /* light background (=='h') /dark background(=='l') */
2168 break;
2169
2170 case 6: /* origin mode */
2171 ip->inside_margins = (c == 'h');
2172 #if 0
2173 ip->curx = 0;
2174 ip->cury = ip->inside_margins ? ip->top_margin : 0;
2175 SUBR_CURSOR(ip, MOVE_CURSOR);
2176 #endif
2177 break;
2178
2179 case 7: /* auto wraparound */
2180 ip->auto_wrap = (c == 'h');
2181 break;
2182
2183 case 8: /* keyboard repeat */
2184 ip->key_repeat = (c == 'h');
2185 break;
2186
2187 case 20: /* newline mode */
2188 ip->linefeed_newline = (c == 'h');
2189 break;
2190
2191 case 25: /* cursor on/off */
2192 SUBR_CURSOR(ip, (c == 'h') ? DRAW_CURSOR : ERASE_CURSOR);
2193 break;
2194 }
2195 ip->escape = 0;
2196 return;
2197
2198 case 'K':
2199 /* selective erase in line */
2200 case 'J':
2201 /* selective erase in display */
2202
2203 default:
2204 ip->escape = 0;
2205 return;
2206 }
2207 break;
2208
2209
2210 default:
2211 ip->escape = 0;
2212 return;
2213 }
2214 }
2215
2216 switch (c) {
2217 case 0x00: /* NUL */
2218 case 0x01: /* SOH */
2219 case 0x02: /* STX */
2220 case 0x03: /* ETX */
2221 case 0x04: /* EOT */
2222 case 0x05: /* ENQ */
2223 case 0x06: /* ACK */
2224 break;
2225
2226 case BEL:
2227 #if NBELL > 0
2228 if (kbd_tty && ite_tty[kbd_ite->device.dv_unit] == kbd_tty)
2229 opm_bell();
2230 #endif
2231 break;
2232
2233 case BS:
2234 if (--ip->curx < 0)
2235 ip->curx = 0;
2236 else
2237 SUBR_CURSOR(ip, MOVE_CURSOR);
2238 break;
2239
2240 case HT:
2241 for (n = ip->curx + 1; n < ip->cols; n++) {
2242 if (ip->tabs[n]) {
2243 ip->curx = n;
2244 SUBR_CURSOR(ip, MOVE_CURSOR);
2245 break;
2246 }
2247 }
2248 break;
2249
2250 case VT: /* VT is treated like LF */
2251 case FF: /* so is FF */
2252 case LF:
2253 /* cr->crlf distinction is done here, on output,
2254 not on input! */
2255 if (ip->linefeed_newline)
2256 ite_crlf (ip);
2257 else
2258 ite_lf (ip);
2259 break;
2260
2261 case CR:
2262 ite_cr (ip);
2263 break;
2264
2265
2266 case SO:
2267 ip->GL = &ip->G1;
2268 break;
2269
2270 case SI:
2271 ip->GL = &ip->G0;
2272 break;
2273
2274 case 0x10: /* DLE */
2275 case 0x11: /* DC1/XON */
2276 case 0x12: /* DC2 */
2277 case 0x13: /* DC3/XOFF */
2278 case 0x14: /* DC4 */
2279 case 0x15: /* NAK */
2280 case 0x16: /* SYN */
2281 case 0x17: /* ETB */
2282 break;
2283
2284 case CAN:
2285 ip->escape = 0; /* cancel any escape sequence in progress */
2286 break;
2287
2288 case 0x19: /* EM */
2289 break;
2290
2291 case SUB:
2292 ip->escape = 0; /* dito, but see below */
2293 /* should also display a reverse question mark!! */
2294 break;
2295
2296 case ESC:
2297 ip->escape = ESC;
2298 break;
2299
2300 case 0x1c: /* FS */
2301 case 0x1d: /* GS */
2302 case 0x1e: /* RS */
2303 case 0x1f: /* US */
2304 break;
2305
2306 /* now it gets weird.. 8bit control sequences.. */
2307 case IND: /* index: move cursor down, scroll */
2308 ite_index (ip);
2309 break;
2310
2311 case NEL: /* next line. next line, first pos. */
2312 ite_crlf (ip);
2313 break;
2314
2315 case HTS: /* set horizontal tab */
2316 if (ip->curx < ip->cols)
2317 ip->tabs[ip->curx] = 1;
2318 break;
2319
2320 case RI: /* reverse index */
2321 ite_rlf (ip);
2322 break;
2323
2324 case SS2: /* go into G2 for one character */
2325 ip->save_GL = ip->GR; /* GL XXX EUC */
2326 ip->GR = &ip->G2; /* GL XXX */
2327 break;
2328
2329 case SS3: /* go into G3 for one character */
2330 ip->save_GL = ip->GR; /* GL XXX EUC */
2331 ip->GR = &ip->G3; /* GL XXX */
2332 break;
2333
2334 case DCS: /* device control string introducer */
2335 ip->escape = DCS;
2336 ip->ap = ip->argbuf;
2337 break;
2338
2339 case CSI: /* control sequence introducer */
2340 ip->escape = CSI;
2341 ip->ap = ip->argbuf;
2342 break;
2343
2344 case ST: /* string terminator */
2345 /* ignore, if not used as terminator */
2346 break;
2347
2348 case OSC: /* introduces OS command. Ignore everything upto ST */
2349 ip->escape = OSC;
2350 break;
2351
2352 case PM: /* privacy message, ignore everything upto ST */
2353 ip->escape = PM;
2354 break;
2355
2356 case APC: /* application program command, ignore everything upto ST */
2357 ip->escape = APC;
2358 break;
2359
2360 case DEL:
2361 break;
2362
2363 default:
2364 if (!ip->save_char && (*((c & 0x80) ? ip->GR : ip->GL) & CSET_MULTI)) {
2365 ip->save_char = c;
2366 break;
2367 }
2368 if (ip->imode)
2369 ite_inchar(ip, ip->save_char ? 2 : 1);
2370 iteprecheckwrap(ip);
2371 #ifdef DO_WEIRD_ATTRIBUTES
2372 if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
2373 attrset(ip, ATTR_INV);
2374 SUBR_PUTC(ip, c, ip->cury, ip->curx, ATTR_INV);
2375 }
2376 else
2377 SUBR_PUTC(ip, c, ip->cury, ip->curx, ATTR_NOR);
2378 #else
2379 SUBR_PUTC(ip, c, ip->cury, ip->curx, ip->attribute);
2380 #endif
2381 /* SUBR_CURSOR(ip, DRAW_CURSOR);*/
2382 itecheckwrap(ip);
2383 if (ip->save_char) {
2384 itecheckwrap(ip);
2385 ip->save_char = 0;
2386 }
2387 if (ip->save_GL) {
2388 /*
2389 * reset single shift
2390 */
2391 ip->GR = ip->save_GL;
2392 ip->save_GL = 0;
2393 }
2394 break;
2395 }
2396 }
2397
2398 static void
2399 iteprecheckwrap(ip)
2400 struct ite_softc *ip;
2401 {
2402 if (ip->auto_wrap && ip->curx + (ip->save_char ? 1 : 0) == ip->cols) {
2403 ip->curx = 0;
2404 clr_attr(ip, ATTR_INV);
2405 if (++ip->cury >= ip->bottom_margin + 1) {
2406 ip->cury = ip->bottom_margin;
2407 /*SUBR_CURSOR(ip, MOVE_CURSOR);*/
2408 SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
2409 ite_clrtoeol(ip);
2410 } /*else
2411 SUBR_CURSOR(ip, MOVE_CURSOR);*/
2412 }
2413 }
2414
2415 static void
2416 itecheckwrap(ip)
2417 struct ite_softc *ip;
2418 {
2419 #if 0
2420 if (++ip->curx == ip->cols) {
2421 if (ip->auto_wrap) {
2422 ip->curx = 0;
2423 clr_attr(ip, ATTR_INV);
2424 if (++ip->cury >= ip->bottom_margin + 1) {
2425 ip->cury = ip->bottom_margin;
2426 SUBR_CURSOR(ip, MOVE_CURSOR);
2427 SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
2428 ite_clrtoeol(ip);
2429 return;
2430 }
2431 } else
2432 /* stay there if no autowrap.. */
2433 ip->curx--;
2434 }
2435 #else
2436 if (ip->curx < ip->cols) {
2437 ip->curx++;
2438 /*SUBR_CURSOR(ip, MOVE_CURSOR);*/
2439 }
2440 #endif
2441 }
2442
2443 #endif
2444
2445 /*
2446 * Console functions
2447 */
2448 #include <dev/cons.h>
2449
2450 /*
2451 * Return a priority in consdev->cn_pri field highest wins. This function
2452 * is called before any devices have been probed.
2453 */
2454 void
2455 itecnprobe(cd)
2456 struct consdev *cd;
2457 {
2458 int maj;
2459
2460 /*
2461 * bring graphics layer up.
2462 */
2463 config_console();
2464
2465 /* locate the major number */
2466 for (maj = 0; maj < nchrdev; maj++)
2467 if (cdevsw[maj].d_open == iteopen)
2468 break;
2469
2470 /*
2471 * return priority of the best ite (already picked from attach)
2472 * or CN_DEAD.
2473 */
2474 if (con_itesoftc.grf == NULL)
2475 cd->cn_pri = CN_DEAD;
2476 else {
2477 con_itesoftc.flags = (ITE_ALIVE|ITE_CONSOLE);
2478 con_itesoftc.isw = &itesw[0]; /* XXX */
2479 cd->cn_pri = CN_INTERNAL;
2480 cd->cn_dev = makedev(maj, 0); /* XXX */
2481 }
2482
2483 }
2484
2485 void
2486 itecninit(cd)
2487 struct consdev *cd;
2488 {
2489 struct ite_softc *ip;
2490
2491 ip = getitesp(cd->cn_dev);
2492 iteinit(cd->cn_dev); /* init console unit */
2493 ip->flags |= ITE_ACTIVE | ITE_ISCONS;
2494 }
2495
2496 /*
2497 * itecnfinish() is called in ite_init() when the device is
2498 * being probed in the normal fasion, thus we can finish setting
2499 * up this ite now that the system is more functional.
2500 */
2501 void
2502 itecnfinish(ip)
2503 struct ite_softc *ip;
2504 {
2505 static int done;
2506
2507 if (done)
2508 return;
2509 done = 1;
2510 }
2511
2512 /*ARGSUSED*/
2513 int
2514 itecngetc(dev)
2515 dev_t dev;
2516 {
2517 register int c;
2518
2519 /* XXX this should be moved */
2520 if (!kbd_init) {
2521 kbd_init = 1;
2522 kbdenable();
2523 }
2524 do {
2525 c = kbdgetcn();
2526 c = ite_cnfilter(c, ITEFILT_CONSOLE);
2527 } while (c == -1);
2528 return (c);
2529 }
2530
2531 void
2532 itecnputc(dev, c)
2533 dev_t dev;
2534 int c;
2535 {
2536 static int paniced = 0;
2537 struct ite_softc *ip = getitesp(dev);
2538 char ch = c;
2539
2540 if (panicstr && !paniced &&
2541 (ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) {
2542 (void) iteon(dev, 3);
2543 paniced = 1;
2544 }
2545 ite_putstr(&ch, 1, dev);
2546 }
2547