1 /* $NetBSD: ite.c,v 1.88 2009/05/19 18:39:26 phx 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 * @(#)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 * @(#)ite.c 7.6 (Berkeley) 5/16/91
78 * ite - bitmaped terminal.
79 * Supports VT200, a few terminal features will be unavailable until
80 * the system actually probes the device (i.e. not after consinit())
85 #include <sys/cdefs.h>
86 __KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.88 2009/05/19 18:39:26 phx Exp $");
88 #include <sys/param.h>
89 #include <sys/kernel.h>
90 #include <sys/device.h>
91 #include <sys/fcntl.h>
92 #include <sys/malloc.h>
93 #include <sys/ioctl.h>
95 #include <sys/termios.h>
96 #include <sys/systm.h>
97 #include <sys/callout.h>
100 #include <sys/kauth.h>
101 #include <amiga/amiga/cc.h>
102 #include <amiga/amiga/color.h> /* DEBUG */
103 #include <amiga/amiga/custom.h> /* DEBUG */
104 #include <amiga/amiga/device.h>
105 #include <amiga/amiga/isr.h>
106 #include <amiga/dev/iteioctl.h>
107 #include <amiga/dev/itevar.h>
108 #include <amiga/dev/kbdmap.h>
109 #include <amiga/dev/grfioctl.h>
110 #include <amiga/dev/grfvar.h>
112 #include <machine/cpu.h> /* for is_draco() */
114 #include <sys/conf.h>
120 * XXX go ask sys/kern/tty.c:ttselect()
123 #define ITEUNIT(dev) (minor(dev))
125 #define SUBR_INIT(ip) (ip)->grf->g_iteinit(ip)
126 #define SUBR_DEINIT(ip) (ip)->grf->g_itedeinit(ip)
127 #define SUBR_PUTC(ip,c,dy,dx,m) (ip)->grf->g_iteputc(ip,c,dy,dx,m)
128 #define SUBR_CURSOR(ip,flg) (ip)->grf->g_itecursor(ip,flg)
129 #define SUBR_CLEAR(ip,sy,sx,h,w) (ip)->grf->g_iteclear(ip,sy,sx,h,w)
130 #define SUBR_SCROLL(ip,sy,sx,count,dir) \
131 (ip)->grf->g_itescroll(ip,sy,sx,count,dir)
133 int start_repeat_timeo
= 30; /* first repeat after x s/100 */
134 int next_repeat_timeo
= 10; /* next repeat after x s/100 */
136 int ite_default_wrap
= 1; /* you want vtxxx-nam, binpatch */
138 struct ite_softc con_itesoftc
;
139 u_char cons_tabs
[MAX_TABS
];
141 struct ite_softc
*kbd_ite
;
143 /* audio bell stuff */
148 static char *bsamplep
;
149 static char sample
[20] = {
150 0,39,75,103,121,127,121,103,75,39,0,
151 -39,-75,-103,-121,-127,-121,-103,-75,-39
154 static callout_t repeat_ch
;
156 void iteputchar(int c
, struct ite_softc
*ip
);
157 void ite_putstr(const char * s
, int len
, dev_t dev
);
158 void iteattach(struct device
*, struct device
*, void *);
159 int itematch(struct device
*, struct cfdata
*, void *);
160 static void iteprecheckwrap(struct ite_softc
*);
161 static void itecheckwrap(struct ite_softc
*);
162 struct ite_softc
*getitesp(dev_t
);
163 void init_bell(void);
165 void itecnpollc(dev_t
, int);
166 static void repeat_handler(void *);
167 inline static void ite_sendstr(const char *);
168 static void alignment_display(struct ite_softc
*);
169 inline static void snap_cury(struct ite_softc
*);
170 inline static void ite_dnchar(struct ite_softc
*, int);
171 inline static void ite_inchar(struct ite_softc
*, int);
172 inline static void ite_clrtoeol(struct ite_softc
*);
173 inline static void ite_clrtobol(struct ite_softc
*);
174 inline static void ite_clrline(struct ite_softc
*);
175 inline static void ite_clrtoeos(struct ite_softc
*);
176 inline static void ite_clrtobos(struct ite_softc
*);
177 inline static void ite_clrscreen(struct ite_softc
*);
178 inline static void ite_dnline(struct ite_softc
*, int);
179 inline static void ite_inline(struct ite_softc
*, int);
180 inline static void ite_lf(struct ite_softc
*);
181 inline static void ite_crlf(struct ite_softc
*);
182 inline static void ite_cr(struct ite_softc
*);
183 inline static void ite_rlf(struct ite_softc
*);
184 inline static int atoi(const char *);
185 inline static int ite_argnum(struct ite_softc
*);
186 inline static int ite_zargnum(struct ite_softc
*);
188 CFATTACH_DECL(ite
, sizeof(struct ite_softc
),
189 itematch
, iteattach
, NULL
, NULL
);
191 extern struct cfdriver ite_cd
;
193 dev_type_open(iteopen
);
194 dev_type_close(iteclose
);
195 dev_type_read(iteread
);
196 dev_type_write(itewrite
);
197 dev_type_ioctl(iteioctl
);
198 dev_type_tty(itetty
);
199 dev_type_poll(itepoll
);
201 const struct cdevsw ite_cdevsw
= {
202 iteopen
, iteclose
, iteread
, itewrite
, iteioctl
,
203 nostop
, itetty
, itepoll
, nommap
, ttykqfilter
, D_TTY
207 itematch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
209 struct grf_softc
*gp
;
216 * normally this would be done in attach, however
217 * during early init we do not have a device pointer
218 * and thus no unit number.
220 maj
= cdevsw_lookup_major(&ite_cdevsw
);
221 gp
->g_itedev
= makedev(maj
, cfp
->cf_unit
);
226 iteattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
228 struct grf_softc
*gp
;
229 struct ite_softc
*ip
;
232 gp
= (struct grf_softc
*)auxp
;
234 ip
= (struct ite_softc
*)dp
;
237 if (con_itesoftc
.grf
!= NULL
&&
238 con_itesoftc
.grf
->g_unit
== gp
->g_unit
) {
240 * console reinit copy params over.
241 * and console always gets keyboard
243 memcpy(&ip
->grf
, &con_itesoftc
.grf
,
244 (char *)&ip
[1] - (char *)&ip
->grf
);
245 con_itesoftc
.grf
= NULL
;
251 iteinit(gp
->g_itedev
);
252 printf(": rows %d cols %d", ip
->rows
, ip
->cols
);
253 printf(" repeat at (%d/100)s next at (%d/100)s",
254 start_repeat_timeo
, next_repeat_timeo
);
259 printf(" has keyboard");
261 ip
->flags
|= ITE_ATTACHED
;
263 if (con_itesoftc
.grf
!= NULL
&&
264 con_itesoftc
.grf
->g_conpri
> gp
->g_conpri
)
266 con_itesoftc
.grf
= gp
;
267 con_itesoftc
.tabs
= cons_tabs
;
274 if (amiga_realconfig
&& con_itesoftc
.grf
== NULL
)
275 return(device_lookup_private(&ite_cd
, ITEUNIT(dev
)));
277 if (con_itesoftc
.grf
== NULL
)
278 panic("no ite_softc for console");
279 return(&con_itesoftc
);
283 * cons.c entry points into ite device.
287 * Return a priority in consdev->cn_pri field highest wins. This function
288 * is called before any devices have been probed.
291 itecnprobe(struct consdev
*cd
)
294 * bring graphics layer up.
299 * return priority of the best ite (already picked from attach)
302 if (con_itesoftc
.grf
== NULL
)
303 cd
->cn_pri
= CN_DEAD
;
305 cd
->cn_pri
= con_itesoftc
.grf
->g_conpri
;
306 cd
->cn_dev
= con_itesoftc
.grf
->g_itedev
;
310 /* audio bell stuff */
314 if (bsamplep
!= NULL
)
316 bsamplep
= alloc_chipmem(20);
317 if (bsamplep
== NULL
)
318 panic("no chipmem for ite_bell");
320 memcpy(bsamplep
, sample
, 20);
330 clock
= 3579545; /* PAL 3546895 */
333 * the number of clock ticks per sample byte must be > 124
334 * ergo bpitch must be < clock / 124*20
335 * i.e. ~1443, 1300 to be safe (PAL etc.). also not zero obviously
337 period
= clock
/ (bpitch
* 20);
338 count
= bmsec
* bpitch
/ 1000;
340 play_sample(10, PREP_DMA_MEM(bsamplep
), period
, bvolume
, 0x3, count
);
344 itecninit(struct consdev
*cd
)
346 struct ite_softc
*ip
;
348 ip
= getitesp(cd
->cn_dev
);
350 ip
->flags
|= ITE_ACTIVE
| ITE_ISCONS
;
359 * ite_cnfinish() is called in ite_init() when the device is
360 * being probed in the normal fasion, thus we can finish setting
361 * up this ite now that the system is more functional.
364 ite_cnfinish(struct ite_softc
*ip
)
378 /* XXX this should be moved */
382 c
= ite_cnfilter(c
, ITEFILT_CONSOLE
);
388 itecnputc(dev_t dev
, int c
)
391 struct ite_softc
*ip
;
397 if (panicstr
&& !paniced
&&
398 (ip
->flags
& (ITE_ACTIVE
| ITE_INGRF
)) != ITE_ACTIVE
) {
406 itecnpollc(dev_t dev
, int on
)
411 * standard entry points to the device.
415 * iteinit() is the standard entry point for initialization of
416 * an ite device, it is also called from ite_cninit().
422 struct ite_softc
*ip
;
423 static int kbdmap_loaded
= 0;
426 if (ip
->flags
& ITE_INITED
)
428 if (kbdmap_loaded
== 0) {
429 memcpy(&kbdmap
, &ascii_kbdmap
, sizeof(struct kbdmap
));
433 callout_init(&repeat_ch
, 0);
438 SUBR_CURSOR(ip
, DRAW_CURSOR
);
439 if (ip
->tabs
== NULL
)
440 ip
->tabs
= malloc(MAX_TABS
* sizeof(u_char
),M_DEVBUF
,M_WAITOK
);
442 ip
->flags
|= ITE_INITED
;
446 iteopen(dev_t dev
, int mode
, int devtype
, struct lwp
*l
)
448 struct ite_softc
*ip
;
450 int error
, first
, unit
;
455 if (unit
>= ite_cd
.cd_ndevs
)
460 if ((ip
->flags
& ITE_ATTACHED
) == 0)
463 if (ip
->tp
== NULL
) {
464 tp
= ip
->tp
= ttymalloc();
469 if (kauth_authorize_device_tty(l
->l_cred
, KAUTH_DEVICE_TTY_OPEN
, tp
))
472 if ((ip
->flags
& ITE_ACTIVE
) == 0) {
476 tp
->t_oproc
= itestart
;
477 tp
->t_param
= ite_param
;
479 if ((tp
->t_state
& TS_ISOPEN
) == 0 && tp
->t_wopen
== 0) {
481 tp
->t_iflag
= TTYDEF_IFLAG
;
482 tp
->t_oflag
= TTYDEF_OFLAG
;
483 tp
->t_cflag
= TTYDEF_CFLAG
;
484 tp
->t_lflag
= TTYDEF_LFLAG
;
485 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
486 tp
->t_state
= TS_CARR_ON
;
489 error
= ttyopen(tp
, 0, mode
& O_NONBLOCK
);
493 error
= tp
->t_linesw
->l_open(dev
, tp
);
497 tp
->t_winsize
.ws_row
= ip
->rows
;
498 tp
->t_winsize
.ws_col
= ip
->cols
;
508 iteclose(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
512 tp
= getitesp(dev
)->tp
;
515 tp
->t_linesw
->l_close(tp
, flag
);
522 iteread(dev_t dev
, struct uio
*uio
, int flag
)
526 tp
= getitesp(dev
)->tp
;
529 return tp
->t_linesw
->l_read(tp
, uio
, flag
);
533 itewrite(dev_t dev
, struct uio
*uio
, int flag
)
537 tp
= getitesp(dev
)->tp
;
540 return tp
->t_linesw
->l_write(tp
, uio
, flag
);
544 itepoll(dev_t dev
, int events
, struct lwp
*l
)
548 tp
= getitesp(dev
)->tp
;
551 return ((*tp
->t_linesw
->l_poll
)(tp
, events
, l
));
557 return (getitesp(dev
)->tp
);
561 iteioctl(dev_t dev
, u_long cmd
, void *addr
, int flag
, struct lwp
*l
)
563 struct iterepeat
*irp
;
564 struct ite_softc
*ip
;
574 error
= tp
->t_linesw
->l_ioctl(tp
, cmd
, addr
, flag
, l
);
575 if (error
!= EPASSTHROUGH
)
577 error
= ttioctl(tp
, cmd
, addr
, flag
, l
);
578 if (error
!= EPASSTHROUGH
)
583 ib
= (struct itebell
*)addr
;
584 ib
->volume
= bvolume
;
589 ib
= (struct itebell
*)addr
;
591 if (ib
->pitch
> MAXBPITCH
|| ib
->pitch
< MINBPITCH
||
592 ib
->volume
> MAXBVOLUME
|| ib
->msec
> MAXBTIME
)
594 bvolume
= ib
->volume
;
601 memcpy(&kbdmap
, addr
, sizeof(struct kbdmap
));
606 memcpy(addr
, &kbdmap
, sizeof(struct kbdmap
));
609 irp
= (struct iterepeat
*)addr
;
610 irp
->start
= start_repeat_timeo
;
611 irp
->next
= next_repeat_timeo
;
614 irp
= (struct iterepeat
*)addr
;
615 if (irp
->start
< ITEMINREPEAT
&& irp
->next
< ITEMINREPEAT
)
617 start_repeat_timeo
= irp
->start
;
618 next_repeat_timeo
= irp
->next
;
623 if (minor(dev
) == 0) {
624 error
= ite_grf_ioctl(ip
, cmd
, addr
, flag
, l
);
629 return (EPASSTHROUGH
);
633 itestart(struct tty
*tp
)
636 struct ite_softc
*ip
;
637 u_char buf
[ITEBURST
];
640 ip
= getitesp(tp
->t_dev
);
645 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
648 tp
->t_state
|= TS_BUSY
;
651 len
= q_to_b(rbp
, buf
, ITEBURST
);
654 /* Here is a really good place to implement pre/jumpscroll() */
655 ite_putstr(buf
, len
, tp
->t_dev
);
658 tp
->t_state
&= ~TS_BUSY
;
659 /* we have characters remaining. */
661 tp
->t_state
|= TS_TIMEOUT
;
662 callout_schedule(&tp
->t_rstrt_ch
, 1);
670 ite_on(dev_t dev
, int flag
)
672 struct ite_softc
*ip
;
678 /* force ite active, overriding graphics mode */
680 ip
->flags
|= ITE_ACTIVE
;
681 ip
->flags
&= ~(ITE_INGRF
| ITE_INITED
);
683 /* leave graphics mode */
685 ip
->flags
&= ~ITE_INGRF
;
686 if ((ip
->flags
& ITE_ACTIVE
) == 0)
689 ip
->flags
|= ITE_ACTIVE
;
690 if (ip
->flags
& ITE_INGRF
)
696 ite_off(dev_t dev
, int flag
)
698 struct ite_softc
*ip
;
702 ip
->flags
|= ITE_INGRF
;
703 if ((ip
->flags
& ITE_ACTIVE
) == 0)
706 (ip
->flags
& (ITE_INGRF
| ITE_ISCONS
| ITE_INITED
)) == ITE_INITED
)
708 /* XXX hmm grfon() I think wants this to go inactive. */
710 ip
->flags
&= ~ITE_ACTIVE
;
713 /* XXX called after changes made in underlying grf layer. */
714 /* I want to nuke this */
716 ite_reinit(dev_t dev
)
718 struct ite_softc
*ip
;
721 ip
->flags
&= ~ITE_INITED
;
726 ite_param(struct tty
*tp
, struct termios
*t
)
728 tp
->t_ispeed
= t
->c_ispeed
;
729 tp
->t_ospeed
= t
->c_ospeed
;
730 tp
->t_cflag
= t
->c_cflag
;
735 ite_reset(struct ite_softc
*ip
)
741 ip
->attribute
= ATTR_NOR
;
744 ip
->save_attribute
= ATTR_NOR
;
749 ip
->bottom_margin
= ip
->rows
- 1;
750 ip
->inside_margins
= 0;
751 ip
->linefeed_newline
= 0;
752 ip
->auto_wrap
= ite_default_wrap
;
753 ip
->cursor_appmode
= 0;
754 ip
->keypad_appmode
= 0;
757 memset(ip
->tabs
, 0, ip
->cols
);
758 for (i
= 0; i
< ip
->cols
; i
++)
759 ip
->tabs
[i
] = ((i
& 7) == 0);
763 * has to be global because of the shared filters.
765 static u_char key_mod
;
766 static u_char last_dead
;
768 /* Used in console at startup only */
770 ite_cnfilter(u_char c
, enum caller caller
)
773 u_char code
, up
, mask
;
776 up
= c
& 0x80 ? 1 : 0;
782 i
= (int)c
- KBD_LEFT_SHIFT
;
783 if (i
>= 0 && i
<= (KBD_RIGHT_META
- KBD_LEFT_SHIFT
)) {
798 /* translate modifiers */
799 if (key_mod
& KBD_MOD_SHIFT
) {
800 if (key_mod
& KBD_MOD_ALT
)
801 key
= kbdmap
.alt_shift_keys
[c
];
803 key
= kbdmap
.shift_keys
[c
];
804 } else if (key_mod
& KBD_MOD_ALT
)
805 key
= kbdmap
.alt_keys
[c
];
807 key
= kbdmap
.keys
[c
];
808 /* if CAPS and key is CAPable (no pun intended) */
809 if ((key_mod
& KBD_MOD_CAPS
) && (key
.mode
& KBD_MODE_CAPS
))
810 key
= kbdmap
.shift_keys
[c
];
814 /* if string return */
815 if (key
.mode
& (KBD_MODE_STRING
| KBD_MODE_KPAD
)) {
819 /* handle dead keys */
820 if (key
.mode
& KBD_MODE_DEAD
) {
821 /* if entered twice, send accent itself */
822 if (last_dead
== (key
.mode
& KBD_MODE_ACCMASK
))
825 last_dead
= key
.mode
& KBD_MODE_ACCMASK
;
831 /* can't apply dead flag to string-keys */
832 if (code
>= '@' && code
< 0x7f)
834 acctable
[KBD_MODE_ACCENT(last_dead
)][code
- '@'];
837 if (key_mod
& KBD_MOD_CTRL
)
839 if (key_mod
& KBD_MOD_META
)
842 /* do console mapping. */
843 code
= code
== '\r' ? '\n' : code
;
849 /* And now the old stuff. */
851 /* these are used to implement repeating keys.. */
852 static u_char last_char
;
853 static u_char tout_pending
;
857 repeat_handler(void *arg
)
861 ite_filter(last_char
, ITEFILT_REPEATER
);
865 ite_filter(u_char c
, enum caller caller
)
868 u_char code
, *str
, up
, mask
;
872 if (kbd_ite
== NULL
|| kbd_ite
->tp
== NULL
)
875 kbd_tty
= kbd_ite
->tp
;
877 /* have to make sure we're at spltty in here */
880 up
= c
& 0x80 ? 1 : 0;
884 i
= (int)c
- KBD_LEFT_SHIFT
;
885 if (i
>= 0 && i
<= (KBD_RIGHT_META
- KBD_LEFT_SHIFT
)) {
894 /* stop repeating on up event */
897 callout_stop(&repeat_ch
);
903 } else if (tout_pending
&& last_char
!= c
) {
904 /* different character, stop also */
905 callout_stop(&repeat_ch
);
909 /* Safety button, switch back to ascii keymap. */
910 if (key_mod
== (KBD_MOD_LALT
| KBD_MOD_LMETA
) && c
== 0x50) {
911 memcpy(&kbdmap
, &ascii_kbdmap
, sizeof(struct kbdmap
));
916 } else if (key_mod
== (KBD_MOD_LALT
| KBD_MOD_LMETA
) && c
== 0x59) {
922 /* translate modifiers */
923 if (key_mod
& KBD_MOD_SHIFT
) {
924 if (key_mod
& KBD_MOD_ALT
)
925 key
= kbdmap
.alt_shift_keys
[c
];
927 key
= kbdmap
.shift_keys
[c
];
928 } else if (key_mod
& KBD_MOD_ALT
)
929 key
= kbdmap
.alt_keys
[c
];
931 key
= kbdmap
.keys
[c
];
932 /* if CAPS and key is CAPable (no pun intended) */
933 if ((key_mod
& KBD_MOD_CAPS
) && (key
.mode
& KBD_MODE_CAPS
))
934 key
= kbdmap
.shift_keys
[c
];
939 * arrange to repeat the keystroke. By doing this at the level
940 * of scan-codes, we can have function keys, and keys that
941 * send strings, repeat too. This also entitles an additional
942 * overhead, since we have to do the conversion each time, but
945 if (!tout_pending
&& caller
== ITEFILT_TTY
&& kbd_ite
->key_repeat
) {
948 callout_reset(&repeat_ch
,
949 start_repeat_timeo
* hz
/ 100, repeat_handler
, NULL
);
950 } else if (!tout_pending
&& caller
== ITEFILT_REPEATER
&&
951 kbd_ite
->key_repeat
) {
954 callout_reset(&repeat_ch
,
955 next_repeat_timeo
* hz
/ 100, repeat_handler
, NULL
);
957 /* handle dead keys */
958 if (key
.mode
& KBD_MODE_DEAD
) {
959 /* if entered twice, send accent itself */
960 if (last_dead
== (key
.mode
& KBD_MODE_ACCMASK
))
963 last_dead
= key
.mode
& KBD_MODE_ACCMASK
;
969 /* can't apply dead flag to string-keys */
970 if (!(key
.mode
& KBD_MODE_STRING
) && code
>= '@' &&
972 code
= acctable
[KBD_MODE_ACCENT(last_dead
)][code
- '@'];
975 /* if not string, apply META and CTRL modifiers */
976 if (!(key
.mode
& KBD_MODE_STRING
)
977 && (!(key
.mode
& KBD_MODE_KPAD
) ||
978 (kbd_ite
&& !kbd_ite
->keypad_appmode
))) {
979 if (key_mod
& KBD_MOD_CTRL
)
981 if (key_mod
& KBD_MOD_META
)
983 } else if ((key
.mode
& KBD_MODE_KPAD
) &&
984 (kbd_ite
&& kbd_ite
->keypad_appmode
)) {
986 0x0f /* 0 */, 0x1d /* 1 */, 0x1e /* 2 */, 0x1f /* 3 */,
987 0x2d /* 4 */, 0x2e /* 5 */, 0x2f /* 6 */, 0x3d /* 7 */,
988 0x3e /* 8 */, 0x3f /* 9 */, 0x4a /* - */, 0x5e /* + */,
989 0x3c /* . */, 0x43 /* e */, 0x5a /* ( */, 0x5b /* ) */,
990 0x5c /* / */, 0x5d /* * */
992 static const char *out
= "pqrstuvwxymlnMPQRS";
993 char *cp
= strchr(in
, c
);
996 * keypad-appmode sends SS3 followed by the above
997 * translated character
999 kbd_tty
->t_linesw
->l_rint(27, kbd_tty
);
1000 kbd_tty
->t_linesw
->l_rint('O', kbd_tty
);
1001 kbd_tty
->t_linesw
->l_rint(out
[cp
- in
], kbd_tty
);
1005 /* *NO* I don't like this.... */
1006 static u_char app_cursor
[] =
1013 str
= kbdmap
.strings
+ code
;
1015 * if this is a cursor key, AND it has the default
1016 * keymap setting, AND we're in app-cursor mode, switch
1017 * to the above table. This is *nasty* !
1019 if (c
>= 0x4c && c
<= 0x4f && kbd_ite
->cursor_appmode
1020 && !memcmp(str
, "\x03\x1b[", 3) &&
1021 strchr("ABCD", str
[3]))
1022 str
= app_cursor
+ 4 * (str
[3] - 'A');
1025 * using a length-byte instead of 0-termination allows
1026 * to embed \0 into strings, although this is not used
1027 * in the default keymap
1029 for (i
= *str
++; i
; i
--)
1030 kbd_tty
->t_linesw
->l_rint(*str
++, kbd_tty
);
1034 kbd_tty
->t_linesw
->l_rint(code
, kbd_tty
);
1040 /* helper functions, makes the code below more readable */
1042 ite_sendstr(const char *str
)
1044 struct tty
*kbd_tty
;
1046 kbd_tty
= kbd_ite
->tp
;
1049 kbd_tty
->t_linesw
->l_rint(*str
++, kbd_tty
);
1053 alignment_display(struct ite_softc
*ip
)
1057 for (j
= 0; j
< ip
->rows
; j
++)
1058 for (i
= 0; i
< ip
->cols
; i
++)
1059 SUBR_PUTC(ip
, 'E', j
, i
, ATTR_NOR
);
1060 attrclr(ip
, 0, 0, ip
->rows
, ip
->cols
);
1061 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1065 snap_cury(struct ite_softc
*ip
)
1067 if (ip
->inside_margins
)
1069 if (ip
->cury
< ip
->top_margin
)
1070 ip
->cury
= ip
->top_margin
;
1071 if (ip
->cury
> ip
->bottom_margin
)
1072 ip
->cury
= ip
->bottom_margin
;
1077 ite_dnchar(struct ite_softc
*ip
, int n
)
1079 n
= min(n
, ip
->cols
- ip
->curx
);
1080 if (n
< ip
->cols
- ip
->curx
)
1082 SUBR_SCROLL(ip
, ip
->cury
, ip
->curx
+ n
, n
, SCROLL_LEFT
);
1083 attrmov(ip
, ip
->cury
, ip
->curx
+ n
, ip
->cury
, ip
->curx
,
1084 1, ip
->cols
- ip
->curx
- n
);
1085 attrclr(ip
, ip
->cury
, ip
->cols
- n
, 1, n
);
1088 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->cols
- n
- 1, ATTR_NOR
);
1089 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1093 ite_inchar(struct ite_softc
*ip
, int n
)
1095 n
= min(n
, ip
->cols
- ip
->curx
);
1096 if (n
< ip
->cols
- ip
->curx
)
1098 SUBR_SCROLL(ip
, ip
->cury
, ip
->curx
, n
, SCROLL_RIGHT
);
1099 attrmov(ip
, ip
->cury
, ip
->curx
, ip
->cury
, ip
->curx
+ n
,
1100 1, ip
->cols
- ip
->curx
- n
);
1101 attrclr(ip
, ip
->cury
, ip
->curx
, 1, n
);
1104 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->curx
+ n
, ATTR_NOR
);
1105 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1109 ite_clrtoeol(struct ite_softc
*ip
)
1111 int y
= ip
->cury
, x
= ip
->curx
;
1112 if (ip
->cols
- x
> 0)
1114 SUBR_CLEAR(ip
, y
, x
, 1, ip
->cols
- x
);
1115 attrclr(ip
, y
, x
, 1, ip
->cols
- x
);
1116 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1121 ite_clrtobol(struct ite_softc
*ip
)
1123 int y
= ip
->cury
, x
= min(ip
->curx
+ 1, ip
->cols
);
1124 SUBR_CLEAR(ip
, y
, 0, 1, x
);
1125 attrclr(ip
, y
, 0, 1, x
);
1126 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1130 ite_clrline(struct ite_softc
*ip
)
1133 SUBR_CLEAR(ip
, y
, 0, 1, ip
->cols
);
1134 attrclr(ip
, y
, 0, 1, ip
->cols
);
1135 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1141 ite_clrtoeos(struct ite_softc
*ip
)
1144 if (ip
->cury
< ip
->rows
- 1)
1146 SUBR_CLEAR(ip
, ip
->cury
+ 1, 0, ip
->rows
- 1 - ip
->cury
, ip
->cols
);
1147 attrclr(ip
, ip
->cury
, 0, ip
->rows
- ip
->cury
, ip
->cols
);
1148 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1153 ite_clrtobos(struct ite_softc
*ip
)
1158 SUBR_CLEAR(ip
, 0, 0, ip
->cury
, ip
->cols
);
1159 attrclr(ip
, 0, 0, ip
->cury
, ip
->cols
);
1160 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1165 ite_clrscreen(struct ite_softc
*ip
)
1167 SUBR_CLEAR(ip
, 0, 0, ip
->rows
, ip
->cols
);
1168 attrclr(ip
, 0, 0, ip
->rows
, ip
->cols
);
1169 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1175 ite_dnline(struct ite_softc
*ip
, int n
)
1177 /* interesting.. if the cursor is outside the scrolling
1178 region, this command is simply ignored.. */
1179 if (ip
->cury
< ip
->top_margin
|| ip
->cury
> ip
->bottom_margin
)
1182 n
= min(n
, ip
->bottom_margin
+ 1 - ip
->cury
);
1183 if (n
<= ip
->bottom_margin
- ip
->cury
)
1185 SUBR_SCROLL(ip
, ip
->cury
+ n
, 0, n
, SCROLL_UP
);
1186 attrmov(ip
, ip
->cury
+ n
, 0, ip
->cury
, 0,
1187 ip
->bottom_margin
+ 1 - ip
->cury
- n
, ip
->cols
);
1189 SUBR_CLEAR(ip
, ip
->bottom_margin
- n
+ 1, 0, n
, ip
->cols
);
1190 attrclr(ip
, ip
->bottom_margin
- n
+ 1, 0, n
, ip
->cols
);
1191 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1195 ite_inline(struct ite_softc
*ip
, int n
)
1197 /* interesting.. if the cursor is outside the scrolling
1198 region, this command is simply ignored.. */
1199 if (ip
->cury
< ip
->top_margin
|| ip
->cury
> ip
->bottom_margin
)
1202 n
= min(n
, ip
->bottom_margin
+ 1 - ip
->cury
);
1203 if (n
<= ip
->bottom_margin
- ip
->cury
)
1205 SUBR_SCROLL(ip
, ip
->cury
, 0, n
, SCROLL_DOWN
);
1206 attrmov(ip
, ip
->cury
, 0, ip
->cury
+ n
, 0,
1207 ip
->bottom_margin
+ 1 - ip
->cury
- n
, ip
->cols
);
1209 SUBR_CLEAR(ip
, ip
->cury
, 0, n
, ip
->cols
);
1210 attrclr(ip
, ip
->cury
, 0, n
, ip
->cols
);
1211 SUBR_CURSOR(ip
, DRAW_CURSOR
);
1215 ite_lf(struct ite_softc
*ip
)
1218 if ((ip
->cury
== ip
->bottom_margin
+1) || (ip
->cury
== ip
->rows
))
1221 SUBR_SCROLL(ip
, ip
->top_margin
+ 1, 0, 1, SCROLL_UP
);
1224 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1225 clr_attr(ip
, ATTR_INV
);
1229 ite_crlf(struct ite_softc
*ip
)
1236 ite_cr(struct ite_softc
*ip
)
1241 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1246 ite_rlf(struct ite_softc
*ip
)
1249 if ((ip
->cury
< 0) || (ip
->cury
== ip
->top_margin
- 1))
1252 SUBR_SCROLL(ip
, ip
->top_margin
, 0, 1, SCROLL_DOWN
);
1255 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1256 clr_attr(ip
, ATTR_INV
);
1260 atoi(const char *cp
)
1264 for (n
= 0; *cp
&& *cp
>= '0' && *cp
<= '9'; cp
++)
1265 n
= n
* 10 + *cp
- '0';
1271 ite_argnum(struct ite_softc
*ip
)
1276 /* convert argument string into number */
1277 if (ip
->ap
== ip
->argbuf
)
1281 n
= atoi (ip
->argbuf
);
1288 ite_zargnum(struct ite_softc
*ip
)
1293 /* convert argument string into number */
1294 if (ip
->ap
== ip
->argbuf
)
1298 n
= atoi (ip
->argbuf
);
1301 return n
; /* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
1305 ite_putstr(const char *s
, int len
, dev_t dev
)
1307 struct ite_softc
*ip
;
1312 /* XXX avoid problems */
1313 if ((ip
->flags
& (ITE_ACTIVE
|ITE_INGRF
)) != ITE_ACTIVE
)
1316 SUBR_CURSOR(ip
, START_CURSOROPT
);
1317 for (i
= 0; i
< len
; i
++)
1319 iteputchar(s
[i
], ip
);
1320 SUBR_CURSOR(ip
, END_CURSOROPT
);
1324 iteprecheckwrap(struct ite_softc
*ip
)
1326 if (ip
->auto_wrap
&& ip
->curx
== ip
->cols
) {
1328 clr_attr(ip
, ATTR_INV
);
1329 if (++ip
->cury
>= ip
->bottom_margin
+ 1) {
1330 ip
->cury
= ip
->bottom_margin
;
1331 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1332 SUBR_SCROLL(ip
, ip
->top_margin
+ 1, 0, 1, SCROLL_UP
);
1335 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1340 itecheckwrap(struct ite_softc
*ip
)
1343 if (++ip
->curx
== ip
->cols
) {
1344 if (ip
->auto_wrap
) {
1346 clr_attr(ip
, ATTR_INV
);
1347 if (++ip
->cury
>= ip
->bottom_margin
+ 1) {
1348 ip
->cury
= ip
->bottom_margin
;
1349 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1350 SUBR_SCROLL(ip
, ip
->top_margin
+ 1, 0, 1, SCROLL_UP
);
1355 /* stay there if no autowrap.. */
1359 if (ip
->curx
< ip
->cols
) {
1361 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1367 iteputchar(register int c
, struct ite_softc
*ip
)
1369 struct tty
*kbd_tty
;
1373 if (kbd_ite
== NULL
)
1376 kbd_tty
= kbd_ite
->tp
;
1379 switch (ip
->escape
) {
1383 * first 7bit equivalents for the
1384 * 8bit control characters
1391 * and fall into the next
1392 * switch below (same for all `break')
1438 /* introduces 7/8bit control */
1440 /* can be followed by either F or G */
1444 * a lot of character set selections, not yet
1445 * used... 94-character sets:
1453 case 'B': /* ASCII */
1454 case 'A': /* ISO latin 1 */
1455 case '<': /* user preferred suplemental */
1456 case '0': /* dec special graphics */
1458 * 96-character sets:
1464 * national character sets:
1466 case '4': /* dutch */
1468 case 'C': /* finnish */
1469 case 'R': /* french */
1470 case 'Q': /* french canadian */
1471 case 'K': /* german */
1472 case 'Y': /* italian */
1473 case '6': /* norwegian/danish */
1475 * note: %5 and %6 are not supported (two
1479 /* just ignore for now */
1482 * locking shift modes (as you might guess, not
1506 /* font width/height control */
1510 /* hard terminal reset .. */
1512 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1516 ip
->save_curx
= ip
->curx
;
1517 ip
->save_cury
= ip
->cury
;
1518 ip
->save_attribute
= ip
->attribute
;
1522 ip
->curx
= ip
->save_curx
;
1523 ip
->cury
= ip
->save_cury
;
1524 ip
->attribute
= ip
->save_attribute
;
1525 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1529 ip
->keypad_appmode
= 1;
1533 ip
->keypad_appmode
= 0;
1536 case 'Z': /* request ID */
1538 if (ip
->emul_level
== EMUL_VT100
)
1539 ite_sendstr("\033[?61;0c");
1541 ite_sendstr("\033[?63;0c");
1546 * default catch all for not recognized ESC
1560 ip
->eightbit_C1
= 0;
1564 ip
->eightbit_C1
= 1;
1576 /* single height, single width */
1580 /* double width, single height */
1592 /* screen alignment pattern... */
1593 alignment_display(ip
);
1618 if (ip
->ap
< ip
->argbuf
+ MAX_ARGSIZE
)
1623 * you wouldn't believe such perversion is
1624 * possible? it is.. BS is allowed in between
1625 * cursor sequences (at least), according to
1631 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1635 if (!strncmp(ip
->argbuf
, "61\"", 3))
1636 ip
->emul_level
= EMUL_VT100
;
1637 else if (!strncmp(ip
->argbuf
, "63;1\"", 5)
1638 || !strncmp(ip
->argbuf
, "62;1\"", 5))
1639 ip
->emul_level
= EMUL_VT300_7
;
1641 ip
->emul_level
= EMUL_VT300_8
;
1647 ip
->ap
= ip
->argbuf
;
1651 if (ip
->argbuf
[0] == '>') {
1652 ite_sendstr("\033[>24;0;0;0c");
1654 switch (ite_zargnum(ip
)) {
1657 * primary DA request, send
1658 * primary DA response
1672 switch (ite_zargnum(ip
)) {
1674 /* no malfunction */
1675 ite_sendstr("\033[0n");
1678 /* cursor position report */
1679 sprintf(ip
->argbuf
, "\033[%d;%dR",
1680 ip
->cury
+ 1, ip
->curx
+ 1);
1681 ite_sendstr(ip
->argbuf
);
1687 switch (ite_zargnum(ip
)) {
1689 /* Fake some terminal parameters. */
1690 ite_sendstr("\033[2;1;1;112;112;1;0x");
1693 ite_sendstr("\033[3;1;1;112;112;1;0x");
1699 switch (ite_zargnum(ip
)) {
1701 if (ip
->curx
< ip
->cols
)
1702 ip
->tabs
[ip
->curx
] = 0;
1705 for (n
= 0; n
< ip
->cols
; n
++)
1713 n
= ite_zargnum(ip
);
1716 /* insert/replace mode */
1717 ip
->imode
= (c
== 'h');
1720 ip
->linefeed_newline
= (c
== 'h');
1726 ite_dnline(ip
, ite_argnum(ip
));
1730 ite_inline(ip
, ite_argnum(ip
));
1734 ite_dnchar(ip
, ite_argnum(ip
));
1738 ite_inchar(ip
, ite_argnum(ip
));
1743 * this one was *not* in my vt320 manual but in
1744 * a vt320 termcap entry.. who is right? It's
1745 * supposed to set the horizontal cursor
1749 x
= atoi(ip
->argbuf
);
1752 ip
->curx
= min(x
, ip
->cols
- 1);
1754 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1755 clr_attr(ip
, ATTR_INV
);
1759 * same thing here, this one's for setting the
1760 * absolute vertical cursor position. Not
1764 y
= atoi(ip
->argbuf
);
1767 if (ip
->inside_margins
)
1768 y
+= ip
->top_margin
;
1769 ip
->cury
= min(y
, ip
->rows
- 1);
1772 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1773 clr_attr(ip
, ATTR_INV
);
1778 y
= atoi(ip
->argbuf
);
1780 cp
= strchr(ip
->argbuf
, ';');
1787 if (ip
->inside_margins
)
1788 y
+= ip
->top_margin
;
1789 ip
->cury
= min(y
, ip
->rows
- 1);
1790 ip
->curx
= min(x
, ip
->cols
- 1);
1793 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1794 clr_attr(ip
, ATTR_INV
);
1798 n
= ip
->cury
- (n
? n
: 1);
1801 if (ip
->inside_margins
)
1802 n
= max(ip
->top_margin
, n
);
1803 else if (n
== ip
->top_margin
- 1)
1805 * allow scrolling outside region, but
1806 * don't scroll out of active region
1807 * without explicit CUP
1812 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1813 clr_attr(ip
, ATTR_INV
);
1817 n
= ip
->cury
+ (n
? n
: 1);
1818 n
= min(ip
->rows
- 1, n
);
1819 if (ip
->inside_margins
)
1820 n
= min(ip
->bottom_margin
, n
);
1821 else if (n
== ip
->bottom_margin
+ 1)
1823 * allow scrolling outside region, but
1824 * don't scroll out of active region
1825 * without explicit CUP
1827 n
= ip
->bottom_margin
;
1830 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1831 clr_attr(ip
, ATTR_INV
);
1836 ip
->curx
= min(ip
->curx
+ n
, ip
->cols
- 1);
1838 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1839 clr_attr(ip
, ATTR_INV
);
1845 ip
->curx
= n
>= 0 ? n
: 0;
1847 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1848 clr_attr(ip
, ATTR_INV
);
1852 n
= ite_zargnum(ip
);
1862 n
= ite_zargnum(ip
);
1872 n
= ite_argnum(ip
) - 1;
1873 n
= min(n
, ip
->cols
- 1 - ip
->curx
);
1874 for (; n
>= 0; n
--) {
1875 attrclr(ip
, ip
->cury
, ip
->curx
+ n
, 1, 1);
1876 SUBR_PUTC(ip
, ' ', ip
->cury
, ip
->curx
+ n
, ATTR_NOR
);
1882 /* status line control */
1887 x
= atoi(ip
->argbuf
);
1890 cp
= strchr(ip
->argbuf
, ';');
1893 y
= y
? y
: ip
->rows
;
1897 * if illegal scrolling region, reset
1905 ip
->top_margin
= min(x
, ip
->rows
- 1);
1906 ip
->bottom_margin
= min(y
, ip
->rows
- 1);
1907 if (ip
->inside_margins
) {
1908 ip
->cury
= ip
->top_margin
;
1910 SUBR_CURSOR(ip
, MOVE_CURSOR
);
1915 /* big attribute setter/resetter */
1918 /* kludge to make CSIm work (== CSI0m) */
1919 if (ip
->ap
== ip
->argbuf
)
1921 for (_cp
= ip
->argbuf
; _cp
< ip
->ap
;) {
1925 clr_attr(ip
, ATTR_ALL
);
1930 set_attr(ip
, ATTR_BOLD
);
1937 clr_attr(ip
, ATTR_BOLD
);
1942 clr_attr(ip
, ATTR_UL
);
1947 clr_attr(ip
, ATTR_BLINK
);
1952 clr_attr(ip
, ATTR_INV
);
1963 set_attr(ip
, ATTR_UL
);
1968 set_attr(ip
, ATTR_BLINK
);
1973 set_attr(ip
, ATTR_INV
);
1986 ite_sendstr("\033P\033\\");
1994 case '?': /* CSI ? */
2010 * Don't fill the last character;
2012 * XXX yeah, where ??
2014 if (ip
->ap
< ip
->argbuf
+ MAX_ARGSIZE
- 1)
2019 if (ip
->ap
== &ip
->argbuf
[2]) {
2020 if (!strncmp(ip
->argbuf
, "15", 2))
2021 /* printer status: no printer */
2022 ite_sendstr("\033[13n");
2024 else if (!strncmp(ip
->argbuf
, "25", 2))
2026 ite_sendstr("\033[20n");
2028 else if (!strncmp(ip
->argbuf
, "26", 2))
2029 /* keyboard dialect: US */
2030 ite_sendstr("\033[27;1n");
2036 n
= ite_zargnum(ip
);
2039 ip
->cursor_appmode
= (c
== 'h');
2042 /* 132/80 columns (132 == 'h') */
2044 case 4: /* smooth scroll */
2048 * light background (=='h') /dark
2052 case 6: /* origin mode */
2053 ip
->inside_margins
= (c
== 'h');
2055 ip
->cury
= ip
->inside_margins
?
2057 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2059 case 7: /* auto wraparound */
2060 ip
->auto_wrap
= (c
== 'h');
2062 case 8: /* keyboard repeat */
2063 ip
->key_repeat
= (c
== 'h');
2065 case 20: /* newline mode */
2066 ip
->linefeed_newline
= (c
== 'h');
2068 case 25: /* cursor on/off */
2069 SUBR_CURSOR(ip
, (c
== 'h') ?
2070 DRAW_CURSOR
: ERASE_CURSOR
);
2086 case VT
: /* VT is treated like LF */
2087 case FF
: /* so is FF */
2090 * cr->crlf distinction is done here, on output, not on input!
2092 if (ip
->linefeed_newline
)
2104 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2107 for (n
= ip
->curx
+ 1; n
< ip
->cols
; n
++) {
2110 SUBR_CURSOR(ip
, MOVE_CURSOR
);
2116 if (kbd_tty
&& kbd_ite
&& kbd_ite
->tp
== kbd_tty
2130 /* send answer-back message !! */
2133 ip
->escape
= 0; /* cancel any escape sequence in progress */
2136 ip
->escape
= 0; /* dito, but see below */
2137 /* should also display a reverse question mark!! */
2143 * now it gets weird.. 8bit control sequences..
2146 /* index: move cursor down, scroll */
2150 /* next line. next line, first pos. */
2154 /* set horizontal tab */
2155 if (ip
->curx
< ip
->cols
)
2156 ip
->tabs
[ip
->curx
] = 1;
2163 /* go into G2 for one character */
2164 /* not yet supported */
2167 /* go into G3 for one character */
2170 /* device control string introducer */
2172 ip
->ap
= ip
->argbuf
;
2175 /* control sequence introducer */
2177 ip
->ap
= ip
->argbuf
;
2180 /* string terminator */
2181 /* ignore, if not used as terminator */
2185 * introduces OS command. Ignore everything
2191 /* privacy message, ignore everything upto ST */
2196 * application program command, ignore * everything upto ST
2201 if ((c
& 0x7f) < ' ' || c
== DEL
)
2205 iteprecheckwrap(ip
);
2206 #ifdef DO_WEIRD_ATTRIBUTES
2207 if ((ip
->attribute
& ATTR_INV
) || attrtest(ip
, ATTR_INV
)) {
2208 attrset(ip
, ATTR_INV
);
2209 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ATTR_INV
);
2211 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ATTR_NOR
);
2213 SUBR_PUTC(ip
, c
, ip
->cury
, ip
->curx
, ip
->attribute
);
2215 SUBR_CURSOR(ip
, DRAW_CURSOR
);