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