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