1 /* $NetBSD: ite.c,v 1.65 2009/03/18 17:06:43 cegger Exp $ */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * from: Utah Hdr: ite.c 1.1 90/07/09
36 * from: @(#)ite.c 7.6 (Berkeley) 5/16/91
39 * Copyright (c) 1988 University of Utah.
41 * This code is derived from software contributed to Berkeley by
42 * the Systems Programming Group of the University of Utah Computer
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * from: Utah Hdr: ite.c 1.1 90/07/09
74 * from: @(#)ite.c 7.6 (Berkeley) 5/16/91
78 * ite - bitmapped terminal.
79 * Supports VT200, a few terminal features will be unavailable until
80 * the system actually probes the device (i.e. not after consinit())
83 #include <sys/cdefs.h>
84 __KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.65 2009/03/18 17:06:43 cegger Exp $");
88 #include <sys/param.h>
89 #include <sys/kernel.h>
91 #include <sys/device.h>
92 #include <sys/malloc.h>
93 #include <sys/fcntl.h>
94 #include <sys/ioctl.h>
96 #include <sys/termios.h>
97 #include <sys/systm.h>
98 #include <sys/callout.h>
100 #include <dev/cons.h>
101 #include <sys/kauth.h>
103 #include <machine/cpu.h>
105 #include <atari/atari/device.h>
106 #include <atari/dev/event_var.h>
107 #include <atari/dev/kbdmap.h>
108 #include <atari/dev/kbdvar.h>
109 #include <atari/dev/iteioctl.h>
110 #include <atari/dev/itevar.h>
111 #include <atari/dev/grfioctl.h>
112 #include <atari/dev/grfabs_reg.h>
113 #include <atari/dev/grfvar.h>
114 #include <atari/dev/viewioctl.h>
115 #include <atari/dev/viewvar.h>
117 #define ITEUNIT(dev) (minor(dev))
119 #define SUBR_INIT(ip) (ip)->grf->g_iteinit(ip)
120 #define SUBR_DEINIT(ip) (ip)->grf->g_itedeinit(ip)
121 #define SUBR_PUTC(ip,c,dy,dx,m) (ip)->grf->g_iteputc(ip,c,dy,dx,m)
122 #define SUBR_CURSOR(ip,flg) (ip)->grf->g_itecursor(ip,flg)
123 #define SUBR_CLEAR(ip,sy,sx,h,w) (ip)->grf->g_iteclear(ip,sy,sx,h,w)
124 #define SUBR_SCROLL(ip,sy,sx,cnt,dir) (ip)->grf->g_itescroll(ip,sy,sx,cnt,dir)
126 int start_repeat_timeo
= 30; /* first repeat after x s/100 */
127 int next_repeat_timeo
= 10; /* next repeat after x s/100 */
132 int ite_default_x
= 0; /* def leftedge offset */
133 int ite_default_y
= 0; /* def topedge offset */
134 int ite_default_width
= 640; /* def width */
135 int ite_default_depth
= 1; /* def depth */
136 int ite_default_height
= 400; /* def height */
137 int ite_default_wrap
= 1; /* if you want vtxxx-nam -> binpatch */
139 struct ite_softc con_itesoftc
;
140 u_char cons_tabs
[MAX_TABS
];
142 struct ite_softc
*kbd_ite
;
145 static inline int atoi(const char *);
146 static inline int ite_argnum(struct ite_softc
*);
147 static inline int ite_zargnum(struct ite_softc
*);
148 static inline void ite_cr(struct ite_softc
*);
149 static inline void ite_crlf(struct ite_softc
*);
150 static inline void ite_clrline(struct ite_softc
*);
151 static inline void ite_clrscreen(struct ite_softc
*);
152 static inline void ite_clrtobos(struct ite_softc
*);
153 static inline void ite_clrtobol(struct ite_softc
*);
154 static inline void ite_clrtoeol(struct ite_softc
*);
155 static inline void ite_clrtoeos(struct ite_softc
*);
156 static inline void ite_dnchar(struct ite_softc
*, int);
157 static inline void ite_inchar(struct ite_softc
*, int);
158 static inline void ite_inline(struct ite_softc
*, int);
159 static inline void ite_lf(struct ite_softc
*);
160 static inline void ite_dnline(struct ite_softc
*, int);
161 static inline void ite_rlf(struct ite_softc
*);
162 static inline void ite_sendstr(const char *);
163 static inline void snap_cury(struct ite_softc
*);
165 static void alignment_display(struct ite_softc
*);
166 static struct ite_softc
*getitesp(dev_t
);
167 static void itecheckwrap(struct ite_softc
*);
168 static void iteprecheckwrap(struct ite_softc
*);
169 static void itestart(struct tty
*);
170 static void ite_switch(int);
171 static void repeat_handler(void *);
173 void iteputchar(int c
, struct ite_softc
*ip
);
174 void ite_putstr(const u_char
* s
, int len
, dev_t dev
);
175 void iteattach(struct device
*, struct device
*, void *);
176 int itematch(struct device
*, struct cfdata
*, void *);
179 * Console specific types.
181 dev_type_cnprobe(itecnprobe
);
182 dev_type_cninit(itecninit
);
183 dev_type_cngetc(itecngetc
);
184 dev_type_cnputc(itecnputc
);
186 CFATTACH_DECL(ite
, sizeof(struct ite_softc
),
187 itematch
, iteattach
, NULL
, NULL
);
189 extern struct cfdriver ite_cd
;
191 dev_type_open(iteopen
);
192 dev_type_close(iteclose
);
193 dev_type_read(iteread
);
194 dev_type_write(itewrite
);
195 dev_type_ioctl(iteioctl
);
196 dev_type_tty(itetty
);
197 dev_type_poll(itepoll
);
199 const struct cdevsw ite_cdevsw
= {
200 iteopen
, iteclose
, iteread
, itewrite
, iteioctl
,
201 nostop
, itetty
, itepoll
, nommap
, ttykqfilter
, D_TTY
205 * Keep track of the device number of the ite console. Only used in the
206 * itematch/iteattach functions.
208 static int cons_ite
= -1;
211 itematch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
215 * Handle early console stuff. The first unit number
216 * is the console unit. All other early matches will fail.
218 if (atari_realconfig
== 0) {
221 cons_ite
= cfp
->cf_unit
;
228 iteattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
230 struct grf_softc
*gp
;
231 struct ite_softc
*ip
;
235 gp
= (struct grf_softc
*)auxp
;
236 ip
= (struct ite_softc
*)dp
;
238 maj
= cdevsw_lookup_major(&ite_cdevsw
);
239 unit
= (dp
!= NULL
) ? device_unit(&ip
->device
) : cons_ite
;
240 gp
->g_itedev
= makedev(maj
, unit
);
244 if(con_itesoftc
.grf
!= NULL
245 && con_itesoftc
.grf
->g_unit
== gp
->g_unit
) {
247 * console reinit copy params over.
248 * and console always gets keyboard
250 memcpy(&ip
->grf
, &con_itesoftc
.grf
,
251 (char *)&ip
[1] - (char *)&ip
->grf
);
252 con_itesoftc
.grf
= NULL
;
258 iteinit(gp
->g_itedev
);
259 printf(": %dx%d", ip
->rows
, ip
->cols
);
260 printf(" repeat at (%d/100)s next at (%d/100)s",
261 start_repeat_timeo
, next_repeat_timeo
);
266 printf(" has keyboard");
268 ip
->flags
|= ITE_ATTACHED
;
270 if (con_itesoftc
.grf
!= NULL
&&
271 con_itesoftc
.grf
->g_conpri
> gp
->g_conpri
)
273 con_itesoftc
.grf
= gp
;
274 con_itesoftc
.tabs
= cons_tabs
;
278 static struct ite_softc
*
281 if(atari_realconfig
&& (con_itesoftc
.grf
== NULL
))
282 return(device_lookup_private(&ite_cd
, ITEUNIT(dev
)));
284 if(con_itesoftc
.grf
== NULL
)
285 panic("no ite_softc for console");
286 return(&con_itesoftc
);
290 * cons.c entry points into ite device.
294 * Return a priority in consdev->cn_pri field highest wins. This function
295 * is called before any devices have been probed.
298 itecnprobe(struct consdev
*cd
)
301 * return priority of the best ite (already picked from attach)
304 if (con_itesoftc
.grf
== NULL
)
305 cd
->cn_pri
= CN_DEAD
;
307 cd
->cn_pri
= con_itesoftc
.grf
->g_conpri
;
308 cd
->cn_dev
= con_itesoftc
.grf
->g_itedev
;
313 itecninit(struct consdev
*cd
)
315 struct ite_softc
*ip
;
317 ip
= getitesp(cd
->cn_dev
);
318 ip
->flags
|= ITE_ISCONS
;
320 ip
->flags
|= ITE_ACTIVE
| ITE_ISCONS
;
324 * ite_cnfinish() is called in ite_init() when the device is
325 * being probed in the normal fasion, thus we can finish setting
326 * up this ite now that the system is more functional.
329 ite_cnfinish(struct ite_softc
*ip
)
345 c
= ite_cnfilter(c
, ITEFILT_CONSOLE
);
351 itecnputc(dev_t dev
, int c
)
354 struct ite_softc
*ip
;
360 if (panicstr
&& !paniced
&&
361 (ip
->flags
& (ITE_ACTIVE
| ITE_INGRF
)) != ITE_ACTIVE
) {
365 SUBR_CURSOR(ip
, START_CURSOROPT
);
367 SUBR_CURSOR(ip
, END_CURSOROPT
);
371 * standard entry points to the device.
375 * iteinit() is the standard entry point for initialization of
376 * an ite device, it is also called from itecninit().
382 struct ite_softc
*ip
;
385 if (ip
->flags
& ITE_INITED
)
387 if (atari_realconfig
) {
388 if (ip
->kbdmap
&& ip
->kbdmap
!= &ascii_kbdmap
)
389 free(ip
->kbdmap
, M_DEVBUF
);
390 ip
->kbdmap
= malloc(sizeof(struct kbdmap
), M_DEVBUF
, M_WAITOK
);
391 memcpy(ip
->kbdmap
, &ascii_kbdmap
, sizeof(struct kbdmap
));
393 else ip
->kbdmap
= &ascii_kbdmap
;
398 SUBR_CURSOR(ip
, DRAW_CURSOR
);
399 if (ip
->tabs
== NULL
)
400 ip
->tabs
= malloc(MAX_TABS
* sizeof(u_char
),M_DEVBUF
,M_WAITOK
);
402 ip
->flags
|= ITE_INITED
;
406 iteopen(dev_t dev
, int mode
, int devtype
, struct lwp
*l
)
408 struct ite_softc
*ip
;
410 int error
, first
, unit
;
413 if (unit
>= ite_cd
.cd_ndevs
)
420 if ((ip
->flags
& ITE_ATTACHED
) == 0)
423 if (ip
->tp
== NULL
) {
424 tp
= ip
->tp
= ttymalloc();
429 if (kauth_authorize_device_tty(l
->l_cred
, KAUTH_DEVICE_TTY_OPEN
, tp
))
432 if ((ip
->flags
& ITE_ACTIVE
) == 0) {
436 if (!(tp
->t_state
& TS_ISOPEN
) && tp
->t_wopen
== 0) {
437 tp
->t_oproc
= itestart
;
438 tp
->t_param
= ite_param
;
440 tp
->t_iflag
= TTYDEF_IFLAG
;
441 tp
->t_oflag
= TTYDEF_OFLAG
;
442 tp
->t_cflag
= TTYDEF_CFLAG
;
443 tp
->t_lflag
= TTYDEF_LFLAG
;
444 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
445 tp
->t_state
= TS_CARR_ON
;
451 error
= ttyopen(tp
, 0, (mode
& O_NONBLOCK
) ? 1 : 0);
455 error
= (*tp
->t_linesw
->l_open
) (dev
, tp
);
459 tp
->t_winsize
.ws_row
= ip
->rows
;
460 tp
->t_winsize
.ws_col
= ip
->cols
;
476 iteclose(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
480 tp
= getitesp(dev
)->tp
;
483 (*tp
->t_linesw
->l_close
) (tp
, flag
);
490 iteread(dev_t dev
, struct uio
*uio
, int flag
)
494 tp
= getitesp(dev
)->tp
;
497 return ((*tp
->t_linesw
->l_read
) (tp
, uio
, flag
));
501 itewrite(dev_t dev
, struct uio
*uio
, int flag
)
505 tp
= getitesp(dev
)->tp
;
508 return ((*tp
->t_linesw
->l_write
) (tp
, uio
, flag
));
512 itepoll(dev_t dev
, int events
, struct lwp
*l
)
516 tp
= getitesp(dev
)->tp
;
519 return ((*tp
->t_linesw
->l_poll
)(tp
, events
, l
));
525 return(getitesp(dev
)->tp
);
529 iteioctl(dev_t dev
, u_long cmd
, void * addr
, int flag
, struct lwp
*l
)
531 struct iterepeat
*irp
;
532 struct ite_softc
*ip
;
535 struct itewinsize
*is
;
541 view
= viewview(ip
->grf
->g_viewdev
);
545 error
= (*tp
->t_linesw
->l_ioctl
) (tp
, cmd
, addr
, flag
, l
);
546 if(error
!= EPASSTHROUGH
)
549 error
= ttioctl(tp
, cmd
, addr
, flag
, l
);
550 if (error
!= EPASSTHROUGH
)
557 memcpy(ip
->kbdmap
, addr
, sizeof(struct kbdmap
));
562 memcpy(&ascii_kbdmap
, addr
, sizeof(struct kbdmap
));
567 memcpy(addr
, ip
->kbdmap
, sizeof(struct kbdmap
));
572 irp
= (struct iterepeat
*)addr
;
573 irp
->start
= start_repeat_timeo
;
574 irp
->next
= next_repeat_timeo
;
579 irp
= (struct iterepeat
*)addr
;
580 if (irp
->start
< ITEMINREPEAT
|| irp
->next
< ITEMINREPEAT
)
582 start_repeat_timeo
= irp
->start
;
583 next_repeat_timeo
= irp
->next
;
588 is
= (struct itewinsize
*)addr
;
589 is
->x
= view
->display
.x
;
590 is
->y
= view
->display
.y
;
591 is
->width
= view
->display
.width
;
592 is
->height
= view
->display
.height
;
593 is
->depth
= view
->bitmap
->depth
;
596 ip
->grf
->g_mode(ip
->grf
, GM_GRFON
, NULL
, 0, 0);
599 ip
->grf
->g_mode(ip
->grf
, GM_GRFOFF
, NULL
, 0, 0);
604 ib
= (struct itebell
*)addr
;
605 kbd_bell_sparms(ib
->volume
, ib
->pitch
, ib
->msec
);
610 ib
= (struct itebell
*)addr
;
611 kbd_bell_gparms(&ib
->volume
, &ib
->pitch
, &ib
->msec
);
614 return (ip
->itexx_ioctl
)(ip
, cmd
, addr
, flag
, l
);
618 itestart(struct tty
*tp
)
621 struct ite_softc
*ip
;
622 u_char buf
[ITEBURST
];
625 ip
= getitesp(tp
->t_dev
);
630 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
633 tp
->t_state
|= TS_BUSY
;
636 len
= q_to_b(rbp
, buf
, ITEBURST
);
639 /* Here is a really good place to implement pre/jumpscroll() */
640 ite_putstr((char *)buf
, len
, tp
->t_dev
);
643 tp
->t_state
&= ~TS_BUSY
;
644 /* we have characters remaining. */
646 tp
->t_state
|= TS_TIMEOUT
;
647 callout_schedule(&tp
->t_rstrt_ch
, 1);
654 ite_on(dev_t dev
, int flag
)
656 struct ite_softc
*ip
;
662 /* force ite active, overriding graphics mode */
664 ip
->flags
|= ITE_ACTIVE
;
665 ip
->flags
&= ~(ITE_INGRF
| ITE_INITED
);
667 /* leave graphics mode */
669 ip
->flags
&= ~ITE_INGRF
;
670 if ((ip
->flags
& ITE_ACTIVE
) == 0)
673 ip
->flags
|= ITE_ACTIVE
;
674 if (ip
->flags
& ITE_INGRF
)
680 ite_off(dev_t dev
, int flag
)
682 struct ite_softc
*ip
;
686 ip
->flags
|= ITE_INGRF
;
687 if ((ip
->flags
& ITE_ACTIVE
) == 0)
690 (ip
->flags
& (ITE_INGRF
| ITE_ISCONS
| ITE_INITED
)) == ITE_INITED
)
692 if ((flag
& 2) == 0) /* XXX hmm grfon() I think wants this to go inactive. */
693 ip
->flags
&= ~ITE_ACTIVE
;
699 struct ite_softc
*ip
;
700 extern const struct cdevsw view_cdevsw
;
703 if ((ip
->flags
& (ITE_ATTACHED
| ITE_INITED
)) == 0)
707 * If switching to an active ite, also switch the keyboard.
709 if (ip
->flags
& ITE_ACTIVE
)
713 * Now make it visible
715 (*view_cdevsw
.d_ioctl
)(ip
->grf
->g_viewdev
, VIOCDISPLAY
, NULL
,
719 * Make sure the cursor's there too....
721 SUBR_CURSOR(ip
, DRAW_CURSOR
);
724 /* XXX called after changes made in underlying grf layer. */
725 /* I want to nuke this */
727 ite_reinit(dev_t dev
)
729 struct ite_softc
*ip
;
732 ip
->flags
&= ~ITE_INITED
;
737 ite_param(struct tty
*tp
, struct termios
*t
)
739 tp
->t_ispeed
= t
->c_ispeed
;
740 tp
->t_ospeed
= t
->c_ospeed
;
741 tp
->t_cflag
= t
->c_cflag
;
746 ite_reset(struct ite_softc
*ip
)
752 ip
->attribute
= ATTR_NOR
;
755 ip
->save_attribute
= ATTR_NOR
;
760 ip
->bottom_margin
= ip
->rows
- 1;
761 ip
->inside_margins
= 0;
762 ip
->linefeed_newline
= 0;
763 ip
->auto_wrap
= ite_default_wrap
;
764 ip
->cursor_appmode
= 0;
765 ip
->keypad_appmode
= 0;
768 memset(ip
->tabs
, 0, ip
->cols
);
769 for (i
= 0; i
< ip
->cols
; i
++)
770 ip
->tabs
[i
] = ((i
& 7) == 0);
774 * has to be global because of the shared filters.
776 static u_char last_dead
;
779 * Used in console at startup only and for DDB.
782 ite_cnfilter(u_int c
, enum caller caller
)
785 struct kbdmap
*kbdmap
;
786 u_char code
, up
, mask
;
789 up
= KBD_RELEASED(c
);
793 kbdmap
= (kbd_ite
== NULL
) ? &ascii_kbdmap
: kbd_ite
->kbdmap
;
798 * No special action if key released
805 /* translate modifiers */
806 if(kbd_modifier
& KBD_MOD_SHIFT
) {
807 if(kbd_modifier
& KBD_MOD_ALT
)
808 key
= kbdmap
->alt_shift_keys
[c
];
809 else key
= kbdmap
->shift_keys
[c
];
811 else if(kbd_modifier
& KBD_MOD_ALT
)
812 key
= kbdmap
->alt_keys
[c
];
814 key
= kbdmap
->keys
[c
];
816 * If CAPS and key is CAPable (no pun intended)
818 if((kbd_modifier
& KBD_MOD_CAPS
) && (key
.mode
& KBD_MODE_CAPS
))
819 key
= kbdmap
->shift_keys
[c
];
823 #ifdef notyet /* LWP: Didn't have time to look at this yet */
825 * If string return simple console filter
827 if(key
->mode
& (KBD_MODE_STRING
| KBD_MODE_KPAD
)) {
831 /* handle dead keys */
832 if(key
->mode
& KBD_MODE_DEAD
) {
833 /* if entered twice, send accent itself */
834 if (last_dead
== key
->mode
& KBD_MODE_ACCMASK
)
837 last_dead
= key
->mode
& KBD_MODE_ACCMASK
;
843 /* can't apply dead flag to string-keys */
844 if (code
>= '@' && code
< 0x7f)
846 acctable
[KBD_MODE_ACCENT(last_dead
)][code
- '@'];
850 if(kbd_modifier
& KBD_MOD_CTRL
)
854 * Do console mapping.
856 code
= code
== '\r' ? '\n' : code
;
862 /* And now the old stuff. */
864 /* these are used to implement repeating keys.. */
865 static u_int last_char
;
866 static u_char tout_pending
;
868 static callout_t repeat_ch
;
872 repeat_handler(void *arg
)
876 add_sicallback((si_farg
)ite_filter
, (void *)last_char
,
877 (void *)ITEFILT_REPEATER
);
881 ite_filter(u_int c
, enum caller caller
)
884 struct kbdmap
*kbdmap
;
885 u_char code
, *str
, up
, mask
;
892 callout_init(&repeat_ch
, 0);
899 kbd_tty
= kbd_ite
->tp
;
900 kbdmap
= kbd_ite
->kbdmap
;
902 up
= KBD_RELEASED(c
);
907 /* have to make sure we're at spltty in here */
911 * keyboard interrupts come at priority 2, while softint
912 * generated keyboard-repeat interrupts come at level 1. So,
913 * to not allow a key-up event to get thru before a repeat for
914 * the key-down, we remove any outstanding callout requests..
916 rem_sicallback((si_farg
)ite_filter
);
919 * Stop repeating on up event
923 callout_stop(&repeat_ch
);
930 else if(tout_pending
&& last_char
!= c
) {
932 * Different character, stop also
934 callout_stop(&repeat_ch
);
940 * Handle ite-switching ALT + Fx
942 if((kbd_modifier
== KBD_MOD_ALT
) && (c
>= 0x3b) && (c
<= 0x44)) {
943 ite_switch(c
- 0x3b);
948 * Safety button, switch back to ascii keymap.
950 if(kbd_modifier
== (KBD_MOD_ALT
| KBD_MOD_LSHIFT
) && c
== 0x3b) {
951 /* ALT + LSHIFT + F1 */
952 memcpy(kbdmap
, &ascii_kbdmap
, sizeof(struct kbdmap
));
957 else if(kbd_modifier
== (KBD_MOD_ALT
| KBD_MOD_LSHIFT
) && c
== 0x43) {
959 * ALT + LSHIFT + F9 -> Debugger!
968 * The rest of the code is senseless when the device is not open.
970 if(kbd_tty
== NULL
) {
976 * Translate modifiers
978 if(kbd_modifier
& KBD_MOD_SHIFT
) {
979 if(kbd_modifier
& KBD_MOD_ALT
)
980 key
= kbdmap
->alt_shift_keys
[c
];
981 else key
= kbdmap
->shift_keys
[c
];
983 else if(kbd_modifier
& KBD_MOD_ALT
)
984 key
= kbdmap
->alt_keys
[c
];
986 key
= kbdmap
->keys
[c
];
988 * If CAPS and key is CAPable (no pun intended)
990 if((kbd_modifier
& KBD_MOD_CAPS
) && (key
.mode
& KBD_MODE_CAPS
))
991 key
= kbdmap
->shift_keys
[c
];
996 * Arrange to repeat the keystroke. By doing this at the level
997 * of scan-codes, we can have function keys, and keys that
998 * send strings, repeat too. This also entitles an additional
999 * overhead, since we have to do the conversion each time, but
1000 * I guess that's ok.
1002 if(!tout_pending
&& caller
== ITEFILT_TTY
&& kbd_ite
->key_repeat
) {
1005 callout_reset(&repeat_ch
, start_repeat_timeo
* hz
/ 100,
1006 repeat_handler
, NULL
);
1008 else if(!tout_pending
&& caller
==ITEFILT_REPEATER
1009 && kbd_ite
->key_repeat
) {
1012 callout_reset(&repeat_ch
, next_repeat_timeo
* hz
/ 100,
1013 repeat_handler
, NULL
);
1015 /* handle dead keys */
1016 if (key
.mode
& KBD_MODE_DEAD
) {
1017 /* if entered twice, send accent itself */
1018 if (last_dead
== (key
.mode
& KBD_MODE_ACCMASK
))
1021 last_dead
= key
.mode
& KBD_MODE_ACCMASK
;
1027 /* can't apply dead flag to string-keys */
1028 if (!(key
.mode
& KBD_MODE_STRING
) && code
>= '@' &&
1030 code
= acctable
[KBD_MODE_ACCENT(last_dead
)][code
- '@'];
1035 * If not string, apply CTRL modifiers
1037 if(!(key
.mode
& KBD_MODE_STRING
)
1038 && (!(key
.mode
& KBD_MODE_KPAD
)
1039 || (kbd_ite
&& !kbd_ite
->keypad_appmode
))) {
1040 if(kbd_modifier
& KBD_MOD_CTRL
)
1043 else if((key
.mode
& KBD_MODE_KPAD
)
1044 && (kbd_ite
&& kbd_ite
->keypad_appmode
)) {
1045 static const char * const in
= "0123456789-+.\r()/*";
1046 static const char * const out
= "pqrstuvwxymlnMPQRS";
1047 char *cp
= strchr(in
, code
);
1050 * keypad-appmode sends SS3 followed by the above
1051 * translated character
1053 kbd_tty
->t_linesw
->l_rint(27, kbd_tty
);
1054 kbd_tty
->t_linesw
->l_rint('O', kbd_tty
);
1055 kbd_tty
->t_linesw
->l_rint(out
[cp
- in
], kbd_tty
);
1059 /* *NO* I don't like this.... */
1060 static u_char app_cursor
[] =
1067 str
= kbdmap
->strings
+ code
;
1069 * if this is a cursor key, AND it has the default
1070 * keymap setting, AND we're in app-cursor mode, switch
1071 * to the above table. This is *nasty* !
1073 if(((c
== 0x48) || (c
== 0x4b) || (c
== 0x4d) || (c
== 0x50))
1074 && kbd_ite
->cursor_appmode
1075 && !memcmp(str
, "\x03\x1b[", 3) &&
1076 strchr("ABCD", str
[3]))
1077 str
= app_cursor
+ 4 * (str
[3] - 'A');
1080 * using a length-byte instead of 0-termination allows
1081 * to embed \0 into strings, although this is not used
1082 * in the default keymap
1084 for (i
= *str
++; i
; i
--)
1085 kbd_tty
->t_linesw
->l_rint(*str
++, kbd_tty
);
1089 kbd_tty
->t_linesw
->l_rint(code
, kbd_tty
);
1095 /* helper functions, makes the code below more readable */
1097 ite_sendstr(const char *str
)
1099 struct tty
*kbd_tty
;
1101 kbd_tty
= kbd_ite
->tp
;
1104 kbd_tty
->t_linesw
->l_rint(*str
++, kbd_tty
);
1108 alignment_display(struct ite_softc
*ip
)
1112 for (j
= 0; j
< ip
->rows
; j
++)
1113 for (i
= 0; i
< ip
->cols
; i
++)
1114 SUBR_PUTC(ip
, 'E', j
, i
, ATTR_NOR
);
1115 attrclr(ip
, 0, 0, ip
->rows
, ip
->cols
);
1116 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1120 snap_cury(struct ite_softc
*ip
)
1122 if (ip
->inside_margins
)
1124 if (ip
->cury
< ip
->top_margin
)
1125 ip
->cury
= ip
->top_margin
;
1126 if (ip
->cury
> ip
->bottom_margin
)
1127 ip
->cury
= ip
->bottom_margin
;
1132 ite_dnchar(struct ite_softc
*ip
, int n
)
1134 n
= min(n
, ip
->cols
- ip
->curx
);
1135 if (n
< ip
->cols
- ip
->curx
)
1137 SUBR_SCROLL(ip
, ip
->cury
, ip
->curx
+ n
, n
, SCROLL_LEFT
);
1138 attrmov(ip
, ip
->cury
, ip
->curx
+ n
, ip
->cury
, ip
->curx
,
1139 1, ip
->cols
- ip
->curx
- n
);
1140 attrclr(ip
, ip
->cury
, ip
->cols
- n
, 1, n
);
1143 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->cols
- n
- 1, ATTR_NOR
);
1144 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1148 ite_inchar(struct ite_softc
*ip
, int n
)
1150 n
= min(n
, ip
->cols
- ip
->curx
);
1151 if (n
< ip
->cols
- ip
->curx
)
1153 SUBR_SCROLL(ip
, ip
->cury
, ip
->curx
, n
, SCROLL_RIGHT
);
1154 attrmov(ip
, ip
->cury
, ip
->curx
, ip
->cury
, ip
->curx
+ n
,
1155 1, ip
->cols
- ip
->curx
- n
);
1156 attrclr(ip
, ip
->cury
, ip
->curx
, 1, n
);
1159 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->curx
+ n
, ATTR_NOR
);
1160 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1164 ite_clrtoeol(struct ite_softc
*ip
)
1166 int y
= ip
->cury
, x
= ip
->curx
;
1167 if (ip
->cols
- x
> 0)
1169 SUBR_CLEAR(ip
, y
, x
, 1, ip
->cols
- x
);
1170 attrclr(ip
, y
, x
, 1, ip
->cols
- x
);
1171 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1176 ite_clrtobol(struct ite_softc
*ip
)
1178 int y
= ip
->cury
, x
= min(ip
->curx
+ 1, ip
->cols
);
1179 SUBR_CLEAR(ip
, y
, 0, 1, x
);
1180 attrclr(ip
, y
, 0, 1, x
);
1181 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1185 ite_clrline(struct ite_softc
*ip
)
1188 SUBR_CLEAR(ip
, y
, 0, 1, ip
->cols
);
1189 attrclr(ip
, y
, 0, 1, ip
->cols
);
1190 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1196 ite_clrtoeos(struct ite_softc
*ip
)
1199 if (ip
->cury
< ip
->rows
- 1)
1201 SUBR_CLEAR(ip
, ip
->cury
+ 1, 0, ip
->rows
- 1 - ip
->cury
, ip
->cols
);
1202 attrclr(ip
, ip
->cury
, 0, ip
->rows
- ip
->cury
, ip
->cols
);
1203 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1208 ite_clrtobos(struct ite_softc
*ip
)
1213 SUBR_CLEAR(ip
, 0, 0, ip
->cury
, ip
->cols
);
1214 attrclr(ip
, 0, 0, ip
->cury
, ip
->cols
);
1215 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1220 ite_clrscreen(struct ite_softc
*ip
)
1222 SUBR_CLEAR(ip
, 0, 0, ip
->rows
, ip
->cols
);
1223 attrclr(ip
, 0, 0, ip
->rows
, ip
->cols
);
1224 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1230 ite_dnline(struct ite_softc
*ip
, int n
)
1232 /* interesting.. if the cursor is outside the scrolling
1233 region, this command is simply ignored.. */
1234 if (ip
->cury
< ip
->top_margin
|| ip
->cury
> ip
->bottom_margin
)
1237 n
= min(n
, ip
->bottom_margin
+ 1 - ip
->cury
);
1238 if (n
<= ip
->bottom_margin
- ip
->cury
)
1240 SUBR_SCROLL(ip
, ip
->cury
+ n
, 0, n
, SCROLL_UP
);
1241 attrmov(ip
, ip
->cury
+ n
, 0, ip
->cury
, 0,
1242 ip
->bottom_margin
+ 1 - ip
->cury
- n
, ip
->cols
);
1244 SUBR_CLEAR(ip
, ip
->bottom_margin
- n
+ 1, 0, n
, ip
->cols
);
1245 attrclr(ip
, ip
->bottom_margin
- n
+ 1, 0, n
, ip
->cols
);
1246 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1250 ite_inline(struct ite_softc
*ip
, int n
)
1252 /* interesting.. if the cursor is outside the scrolling
1253 region, this command is simply ignored.. */
1254 if (ip
->cury
< ip
->top_margin
|| ip
->cury
> ip
->bottom_margin
)
1257 n
= min(n
, ip
->bottom_margin
+ 1 - ip
->cury
);
1258 if (n
<= ip
->bottom_margin
- ip
->cury
)
1260 SUBR_SCROLL(ip
, ip
->cury
, 0, n
, SCROLL_DOWN
);
1261 attrmov(ip
, ip
->cury
, 0, ip
->cury
+ n
, 0,
1262 ip
->bottom_margin
+ 1 - ip
->cury
- n
, ip
->cols
);
1264 SUBR_CLEAR(ip
, ip
->cury
, 0, n
, ip
->cols
);
1265 attrclr(ip
, ip
->cury
, 0, n
, ip
->cols
);
1266 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1270 ite_lf (struct ite_softc
*ip
)
1273 if ((ip
->cury
== ip
->bottom_margin
+1) || (ip
->cury
== ip
->rows
))
1276 SUBR_SCROLL(ip
, ip
->top_margin
+ 1, 0, 1, SCROLL_UP
);
1279 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1280 clr_attr(ip
, ATTR_INV
);
1284 ite_crlf (struct ite_softc
*ip
)
1291 ite_cr (struct ite_softc
*ip
)
1296 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1301 ite_rlf (struct ite_softc
*ip
)
1304 if ((ip
->cury
< 0) || (ip
->cury
== ip
->top_margin
- 1))
1307 SUBR_SCROLL(ip
, ip
->top_margin
, 0, 1, SCROLL_DOWN
);
1310 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1311 clr_attr(ip
, ATTR_INV
);
1315 atoi (const char *cp
)
1319 for (n
= 0; *cp
&& *cp
>= '0' && *cp
<= '9'; cp
++)
1320 n
= n
* 10 + *cp
- '0';
1326 ite_argnum (struct ite_softc
*ip
)
1331 /* convert argument string into number */
1332 if (ip
->ap
== ip
->argbuf
)
1336 n
= atoi (ip
->argbuf
);
1343 ite_zargnum (struct ite_softc
*ip
)
1348 /* convert argument string into number */
1349 if (ip
->ap
== ip
->argbuf
)
1353 n
= atoi (ip
->argbuf
);
1356 return n
; /* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
1360 ite_putstr(const u_char
*s
, int len
, dev_t dev
)
1362 struct ite_softc
*ip
;
1367 /* XXX avoid problems */
1368 if ((ip
->flags
& (ITE_ACTIVE
|ITE_INGRF
)) != ITE_ACTIVE
)
1371 SUBR_CURSOR(ip
, START_CURSOROPT
);
1372 for (i
= 0; i
< len
; i
++)
1374 iteputchar(s
[i
], ip
);
1375 SUBR_CURSOR(ip
, END_CURSOROPT
);
1380 iteputchar(register int c
, struct ite_softc
*ip
)
1382 struct tty
*kbd_tty
;
1386 if (kbd_ite
== NULL
)
1389 kbd_tty
= kbd_ite
->tp
;
1398 /* first 7bit equivalents for the 8bit control characters */
1403 break; /* and fall into the next switch below (same for all `break') */
1461 /* introduces 7/8bit control */
1463 /* can be followed by either F or G */
1468 /* a lot of character set selections, not yet used...
1469 94-character sets: */
1477 case 'B': /* ASCII */
1478 case 'A': /* ISO latin 1 */
1479 case '<': /* user preferred suplemental */
1480 case '0': /* dec special graphics */
1482 /* 96-character sets: */
1487 /* national character sets: */
1488 case '4': /* dutch */
1490 case 'C': /* finnish */
1491 case 'R': /* french */
1492 case 'Q': /* french canadian */
1493 case 'K': /* german */
1494 case 'Y': /* italian */
1495 case '6': /* norwegian/danish */
1496 /* note: %5 and %6 are not supported (two chars..) */
1499 /* just ignore for now */
1503 /* locking shift modes (as you might guess, not yet supported..) */
1530 /* font width/height control */
1536 /* hard terminal reset .. */
1539 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1545 ip
->save_curx
= ip
->curx
;
1546 ip
->save_cury
= ip
->cury
;
1547 ip
->save_attribute
= ip
->attribute
;
1552 ip
->curx
= ip
->save_curx
;
1553 ip
->cury
= ip
->save_cury
;
1554 ip
->attribute
= ip
->save_attribute
;
1555 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1560 ip
->keypad_appmode
= 1;
1565 ip
->keypad_appmode
= 0;
1569 case 'Z': /* request ID */
1570 if (ip
->emul_level
== EMUL_VT100
)
1571 ite_sendstr ("\033[?61;0c"); /* XXX not clean */
1573 ite_sendstr ("\033[?63;0c"); /* XXX not clean */
1577 /* default catch all for not recognized ESC sequences */
1595 ip
->eightbit_C1
= 0;
1600 ip
->eightbit_C1
= 1;
1616 /* single height, single width */
1621 /* double width, single height */
1636 /* screen alignment pattern... */
1637 alignment_display (ip
);
1653 case '0': case '1': case '2': case '3': case '4':
1654 case '5': case '6': case '7': case '8': case '9':
1655 case ';': case '\"': case '$': case '>':
1656 if (ip
->ap
< ip
->argbuf
+ MAX_ARGSIZE
)
1661 /* you wouldn't believe such perversion is possible?
1662 it is.. BS is allowed in between cursor sequences
1663 (at least), according to vttest.. */
1667 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1672 if (! strncmp (ip
->argbuf
, "61\"", 3))
1673 ip
->emul_level
= EMUL_VT100
;
1674 else if (! strncmp (ip
->argbuf
, "63;1\"", 5)
1675 || ! strncmp (ip
->argbuf
, "62;1\"", 5))
1676 ip
->emul_level
= EMUL_VT300_7
;
1678 ip
->emul_level
= EMUL_VT300_8
;
1686 ip
->ap
= ip
->argbuf
;
1692 if (ip
->argbuf
[0] == '>')
1694 ite_sendstr ("\033[>24;0;0;0c");
1696 else switch (ite_zargnum(ip
))
1699 /* primary DA request, send primary DA response */
1700 if (ip
->emul_level
== EMUL_VT100
)
1701 ite_sendstr ("\033[?1;1c");
1703 ite_sendstr ("\033[?63;1c");
1710 switch (ite_zargnum(ip
))
1713 ite_sendstr ("\033[0n"); /* no malfunction */
1716 /* cursor position report */
1717 sprintf (ip
->argbuf
, "\033[%d;%dR",
1718 ip
->cury
+ 1, ip
->curx
+ 1);
1719 ite_sendstr (ip
->argbuf
);
1727 switch (ite_zargnum(ip
))
1730 /* Fake some terminal parameters. */
1731 ite_sendstr ("\033[2;1;1;112;112;1;0x");
1734 ite_sendstr ("\033[3;1;1;112;112;1;0x");
1742 switch (ite_zargnum(ip
))
1745 if (ip
->curx
< ip
->cols
)
1746 ip
->tabs
[ip
->curx
] = 0;
1749 for (n
= 0; n
< ip
->cols
; n
++)
1758 n
= ite_zargnum (ip
);
1762 ip
->imode
= (c
== 'h'); /* insert/replace mode */
1765 ip
->linefeed_newline
= (c
== 'h');
1773 ite_dnline (ip
, ite_argnum (ip
));
1779 ite_inline (ip
, ite_argnum (ip
));
1785 ite_dnchar (ip
, ite_argnum (ip
));
1791 ite_inchar (ip
, ite_argnum (ip
));
1797 /* this one was *not* in my vt320 manual but in
1798 a vt320 termcap entry.. who is right?
1799 It's supposed to set the horizontal cursor position. */
1801 x
= atoi (ip
->argbuf
);
1803 ip
->curx
= min(x
, ip
->cols
- 1);
1805 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1806 clr_attr (ip
, ATTR_INV
);
1811 /* same thing here, this one's for setting the absolute
1812 vertical cursor position. Not documented... */
1814 y
= atoi (ip
->argbuf
);
1816 if (ip
->inside_margins
)
1817 y
+= ip
->top_margin
;
1818 ip
->cury
= min(y
, ip
->rows
- 1);
1821 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1822 clr_attr (ip
, ATTR_INV
);
1829 y
= atoi (ip
->argbuf
);
1831 cp
= strchr(ip
->argbuf
, ';');
1836 if (ip
->inside_margins
)
1837 y
+= ip
->top_margin
;
1838 ip
->cury
= min(y
, ip
->rows
- 1);
1839 ip
->curx
= min(x
, ip
->cols
- 1);
1842 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1843 clr_attr (ip
, ATTR_INV
);
1847 n
= ite_argnum (ip
);
1848 n
= ip
->cury
- (n
? n
: 1);
1850 if (ip
->inside_margins
)
1851 n
= max(ip
->top_margin
, n
);
1852 else if (n
== ip
->top_margin
- 1)
1853 /* allow scrolling outside region, but don't scroll out
1854 of active region without explicit CUP */
1858 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1859 clr_attr (ip
, ATTR_INV
);
1863 n
= ite_argnum (ip
);
1864 n
= ip
->cury
+ (n
? n
: 1);
1865 n
= min(ip
->rows
- 1, n
);
1866 if (ip
->inside_margins
)
1867 n
= min(ip
->bottom_margin
, n
);
1868 else if (n
== ip
->bottom_margin
+ 1)
1869 /* allow scrolling outside region, but don't scroll out
1870 of active region without explicit CUP */
1871 n
= ip
->bottom_margin
;
1874 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1875 clr_attr (ip
, ATTR_INV
);
1879 n
= ite_argnum (ip
);
1881 ip
->curx
= min(ip
->curx
+ n
, ip
->cols
- 1);
1883 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1884 clr_attr (ip
, ATTR_INV
);
1888 n
= ite_argnum (ip
);
1891 ip
->curx
= n
>= 0 ? n
: 0;
1893 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1894 clr_attr (ip
, ATTR_INV
);
1902 n
= ite_zargnum (ip
);
1914 n
= ite_zargnum (ip
);
1926 n
= ite_argnum(ip
) - 1;
1927 n
= min(n
, ip
->cols
- 1 - ip
->curx
);
1930 attrclr(ip
, ip
->cury
, ip
->curx
+ n
, 1, 1);
1931 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->curx
+ n
, ATTR_NOR
);
1938 /* status line control */
1945 x
= atoi (ip
->argbuf
);
1948 cp
= strchr(ip
->argbuf
, ';');
1952 y
= y
? y
: ip
->rows
;
1956 /* if illegal scrolling region, reset to defaults */
1962 ip
->top_margin
= min(x
, ip
->rows
- 1);
1963 ip
->bottom_margin
= min(y
, ip
->rows
- 1);
1964 if (ip
->inside_margins
)
1966 ip
->cury
= ip
->top_margin
;
1968 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1975 /* big attribute setter/resetter */
1979 /* kludge to make CSIm work (== CSI0m) */
1980 if (ip
->ap
== ip
->argbuf
)
1982 for (chp
= ip
->argbuf
; chp
< ip
->ap
; )
1988 clr_attr (ip
, ATTR_ALL
);
1993 set_attr (ip
, ATTR_BOLD
);
2001 clr_attr (ip
, ATTR_BOLD
);
2006 clr_attr (ip
, ATTR_UL
);
2011 clr_attr (ip
, ATTR_BLINK
);
2016 clr_attr (ip
, ATTR_INV
);
2027 set_attr (ip
, ATTR_UL
);
2032 set_attr (ip
, ATTR_BLINK
);
2037 set_attr (ip
, ATTR_INV
);
2054 ite_sendstr ("\033P\033\\");
2068 case '?': /* CSI ? */
2071 case '0': case '1': case '2': case '3': case '4':
2072 case '5': case '6': case '7': case '8': case '9':
2073 case ';': case '\"': case '$':
2074 /* Don't fill the last character; it's needed. */
2075 /* XXX yeah, where ?? */
2076 if (ip
->ap
< ip
->argbuf
+ MAX_ARGSIZE
- 1)
2083 if (ip
->ap
== &ip
->argbuf
[2])
2085 if (! strncmp (ip
->argbuf
, "15", 2))
2086 /* printer status: no printer */
2087 ite_sendstr ("\033[13n");
2089 else if (! strncmp (ip
->argbuf
, "25", 2))
2091 ite_sendstr ("\033[20n");
2093 else if (! strncmp (ip
->argbuf
, "26", 2))
2094 /* keyboard dialect: US */
2095 ite_sendstr ("\033[27;1n");
2102 n
= ite_zargnum (ip
);
2106 ip
->cursor_appmode
= (c
== 'h');
2110 /* 132/80 columns (132 == 'h') */
2113 case 4: /* smooth scroll */
2117 /* light background (=='h') /dark background(=='l') */
2120 case 6: /* origin mode */
2121 ip
->inside_margins
= (c
== 'h');
2123 ip
->cury
= ip
->inside_margins
? ip
->top_margin
: 0;
2124 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2127 case 7: /* auto wraparound */
2128 ip
->auto_wrap
= (c
== 'h');
2131 case 8: /* keyboard repeat */
2132 ip
->key_repeat
= (c
== 'h');
2135 case 20: /* newline mode */
2136 ip
->linefeed_newline
= (c
== 'h');
2139 case 25: /* cursor on/off */
2140 SUBR_CURSOR(ip
, (c
== 'h') ? DRAW_CURSOR
: ERASE_CURSOR
);
2161 case VT
: /* VT is treated like LF */
2162 case FF
: /* so is FF */
2164 /* cr->crlf distinction is done here, on output,
2166 if (ip
->linefeed_newline
)
2180 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2184 for (n
= ip
->curx
+ 1; n
< ip
->cols
; n
++) {
2187 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2194 if(kbd_tty
&& kbd_ite
&& kbd_ite
->tp
== kbd_tty
)
2207 /* send answer-back message !! */
2211 ip
->escape
= 0; /* cancel any escape sequence in progress */
2215 ip
->escape
= 0; /* dito, but see below */
2216 /* should also display a reverse question mark!! */
2224 /* now it gets weird.. 8bit control sequences.. */
2225 case IND
: /* index: move cursor down, scroll */
2229 case NEL
: /* next line. next line, first pos. */
2233 case HTS
: /* set horizontal tab */
2234 if (ip
->curx
< ip
->cols
)
2235 ip
->tabs
[ip
->curx
] = 1;
2238 case RI
: /* reverse index */
2242 case SS2
: /* go into G2 for one character */
2243 /* not yet supported */
2246 case SS3
: /* go into G3 for one character */
2249 case DCS
: /* device control string introducer */
2251 ip
->ap
= ip
->argbuf
;
2254 case CSI
: /* control sequence introducer */
2256 ip
->ap
= ip
->argbuf
;
2259 case ST
: /* string terminator */
2260 /* ignore, if not used as terminator */
2263 case OSC
: /* introduces OS command. Ignore everything upto ST */
2267 case PM
: /* privacy message, ignore everything upto ST */
2271 case APC
: /* application program command, ignore everything upto ST */
2276 if (c
< ' ' || c
== DEL
)
2280 iteprecheckwrap(ip
);
2281 #ifdef DO_WEIRD_ATTRIBUTES
2282 if ((ip
->attribute
& ATTR_INV
) || attrtest(ip
, ATTR_INV
)) {
2283 attrset(ip
, ATTR_INV
);
2284 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ATTR_INV
);
2287 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ATTR_NOR
);
2289 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ip
->attribute
);
2291 SUBR_CURSOR(ip
, DRAW_CURSOR
);
2298 iteprecheckwrap(struct ite_softc
*ip
)
2300 if (ip
->auto_wrap
&& ip
->curx
== ip
->cols
) {
2302 clr_attr(ip
, ATTR_INV
);
2303 if (++ip
->cury
>= ip
->bottom_margin
+ 1) {
2304 ip
->cury
= ip
->bottom_margin
;
2305 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2306 SUBR_SCROLL(ip
, ip
->top_margin
+ 1, 0, 1, SCROLL_UP
);
2309 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2314 itecheckwrap(struct ite_softc
*ip
)
2316 if (ip
->curx
< ip
->cols
) {
2318 SUBR_CURSOR(ip
, MOVE_CURSOR
);