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