Wed Feb 19 11:40:31 2014 UTC ()
Fix kernel crash when a user tries to switch to nonexistent terminal.

Reported by Gabor Sebestyen in PR port-atari/48599.

Should be pulled up to all netbsd-6 branches.


(tsutsui)
diff -r1.71 -r1.72 src/sys/arch/atari/dev/ite.c

cvs diff -r1.71 -r1.72 src/sys/arch/atari/dev/ite.c (switch to unified diff)

--- src/sys/arch/atari/dev/ite.c 2011/06/05 16:25:12 1.71
+++ src/sys/arch/atari/dev/ite.c 2014/02/19 11:40:31 1.72
@@ -1,1668 +1,1668 @@ @@ -1,1668 +1,1668 @@
1/* $NetBSD: ite.c,v 1.71 2011/06/05 16:25:12 tsutsui Exp $ */ 1/* $NetBSD: ite.c,v 1.72 2014/02/19 11:40:31 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990 The Regents of the University of California. 5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department. 10 * Science Department.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors 20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software 21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission. 22 * without specific prior written permission.
23 * 23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: Utah Hdr: ite.c 1.1 90/07/09 36 * from: Utah Hdr: ite.c 1.1 90/07/09
37 * from: @(#)ite.c 7.6 (Berkeley) 5/16/91 37 * from: @(#)ite.c 7.6 (Berkeley) 5/16/91
38 */ 38 */
39 39
40/* 40/*
41 * ite - bitmapped terminal. 41 * ite - bitmapped terminal.
42 * Supports VT200, a few terminal features will be unavailable until 42 * Supports VT200, a few terminal features will be unavailable until
43 * the system actually probes the device (i.e. not after consinit()) 43 * the system actually probes the device (i.e. not after consinit())
44 */ 44 */
45 45
46#include <sys/cdefs.h> 46#include <sys/cdefs.h>
47__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.71 2011/06/05 16:25:12 tsutsui Exp $"); 47__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.72 2014/02/19 11:40:31 tsutsui Exp $");
48 48
49#include "opt_ddb.h" 49#include "opt_ddb.h"
50 50
51#include <sys/param.h> 51#include <sys/param.h>
52#include <sys/kernel.h> 52#include <sys/kernel.h>
53#include <sys/conf.h> 53#include <sys/conf.h>
54#include <sys/device.h> 54#include <sys/device.h>
55#include <sys/malloc.h> 55#include <sys/malloc.h>
56#include <sys/fcntl.h> 56#include <sys/fcntl.h>
57#include <sys/ioctl.h> 57#include <sys/ioctl.h>
58#include <sys/tty.h> 58#include <sys/tty.h>
59#include <sys/termios.h> 59#include <sys/termios.h>
60#include <sys/systm.h> 60#include <sys/systm.h>
61#include <sys/callout.h> 61#include <sys/callout.h>
62#include <sys/proc.h> 62#include <sys/proc.h>
63#include <dev/cons.h> 63#include <dev/cons.h>
64#include <sys/kauth.h> 64#include <sys/kauth.h>
65 65
66#include <machine/cpu.h> 66#include <machine/cpu.h>
67 67
68#include <atari/atari/device.h> 68#include <atari/atari/device.h>
69#include <atari/dev/event_var.h> 69#include <atari/dev/event_var.h>
70#include <atari/dev/kbdmap.h> 70#include <atari/dev/kbdmap.h>
71#include <atari/dev/kbdvar.h> 71#include <atari/dev/kbdvar.h>
72#include <atari/dev/iteioctl.h> 72#include <atari/dev/iteioctl.h>
73#include <atari/dev/itevar.h> 73#include <atari/dev/itevar.h>
74#include <atari/dev/grfioctl.h> 74#include <atari/dev/grfioctl.h>
75#include <atari/dev/grfabs_reg.h> 75#include <atari/dev/grfabs_reg.h>
76#include <atari/dev/grfvar.h> 76#include <atari/dev/grfvar.h>
77#include <atari/dev/viewioctl.h> 77#include <atari/dev/viewioctl.h>
78#include <atari/dev/viewvar.h> 78#include <atari/dev/viewvar.h>
79 79
80#include "ioconf.h" 80#include "ioconf.h"
81 81
82#define ITEUNIT(dev) (minor(dev)) 82#define ITEUNIT(dev) (minor(dev))
83 83
84#define SUBR_INIT(sc) (sc)->grf->g_iteinit(sc) 84#define SUBR_INIT(sc) (sc)->grf->g_iteinit(sc)
85#define SUBR_DEINIT(sc) (sc)->grf->g_itedeinit(sc) 85#define SUBR_DEINIT(sc) (sc)->grf->g_itedeinit(sc)
86#define SUBR_PUTC(sc,c,dy,dx,m) (sc)->grf->g_iteputc(sc,c,dy,dx,m) 86#define SUBR_PUTC(sc,c,dy,dx,m) (sc)->grf->g_iteputc(sc,c,dy,dx,m)
87#define SUBR_CURSOR(sc,flg) (sc)->grf->g_itecursor(sc,flg) 87#define SUBR_CURSOR(sc,flg) (sc)->grf->g_itecursor(sc,flg)
88#define SUBR_CLEAR(sc,sy,sx,h,w) (sc)->grf->g_iteclear(sc,sy,sx,h,w) 88#define SUBR_CLEAR(sc,sy,sx,h,w) (sc)->grf->g_iteclear(sc,sy,sx,h,w)
89#define SUBR_SCROLL(sc,sy,sx,cnt,dir) (sc)->grf->g_itescroll(sc,sy,sx,cnt,dir) 89#define SUBR_SCROLL(sc,sy,sx,cnt,dir) (sc)->grf->g_itescroll(sc,sy,sx,cnt,dir)
90 90
91int start_repeat_timeo = 30; /* first repeat after x s/100 */ 91int start_repeat_timeo = 30; /* first repeat after x s/100 */
92int next_repeat_timeo = 10; /* next repeat after x s/100 */ 92int next_repeat_timeo = 10; /* next repeat after x s/100 */
93 93
94/* 94/*
95 * Patchable 95 * Patchable
96 */ 96 */
97int ite_default_x = 0; /* def leftedge offset */ 97int ite_default_x = 0; /* def leftedge offset */
98int ite_default_y = 0; /* def topedge offset */ 98int ite_default_y = 0; /* def topedge offset */
99int ite_default_width = 640; /* def width */ 99int ite_default_width = 640; /* def width */
100int ite_default_depth = 1; /* def depth */ 100int ite_default_depth = 1; /* def depth */
101int ite_default_height = 400; /* def height */ 101int ite_default_height = 400; /* def height */
102int ite_default_wrap = 1; /* if you want vtxxx-nam -> binpatch */ 102int ite_default_wrap = 1; /* if you want vtxxx-nam -> binpatch */
103 103
104struct ite_softc con_itesoftc; 104struct ite_softc con_itesoftc;
105u_char cons_tabs[MAX_TABS]; 105u_char cons_tabs[MAX_TABS];
106 106
107struct ite_softc *kbd_ite; 107struct ite_softc *kbd_ite;
108int kbd_init; 108int kbd_init;
109 109
110static inline int atoi(const char *); 110static inline int atoi(const char *);
111static inline int ite_argnum(struct ite_softc *); 111static inline int ite_argnum(struct ite_softc *);
112static inline int ite_zargnum(struct ite_softc *); 112static inline int ite_zargnum(struct ite_softc *);
113static inline void ite_cr(struct ite_softc *); 113static inline void ite_cr(struct ite_softc *);
114static inline void ite_crlf(struct ite_softc *); 114static inline void ite_crlf(struct ite_softc *);
115static inline void ite_clrline(struct ite_softc *); 115static inline void ite_clrline(struct ite_softc *);
116static inline void ite_clrscreen(struct ite_softc *); 116static inline void ite_clrscreen(struct ite_softc *);
117static inline void ite_clrtobos(struct ite_softc *); 117static inline void ite_clrtobos(struct ite_softc *);
118static inline void ite_clrtobol(struct ite_softc *); 118static inline void ite_clrtobol(struct ite_softc *);
119static inline void ite_clrtoeol(struct ite_softc *); 119static inline void ite_clrtoeol(struct ite_softc *);
120static inline void ite_clrtoeos(struct ite_softc *); 120static inline void ite_clrtoeos(struct ite_softc *);
121static inline void ite_dnchar(struct ite_softc *, int); 121static inline void ite_dnchar(struct ite_softc *, int);
122static inline void ite_inchar(struct ite_softc *, int); 122static inline void ite_inchar(struct ite_softc *, int);
123static inline void ite_inline(struct ite_softc *, int); 123static inline void ite_inline(struct ite_softc *, int);
124static inline void ite_lf(struct ite_softc *); 124static inline void ite_lf(struct ite_softc *);
125static inline void ite_dnline(struct ite_softc *, int); 125static inline void ite_dnline(struct ite_softc *, int);
126static inline void ite_rlf(struct ite_softc *); 126static inline void ite_rlf(struct ite_softc *);
127static inline void ite_sendstr(const char *); 127static inline void ite_sendstr(const char *);
128static inline void snap_cury(struct ite_softc *); 128static inline void snap_cury(struct ite_softc *);
129 129
130static void alignment_display(struct ite_softc *); 130static void alignment_display(struct ite_softc *);
131static struct ite_softc *getitesp(dev_t); 131static struct ite_softc *getitesp(dev_t);
132static void itecheckwrap(struct ite_softc *); 132static void itecheckwrap(struct ite_softc *);
133static void iteprecheckwrap(struct ite_softc *); 133static void iteprecheckwrap(struct ite_softc *);
134static void itestart(struct tty *); 134static void itestart(struct tty *);
135static void ite_switch(int); 135static void ite_switch(int);
136static void repeat_handler(void *); 136static void repeat_handler(void *);
137 137
138void iteputchar(int c, struct ite_softc *sc); 138void iteputchar(int c, struct ite_softc *sc);
139void ite_putstr(const u_char * s, int len, dev_t dev); 139void ite_putstr(const u_char * s, int len, dev_t dev);
140void iteattach(device_t, device_t, void *); 140void iteattach(device_t, device_t, void *);
141int itematch(device_t, cfdata_t, void *); 141int itematch(device_t, cfdata_t, void *);
142 142
143/* 143/*
144 * Console specific types. 144 * Console specific types.
145 */ 145 */
146dev_type_cnprobe(itecnprobe); 146dev_type_cnprobe(itecnprobe);
147dev_type_cninit(itecninit); 147dev_type_cninit(itecninit);
148dev_type_cngetc(itecngetc); 148dev_type_cngetc(itecngetc);
149dev_type_cnputc(itecnputc); 149dev_type_cnputc(itecnputc);
150 150
151CFATTACH_DECL_NEW(ite, sizeof(struct ite_softc), 151CFATTACH_DECL_NEW(ite, sizeof(struct ite_softc),
152 itematch, iteattach, NULL, NULL); 152 itematch, iteattach, NULL, NULL);
153 153
154dev_type_open(iteopen); 154dev_type_open(iteopen);
155dev_type_close(iteclose); 155dev_type_close(iteclose);
156dev_type_read(iteread); 156dev_type_read(iteread);
157dev_type_write(itewrite); 157dev_type_write(itewrite);
158dev_type_ioctl(iteioctl); 158dev_type_ioctl(iteioctl);
159dev_type_tty(itetty); 159dev_type_tty(itetty);
160dev_type_poll(itepoll); 160dev_type_poll(itepoll);
161 161
162const struct cdevsw ite_cdevsw = { 162const struct cdevsw ite_cdevsw = {
163 iteopen, iteclose, iteread, itewrite, iteioctl, 163 iteopen, iteclose, iteread, itewrite, iteioctl,
164 nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY 164 nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY
165}; 165};
166 166
167/* 167/*
168 * Keep track of the device number of the ite console. Only used in the 168 * Keep track of the device number of the ite console. Only used in the
169 * itematch/iteattach functions. 169 * itematch/iteattach functions.
170 */ 170 */
171static int cons_ite = -1; 171static int cons_ite = -1;
172 172
173int 173int
174itematch(device_t parent, cfdata_t cf, void *aux) 174itematch(device_t parent, cfdata_t cf, void *aux)
175{ 175{
176  176
177 /* 177 /*
178 * Handle early console stuff. The first unit number 178 * Handle early console stuff. The first unit number
179 * is the console unit. All other early matches will fail. 179 * is the console unit. All other early matches will fail.
180 */ 180 */
181 if (atari_realconfig == 0) { 181 if (atari_realconfig == 0) {
182 if (cons_ite >= 0) 182 if (cons_ite >= 0)
183 return 0; 183 return 0;
184 cons_ite = cf->cf_unit; 184 cons_ite = cf->cf_unit;
185 return 1; 185 return 1;
186 } 186 }
187 return 1; 187 return 1;
188} 188}
189 189
190void 190void
191iteattach(device_t parent, device_t self, void *aux) 191iteattach(device_t parent, device_t self, void *aux)
192{ 192{
193 struct grf_softc *gsc; 193 struct grf_softc *gsc;
194 struct ite_softc *sc; 194 struct ite_softc *sc;
195 int s; 195 int s;
196 int maj, unit; 196 int maj, unit;
197 197
198 gsc = device_private(parent); 198 gsc = device_private(parent);
199 sc = device_private(self); 199 sc = device_private(self);
200 200
201 maj = cdevsw_lookup_major(&ite_cdevsw); 201 maj = cdevsw_lookup_major(&ite_cdevsw);
202 unit = (self != NULL) ? device_unit(self) : cons_ite; 202 unit = (self != NULL) ? device_unit(self) : cons_ite;
203 gsc->g_itedev = makedev(maj, unit); 203 gsc->g_itedev = makedev(maj, unit);
204 204
205 if (self != NULL) { 205 if (self != NULL) {
206 s = spltty(); 206 s = spltty();
207 if (con_itesoftc.grf != NULL && 207 if (con_itesoftc.grf != NULL &&
208 con_itesoftc.grf->g_unit == gsc->g_unit) { 208 con_itesoftc.grf->g_unit == gsc->g_unit) {
209 /* 209 /*
210 * console reinit copy params over. 210 * console reinit copy params over.
211 * and console always gets keyboard 211 * and console always gets keyboard
212 */ 212 */
213 memcpy(&sc->grf, &con_itesoftc.grf, 213 memcpy(&sc->grf, &con_itesoftc.grf,
214 (char *)&sc[1] - (char *)&sc->grf); 214 (char *)&sc[1] - (char *)&sc->grf);
215 con_itesoftc.grf = NULL; 215 con_itesoftc.grf = NULL;
216 kbd_ite = sc; 216 kbd_ite = sc;
217 } 217 }
218 sc->grf = gsc; 218 sc->grf = gsc;
219 splx(s); 219 splx(s);
220 220
221 iteinit(gsc->g_itedev); 221 iteinit(gsc->g_itedev);
222 printf(": %dx%d", sc->rows, sc->cols); 222 printf(": %dx%d", sc->rows, sc->cols);
223 printf(" repeat at (%d/100)s next at (%d/100)s", 223 printf(" repeat at (%d/100)s next at (%d/100)s",
224 start_repeat_timeo, next_repeat_timeo); 224 start_repeat_timeo, next_repeat_timeo);
225 225
226 if (kbd_ite == NULL) 226 if (kbd_ite == NULL)
227 kbd_ite = sc; 227 kbd_ite = sc;
228 if (kbd_ite == sc) 228 if (kbd_ite == sc)
229 printf(" has keyboard"); 229 printf(" has keyboard");
230 printf("\n"); 230 printf("\n");
231 sc->flags |= ITE_ATTACHED; 231 sc->flags |= ITE_ATTACHED;
232 } else { 232 } else {
233 if (con_itesoftc.grf != NULL && 233 if (con_itesoftc.grf != NULL &&
234 con_itesoftc.grf->g_conpri > gsc->g_conpri) 234 con_itesoftc.grf->g_conpri > gsc->g_conpri)
235 return; 235 return;
236 con_itesoftc.grf = gsc; 236 con_itesoftc.grf = gsc;
237 con_itesoftc.tabs = cons_tabs; 237 con_itesoftc.tabs = cons_tabs;
238 } 238 }
239} 239}
240 240
241static struct ite_softc * 241static struct ite_softc *
242getitesp(dev_t dev) 242getitesp(dev_t dev)
243{ 243{
244 244
245 if (atari_realconfig && (con_itesoftc.grf == NULL)) 245 if (atari_realconfig && (con_itesoftc.grf == NULL))
246 return(device_lookup_private(&ite_cd, ITEUNIT(dev))); 246 return(device_lookup_private(&ite_cd, ITEUNIT(dev)));
247 247
248 if (con_itesoftc.grf == NULL) 248 if (con_itesoftc.grf == NULL)
249 panic("no ite_softc for console"); 249 panic("no ite_softc for console");
250 return(&con_itesoftc); 250 return(&con_itesoftc);
251} 251}
252 252
253/* 253/*
254 * cons.c entry points into ite device. 254 * cons.c entry points into ite device.
255 */ 255 */
256 256
257/* 257/*
258 * Return a priority in consdev->cn_pri field highest wins. This function 258 * Return a priority in consdev->cn_pri field highest wins. This function
259 * is called before any devices have been probed. 259 * is called before any devices have been probed.
260 */ 260 */
261void 261void
262itecnprobe(struct consdev *cd) 262itecnprobe(struct consdev *cd)
263{ 263{
264 /*  264 /*
265 * return priority of the best ite (already picked from attach) 265 * return priority of the best ite (already picked from attach)
266 * or CN_DEAD. 266 * or CN_DEAD.
267 */ 267 */
268 if (con_itesoftc.grf == NULL) 268 if (con_itesoftc.grf == NULL)
269 cd->cn_pri = CN_DEAD; 269 cd->cn_pri = CN_DEAD;
270 else { 270 else {
271 cd->cn_pri = con_itesoftc.grf->g_conpri; 271 cd->cn_pri = con_itesoftc.grf->g_conpri;
272 cd->cn_dev = con_itesoftc.grf->g_itedev; 272 cd->cn_dev = con_itesoftc.grf->g_itedev;
273 } 273 }
274} 274}
275 275
276void 276void
277itecninit(struct consdev *cd) 277itecninit(struct consdev *cd)
278{ 278{
279 struct ite_softc *sc; 279 struct ite_softc *sc;
280 280
281 sc = getitesp(cd->cn_dev); 281 sc = getitesp(cd->cn_dev);
282 sc->flags |= ITE_ISCONS; 282 sc->flags |= ITE_ISCONS;
283 iteinit(cd->cn_dev); 283 iteinit(cd->cn_dev);
284 sc->flags |= ITE_ACTIVE | ITE_ISCONS; 284 sc->flags |= ITE_ACTIVE | ITE_ISCONS;
285} 285}
286 286
287/* 287/*
288 * ite_cnfinish() is called in ite_init() when the device is 288 * ite_cnfinish() is called in ite_init() when the device is
289 * being probed in the normal fasion, thus we can finish setting 289 * being probed in the normal fasion, thus we can finish setting
290 * up this ite now that the system is more functional. 290 * up this ite now that the system is more functional.
291 */ 291 */
292void 292void
293ite_cnfinish(struct ite_softc *sc) 293ite_cnfinish(struct ite_softc *sc)
294{ 294{
295 static int done; 295 static int done;
296 296
297 if (done) 297 if (done)
298 return; 298 return;
299 done = 1; 299 done = 1;
300} 300}
301 301
302int 302int
303itecngetc(dev_t dev) 303itecngetc(dev_t dev)
304{ 304{
305 int c; 305 int c;
306 306
307 do { 307 do {
308 c = kbdgetcn(); 308 c = kbdgetcn();
309 c = ite_cnfilter(c, ITEFILT_CONSOLE); 309 c = ite_cnfilter(c, ITEFILT_CONSOLE);
310 } while (c == -1); 310 } while (c == -1);
311 return (c); 311 return (c);
312} 312}
313 313
314void 314void
315itecnputc(dev_t dev, int c) 315itecnputc(dev_t dev, int c)
316{ 316{
317 static int paniced; 317 static int paniced;
318 struct ite_softc *sc; 318 struct ite_softc *sc;
319 char ch; 319 char ch;
320 320
321 sc = getitesp(dev); 321 sc = getitesp(dev);
322 ch = c; 322 ch = c;
323 323
324 if (panicstr && !paniced && 324 if (panicstr && !paniced &&
325 (sc->flags & (ITE_ACTIVE | ITE_INGRF)) != ITE_ACTIVE) { 325 (sc->flags & (ITE_ACTIVE | ITE_INGRF)) != ITE_ACTIVE) {
326 ite_on(dev, 3); 326 ite_on(dev, 3);
327 paniced = 1; 327 paniced = 1;
328 } 328 }
329 SUBR_CURSOR(sc, START_CURSOROPT); 329 SUBR_CURSOR(sc, START_CURSOROPT);
330 iteputchar(ch, sc); 330 iteputchar(ch, sc);
331 SUBR_CURSOR(sc, END_CURSOROPT); 331 SUBR_CURSOR(sc, END_CURSOROPT);
332} 332}
333 333
334/* 334/*
335 * standard entry points to the device. 335 * standard entry points to the device.
336 */ 336 */
337 337
338/*  338/*
339 * iteinit() is the standard entry point for initialization of 339 * iteinit() is the standard entry point for initialization of
340 * an ite device, it is also called from itecninit(). 340 * an ite device, it is also called from itecninit().
341 * 341 *
342 */ 342 */
343void 343void
344iteinit(dev_t dev) 344iteinit(dev_t dev)
345{ 345{
346 struct ite_softc *sc; 346 struct ite_softc *sc;
347 347
348 sc = getitesp(dev); 348 sc = getitesp(dev);
349 if (sc->flags & ITE_INITED) 349 if (sc->flags & ITE_INITED)
350 return; 350 return;
351 if (atari_realconfig) { 351 if (atari_realconfig) {
352 if (sc->kbdmap && sc->kbdmap != &ascii_kbdmap) 352 if (sc->kbdmap && sc->kbdmap != &ascii_kbdmap)
353 free(sc->kbdmap, M_DEVBUF); 353 free(sc->kbdmap, M_DEVBUF);
354 sc->kbdmap = malloc(sizeof(struct kbdmap), M_DEVBUF, M_WAITOK); 354 sc->kbdmap = malloc(sizeof(struct kbdmap), M_DEVBUF, M_WAITOK);
355 memcpy(sc->kbdmap, &ascii_kbdmap, sizeof(struct kbdmap)); 355 memcpy(sc->kbdmap, &ascii_kbdmap, sizeof(struct kbdmap));
356 } 356 }
357 else 357 else
358 sc->kbdmap = &ascii_kbdmap; 358 sc->kbdmap = &ascii_kbdmap;
359 359
360 sc->cursorx = 0; 360 sc->cursorx = 0;
361 sc->cursory = 0; 361 sc->cursory = 0;
362 SUBR_INIT(sc); 362 SUBR_INIT(sc);
363 SUBR_CURSOR(sc, DRAW_CURSOR); 363 SUBR_CURSOR(sc, DRAW_CURSOR);
364 if (sc->tabs == NULL) 364 if (sc->tabs == NULL)
365 sc->tabs = malloc(MAX_TABS * sizeof(u_char),M_DEVBUF,M_WAITOK); 365 sc->tabs = malloc(MAX_TABS * sizeof(u_char),M_DEVBUF,M_WAITOK);
366 ite_reset(sc); 366 ite_reset(sc);
367 sc->flags |= ITE_INITED; 367 sc->flags |= ITE_INITED;
368} 368}
369 369
370int 370int
371iteopen(dev_t dev, int mode, int devtype, struct lwp *l) 371iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
372{ 372{
373 struct ite_softc *sc; 373 struct ite_softc *sc;
374 struct tty *tp; 374 struct tty *tp;
375 int error, first, unit; 375 int error, first, unit;
376 376
377 unit = ITEUNIT(dev); 377 unit = ITEUNIT(dev);
378 if (unit >= ite_cd.cd_ndevs) 378 if (unit >= ite_cd.cd_ndevs)
379 return ENXIO; 379 return ENXIO;
380 380
381 first = 0; 381 first = 0;
382 sc = getitesp(dev); 382 sc = getitesp(dev);
383 if (sc == NULL) 383 if (sc == NULL)
384 return ENXIO; 384 return ENXIO;
385 if ((sc->flags & ITE_ATTACHED) == 0) 385 if ((sc->flags & ITE_ATTACHED) == 0)
386 return (ENXIO); 386 return (ENXIO);
387 387
388 if (sc->tp == NULL) { 388 if (sc->tp == NULL) {
389 tp = sc->tp = tty_alloc(); 389 tp = sc->tp = tty_alloc();
390 tty_attach(tp); 390 tty_attach(tp);
391 } 391 }
392 else 392 else
393 tp = sc->tp; 393 tp = sc->tp;
394 394
395 if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp)) 395 if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
396 return (EBUSY); 396 return (EBUSY);
397 397
398 if ((sc->flags & ITE_ACTIVE) == 0) { 398 if ((sc->flags & ITE_ACTIVE) == 0) {
399 ite_on(dev, 0); 399 ite_on(dev, 0);
400 first = 1; 400 first = 1;
401 } 401 }
402 if (!(tp->t_state & TS_ISOPEN) && tp->t_wopen == 0) { 402 if (!(tp->t_state & TS_ISOPEN) && tp->t_wopen == 0) {
403 tp->t_oproc = itestart; 403 tp->t_oproc = itestart;
404 tp->t_param = ite_param; 404 tp->t_param = ite_param;
405 tp->t_dev = dev; 405 tp->t_dev = dev;
406 tp->t_iflag = TTYDEF_IFLAG; 406 tp->t_iflag = TTYDEF_IFLAG;
407 tp->t_oflag = TTYDEF_OFLAG; 407 tp->t_oflag = TTYDEF_OFLAG;
408 tp->t_cflag = TTYDEF_CFLAG; 408 tp->t_cflag = TTYDEF_CFLAG;
409 tp->t_lflag = TTYDEF_LFLAG; 409 tp->t_lflag = TTYDEF_LFLAG;
410 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 410 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
411 tp->t_state = TS_CARR_ON; 411 tp->t_state = TS_CARR_ON;
412 ttychars(tp); 412 ttychars(tp);
413 ttsetwater(tp); 413 ttsetwater(tp);
414 } 414 }
415 415
416 416
417 error = ttyopen(tp, 0, (mode & O_NONBLOCK) ? 1 : 0); 417 error = ttyopen(tp, 0, (mode & O_NONBLOCK) ? 1 : 0);
418 if (error) 418 if (error)
419 goto bad; 419 goto bad;
420 420
421 error = (*tp->t_linesw->l_open) (dev, tp); 421 error = (*tp->t_linesw->l_open) (dev, tp);
422 if (error) 422 if (error)
423 goto bad; 423 goto bad;
424 424
425 tp->t_winsize.ws_row = sc->rows; 425 tp->t_winsize.ws_row = sc->rows;
426 tp->t_winsize.ws_col = sc->cols; 426 tp->t_winsize.ws_col = sc->cols;
427 if (!kbd_init) { 427 if (!kbd_init) {
428 kbd_init = 1; 428 kbd_init = 1;
429 kbdenable(); 429 kbdenable();
430 } 430 }
431 return (0); 431 return (0);
432 432
433 433
434bad: 434bad:
435 if (first) 435 if (first)
436 ite_off(dev, 0); 436 ite_off(dev, 0);
437 437
438 return (error); 438 return (error);
439} 439}
440 440
441int 441int
442iteclose(dev_t dev, int flag, int mode, struct lwp *l) 442iteclose(dev_t dev, int flag, int mode, struct lwp *l)
443{ 443{
444 struct tty *tp; 444 struct tty *tp;
445 445
446 tp = getitesp(dev)->tp; 446 tp = getitesp(dev)->tp;
447 447
448 KDASSERT(tp); 448 KDASSERT(tp);
449 (*tp->t_linesw->l_close) (tp, flag); 449 (*tp->t_linesw->l_close) (tp, flag);
450 ttyclose(tp); 450 ttyclose(tp);
451 ite_off(dev, 0); 451 ite_off(dev, 0);
452 return (0); 452 return (0);
453} 453}
454 454
455int 455int
456iteread(dev_t dev, struct uio *uio, int flag) 456iteread(dev_t dev, struct uio *uio, int flag)
457{ 457{
458 struct tty *tp; 458 struct tty *tp;
459 459
460 tp = getitesp(dev)->tp; 460 tp = getitesp(dev)->tp;
461 461
462 KDASSERT(tp); 462 KDASSERT(tp);
463 return ((*tp->t_linesw->l_read) (tp, uio, flag)); 463 return ((*tp->t_linesw->l_read) (tp, uio, flag));
464} 464}
465 465
466int 466int
467itewrite(dev_t dev, struct uio *uio, int flag) 467itewrite(dev_t dev, struct uio *uio, int flag)
468{ 468{
469 struct tty *tp; 469 struct tty *tp;
470 470
471 tp = getitesp(dev)->tp; 471 tp = getitesp(dev)->tp;
472 472
473 KDASSERT(tp); 473 KDASSERT(tp);
474 return ((*tp->t_linesw->l_write) (tp, uio, flag)); 474 return ((*tp->t_linesw->l_write) (tp, uio, flag));
475} 475}
476 476
477int 477int
478itepoll(dev_t dev, int events, struct lwp *l) 478itepoll(dev_t dev, int events, struct lwp *l)
479{ 479{
480 struct tty *tp; 480 struct tty *tp;
481 481
482 tp = getitesp(dev)->tp; 482 tp = getitesp(dev)->tp;
483 483
484 KDASSERT(tp); 484 KDASSERT(tp);
485 return ((*tp->t_linesw->l_poll)(tp, events, l)); 485 return ((*tp->t_linesw->l_poll)(tp, events, l));
486} 486}
487 487
488struct tty * 488struct tty *
489itetty(dev_t dev) 489itetty(dev_t dev)
490{ 490{
491 return(getitesp(dev)->tp); 491 return(getitesp(dev)->tp);
492} 492}
493 493
494int 494int
495iteioctl(dev_t dev, u_long cmd, void * addr, int flag, struct lwp *l) 495iteioctl(dev_t dev, u_long cmd, void * addr, int flag, struct lwp *l)
496{ 496{
497 struct iterepeat *irp; 497 struct iterepeat *irp;
498 struct ite_softc *sc; 498 struct ite_softc *sc;
499 struct tty *tp; 499 struct tty *tp;
500 view_t *view; 500 view_t *view;
501 struct itewinsize *is; 501 struct itewinsize *is;
502 struct itebell *ib; 502 struct itebell *ib;
503 int error; 503 int error;
504  504
505 sc = getitesp(dev); 505 sc = getitesp(dev);
506 tp = sc->tp; 506 tp = sc->tp;
507 view = viewview(sc->grf->g_viewdev); 507 view = viewview(sc->grf->g_viewdev);
508 508
509 KDASSERT(tp); 509 KDASSERT(tp);
510 510
511 error = (*tp->t_linesw->l_ioctl) (tp, cmd, addr, flag, l); 511 error = (*tp->t_linesw->l_ioctl) (tp, cmd, addr, flag, l);
512 if (error != EPASSTHROUGH) 512 if (error != EPASSTHROUGH)
513 return (error); 513 return (error);
514 514
515 error = ttioctl(tp, cmd, addr, flag, l); 515 error = ttioctl(tp, cmd, addr, flag, l);
516 if (error != EPASSTHROUGH) 516 if (error != EPASSTHROUGH)
517 return (error); 517 return (error);
518 518
519 switch (cmd) { 519 switch (cmd) {
520 case ITEIOCSKMAP: 520 case ITEIOCSKMAP:
521 if (addr == NULL) 521 if (addr == NULL)
522 return(EFAULT); 522 return(EFAULT);
523 memcpy(sc->kbdmap, addr, sizeof(struct kbdmap)); 523 memcpy(sc->kbdmap, addr, sizeof(struct kbdmap));
524 return 0; 524 return 0;
525 case ITEIOCSSKMAP: 525 case ITEIOCSSKMAP:
526 if (addr == NULL) 526 if (addr == NULL)
527 return(EFAULT); 527 return(EFAULT);
528 memcpy(&ascii_kbdmap, addr, sizeof(struct kbdmap)); 528 memcpy(&ascii_kbdmap, addr, sizeof(struct kbdmap));
529 return 0; 529 return 0;
530 case ITEIOCGKMAP: 530 case ITEIOCGKMAP:
531 if (addr == NULL) 531 if (addr == NULL)
532 return(EFAULT); 532 return(EFAULT);
533 memcpy(addr, sc->kbdmap, sizeof(struct kbdmap)); 533 memcpy(addr, sc->kbdmap, sizeof(struct kbdmap));
534 return 0; 534 return 0;
535 case ITEIOCGREPT: 535 case ITEIOCGREPT:
536 if (addr == NULL) 536 if (addr == NULL)
537 return(EFAULT); 537 return(EFAULT);
538 irp = (struct iterepeat *)addr; 538 irp = (struct iterepeat *)addr;
539 irp->start = start_repeat_timeo; 539 irp->start = start_repeat_timeo;
540 irp->next = next_repeat_timeo; 540 irp->next = next_repeat_timeo;
541 return 0; 541 return 0;
542 case ITEIOCSREPT: 542 case ITEIOCSREPT:
543 if (addr == NULL) 543 if (addr == NULL)
544 return(EFAULT); 544 return(EFAULT);
545 irp = (struct iterepeat *)addr; 545 irp = (struct iterepeat *)addr;
546 if (irp->start < ITEMINREPEAT || irp->next < ITEMINREPEAT) 546 if (irp->start < ITEMINREPEAT || irp->next < ITEMINREPEAT)
547 return(EINVAL); 547 return(EINVAL);
548 start_repeat_timeo = irp->start; 548 start_repeat_timeo = irp->start;
549 next_repeat_timeo = irp->next; 549 next_repeat_timeo = irp->next;
550 return 0; 550 return 0;
551 case ITEIOCGWINSZ: 551 case ITEIOCGWINSZ:
552 if (addr == NULL) 552 if (addr == NULL)
553 return(EFAULT); 553 return(EFAULT);
554 is = (struct itewinsize *)addr; 554 is = (struct itewinsize *)addr;
555 is->x = view->display.x; 555 is->x = view->display.x;
556 is->y = view->display.y; 556 is->y = view->display.y;
557 is->width = view->display.width; 557 is->width = view->display.width;
558 is->height = view->display.height; 558 is->height = view->display.height;
559 is->depth = view->bitmap->depth; 559 is->depth = view->bitmap->depth;
560 return 0; 560 return 0;
561 case ITEIOCDSPWIN: 561 case ITEIOCDSPWIN:
562 sc->grf->g_mode(sc->grf, GM_GRFON, NULL, 0, 0); 562 sc->grf->g_mode(sc->grf, GM_GRFON, NULL, 0, 0);
563 return 0; 563 return 0;
564 case ITEIOCREMWIN: 564 case ITEIOCREMWIN:
565 sc->grf->g_mode(sc->grf, GM_GRFOFF, NULL, 0, 0); 565 sc->grf->g_mode(sc->grf, GM_GRFOFF, NULL, 0, 0);
566 return 0; 566 return 0;
567 case ITEIOCSBELL: 567 case ITEIOCSBELL:
568 if (addr == NULL) 568 if (addr == NULL)
569 return(EFAULT); 569 return(EFAULT);
570 ib = (struct itebell *)addr; 570 ib = (struct itebell *)addr;
571 kbd_bell_sparms(ib->volume, ib->pitch, ib->msec); 571 kbd_bell_sparms(ib->volume, ib->pitch, ib->msec);
572 return 0; 572 return 0;
573 case ITEIOCGBELL: 573 case ITEIOCGBELL:
574 if (addr == NULL) 574 if (addr == NULL)
575 return(EFAULT); 575 return(EFAULT);
576 ib = (struct itebell *)addr; 576 ib = (struct itebell *)addr;
577 kbd_bell_gparms(&ib->volume, &ib->pitch, &ib->msec); 577 kbd_bell_gparms(&ib->volume, &ib->pitch, &ib->msec);
578 return 0; 578 return 0;
579 } 579 }
580 return (sc->itexx_ioctl)(sc, cmd, addr, flag, l); 580 return (sc->itexx_ioctl)(sc, cmd, addr, flag, l);
581} 581}
582 582
583void 583void
584itestart(struct tty *tp) 584itestart(struct tty *tp)
585{ 585{
586 struct clist *rbp; 586 struct clist *rbp;
587 struct ite_softc *sc; 587 struct ite_softc *sc;
588 u_char buf[ITEBURST]; 588 u_char buf[ITEBURST];
589 int s, len; 589 int s, len;
590 590
591 sc = getitesp(tp->t_dev); 591 sc = getitesp(tp->t_dev);
592 592
593 KDASSERT(tp); 593 KDASSERT(tp);
594 594
595 s = spltty(); { 595 s = spltty(); {
596 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) 596 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
597 goto out; 597 goto out;
598 598
599 tp->t_state |= TS_BUSY; 599 tp->t_state |= TS_BUSY;
600 rbp = &tp->t_outq; 600 rbp = &tp->t_outq;
601  601
602 len = q_to_b(rbp, buf, ITEBURST); 602 len = q_to_b(rbp, buf, ITEBURST);
603 } splx(s); 603 } splx(s);
604 604
605 /* Here is a really good place to implement pre/jumpscroll() */ 605 /* Here is a really good place to implement pre/jumpscroll() */
606 ite_putstr((char *)buf, len, tp->t_dev); 606 ite_putstr((char *)buf, len, tp->t_dev);
607 607
608 s = spltty(); { 608 s = spltty(); {
609 tp->t_state &= ~TS_BUSY; 609 tp->t_state &= ~TS_BUSY;
610 /* we have characters remaining. */ 610 /* we have characters remaining. */
611 if (ttypull(tp)) { 611 if (ttypull(tp)) {
612 tp->t_state |= TS_TIMEOUT; 612 tp->t_state |= TS_TIMEOUT;
613 callout_schedule(&tp->t_rstrt_ch, 1); 613 callout_schedule(&tp->t_rstrt_ch, 1);
614 } 614 }
615 out: ; 615 out: ;
616 } splx(s); 616 } splx(s);
617} 617}
618 618
619void 619void
620ite_on(dev_t dev, int flag) 620ite_on(dev_t dev, int flag)
621{ 621{
622 struct ite_softc *sc; 622 struct ite_softc *sc;
623 int unit; 623 int unit;
624 624
625 unit = ITEUNIT(dev); 625 unit = ITEUNIT(dev);
626 sc = getitesp(dev);  626 sc = getitesp(dev);
627 627
628 /* force ite active, overriding graphics mode */ 628 /* force ite active, overriding graphics mode */
629 if (flag & 1) { 629 if (flag & 1) {
630 sc->flags |= ITE_ACTIVE; 630 sc->flags |= ITE_ACTIVE;
631 sc->flags &= ~(ITE_INGRF | ITE_INITED); 631 sc->flags &= ~(ITE_INGRF | ITE_INITED);
632 } 632 }
633 /* leave graphics mode */ 633 /* leave graphics mode */
634 if (flag & 2) { 634 if (flag & 2) {
635 sc->flags &= ~ITE_INGRF; 635 sc->flags &= ~ITE_INGRF;
636 if ((sc->flags & ITE_ACTIVE) == 0) 636 if ((sc->flags & ITE_ACTIVE) == 0)
637 return; 637 return;
638 } 638 }
639 sc->flags |= ITE_ACTIVE; 639 sc->flags |= ITE_ACTIVE;
640 if (sc->flags & ITE_INGRF) 640 if (sc->flags & ITE_INGRF)
641 return; 641 return;
642 iteinit(dev); 642 iteinit(dev);
643} 643}
644 644
645void 645void
646ite_off(dev_t dev, int flag) 646ite_off(dev_t dev, int flag)
647{ 647{
648 struct ite_softc *sc; 648 struct ite_softc *sc;
649 649
650 sc = getitesp(dev); 650 sc = getitesp(dev);
651 if (flag & 2) 651 if (flag & 2)
652 sc->flags |= ITE_INGRF; 652 sc->flags |= ITE_INGRF;
653 if ((sc->flags & ITE_ACTIVE) == 0) 653 if ((sc->flags & ITE_ACTIVE) == 0)
654 return; 654 return;
655 if ((flag & 1) || 655 if ((flag & 1) ||
656 (sc->flags & (ITE_INGRF | ITE_ISCONS | ITE_INITED)) == ITE_INITED) 656 (sc->flags & (ITE_INGRF | ITE_ISCONS | ITE_INITED)) == ITE_INITED)
657 SUBR_DEINIT(sc); 657 SUBR_DEINIT(sc);
658 if ((flag & 2) == 0) /* XXX hmm grfon() I think wants this to go inactive. */ 658 if ((flag & 2) == 0) /* XXX hmm grfon() I think wants this to go inactive. */
659 sc->flags &= ~ITE_ACTIVE; 659 sc->flags &= ~ITE_ACTIVE;
660} 660}
661 661
662static void 662static void
663ite_switch(int unit) 663ite_switch(int unit)
664{ 664{
665 struct ite_softc *sc; 665 struct ite_softc *sc;
666 extern const struct cdevsw view_cdevsw; 666 extern const struct cdevsw view_cdevsw;
667 667
668 sc = getitesp(unit); 668 sc = device_lookup_private(&ite_cd, unit);
669 if ((sc->flags & (ITE_ATTACHED | ITE_INITED)) == 0) 669 if (sc == NULL || (sc->flags & (ITE_ATTACHED | ITE_INITED)) == 0)
670 return; 670 return;
671 671
672 /* 672 /*
673 * If switching to an active ite, also switch the keyboard. 673 * If switching to an active ite, also switch the keyboard.
674 */ 674 */
675 if (sc->flags & ITE_ACTIVE) 675 if (sc->flags & ITE_ACTIVE)
676 kbd_ite = sc; 676 kbd_ite = sc;
677 677
678 /* 678 /*
679 * Now make it visible 679 * Now make it visible
680 */ 680 */
681 (*view_cdevsw.d_ioctl)(sc->grf->g_viewdev, VIOCDISPLAY, NULL, 681 (*view_cdevsw.d_ioctl)(sc->grf->g_viewdev, VIOCDISPLAY, NULL,
682 0, NOLWP); 682 0, NOLWP);
683 683
684 /* 684 /*
685 * Make sure the cursor's there too.... 685 * Make sure the cursor's there too....
686 */ 686 */
687 SUBR_CURSOR(sc, DRAW_CURSOR); 687 SUBR_CURSOR(sc, DRAW_CURSOR);
688} 688}
689 689
690/* XXX called after changes made in underlying grf layer. */ 690/* XXX called after changes made in underlying grf layer. */
691/* I want to nuke this */ 691/* I want to nuke this */
692void 692void
693ite_reinit(dev_t dev) 693ite_reinit(dev_t dev)
694{ 694{
695 struct ite_softc *sc; 695 struct ite_softc *sc;
696 696
697 sc = getitesp(dev); 697 sc = getitesp(dev);
698 sc->flags &= ~ITE_INITED; 698 sc->flags &= ~ITE_INITED;
699 iteinit(dev); 699 iteinit(dev);
700} 700}
701 701
702int 702int
703ite_param(struct tty *tp, struct termios *t) 703ite_param(struct tty *tp, struct termios *t)
704{ 704{
705 tp->t_ispeed = t->c_ispeed; 705 tp->t_ispeed = t->c_ispeed;
706 tp->t_ospeed = t->c_ospeed; 706 tp->t_ospeed = t->c_ospeed;
707 tp->t_cflag = t->c_cflag; 707 tp->t_cflag = t->c_cflag;
708 return (0); 708 return (0);
709} 709}
710 710
711void 711void
712ite_reset(struct ite_softc *sc) 712ite_reset(struct ite_softc *sc)
713{ 713{
714 int i; 714 int i;
715 715
716 sc->curx = 0; 716 sc->curx = 0;
717 sc->cury = 0; 717 sc->cury = 0;
718 sc->attribute = ATTR_NOR; 718 sc->attribute = ATTR_NOR;
719 sc->save_curx = 0; 719 sc->save_curx = 0;
720 sc->save_cury = 0; 720 sc->save_cury = 0;
721 sc->save_attribute = ATTR_NOR; 721 sc->save_attribute = ATTR_NOR;
722 sc->ap = sc->argbuf; 722 sc->ap = sc->argbuf;
723 sc->emul_level = 0; 723 sc->emul_level = 0;
724 sc->eightbit_C1 = 0; 724 sc->eightbit_C1 = 0;
725 sc->top_margin = 0; 725 sc->top_margin = 0;
726 sc->bottom_margin = sc->rows - 1; 726 sc->bottom_margin = sc->rows - 1;
727 sc->inside_margins = 0; 727 sc->inside_margins = 0;
728 sc->linefeed_newline = 0; 728 sc->linefeed_newline = 0;
729 sc->auto_wrap = ite_default_wrap; 729 sc->auto_wrap = ite_default_wrap;
730 sc->cursor_appmode = 0; 730 sc->cursor_appmode = 0;
731 sc->keypad_appmode = 0; 731 sc->keypad_appmode = 0;
732 sc->imode = 0; 732 sc->imode = 0;
733 sc->key_repeat = 1; 733 sc->key_repeat = 1;
734 memset(sc->tabs, 0, sc->cols); 734 memset(sc->tabs, 0, sc->cols);
735 for (i = 0; i < sc->cols; i++) 735 for (i = 0; i < sc->cols; i++)
736 sc->tabs[i] = ((i & 7) == 0); 736 sc->tabs[i] = ((i & 7) == 0);
737} 737}
738 738
739/* 739/*
740 * has to be global because of the shared filters. 740 * has to be global because of the shared filters.
741 */ 741 */
742static u_char last_dead; 742static u_char last_dead;
743 743
744/* 744/*
745 * Used in console at startup only and for DDB. 745 * Used in console at startup only and for DDB.
746 */ 746 */
747int 747int
748ite_cnfilter(u_int c, enum caller caller) 748ite_cnfilter(u_int c, enum caller caller)
749{ 749{
750 struct key key; 750 struct key key;
751 struct kbdmap *kbdmap; 751 struct kbdmap *kbdmap;
752 u_char code, up, mask; 752 u_char code, up, mask;
753 int s; 753 int s;
754 754
755 up = KBD_RELEASED(c); 755 up = KBD_RELEASED(c);
756 c = KBD_SCANCODE(c); 756 c = KBD_SCANCODE(c);
757 code = 0; 757 code = 0;
758 mask = 0; 758 mask = 0;
759 kbdmap = (kbd_ite == NULL) ? &ascii_kbdmap : kbd_ite->kbdmap; 759 kbdmap = (kbd_ite == NULL) ? &ascii_kbdmap : kbd_ite->kbdmap;
760 760
761 s = spltty(); 761 s = spltty();
762 762
763 /* 763 /*
764 * No special action if key released 764 * No special action if key released
765 */ 765 */
766 if (up) { 766 if (up) {
767 splx(s); 767 splx(s);
768 return -1; 768 return -1;
769 } 769 }
770  770
771 /* translate modifiers */ 771 /* translate modifiers */
772 if (kbd_modifier & KBD_MOD_SHIFT) { 772 if (kbd_modifier & KBD_MOD_SHIFT) {
773 if (kbd_modifier & KBD_MOD_ALT) 773 if (kbd_modifier & KBD_MOD_ALT)
774 key = kbdmap->alt_shift_keys[c]; 774 key = kbdmap->alt_shift_keys[c];
775 else 775 else
776 key = kbdmap->shift_keys[c]; 776 key = kbdmap->shift_keys[c];
777 } 777 }
778 else if (kbd_modifier & KBD_MOD_ALT) 778 else if (kbd_modifier & KBD_MOD_ALT)
779 key = kbdmap->alt_keys[c]; 779 key = kbdmap->alt_keys[c];
780 else { 780 else {
781 key = kbdmap->keys[c]; 781 key = kbdmap->keys[c];
782 /* 782 /*
783 * If CAPS and key is CAPable (no pun intended) 783 * If CAPS and key is CAPable (no pun intended)
784 */ 784 */
785 if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS)) 785 if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
786 key = kbdmap->shift_keys[c]; 786 key = kbdmap->shift_keys[c];
787 } 787 }
788 code = key.code; 788 code = key.code;
789 789
790#ifdef notyet /* LWP: Didn't have time to look at this yet */ 790#ifdef notyet /* LWP: Didn't have time to look at this yet */
791 /* 791 /*
792 * If string return simple console filter 792 * If string return simple console filter
793 */ 793 */
794 if (key->mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) { 794 if (key->mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) {
795 splx(s); 795 splx(s);
796 return -1; 796 return -1;
797 } 797 }
798 /* handle dead keys */ 798 /* handle dead keys */
799 if (key->mode & KBD_MODE_DEAD) { 799 if (key->mode & KBD_MODE_DEAD) {
800 /* if entered twice, send accent itself */ 800 /* if entered twice, send accent itself */
801 if (last_dead == key->mode & KBD_MODE_ACCMASK) 801 if (last_dead == key->mode & KBD_MODE_ACCMASK)
802 last_dead = 0; 802 last_dead = 0;
803 else { 803 else {
804 last_dead = key->mode & KBD_MODE_ACCMASK; 804 last_dead = key->mode & KBD_MODE_ACCMASK;
805 splx(s); 805 splx(s);
806 return -1; 806 return -1;
807 } 807 }
808 } 808 }
809 if (last_dead) { 809 if (last_dead) {
810 /* can't apply dead flag to string-keys */ 810 /* can't apply dead flag to string-keys */
811 if (code >= '@' && code < 0x7f) 811 if (code >= '@' && code < 0x7f)
812 code = 812 code =
813 acctable[KBD_MODE_ACCENT(last_dead)][code - '@']; 813 acctable[KBD_MODE_ACCENT(last_dead)][code - '@'];
814 last_dead = 0; 814 last_dead = 0;
815 } 815 }
816#endif 816#endif
817 if (kbd_modifier & KBD_MOD_CTRL) 817 if (kbd_modifier & KBD_MOD_CTRL)
818 code &= 0x1f; 818 code &= 0x1f;
819 819
820 /* 820 /*
821 * Do console mapping. 821 * Do console mapping.
822 */ 822 */
823 code = code == '\r' ? '\n' : code; 823 code = code == '\r' ? '\n' : code;
824 824
825 splx(s); 825 splx(s);
826 return (code); 826 return (code);
827} 827}
828 828
829/* And now the old stuff. */ 829/* And now the old stuff. */
830 830
831/* these are used to implement repeating keys.. */ 831/* these are used to implement repeating keys.. */
832static u_int last_char; 832static u_int last_char;
833static u_char tout_pending; 833static u_char tout_pending;
834 834
835static callout_t repeat_ch; 835static callout_t repeat_ch;
836 836
837/*ARGSUSED*/ 837/*ARGSUSED*/
838static void 838static void
839repeat_handler(void *arg) 839repeat_handler(void *arg)
840{ 840{
841 tout_pending = 0; 841 tout_pending = 0;
842 if (last_char)  842 if (last_char)
843 add_sicallback((si_farg)ite_filter, (void *)last_char, 843 add_sicallback((si_farg)ite_filter, (void *)last_char,
844 (void *)ITEFILT_REPEATER); 844 (void *)ITEFILT_REPEATER);
845} 845}
846 846
847void 847void
848ite_filter(u_int c, enum caller caller) 848ite_filter(u_int c, enum caller caller)
849{ 849{
850 struct tty *kbd_tty; 850 struct tty *kbd_tty;
851 struct kbdmap *kbdmap; 851 struct kbdmap *kbdmap;
852 u_char code, *str, up, mask; 852 u_char code, *str, up, mask;
853 struct key key; 853 struct key key;
854 int s, i; 854 int s, i;
855 static bool again; 855 static bool again;
856 856
857 if (!again) { 857 if (!again) {
858 /* XXX */ 858 /* XXX */
859 callout_init(&repeat_ch, 0); 859 callout_init(&repeat_ch, 0);
860 again = true; 860 again = true;
861 } 861 }
862 862
863 if (kbd_ite == NULL) 863 if (kbd_ite == NULL)
864 return; 864 return;
865 865
866 kbd_tty = kbd_ite->tp; 866 kbd_tty = kbd_ite->tp;
867 kbdmap = kbd_ite->kbdmap; 867 kbdmap = kbd_ite->kbdmap;
868 868
869 up = KBD_RELEASED(c); 869 up = KBD_RELEASED(c);
870 c = KBD_SCANCODE(c); 870 c = KBD_SCANCODE(c);
871 code = 0; 871 code = 0;
872 mask = 0; 872 mask = 0;
873 873
874 /* have to make sure we're at spltty in here */ 874 /* have to make sure we're at spltty in here */
875 s = spltty(); 875 s = spltty();
876 876
877 /*  877 /*
878 * keyboard interrupts come at priority 2, while softint 878 * keyboard interrupts come at priority 2, while softint
879 * generated keyboard-repeat interrupts come at level 1. So, 879 * generated keyboard-repeat interrupts come at level 1. So,
880 * to not allow a key-up event to get thru before a repeat for 880 * to not allow a key-up event to get thru before a repeat for
881 * the key-down, we remove any outstanding callout requests.. 881 * the key-down, we remove any outstanding callout requests..
882 */ 882 */
883 rem_sicallback((si_farg)ite_filter); 883 rem_sicallback((si_farg)ite_filter);
884 884
885 /* 885 /*
886 * Stop repeating on up event 886 * Stop repeating on up event
887 */ 887 */
888 if (up) { 888 if (up) {
889 if (tout_pending) { 889 if (tout_pending) {
890 callout_stop(&repeat_ch); 890 callout_stop(&repeat_ch);
891 tout_pending = 0; 891 tout_pending = 0;
892 last_char = 0; 892 last_char = 0;
893 } 893 }
894 splx(s); 894 splx(s);
895 return; 895 return;
896 } 896 }
897 else if (tout_pending && last_char != c) { 897 else if (tout_pending && last_char != c) {
898 /* 898 /*
899 * Different character, stop also 899 * Different character, stop also
900 */ 900 */
901 callout_stop(&repeat_ch); 901 callout_stop(&repeat_ch);
902 tout_pending = 0; 902 tout_pending = 0;
903 last_char = 0; 903 last_char = 0;
904 } 904 }
905 905
906 /* 906 /*
907 * Handle ite-switching ALT + Fx 907 * Handle ite-switching ALT + Fx
908 */ 908 */
909 if ((kbd_modifier == KBD_MOD_ALT) && (c >= 0x3b) && (c <= 0x44)) { 909 if ((kbd_modifier == KBD_MOD_ALT) && (c >= 0x3b) && (c <= 0x44)) {
910 ite_switch(c - 0x3b); 910 ite_switch(c - 0x3b);
911 splx(s); 911 splx(s);
912 return; 912 return;
913 } 913 }
914 /* 914 /*
915 * Safety button, switch back to ascii keymap. 915 * Safety button, switch back to ascii keymap.
916 */ 916 */
917 if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) && c == 0x3b) { 917 if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) && c == 0x3b) {
918 /* ALT + LSHIFT + F1 */ 918 /* ALT + LSHIFT + F1 */
919 memcpy(kbdmap, &ascii_kbdmap, sizeof(struct kbdmap)); 919 memcpy(kbdmap, &ascii_kbdmap, sizeof(struct kbdmap));
920 splx(s); 920 splx(s);
921 return; 921 return;
922#ifdef DDB 922#ifdef DDB
923 } else if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) && 923 } else if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) &&
924 c == 0x43) { 924 c == 0x43) {
925 /* 925 /*
926 * ALT + LSHIFT + F9 -> Debugger! 926 * ALT + LSHIFT + F9 -> Debugger!
927 */ 927 */
928 Debugger(); 928 Debugger();
929 splx(s); 929 splx(s);
930 return; 930 return;
931#endif 931#endif
932 } 932 }
933 933
934 /* 934 /*
935 * The rest of the code is senseless when the device is not open. 935 * The rest of the code is senseless when the device is not open.
936 */ 936 */
937 if (kbd_tty == NULL) { 937 if (kbd_tty == NULL) {
938 splx(s); 938 splx(s);
939 return; 939 return;
940 } 940 }
941 941
942 /* 942 /*
943 * Translate modifiers 943 * Translate modifiers
944 */ 944 */
945 if (kbd_modifier & KBD_MOD_SHIFT) { 945 if (kbd_modifier & KBD_MOD_SHIFT) {
946 if (kbd_modifier & KBD_MOD_ALT) 946 if (kbd_modifier & KBD_MOD_ALT)
947 key = kbdmap->alt_shift_keys[c]; 947 key = kbdmap->alt_shift_keys[c];
948 else 948 else
949 key = kbdmap->shift_keys[c]; 949 key = kbdmap->shift_keys[c];
950 } 950 }
951 else if (kbd_modifier & KBD_MOD_ALT) 951 else if (kbd_modifier & KBD_MOD_ALT)
952 key = kbdmap->alt_keys[c]; 952 key = kbdmap->alt_keys[c];
953 else { 953 else {
954 key = kbdmap->keys[c]; 954 key = kbdmap->keys[c];
955 /* 955 /*
956 * If CAPS and key is CAPable (no pun intended) 956 * If CAPS and key is CAPable (no pun intended)
957 */ 957 */
958 if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS)) 958 if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
959 key = kbdmap->shift_keys[c]; 959 key = kbdmap->shift_keys[c];
960 } 960 }
961 code = key.code; 961 code = key.code;
962 962
963 /*  963 /*
964 * Arrange to repeat the keystroke. By doing this at the level 964 * Arrange to repeat the keystroke. By doing this at the level
965 * of scan-codes, we can have function keys, and keys that 965 * of scan-codes, we can have function keys, and keys that
966 * send strings, repeat too. This also entitles an additional 966 * send strings, repeat too. This also entitles an additional
967 * overhead, since we have to do the conversion each time, but 967 * overhead, since we have to do the conversion each time, but
968 * I guess that's ok. 968 * I guess that's ok.
969 */ 969 */
970 if (!tout_pending && caller == ITEFILT_TTY && kbd_ite->key_repeat) { 970 if (!tout_pending && caller == ITEFILT_TTY && kbd_ite->key_repeat) {
971 tout_pending = 1; 971 tout_pending = 1;
972 last_char = c; 972 last_char = c;
973 callout_reset(&repeat_ch, start_repeat_timeo * hz / 100, 973 callout_reset(&repeat_ch, start_repeat_timeo * hz / 100,
974 repeat_handler, NULL); 974 repeat_handler, NULL);
975 } else if (!tout_pending && caller==ITEFILT_REPEATER && 975 } else if (!tout_pending && caller==ITEFILT_REPEATER &&
976 kbd_ite->key_repeat) { 976 kbd_ite->key_repeat) {
977 tout_pending = 1; 977 tout_pending = 1;
978 last_char = c; 978 last_char = c;
979 callout_reset(&repeat_ch, next_repeat_timeo * hz / 100, 979 callout_reset(&repeat_ch, next_repeat_timeo * hz / 100,
980 repeat_handler, NULL); 980 repeat_handler, NULL);
981 } 981 }
982 /* handle dead keys */ 982 /* handle dead keys */
983 if (key.mode & KBD_MODE_DEAD) { 983 if (key.mode & KBD_MODE_DEAD) {
984 /* if entered twice, send accent itself */ 984 /* if entered twice, send accent itself */
985 if (last_dead == (key.mode & KBD_MODE_ACCMASK)) 985 if (last_dead == (key.mode & KBD_MODE_ACCMASK))
986 last_dead = 0; 986 last_dead = 0;
987 else { 987 else {
988 last_dead = key.mode & KBD_MODE_ACCMASK; 988 last_dead = key.mode & KBD_MODE_ACCMASK;
989 splx(s); 989 splx(s);
990 return; 990 return;
991 } 991 }
992 } 992 }
993 if (last_dead) { 993 if (last_dead) {
994 /* can't apply dead flag to string-keys */ 994 /* can't apply dead flag to string-keys */
995 if (!(key.mode & KBD_MODE_STRING) && code >= '@' && 995 if (!(key.mode & KBD_MODE_STRING) && code >= '@' &&
996 code < 0x7f) 996 code < 0x7f)
997 code = acctable[KBD_MODE_ACCENT(last_dead)][code - '@']; 997 code = acctable[KBD_MODE_ACCENT(last_dead)][code - '@'];
998 last_dead = 0; 998 last_dead = 0;
999 } 999 }
1000 1000
1001 /* 1001 /*
1002 * If not string, apply CTRL modifiers 1002 * If not string, apply CTRL modifiers
1003 */ 1003 */
1004 if (!(key.mode & KBD_MODE_STRING) && 1004 if (!(key.mode & KBD_MODE_STRING) &&
1005 (!(key.mode & KBD_MODE_KPAD) || 1005 (!(key.mode & KBD_MODE_KPAD) ||
1006 (kbd_ite && !kbd_ite->keypad_appmode))) { 1006 (kbd_ite && !kbd_ite->keypad_appmode))) {
1007 if (kbd_modifier & KBD_MOD_CTRL) 1007 if (kbd_modifier & KBD_MOD_CTRL)
1008 code &= 0x1f; 1008 code &= 0x1f;
1009 } else if ((key.mode & KBD_MODE_KPAD) && 1009 } else if ((key.mode & KBD_MODE_KPAD) &&
1010 (kbd_ite && kbd_ite->keypad_appmode)) { 1010 (kbd_ite && kbd_ite->keypad_appmode)) {
1011 static const char * const in = "0123456789-+.\r()/*"; 1011 static const char * const in = "0123456789-+.\r()/*";
1012 static const char * const out = "pqrstuvwxymlnMPQRS"; 1012 static const char * const out = "pqrstuvwxymlnMPQRS";
1013 char *cp = strchr(in, code); 1013 char *cp = strchr(in, code);
1014 1014
1015 /*  1015 /*
1016 * keypad-appmode sends SS3 followed by the above 1016 * keypad-appmode sends SS3 followed by the above
1017 * translated character 1017 * translated character
1018 */ 1018 */
1019 kbd_tty->t_linesw->l_rint(27, kbd_tty); 1019 kbd_tty->t_linesw->l_rint(27, kbd_tty);
1020 kbd_tty->t_linesw->l_rint('O', kbd_tty); 1020 kbd_tty->t_linesw->l_rint('O', kbd_tty);
1021 kbd_tty->t_linesw->l_rint(out[cp - in], kbd_tty); 1021 kbd_tty->t_linesw->l_rint(out[cp - in], kbd_tty);
1022 splx(s); 1022 splx(s);
1023 return; 1023 return;
1024 } else { 1024 } else {
1025 /* *NO* I don't like this.... */ 1025 /* *NO* I don't like this.... */
1026 static u_char app_cursor[] = 1026 static u_char app_cursor[] =
1027 { 1027 {
1028 3, 27, 'O', 'A', 1028 3, 27, 'O', 'A',
1029 3, 27, 'O', 'B', 1029 3, 27, 'O', 'B',
1030 3, 27, 'O', 'C', 1030 3, 27, 'O', 'C',
1031 3, 27, 'O', 'D'}; 1031 3, 27, 'O', 'D'};
1032 1032
1033 str = kbdmap->strings + code; 1033 str = kbdmap->strings + code;
1034 /*  1034 /*
1035 * if this is a cursor key, AND it has the default 1035 * if this is a cursor key, AND it has the default
1036 * keymap setting, AND we're in app-cursor mode, switch 1036 * keymap setting, AND we're in app-cursor mode, switch
1037 * to the above table. This is *nasty* ! 1037 * to the above table. This is *nasty* !
1038 */ 1038 */
1039 if (((c == 0x48) || (c == 0x4b) ||(c == 0x4d) || (c == 0x50)) && 1039 if (((c == 0x48) || (c == 0x4b) ||(c == 0x4d) || (c == 0x50)) &&
1040 kbd_ite->cursor_appmode && 1040 kbd_ite->cursor_appmode &&
1041 !memcmp(str, "\x03\x1b[", 3) && 1041 !memcmp(str, "\x03\x1b[", 3) &&
1042 strchr("ABCD", str[3])) 1042 strchr("ABCD", str[3]))
1043 str = app_cursor + 4 * (str[3] - 'A'); 1043 str = app_cursor + 4 * (str[3] - 'A');
1044 1044
1045 /*  1045 /*
1046 * using a length-byte instead of 0-termination allows 1046 * using a length-byte instead of 0-termination allows
1047 * to embed \0 into strings, although this is not used 1047 * to embed \0 into strings, although this is not used
1048 * in the default keymap 1048 * in the default keymap
1049 */ 1049 */
1050 for (i = *str++; i; i--) 1050 for (i = *str++; i; i--)
1051 kbd_tty->t_linesw->l_rint(*str++, kbd_tty); 1051 kbd_tty->t_linesw->l_rint(*str++, kbd_tty);
1052 splx(s); 1052 splx(s);
1053 return; 1053 return;
1054 } 1054 }
1055 kbd_tty->t_linesw->l_rint(code, kbd_tty); 1055 kbd_tty->t_linesw->l_rint(code, kbd_tty);
1056 1056
1057 splx(s); 1057 splx(s);
1058 return; 1058 return;
1059} 1059}
1060 1060
1061/* helper functions, makes the code below more readable */ 1061/* helper functions, makes the code below more readable */
1062static inline void 1062static inline void
1063ite_sendstr(const char *str) 1063ite_sendstr(const char *str)
1064{ 1064{
1065 struct tty *kbd_tty; 1065 struct tty *kbd_tty;
1066 1066
1067 kbd_tty = kbd_ite->tp; 1067 kbd_tty = kbd_ite->tp;
1068 KDASSERT(kbd_tty); 1068 KDASSERT(kbd_tty);
1069 while (*str) 1069 while (*str)
1070 kbd_tty->t_linesw->l_rint(*str++, kbd_tty); 1070 kbd_tty->t_linesw->l_rint(*str++, kbd_tty);
1071} 1071}
1072 1072
1073static void 1073static void
1074alignment_display(struct ite_softc *sc) 1074alignment_display(struct ite_softc *sc)
1075{ 1075{
1076 int i, j; 1076 int i, j;
1077 1077
1078 for (j = 0; j < sc->rows; j++) 1078 for (j = 0; j < sc->rows; j++)
1079 for (i = 0; i < sc->cols; i++) 1079 for (i = 0; i < sc->cols; i++)
1080 SUBR_PUTC(sc, 'E', j, i, ATTR_NOR); 1080 SUBR_PUTC(sc, 'E', j, i, ATTR_NOR);
1081 attrclr(sc, 0, 0, sc->rows, sc->cols); 1081 attrclr(sc, 0, 0, sc->rows, sc->cols);
1082 SUBR_CURSOR(sc, DRAW_CURSOR); 1082 SUBR_CURSOR(sc, DRAW_CURSOR);
1083} 1083}
1084 1084
1085static inline void 1085static inline void
1086snap_cury(struct ite_softc *sc) 1086snap_cury(struct ite_softc *sc)
1087{ 1087{
1088 if (sc->inside_margins) 1088 if (sc->inside_margins)
1089 { 1089 {
1090 if (sc->cury < sc->top_margin) 1090 if (sc->cury < sc->top_margin)
1091 sc->cury = sc->top_margin; 1091 sc->cury = sc->top_margin;
1092 if (sc->cury > sc->bottom_margin) 1092 if (sc->cury > sc->bottom_margin)
1093 sc->cury = sc->bottom_margin; 1093 sc->cury = sc->bottom_margin;
1094 } 1094 }
1095} 1095}
1096 1096
1097static inline void 1097static inline void
1098ite_dnchar(struct ite_softc *sc, int n) 1098ite_dnchar(struct ite_softc *sc, int n)
1099{ 1099{
1100 n = min(n, sc->cols - sc->curx); 1100 n = min(n, sc->cols - sc->curx);
1101 if (n < sc->cols - sc->curx) 1101 if (n < sc->cols - sc->curx)
1102 { 1102 {
1103 SUBR_SCROLL(sc, sc->cury, sc->curx + n, n, SCROLL_LEFT); 1103 SUBR_SCROLL(sc, sc->cury, sc->curx + n, n, SCROLL_LEFT);
1104 attrmov(sc, sc->cury, sc->curx + n, sc->cury, sc->curx, 1104 attrmov(sc, sc->cury, sc->curx + n, sc->cury, sc->curx,
1105 1, sc->cols - sc->curx - n); 1105 1, sc->cols - sc->curx - n);
1106 attrclr(sc, sc->cury, sc->cols - n, 1, n); 1106 attrclr(sc, sc->cury, sc->cols - n, 1, n);
1107 } 1107 }
1108 while (n-- > 0) 1108 while (n-- > 0)
1109 SUBR_PUTC(sc, ' ', sc->cury, sc->cols - n - 1, ATTR_NOR); 1109 SUBR_PUTC(sc, ' ', sc->cury, sc->cols - n - 1, ATTR_NOR);
1110 SUBR_CURSOR(sc, DRAW_CURSOR); 1110 SUBR_CURSOR(sc, DRAW_CURSOR);
1111} 1111}
1112 1112
1113static inline void 1113static inline void
1114ite_inchar(struct ite_softc *sc, int n) 1114ite_inchar(struct ite_softc *sc, int n)
1115{ 1115{
1116 n = min(n, sc->cols - sc->curx); 1116 n = min(n, sc->cols - sc->curx);
1117 if (n < sc->cols - sc->curx) 1117 if (n < sc->cols - sc->curx)
1118 { 1118 {
1119 SUBR_SCROLL(sc, sc->cury, sc->curx, n, SCROLL_RIGHT); 1119 SUBR_SCROLL(sc, sc->cury, sc->curx, n, SCROLL_RIGHT);
1120 attrmov(sc, sc->cury, sc->curx, sc->cury, sc->curx + n, 1120 attrmov(sc, sc->cury, sc->curx, sc->cury, sc->curx + n,
1121 1, sc->cols - sc->curx - n); 1121 1, sc->cols - sc->curx - n);
1122 attrclr(sc, sc->cury, sc->curx, 1, n); 1122 attrclr(sc, sc->cury, sc->curx, 1, n);
1123 } 1123 }
1124 while (n--) 1124 while (n--)
1125 SUBR_PUTC(sc, ' ', sc->cury, sc->curx + n, ATTR_NOR); 1125 SUBR_PUTC(sc, ' ', sc->cury, sc->curx + n, ATTR_NOR);
1126 SUBR_CURSOR(sc, DRAW_CURSOR); 1126 SUBR_CURSOR(sc, DRAW_CURSOR);
1127} 1127}
1128 1128
1129static inline void 1129static inline void
1130ite_clrtoeol(struct ite_softc *sc) 1130ite_clrtoeol(struct ite_softc *sc)
1131{ 1131{
1132 int y = sc->cury, x = sc->curx; 1132 int y = sc->cury, x = sc->curx;
1133 if (sc->cols - x > 0) 1133 if (sc->cols - x > 0)
1134 { 1134 {
1135 SUBR_CLEAR(sc, y, x, 1, sc->cols - x); 1135 SUBR_CLEAR(sc, y, x, 1, sc->cols - x);
1136 attrclr(sc, y, x, 1, sc->cols - x); 1136 attrclr(sc, y, x, 1, sc->cols - x);
1137 SUBR_CURSOR(sc, DRAW_CURSOR); 1137 SUBR_CURSOR(sc, DRAW_CURSOR);
1138 } 1138 }
1139} 1139}
1140 1140
1141static inline void 1141static inline void
1142ite_clrtobol(struct ite_softc *sc) 1142ite_clrtobol(struct ite_softc *sc)
1143{ 1143{
1144 int y = sc->cury, x = min(sc->curx + 1, sc->cols); 1144 int y = sc->cury, x = min(sc->curx + 1, sc->cols);
1145 SUBR_CLEAR(sc, y, 0, 1, x); 1145 SUBR_CLEAR(sc, y, 0, 1, x);
1146 attrclr(sc, y, 0, 1, x); 1146 attrclr(sc, y, 0, 1, x);
1147 SUBR_CURSOR(sc, DRAW_CURSOR); 1147 SUBR_CURSOR(sc, DRAW_CURSOR);
1148} 1148}
1149 1149
1150static inline void 1150static inline void
1151ite_clrline(struct ite_softc *sc) 1151ite_clrline(struct ite_softc *sc)
1152{ 1152{
1153 int y = sc->cury; 1153 int y = sc->cury;
1154 SUBR_CLEAR(sc, y, 0, 1, sc->cols); 1154 SUBR_CLEAR(sc, y, 0, 1, sc->cols);
1155 attrclr(sc, y, 0, 1, sc->cols); 1155 attrclr(sc, y, 0, 1, sc->cols);
1156 SUBR_CURSOR(sc, DRAW_CURSOR); 1156 SUBR_CURSOR(sc, DRAW_CURSOR);
1157} 1157}
1158 1158
1159 1159
1160 1160
1161static inline void 1161static inline void
1162ite_clrtoeos(struct ite_softc *sc) 1162ite_clrtoeos(struct ite_softc *sc)
1163{ 1163{
1164 ite_clrtoeol(sc); 1164 ite_clrtoeol(sc);
1165 if (sc->cury < sc->rows - 1) 1165 if (sc->cury < sc->rows - 1)
1166 { 1166 {
1167 SUBR_CLEAR(sc, sc->cury + 1, 0, sc->rows - 1 - sc->cury, sc->cols); 1167 SUBR_CLEAR(sc, sc->cury + 1, 0, sc->rows - 1 - sc->cury, sc->cols);
1168 attrclr(sc, sc->cury, 0, sc->rows - sc->cury, sc->cols); 1168 attrclr(sc, sc->cury, 0, sc->rows - sc->cury, sc->cols);
1169 SUBR_CURSOR(sc, DRAW_CURSOR); 1169 SUBR_CURSOR(sc, DRAW_CURSOR);
1170 } 1170 }
1171} 1171}
1172 1172
1173static inline void 1173static inline void
1174ite_clrtobos(struct ite_softc *sc) 1174ite_clrtobos(struct ite_softc *sc)
1175{ 1175{
1176 ite_clrtobol(sc); 1176 ite_clrtobol(sc);
1177 if (sc->cury > 0) 1177 if (sc->cury > 0)
1178 { 1178 {
1179 SUBR_CLEAR(sc, 0, 0, sc->cury, sc->cols); 1179 SUBR_CLEAR(sc, 0, 0, sc->cury, sc->cols);
1180 attrclr(sc, 0, 0, sc->cury, sc->cols); 1180 attrclr(sc, 0, 0, sc->cury, sc->cols);
1181 SUBR_CURSOR(sc, DRAW_CURSOR); 1181 SUBR_CURSOR(sc, DRAW_CURSOR);
1182 } 1182 }
1183} 1183}
1184 1184
1185static inline void 1185static inline void
1186ite_clrscreen(struct ite_softc *sc) 1186ite_clrscreen(struct ite_softc *sc)
1187{ 1187{
1188 SUBR_CLEAR(sc, 0, 0, sc->rows, sc->cols); 1188 SUBR_CLEAR(sc, 0, 0, sc->rows, sc->cols);
1189 attrclr(sc, 0, 0, sc->rows, sc->cols); 1189 attrclr(sc, 0, 0, sc->rows, sc->cols);
1190 SUBR_CURSOR(sc, DRAW_CURSOR); 1190 SUBR_CURSOR(sc, DRAW_CURSOR);
1191} 1191}
1192 1192
1193 1193
1194 1194
1195static inline void 1195static inline void
1196ite_dnline(struct ite_softc *sc, int n) 1196ite_dnline(struct ite_softc *sc, int n)
1197{ 1197{
1198 /* interesting.. if the cursor is outside the scrolling 1198 /* interesting.. if the cursor is outside the scrolling
1199 region, this command is simply ignored.. */ 1199 region, this command is simply ignored.. */
1200 if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin) 1200 if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin)
1201 return; 1201 return;
1202 1202
1203 n = min(n, sc->bottom_margin + 1 - sc->cury); 1203 n = min(n, sc->bottom_margin + 1 - sc->cury);
1204 if (n <= sc->bottom_margin - sc->cury) 1204 if (n <= sc->bottom_margin - sc->cury)
1205 { 1205 {
1206 SUBR_SCROLL(sc, sc->cury + n, 0, n, SCROLL_UP); 1206 SUBR_SCROLL(sc, sc->cury + n, 0, n, SCROLL_UP);
1207 attrmov(sc, sc->cury + n, 0, sc->cury, 0, 1207 attrmov(sc, sc->cury + n, 0, sc->cury, 0,
1208 sc->bottom_margin + 1 - sc->cury - n, sc->cols); 1208 sc->bottom_margin + 1 - sc->cury - n, sc->cols);
1209 } 1209 }
1210 SUBR_CLEAR(sc, sc->bottom_margin - n + 1, 0, n, sc->cols); 1210 SUBR_CLEAR(sc, sc->bottom_margin - n + 1, 0, n, sc->cols);
1211 attrclr(sc, sc->bottom_margin - n + 1, 0, n, sc->cols); 1211 attrclr(sc, sc->bottom_margin - n + 1, 0, n, sc->cols);
1212 SUBR_CURSOR(sc, DRAW_CURSOR); 1212 SUBR_CURSOR(sc, DRAW_CURSOR);
1213} 1213}
1214 1214
1215static inline void 1215static inline void
1216ite_inline(struct ite_softc *sc, int n) 1216ite_inline(struct ite_softc *sc, int n)
1217{ 1217{
1218 /* interesting.. if the cursor is outside the scrolling 1218 /* interesting.. if the cursor is outside the scrolling
1219 region, this command is simply ignored.. */ 1219 region, this command is simply ignored.. */
1220 if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin) 1220 if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin)
1221 return; 1221 return;
1222 1222
1223 n = min(n, sc->bottom_margin + 1 - sc->cury); 1223 n = min(n, sc->bottom_margin + 1 - sc->cury);
1224 if (n <= sc->bottom_margin - sc->cury) 1224 if (n <= sc->bottom_margin - sc->cury)
1225 { 1225 {
1226 SUBR_SCROLL(sc, sc->cury, 0, n, SCROLL_DOWN); 1226 SUBR_SCROLL(sc, sc->cury, 0, n, SCROLL_DOWN);
1227 attrmov(sc, sc->cury, 0, sc->cury + n, 0, 1227 attrmov(sc, sc->cury, 0, sc->cury + n, 0,
1228 sc->bottom_margin + 1 - sc->cury - n, sc->cols); 1228 sc->bottom_margin + 1 - sc->cury - n, sc->cols);
1229 } 1229 }
1230 SUBR_CLEAR(sc, sc->cury, 0, n, sc->cols); 1230 SUBR_CLEAR(sc, sc->cury, 0, n, sc->cols);
1231 attrclr(sc, sc->cury, 0, n, sc->cols); 1231 attrclr(sc, sc->cury, 0, n, sc->cols);
1232 SUBR_CURSOR(sc, DRAW_CURSOR); 1232 SUBR_CURSOR(sc, DRAW_CURSOR);
1233} 1233}
1234 1234
1235static inline void 1235static inline void
1236ite_lf (struct ite_softc *sc) 1236ite_lf (struct ite_softc *sc)
1237{ 1237{
1238 ++sc->cury; 1238 ++sc->cury;
1239 if ((sc->cury == sc->bottom_margin+1) || (sc->cury == sc->rows)) 1239 if ((sc->cury == sc->bottom_margin+1) || (sc->cury == sc->rows))
1240 { 1240 {
1241 sc->cury--; 1241 sc->cury--;
1242 SUBR_SCROLL(sc, sc->top_margin + 1, 0, 1, SCROLL_UP); 1242 SUBR_SCROLL(sc, sc->top_margin + 1, 0, 1, SCROLL_UP);
1243 ite_clrline(sc); 1243 ite_clrline(sc);
1244 } 1244 }
1245 SUBR_CURSOR(sc, MOVE_CURSOR); 1245 SUBR_CURSOR(sc, MOVE_CURSOR);
1246 clr_attr(sc, ATTR_INV); 1246 clr_attr(sc, ATTR_INV);
1247} 1247}
1248 1248
1249static inline void 1249static inline void
1250ite_crlf (struct ite_softc *sc) 1250ite_crlf (struct ite_softc *sc)
1251{ 1251{
1252 sc->curx = 0; 1252 sc->curx = 0;
1253 ite_lf (sc); 1253 ite_lf (sc);
1254} 1254}
1255 1255
1256static inline void 1256static inline void
1257ite_cr (struct ite_softc *sc) 1257ite_cr (struct ite_softc *sc)
1258{ 1258{
1259 if (sc->curx) 1259 if (sc->curx)
1260 { 1260 {
1261 sc->curx = 0; 1261 sc->curx = 0;
1262 SUBR_CURSOR(sc, MOVE_CURSOR); 1262 SUBR_CURSOR(sc, MOVE_CURSOR);
1263 } 1263 }
1264} 1264}
1265 1265
1266static inline void 1266static inline void
1267ite_rlf (struct ite_softc *sc) 1267ite_rlf (struct ite_softc *sc)
1268{ 1268{
1269 sc->cury--; 1269 sc->cury--;
1270 if ((sc->cury < 0) || (sc->cury == sc->top_margin - 1)) 1270 if ((sc->cury < 0) || (sc->cury == sc->top_margin - 1))
1271 { 1271 {
1272 sc->cury++; 1272 sc->cury++;
1273 SUBR_SCROLL(sc, sc->top_margin, 0, 1, SCROLL_DOWN); 1273 SUBR_SCROLL(sc, sc->top_margin, 0, 1, SCROLL_DOWN);
1274 ite_clrline(sc); 1274 ite_clrline(sc);
1275 } 1275 }
1276 SUBR_CURSOR(sc, MOVE_CURSOR); 1276 SUBR_CURSOR(sc, MOVE_CURSOR);
1277 clr_attr(sc, ATTR_INV); 1277 clr_attr(sc, ATTR_INV);
1278} 1278}
1279 1279
1280static inline int 1280static inline int
1281atoi (const char *cp) 1281atoi (const char *cp)
1282{ 1282{
1283 int n; 1283 int n;
1284 1284
1285 for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++) 1285 for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++)
1286 n = n * 10 + *cp - '0'; 1286 n = n * 10 + *cp - '0';
1287 1287
1288 return n; 1288 return n;
1289} 1289}
1290 1290
1291static inline int 1291static inline int
1292ite_argnum (struct ite_softc *sc) 1292ite_argnum (struct ite_softc *sc)
1293{ 1293{
1294 char ch; 1294 char ch;
1295 int n; 1295 int n;
1296 1296
1297 /* convert argument string into number */ 1297 /* convert argument string into number */
1298 if (sc->ap == sc->argbuf) 1298 if (sc->ap == sc->argbuf)
1299 return 1; 1299 return 1;
1300 ch = *sc->ap; 1300 ch = *sc->ap;
1301 *sc->ap = 0; 1301 *sc->ap = 0;
1302 n = atoi (sc->argbuf); 1302 n = atoi (sc->argbuf);
1303 *sc->ap = ch; 1303 *sc->ap = ch;
1304  1304
1305 return n; 1305 return n;
1306} 1306}
1307 1307
1308static inline int 1308static inline int
1309ite_zargnum (struct ite_softc *sc) 1309ite_zargnum (struct ite_softc *sc)
1310{ 1310{
1311 char ch; 1311 char ch;
1312 int n; 1312 int n;
1313 1313
1314 /* convert argument string into number */ 1314 /* convert argument string into number */
1315 if (sc->ap == sc->argbuf) 1315 if (sc->ap == sc->argbuf)
1316 return 0; 1316 return 0;
1317 ch = *sc->ap; 1317 ch = *sc->ap;
1318 *sc->ap = 0; 1318 *sc->ap = 0;
1319 n = atoi (sc->argbuf); 1319 n = atoi (sc->argbuf);
1320 *sc->ap = ch; 1320 *sc->ap = ch;
1321  1321
1322 return n; /* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */ 1322 return n; /* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
1323} 1323}
1324 1324
1325void 1325void
1326ite_putstr(const u_char *s, int len, dev_t dev) 1326ite_putstr(const u_char *s, int len, dev_t dev)
1327{ 1327{
1328 struct ite_softc *sc; 1328 struct ite_softc *sc;
1329 int i; 1329 int i;
1330  1330
1331 sc = getitesp(dev); 1331 sc = getitesp(dev);
1332 1332
1333 /* XXX avoid problems */ 1333 /* XXX avoid problems */
1334 if ((sc->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) 1334 if ((sc->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
1335 return; 1335 return;
1336 1336
1337 SUBR_CURSOR(sc, START_CURSOROPT); 1337 SUBR_CURSOR(sc, START_CURSOROPT);
1338 for (i = 0; i < len; i++) 1338 for (i = 0; i < len; i++)
1339 if (s[i]) 1339 if (s[i])
1340 iteputchar(s[i], sc); 1340 iteputchar(s[i], sc);
1341 SUBR_CURSOR(sc, END_CURSOROPT); 1341 SUBR_CURSOR(sc, END_CURSOROPT);
1342} 1342}
1343 1343
1344 1344
1345void 1345void
1346iteputchar(register int c, struct ite_softc *sc) 1346iteputchar(register int c, struct ite_softc *sc)
1347{ 1347{
1348 struct tty *kbd_tty; 1348 struct tty *kbd_tty;
1349 int n, x, y; 1349 int n, x, y;
1350 char *cp; 1350 char *cp;
1351 1351
1352 if (kbd_ite == NULL) 1352 if (kbd_ite == NULL)
1353 kbd_tty = NULL; 1353 kbd_tty = NULL;
1354 else 1354 else
1355 kbd_tty = kbd_ite->tp; 1355 kbd_tty = kbd_ite->tp;
1356 1356
1357 if (sc->escape)  1357 if (sc->escape)
1358 { 1358 {
1359 switch (sc->escape)  1359 switch (sc->escape)
1360 { 1360 {
1361 case ESC: 1361 case ESC:
1362 switch (c) 1362 switch (c)
1363 { 1363 {
1364 /* first 7bit equivalents for the 8bit control characters */ 1364 /* first 7bit equivalents for the 8bit control characters */
1365  1365
1366 case 'D': 1366 case 'D':
1367 c = IND; 1367 c = IND;
1368 sc->escape = 0; 1368 sc->escape = 0;
1369 break; /* and fall into the next switch below (same for all `break') */ 1369 break; /* and fall into the next switch below (same for all `break') */
1370  1370
1371 case 'E': 1371 case 'E':
1372 c = NEL; 1372 c = NEL;
1373 sc->escape = 0; 1373 sc->escape = 0;
1374 break; 1374 break;
1375  1375
1376 case 'H': 1376 case 'H':
1377 c = HTS; 1377 c = HTS;
1378 sc->escape = 0; 1378 sc->escape = 0;
1379 break; 1379 break;
1380  1380
1381 case 'M': 1381 case 'M':
1382 c = RI; 1382 c = RI;
1383 sc->escape = 0; 1383 sc->escape = 0;
1384 break; 1384 break;
1385  1385
1386 case 'N': 1386 case 'N':
1387 c = SS2; 1387 c = SS2;
1388 sc->escape = 0; 1388 sc->escape = 0;
1389 break; 1389 break;
1390  1390
1391 case 'O': 1391 case 'O':
1392 c = SS3; 1392 c = SS3;
1393 sc->escape = 0; 1393 sc->escape = 0;
1394 break; 1394 break;
1395  1395
1396 case 'P': 1396 case 'P':
1397 c = DCS; 1397 c = DCS;
1398 sc->escape = 0; 1398 sc->escape = 0;
1399 break; 1399 break;
1400  1400
1401 case '[': 1401 case '[':
1402 c = CSI; 1402 c = CSI;
1403 sc->escape = 0; 1403 sc->escape = 0;
1404 break; 1404 break;
1405  1405
1406 case '\\': 1406 case '\\':
1407 c = ST; 1407 c = ST;
1408 sc->escape = 0; 1408 sc->escape = 0;
1409 break; 1409 break;
1410  1410
1411 case ']': 1411 case ']':
1412 c = OSC; 1412 c = OSC;
1413 sc->escape = 0; 1413 sc->escape = 0;
1414 break; 1414 break;
1415  1415
1416 case '^': 1416 case '^':
1417 c = PM; 1417 c = PM;
1418 sc->escape = 0; 1418 sc->escape = 0;
1419 break; 1419 break;
1420  1420
1421 case '_': 1421 case '_':
1422 c = APC; 1422 c = APC;
1423 sc->escape = 0; 1423 sc->escape = 0;
1424 break; 1424 break;
1425 1425
1426 1426
1427 /* introduces 7/8bit control */ 1427 /* introduces 7/8bit control */
1428 case ' ': 1428 case ' ':
1429 /* can be followed by either F or G */ 1429 /* can be followed by either F or G */
1430 sc->escape = ' '; 1430 sc->escape = ' ';
1431 break; 1431 break;
1432 1432
1433  1433
1434 /* a lot of character set selections, not yet used...  1434 /* a lot of character set selections, not yet used...
1435 94-character sets: */ 1435 94-character sets: */
1436 case '(': /* G0 */ 1436 case '(': /* G0 */
1437 case ')': /* G1 */ 1437 case ')': /* G1 */
1438 sc->escape = c; 1438 sc->escape = c;
1439 return; 1439 return;
1440 1440
1441 case '*': /* G2 */ 1441 case '*': /* G2 */
1442 case '+': /* G3 */ 1442 case '+': /* G3 */
1443 case 'B': /* ASCII */ 1443 case 'B': /* ASCII */
1444 case 'A': /* ISO latin 1 */ 1444 case 'A': /* ISO latin 1 */
1445 case '<': /* user preferred suplemental */ 1445 case '<': /* user preferred suplemental */
1446 case '0': /* dec special graphics */ 1446 case '0': /* dec special graphics */
1447  1447
1448 /* 96-character sets: */ 1448 /* 96-character sets: */
1449 case '-': /* G1 */ 1449 case '-': /* G1 */
1450 case '.': /* G2 */ 1450 case '.': /* G2 */
1451 case '/': /* G3 */ 1451 case '/': /* G3 */
1452  1452
1453 /* national character sets: */ 1453 /* national character sets: */
1454 case '4': /* dutch */ 1454 case '4': /* dutch */
1455 case '5': 1455 case '5':
1456 case 'C': /* finnish */ 1456 case 'C': /* finnish */
1457 case 'R': /* french */ 1457 case 'R': /* french */
1458 case 'Q': /* french canadian */ 1458 case 'Q': /* french canadian */
1459 case 'K': /* german */ 1459 case 'K': /* german */
1460 case 'Y': /* italian */ 1460 case 'Y': /* italian */
1461 case '6': /* norwegian/danish */ 1461 case '6': /* norwegian/danish */
1462 /* note: %5 and %6 are not supported (two chars..) */ 1462 /* note: %5 and %6 are not supported (two chars..) */
1463  1463
1464 sc->escape = 0; 1464 sc->escape = 0;
1465 /* just ignore for now */ 1465 /* just ignore for now */
1466 return; 1466 return;
1467  1467
1468  1468
1469 /* locking shift modes (as you might guess, not yet supported..) */ 1469 /* locking shift modes (as you might guess, not yet supported..) */
1470 case '`': 1470 case '`':
1471 sc->GR = sc->G1; 1471 sc->GR = sc->G1;
1472 sc->escape = 0; 1472 sc->escape = 0;
1473 return; 1473 return;
1474  1474
1475 case 'n': 1475 case 'n':
1476 sc->GL = sc->G2; 1476 sc->GL = sc->G2;
1477 sc->escape = 0; 1477 sc->escape = 0;
1478 return; 1478 return;
1479  1479
1480 case '}': 1480 case '}':
1481 sc->GR = sc->G2; 1481 sc->GR = sc->G2;
1482 sc->escape = 0; 1482 sc->escape = 0;
1483 return; 1483 return;
1484  1484
1485 case 'o': 1485 case 'o':
1486 sc->GL = sc->G3; 1486 sc->GL = sc->G3;
1487 sc->escape = 0; 1487 sc->escape = 0;
1488 return; 1488 return;
1489  1489
1490 case '|': 1490 case '|':
1491 sc->GR = sc->G3; 1491 sc->GR = sc->G3;
1492 sc->escape = 0; 1492 sc->escape = 0;
1493 return; 1493 return;
1494  1494
1495  1495
1496 /* font width/height control */ 1496 /* font width/height control */
1497 case '#': 1497 case '#':
1498 sc->escape = '#'; 1498 sc->escape = '#';
1499 return; 1499 return;
1500  1500
1501  1501
1502 /* hard terminal reset .. */ 1502 /* hard terminal reset .. */
1503 case 'c': 1503 case 'c':
1504 ite_reset (sc); 1504 ite_reset (sc);
1505 SUBR_CURSOR(sc, MOVE_CURSOR); 1505 SUBR_CURSOR(sc, MOVE_CURSOR);
1506 sc->escape = 0; 1506 sc->escape = 0;
1507 return; 1507 return;
1508 1508
1509 1509
1510 case '7': 1510 case '7':
1511 sc->save_curx = sc->curx; 1511 sc->save_curx = sc->curx;
1512 sc->save_cury = sc->cury; 1512 sc->save_cury = sc->cury;
1513 sc->save_attribute = sc->attribute; 1513 sc->save_attribute = sc->attribute;
1514 sc->escape = 0; 1514 sc->escape = 0;
1515 return; 1515 return;
1516  1516
1517 case '8': 1517 case '8':
1518 sc->curx = sc->save_curx; 1518 sc->curx = sc->save_curx;
1519 sc->cury = sc->save_cury; 1519 sc->cury = sc->save_cury;
1520 sc->attribute = sc->save_attribute; 1520 sc->attribute = sc->save_attribute;
1521 SUBR_CURSOR(sc, MOVE_CURSOR); 1521 SUBR_CURSOR(sc, MOVE_CURSOR);
1522 sc->escape = 0; 1522 sc->escape = 0;
1523 return; 1523 return;
1524  1524
1525 case '=': 1525 case '=':
1526 sc->keypad_appmode = 1; 1526 sc->keypad_appmode = 1;
1527 sc->escape = 0; 1527 sc->escape = 0;
1528 return; 1528 return;
1529  1529
1530 case '>': 1530 case '>':
1531 sc->keypad_appmode = 0; 1531 sc->keypad_appmode = 0;
1532 sc->escape = 0; 1532 sc->escape = 0;
1533 return; 1533 return;
1534  1534
1535 case 'Z': /* request ID */ 1535 case 'Z': /* request ID */
1536 if (sc->emul_level == EMUL_VT100) 1536 if (sc->emul_level == EMUL_VT100)
1537 ite_sendstr ("\033[?61;0c"); /* XXX not clean */ 1537 ite_sendstr ("\033[?61;0c"); /* XXX not clean */
1538 else 1538 else
1539 ite_sendstr ("\033[?63;0c"); /* XXX not clean */ 1539 ite_sendstr ("\033[?63;0c"); /* XXX not clean */
1540 sc->escape = 0; 1540 sc->escape = 0;
1541 return; 1541 return;
1542 1542
1543 /* default catch all for not recognized ESC sequences */ 1543 /* default catch all for not recognized ESC sequences */
1544 default: 1544 default:
1545 sc->escape = 0; 1545 sc->escape = 0;
1546 return; 1546 return;
1547 } 1547 }
1548 break; 1548 break;
1549 1549
1550 1550
1551 case '(': 1551 case '(':
1552 case ')': 1552 case ')':
1553 sc->escape = 0; 1553 sc->escape = 0;
1554 return; 1554 return;
1555 1555
1556 1556
1557 case ' ': 1557 case ' ':
1558 switch (c) 1558 switch (c)
1559 { 1559 {
1560 case 'F': 1560 case 'F':
1561 sc->eightbit_C1 = 0; 1561 sc->eightbit_C1 = 0;
1562 sc->escape = 0; 1562 sc->escape = 0;
1563 return; 1563 return;
1564  1564
1565 case 'G': 1565 case 'G':
1566 sc->eightbit_C1 = 1; 1566 sc->eightbit_C1 = 1;
1567 sc->escape = 0; 1567 sc->escape = 0;
1568 return; 1568 return;
1569  1569
1570 default: 1570 default:
1571 /* not supported */ 1571 /* not supported */
1572 sc->escape = 0; 1572 sc->escape = 0;
1573 return; 1573 return;
1574 } 1574 }
1575 break; 1575 break;
1576  1576
1577  1577
1578 case '#': 1578 case '#':
1579 switch (c) 1579 switch (c)
1580 { 1580 {
1581 case '5': 1581 case '5':
1582 /* single height, single width */ 1582 /* single height, single width */
1583 sc->escape = 0; 1583 sc->escape = 0;
1584 return; 1584 return;
1585  1585
1586 case '6': 1586 case '6':
1587 /* double width, single height */ 1587 /* double width, single height */
1588 sc->escape = 0; 1588 sc->escape = 0;
1589 return; 1589 return;
1590  1590
1591 case '3': 1591 case '3':
1592 /* top half */ 1592 /* top half */
1593 sc->escape = 0; 1593 sc->escape = 0;
1594 return; 1594 return;
1595  1595
1596 case '4': 1596 case '4':
1597 /* bottom half */ 1597 /* bottom half */
1598 sc->escape = 0; 1598 sc->escape = 0;
1599 return; 1599 return;
1600  1600
1601 case '8': 1601 case '8':
1602 /* screen alignment pattern... */ 1602 /* screen alignment pattern... */
1603 alignment_display (sc); 1603 alignment_display (sc);
1604 sc->escape = 0; 1604 sc->escape = 0;
1605 return; 1605 return;
1606  1606
1607 default: 1607 default:
1608 sc->escape = 0; 1608 sc->escape = 0;
1609 return; 1609 return;
1610 } 1610 }
1611 break; 1611 break;
1612  1612
1613 1613
1614 1614
1615 case CSI: 1615 case CSI:
1616 /* the biggie... */ 1616 /* the biggie... */
1617 switch (c) 1617 switch (c)
1618 { 1618 {
1619 case '0': case '1': case '2': case '3': case '4': 1619 case '0': case '1': case '2': case '3': case '4':
1620 case '5': case '6': case '7': case '8': case '9': 1620 case '5': case '6': case '7': case '8': case '9':
1621 case ';': case '\"': case '$': case '>': 1621 case ';': case '\"': case '$': case '>':
1622 if (sc->ap < sc->argbuf + MAX_ARGSIZE) 1622 if (sc->ap < sc->argbuf + MAX_ARGSIZE)
1623 *sc->ap++ = c; 1623 *sc->ap++ = c;
1624 return; 1624 return;
1625 1625
1626 case BS: 1626 case BS:
1627 /* you wouldn't believe such perversion is possible? 1627 /* you wouldn't believe such perversion is possible?
1628 it is.. BS is allowed in between cursor sequences 1628 it is.. BS is allowed in between cursor sequences
1629 (at least), according to vttest.. */ 1629 (at least), according to vttest.. */
1630 if (--sc->curx < 0) 1630 if (--sc->curx < 0)
1631 sc->curx = 0; 1631 sc->curx = 0;
1632 else 1632 else
1633 SUBR_CURSOR(sc, MOVE_CURSOR); 1633 SUBR_CURSOR(sc, MOVE_CURSOR);
1634 break; 1634 break;
1635 1635
1636 case 'p': 1636 case 'p':
1637 *sc->ap = 0; 1637 *sc->ap = 0;
1638 if (! strncmp (sc->argbuf, "61\"", 3)) 1638 if (! strncmp (sc->argbuf, "61\"", 3))
1639 sc->emul_level = EMUL_VT100; 1639 sc->emul_level = EMUL_VT100;
1640 else if (! strncmp (sc->argbuf, "63;1\"", 5) 1640 else if (! strncmp (sc->argbuf, "63;1\"", 5)
1641 || ! strncmp (sc->argbuf, "62;1\"", 5)) 1641 || ! strncmp (sc->argbuf, "62;1\"", 5))
1642 sc->emul_level = EMUL_VT300_7; 1642 sc->emul_level = EMUL_VT300_7;
1643 else 1643 else
1644 sc->emul_level = EMUL_VT300_8; 1644 sc->emul_level = EMUL_VT300_8;
1645 sc->escape = 0; 1645 sc->escape = 0;
1646 return; 1646 return;
1647  1647
1648  1648
1649 case '?': 1649 case '?':
1650 *sc->ap = 0; 1650 *sc->ap = 0;
1651 sc->escape = '?'; 1651 sc->escape = '?';
1652 sc->ap = sc->argbuf; 1652 sc->ap = sc->argbuf;
1653 return; 1653 return;
1654 1654
1655 1655
1656 case 'c': 1656 case 'c':
1657 *sc->ap = 0; 1657 *sc->ap = 0;
1658 if (sc->argbuf[0] == '>') 1658 if (sc->argbuf[0] == '>')
1659 { 1659 {
1660 ite_sendstr ("\033[>24;0;0;0c"); 1660 ite_sendstr ("\033[>24;0;0;0c");
1661 } 1661 }
1662 else switch (ite_zargnum(sc)) 1662 else switch (ite_zargnum(sc))
1663 { 1663 {
1664 case 0: 1664 case 0:
1665 /* primary DA request, send primary DA response */ 1665 /* primary DA request, send primary DA response */
1666 if (sc->emul_level == EMUL_VT100) 1666 if (sc->emul_level == EMUL_VT100)
1667 ite_sendstr ("\033[?1;1c"); 1667 ite_sendstr ("\033[?1;1c");
1668 else 1668 else