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