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