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