wsemul_sun.c revision 1.21 1 1.21 martin /* $NetBSD: wsemul_sun.c,v 1.21 2005/05/30 09:36:50 martin Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 1.1 drochner *
6 1.1 drochner * Redistribution and use in source and binary forms, with or without
7 1.1 drochner * modification, are permitted provided that the following conditions
8 1.1 drochner * are met:
9 1.1 drochner * 1. Redistributions of source code must retain the above copyright
10 1.1 drochner * notice, this list of conditions and the following disclaimer.
11 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 drochner * notice, this list of conditions and the following disclaimer in the
13 1.1 drochner * documentation and/or other materials provided with the distribution.
14 1.1 drochner * 3. All advertising materials mentioning features or use of this software
15 1.1 drochner * must display the following acknowledgement:
16 1.1 drochner * This product includes software developed by Christopher G. Demetriou
17 1.1 drochner * for the NetBSD Project.
18 1.1 drochner * 4. The name of the author may not be used to endorse or promote products
19 1.1 drochner * derived from this software without specific prior written permission
20 1.1 drochner *
21 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 drochner */
32 1.1 drochner
33 1.11 drochner /* XXX DESCRIPTION/SOURCE OF INFORMATION */
34 1.1 drochner
35 1.11 drochner #include <sys/cdefs.h>
36 1.21 martin __KERNEL_RCSID(0, "$NetBSD: wsemul_sun.c,v 1.21 2005/05/30 09:36:50 martin Exp $");
37 1.1 drochner
38 1.1 drochner #include <sys/param.h>
39 1.1 drochner #include <sys/systm.h>
40 1.1 drochner #include <sys/time.h>
41 1.1 drochner #include <sys/malloc.h>
42 1.1 drochner #include <sys/fcntl.h>
43 1.1 drochner
44 1.1 drochner #include <dev/wscons/wsconsio.h>
45 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
46 1.1 drochner #include <dev/wscons/wsemulvar.h>
47 1.6 drochner #include <dev/wscons/wsksymdef.h>
48 1.1 drochner #include <dev/wscons/ascii.h>
49 1.1 drochner
50 1.13 augustss void *wsemul_sun_cnattach(const struct wsscreen_descr *, void *,
51 1.13 augustss int, int, long);
52 1.13 augustss void *wsemul_sun_attach(int console, const struct wsscreen_descr *,
53 1.13 augustss void *, int, int, void *, long);
54 1.13 augustss void wsemul_sun_output(void *cookie, const u_char *data, u_int count,
55 1.13 augustss int);
56 1.21 martin int wsemul_sun_translate(void *cookie, keysym_t, const char **);
57 1.13 augustss void wsemul_sun_detach(void *cookie, u_int *crowp, u_int *ccolp);
58 1.13 augustss void wsemul_sun_resetop(void *, enum wsemul_resetops);
59 1.1 drochner
60 1.1 drochner const struct wsemul_ops wsemul_sun_ops = {
61 1.1 drochner "sun",
62 1.1 drochner wsemul_sun_cnattach,
63 1.1 drochner wsemul_sun_attach,
64 1.1 drochner wsemul_sun_output,
65 1.6 drochner wsemul_sun_translate,
66 1.1 drochner wsemul_sun_detach,
67 1.10 drochner wsemul_sun_resetop
68 1.1 drochner };
69 1.1 drochner
70 1.1 drochner #define SUN_EMUL_STATE_NORMAL 0 /* normal processing */
71 1.1 drochner #define SUN_EMUL_STATE_HAVEESC 1 /* seen start of ctl seq */
72 1.1 drochner #define SUN_EMUL_STATE_CONTROL 2 /* processing ctl seq */
73 1.1 drochner
74 1.1 drochner #define SUN_EMUL_NARGS 2 /* max # of args to a command */
75 1.1 drochner
76 1.1 drochner struct wsemul_sun_emuldata {
77 1.1 drochner const struct wsdisplay_emulops *emulops;
78 1.1 drochner void *emulcookie;
79 1.1 drochner void *cbcookie;
80 1.3 drochner int scrcapabilities;
81 1.1 drochner u_int nrows, ncols, crow, ccol;
82 1.1 drochner
83 1.3 drochner u_int state; /* processing state */
84 1.3 drochner u_int args[SUN_EMUL_NARGS]; /* command args, if CONTROL */
85 1.3 drochner u_int scrolldist; /* distance to scroll */
86 1.3 drochner long defattr; /* default attribute (rendition) */
87 1.3 drochner long bowattr; /* attribute for reversed mode */
88 1.3 drochner int rendflags;
89 1.3 drochner #define REND_BOW 1
90 1.3 drochner #define REND_SO 2
91 1.3 drochner long curattr; /* currently used attribute */
92 1.3 drochner long kernattr; /* attribute for kernel output */
93 1.3 drochner #ifdef DIAGNOSTIC
94 1.3 drochner int console;
95 1.3 drochner #endif
96 1.1 drochner };
97 1.1 drochner
98 1.13 augustss static u_int wsemul_sun_output_normal(struct wsemul_sun_emuldata *,
99 1.13 augustss u_char, int);
100 1.13 augustss static u_int wsemul_sun_output_haveesc(struct wsemul_sun_emuldata *, u_char);
101 1.13 augustss static u_int wsemul_sun_output_control(struct wsemul_sun_emuldata *, u_char);
102 1.13 augustss static void wsemul_sun_control(struct wsemul_sun_emuldata *, u_char);
103 1.1 drochner
104 1.1 drochner struct wsemul_sun_emuldata wsemul_sun_console_emuldata;
105 1.1 drochner
106 1.1 drochner /* some useful utility macros */
107 1.1 drochner #define ARG(n) (edp->args[(n)])
108 1.1 drochner #define NORMALIZE_ARG(n) (ARG(n) ? ARG(n) : 1)
109 1.1 drochner #define COLS_LEFT (edp->ncols - edp->ccol - 1)
110 1.1 drochner #define ROWS_LEFT (edp->nrows - edp->crow - 1)
111 1.1 drochner
112 1.1 drochner void *
113 1.13 augustss wsemul_sun_cnattach(const struct wsscreen_descr *type, void *cookie,
114 1.13 augustss int ccol, int crow, long defattr)
115 1.1 drochner {
116 1.1 drochner struct wsemul_sun_emuldata *edp;
117 1.3 drochner int res;
118 1.1 drochner
119 1.1 drochner edp = &wsemul_sun_console_emuldata;
120 1.1 drochner
121 1.1 drochner edp->emulops = type->textops;
122 1.1 drochner edp->emulcookie = cookie;
123 1.3 drochner edp->scrcapabilities = type->capabilities;
124 1.1 drochner edp->nrows = type->nrows;
125 1.1 drochner edp->ncols = type->ncols;
126 1.1 drochner edp->crow = crow;
127 1.1 drochner edp->ccol = ccol;
128 1.4 drochner edp->curattr = edp->defattr = defattr;
129 1.3 drochner #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
130 1.3 drochner defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
131 1.3 drochner #ifndef WS_KERNEL_FG
132 1.3 drochner #define WS_KERNEL_FG WSCOL_WHITE
133 1.3 drochner #endif
134 1.3 drochner #ifndef WS_KERNEL_BG
135 1.3 drochner #define WS_KERNEL_BG WSCOL_BLACK
136 1.3 drochner #endif
137 1.3 drochner #ifndef WS_KERNEL_COLATTR
138 1.3 drochner #define WS_KERNEL_COLATTR 0
139 1.3 drochner #endif
140 1.3 drochner #ifndef WS_KERNEL_MONOATTR
141 1.3 drochner #define WS_KERNEL_MONOATTR 0
142 1.3 drochner #endif
143 1.3 drochner if (type->capabilities & WSSCREEN_WSCOLORS)
144 1.15 junyoung res = (*edp->emulops->allocattr)(cookie,
145 1.3 drochner WS_KERNEL_FG, WS_KERNEL_BG,
146 1.3 drochner WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
147 1.3 drochner &edp->kernattr);
148 1.3 drochner else
149 1.15 junyoung res = (*edp->emulops->allocattr)(cookie, 0, 0,
150 1.3 drochner WS_KERNEL_MONOATTR,
151 1.3 drochner &edp->kernattr);
152 1.3 drochner if (res)
153 1.3 drochner #else
154 1.3 drochner res = 0; /* XXX gcc */
155 1.3 drochner #endif
156 1.3 drochner edp->kernattr = defattr;
157 1.3 drochner
158 1.1 drochner edp->cbcookie = NULL;
159 1.1 drochner
160 1.1 drochner edp->state = SUN_EMUL_STATE_NORMAL;
161 1.1 drochner edp->scrolldist = 1;
162 1.3 drochner #ifdef DIAGNOSTIC
163 1.3 drochner edp->console = 1;
164 1.3 drochner #endif
165 1.1 drochner return (edp);
166 1.1 drochner }
167 1.1 drochner
168 1.1 drochner void *
169 1.13 augustss wsemul_sun_attach(int console, const struct wsscreen_descr *type,
170 1.13 augustss void *cookie, int ccol, int crow, void *cbcookie, long defattr)
171 1.1 drochner {
172 1.1 drochner struct wsemul_sun_emuldata *edp;
173 1.1 drochner
174 1.3 drochner if (console) {
175 1.1 drochner edp = &wsemul_sun_console_emuldata;
176 1.3 drochner #ifdef DIAGNOSTIC
177 1.3 drochner KASSERT(edp->console == 1);
178 1.3 drochner #endif
179 1.3 drochner } else {
180 1.1 drochner edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
181 1.1 drochner
182 1.1 drochner edp->emulops = type->textops;
183 1.1 drochner edp->emulcookie = cookie;
184 1.3 drochner edp->scrcapabilities = type->capabilities;
185 1.1 drochner edp->nrows = type->nrows;
186 1.1 drochner edp->ncols = type->ncols;
187 1.1 drochner edp->crow = crow;
188 1.1 drochner edp->ccol = ccol;
189 1.3 drochner edp->defattr = defattr;
190 1.1 drochner
191 1.1 drochner edp->state = SUN_EMUL_STATE_NORMAL;
192 1.1 drochner edp->scrolldist = 1;
193 1.3 drochner #ifdef DIAGNOSTIC
194 1.3 drochner edp->console = 0;
195 1.3 drochner #endif
196 1.1 drochner }
197 1.1 drochner
198 1.1 drochner edp->cbcookie = cbcookie;
199 1.1 drochner
200 1.20 martin if ((!(edp->scrcapabilities & WSSCREEN_REVERSE) ||
201 1.20 martin (*edp->emulops->allocattr)(edp->emulcookie, 0, 0,
202 1.20 martin WSATTR_REVERSE,
203 1.20 martin &edp->bowattr)) &&
204 1.20 martin (!(edp->scrcapabilities & WSSCREEN_WSCOLORS) ||
205 1.15 junyoung (*edp->emulops->allocattr)(edp->emulcookie,
206 1.15 junyoung WSCOL_BLACK, WSCOL_WHITE,
207 1.15 junyoung WSATTR_WSCOLORS,
208 1.15 junyoung &edp->bowattr)))
209 1.3 drochner edp->bowattr = edp->defattr;
210 1.3 drochner
211 1.3 drochner edp->curattr = edp->defattr;
212 1.3 drochner edp->rendflags = 0;
213 1.3 drochner
214 1.1 drochner return (edp);
215 1.1 drochner }
216 1.1 drochner
217 1.1 drochner static inline u_int
218 1.13 augustss wsemul_sun_output_normal(struct wsemul_sun_emuldata *edp, u_char c, int kernel)
219 1.1 drochner {
220 1.1 drochner u_int newstate = SUN_EMUL_STATE_NORMAL;
221 1.1 drochner u_int n;
222 1.1 drochner
223 1.1 drochner switch (c) {
224 1.1 drochner case ASCII_BEL: /* "Bell (BEL)" */
225 1.1 drochner wsdisplay_emulbell(edp->cbcookie);
226 1.1 drochner break;
227 1.1 drochner
228 1.1 drochner case ASCII_BS: /* "Backspace (BS)" */
229 1.1 drochner if (edp->ccol > 0)
230 1.1 drochner edp->ccol--;
231 1.1 drochner break;
232 1.1 drochner
233 1.1 drochner case ASCII_CR: /* "Return (CR)" */
234 1.1 drochner edp->ccol = 0;
235 1.1 drochner break;
236 1.1 drochner
237 1.1 drochner case ASCII_HT: /* "Tab (TAB)" */
238 1.2 drochner n = min(8 - (edp->ccol & 7), COLS_LEFT);
239 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
240 1.3 drochner edp->ccol, n,
241 1.3 drochner kernel ? edp->kernattr : edp->curattr);
242 1.1 drochner edp->ccol += n;
243 1.1 drochner break;
244 1.1 drochner
245 1.7 drochner case ASCII_FF: /* "Form Feed (FF)" */
246 1.3 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
247 1.3 drochner kernel ? edp->kernattr : edp->curattr);
248 1.3 drochner /* XXX possible in kernel output? */
249 1.1 drochner edp->ccol = 0;
250 1.1 drochner edp->crow = 0;
251 1.1 drochner break;
252 1.1 drochner
253 1.1 drochner case ASCII_VT: /* "Reverse Line Feed" */
254 1.1 drochner if (edp->crow > 0)
255 1.1 drochner edp->crow--;
256 1.1 drochner break;
257 1.1 drochner
258 1.1 drochner case ASCII_ESC: /* "Escape (ESC)" */
259 1.12 jdolecek if (kernel) {
260 1.12 jdolecek printf("wsemul_sun_output_normal: ESC in kernel output ignored\n");
261 1.12 jdolecek break; /* ignore the ESC */
262 1.12 jdolecek }
263 1.12 jdolecek
264 1.1 drochner if (edp->state == SUN_EMUL_STATE_NORMAL) {
265 1.1 drochner newstate = SUN_EMUL_STATE_HAVEESC;
266 1.1 drochner break;
267 1.1 drochner }
268 1.1 drochner /* special case: fall through, we're printing one out */
269 1.1 drochner /* FALLTHRU */
270 1.1 drochner
271 1.1 drochner default: /* normal character */
272 1.8 drochner (*edp->emulops->putchar)(edp->emulcookie, edp->crow, edp->ccol,
273 1.8 drochner c, kernel ? edp->kernattr : edp->curattr);
274 1.1 drochner edp->ccol++;
275 1.1 drochner
276 1.1 drochner /* if cur col is still on cur line, done. */
277 1.1 drochner if (edp->ccol < edp->ncols)
278 1.1 drochner break;
279 1.1 drochner
280 1.1 drochner /* wrap the column around. */
281 1.1 drochner edp->ccol = 0;
282 1.1 drochner
283 1.1 drochner /* FALLTHRU */
284 1.1 drochner
285 1.1 drochner case ASCII_LF: /* "Line Feed (LF)" */
286 1.1 drochner /* if the cur line isn't the last, incr and leave. */
287 1.1 drochner if (edp->crow < edp->nrows - 1) {
288 1.1 drochner edp->crow++;
289 1.1 drochner break;
290 1.1 drochner }
291 1.1 drochner
292 1.1 drochner /*
293 1.1 drochner * if we're in wrap-around mode, go to the first
294 1.1 drochner * line and clear it.
295 1.1 drochner */
296 1.1 drochner if (edp->scrolldist == 0) {
297 1.1 drochner edp->crow = 0;
298 1.3 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, 1,
299 1.3 drochner edp->curattr);
300 1.1 drochner break;
301 1.1 drochner }
302 1.1 drochner
303 1.1 drochner /* scroll by the scrolling distance. */
304 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie, edp->scrolldist, 0,
305 1.1 drochner edp->nrows - edp->scrolldist);
306 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
307 1.3 drochner edp->nrows - edp->scrolldist, edp->scrolldist,
308 1.3 drochner edp->curattr);
309 1.1 drochner edp->crow -= edp->scrolldist - 1;
310 1.1 drochner break;
311 1.1 drochner }
312 1.1 drochner
313 1.1 drochner return (newstate);
314 1.1 drochner }
315 1.1 drochner
316 1.1 drochner static inline u_int
317 1.13 augustss wsemul_sun_output_haveesc(struct wsemul_sun_emuldata *edp, u_char c)
318 1.1 drochner {
319 1.1 drochner u_int newstate;
320 1.1 drochner
321 1.1 drochner switch (c) {
322 1.1 drochner case '[': /* continuation of multi-char sequence */
323 1.9 augustss memset(edp->args, 0, sizeof (edp->args));
324 1.1 drochner newstate = SUN_EMUL_STATE_CONTROL;
325 1.1 drochner break;
326 1.1 drochner
327 1.1 drochner default:
328 1.1 drochner /* spit out the escape char (???), then the new character */
329 1.3 drochner wsemul_sun_output_normal(edp, ASCII_ESC, 0); /* ??? */
330 1.3 drochner newstate = wsemul_sun_output_normal(edp, c, 0);
331 1.1 drochner break;
332 1.1 drochner }
333 1.1 drochner
334 1.1 drochner return (newstate);
335 1.1 drochner }
336 1.1 drochner
337 1.1 drochner static inline void
338 1.13 augustss wsemul_sun_control(struct wsemul_sun_emuldata *edp, u_char c)
339 1.1 drochner {
340 1.1 drochner u_int n, src, dst;
341 1.1 drochner
342 1.1 drochner switch (c) {
343 1.1 drochner case '@': /* "Insert Character (ICH)" */
344 1.1 drochner n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
345 1.1 drochner src = edp->ccol;
346 1.1 drochner dst = edp->ccol + n;
347 1.1 drochner if (dst < edp->ncols) {
348 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
349 1.1 drochner src, dst, edp->ncols - dst);
350 1.1 drochner }
351 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
352 1.3 drochner src, dst - src, edp->curattr);
353 1.1 drochner break;
354 1.1 drochner
355 1.1 drochner case 'A': /* "Cursor Up (CUU)" */
356 1.1 drochner edp->crow -= min(NORMALIZE_ARG(0), edp->crow);
357 1.1 drochner break;
358 1.1 drochner
359 1.5 drochner case 'E': /* "Cursor Next Line (CNL)" */
360 1.5 drochner edp->ccol = 0;
361 1.5 drochner /* FALLTHRU */
362 1.1 drochner case 'B': /* "Cursor Down (CUD)" */
363 1.1 drochner edp->crow += min(NORMALIZE_ARG(0), ROWS_LEFT);
364 1.1 drochner break;
365 1.1 drochner
366 1.1 drochner case 'C': /* "Cursor Forward (CUF)" */
367 1.1 drochner edp->ccol += min(NORMALIZE_ARG(0), COLS_LEFT);
368 1.1 drochner break;
369 1.1 drochner
370 1.1 drochner case 'D': /* "Cursor Backward (CUB)" */
371 1.1 drochner edp->ccol -= min(NORMALIZE_ARG(0), edp->ccol);
372 1.1 drochner break;
373 1.1 drochner
374 1.1 drochner case 'f': /* "Horizontal And Vertical Position (HVP)" */
375 1.1 drochner case 'H': /* "Cursor Position (CUP)" */
376 1.1 drochner edp->crow = min(NORMALIZE_ARG(1), edp->nrows) - 1;
377 1.1 drochner edp->ccol = min(NORMALIZE_ARG(0), edp->ncols) - 1;
378 1.1 drochner break;
379 1.1 drochner
380 1.1 drochner case 'J': /* "Erase in Display (ED)" */
381 1.1 drochner if (ROWS_LEFT > 0) {
382 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
383 1.3 drochner edp->crow + 1, ROWS_LEFT, edp->curattr);
384 1.1 drochner }
385 1.1 drochner /* FALLTHRU */
386 1.1 drochner case 'K': /* "Erase in Line (EL)" */
387 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
388 1.3 drochner edp->ccol, COLS_LEFT + 1, edp->curattr);
389 1.1 drochner break;
390 1.1 drochner
391 1.1 drochner case 'L': /* "Insert Line (IL)" */
392 1.1 drochner n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
393 1.1 drochner src = edp->crow;
394 1.1 drochner dst = edp->crow + n;
395 1.1 drochner if (dst < edp->nrows) {
396 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
397 1.1 drochner src, dst, edp->nrows - dst);
398 1.1 drochner }
399 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
400 1.3 drochner src, dst - src, edp->curattr);
401 1.1 drochner break;
402 1.1 drochner
403 1.1 drochner case 'M': /* "Delete Line (DL)" */
404 1.1 drochner n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
405 1.1 drochner src = edp->crow + n;
406 1.1 drochner dst = edp->crow;
407 1.1 drochner if (src < edp->nrows) {
408 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
409 1.1 drochner src, dst, edp->nrows - src);
410 1.1 drochner }
411 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
412 1.3 drochner dst + edp->nrows - src, src - dst, edp->curattr);
413 1.1 drochner break;
414 1.1 drochner
415 1.1 drochner case 'P': /* "Delete Character (DCH)" */
416 1.1 drochner n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
417 1.1 drochner src = edp->ccol + n;
418 1.1 drochner dst = edp->ccol;
419 1.1 drochner if (src < edp->ncols) {
420 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
421 1.1 drochner src, dst, edp->ncols - src);
422 1.1 drochner }
423 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
424 1.3 drochner dst + edp->ncols - src, src - dst, edp->curattr);
425 1.1 drochner break;
426 1.1 drochner
427 1.1 drochner case 'm': /* "Select Graphic Rendition (SGR)" */
428 1.3 drochner if (ARG(0))
429 1.3 drochner edp->rendflags |= REND_SO;
430 1.3 drochner else
431 1.3 drochner edp->rendflags &= ~REND_SO;
432 1.3 drochner goto setattr;
433 1.1 drochner
434 1.1 drochner case 'p': /* "Black On White (SUNBOW)" */
435 1.3 drochner edp->rendflags |= REND_BOW;
436 1.3 drochner goto setattr;
437 1.1 drochner
438 1.1 drochner case 'q': /* "White On Black (SUNWOB)" */
439 1.3 drochner edp->rendflags &= ~REND_BOW;
440 1.3 drochner goto setattr;
441 1.1 drochner
442 1.1 drochner case 'r': /* "Set Scrolling (SUNSCRL)" */
443 1.2 drochner edp->scrolldist = min(ARG(0), edp->nrows);
444 1.1 drochner break;
445 1.1 drochner
446 1.1 drochner case 's': /* "Reset Terminal Emulator (SUNRESET)" */
447 1.1 drochner edp->scrolldist = 1;
448 1.3 drochner edp->rendflags = 0;
449 1.3 drochner setattr:
450 1.3 drochner if (((edp->rendflags & REND_BOW) != 0) ^
451 1.3 drochner ((edp->rendflags & REND_SO) != 0))
452 1.3 drochner edp->curattr = edp->bowattr;
453 1.3 drochner else
454 1.3 drochner edp->curattr = edp->defattr;
455 1.1 drochner break;
456 1.1 drochner }
457 1.1 drochner }
458 1.1 drochner
459 1.1 drochner static inline u_int
460 1.13 augustss wsemul_sun_output_control(struct wsemul_sun_emuldata *edp, u_char c)
461 1.1 drochner {
462 1.1 drochner u_int newstate = SUN_EMUL_STATE_CONTROL;
463 1.1 drochner u_int i;
464 1.1 drochner
465 1.1 drochner switch (c) {
466 1.1 drochner case '0': case '1': case '2': case '3': case '4': /* argument digit */
467 1.1 drochner case '5': case '6': case '7': case '8': case '9':
468 1.1 drochner edp->args[0] = (edp->args[0] * 10) + (c - '0');
469 1.1 drochner break;
470 1.1 drochner
471 1.1 drochner case ';': /* argument terminator */
472 1.1 drochner for (i = 1; i < SUN_EMUL_NARGS; i++)
473 1.1 drochner edp->args[i] = edp->args[i - 1];
474 1.1 drochner edp->args[0] = 0;
475 1.1 drochner break;
476 1.1 drochner
477 1.1 drochner default: /* end of escape sequence */
478 1.1 drochner wsemul_sun_control(edp, c);
479 1.1 drochner newstate = SUN_EMUL_STATE_NORMAL;
480 1.1 drochner break;
481 1.1 drochner }
482 1.1 drochner return (newstate);
483 1.1 drochner }
484 1.1 drochner
485 1.1 drochner void
486 1.13 augustss wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
487 1.1 drochner {
488 1.1 drochner struct wsemul_sun_emuldata *edp = cookie;
489 1.1 drochner u_int newstate;
490 1.1 drochner
491 1.3 drochner #ifdef DIAGNOSTIC
492 1.3 drochner if (kernel && !edp->console)
493 1.3 drochner panic("wsemul_sun_output: kernel output, not console");
494 1.3 drochner #endif
495 1.3 drochner
496 1.1 drochner /* XXX */
497 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
498 1.1 drochner for (; count > 0; data++, count--) {
499 1.3 drochner if (kernel) {
500 1.3 drochner wsemul_sun_output_normal(edp, *data, 1);
501 1.3 drochner continue;
502 1.3 drochner }
503 1.1 drochner switch (edp->state) {
504 1.1 drochner case SUN_EMUL_STATE_NORMAL:
505 1.1 drochner /* XXX SCAN INPUT FOR NEWLINES, DO PRESCROLLING */
506 1.3 drochner newstate = wsemul_sun_output_normal(edp, *data, 0);
507 1.1 drochner break;
508 1.1 drochner case SUN_EMUL_STATE_HAVEESC:
509 1.1 drochner newstate = wsemul_sun_output_haveesc(edp, *data);
510 1.1 drochner break;
511 1.1 drochner case SUN_EMUL_STATE_CONTROL:
512 1.1 drochner newstate = wsemul_sun_output_control(edp, *data);
513 1.1 drochner break;
514 1.1 drochner default:
515 1.1 drochner #ifdef DIAGNOSTIC
516 1.17 provos panic("wsemul_sun: invalid state %d", edp->state);
517 1.1 drochner #endif
518 1.1 drochner /* try to recover, if things get screwed up... */
519 1.3 drochner newstate = wsemul_sun_output_normal(edp, *data, 0);
520 1.1 drochner break;
521 1.1 drochner }
522 1.1 drochner edp->state = newstate;
523 1.1 drochner }
524 1.1 drochner /* XXX */
525 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
526 1.6 drochner }
527 1.6 drochner
528 1.6 drochner static char *sun_fkeys[] = {
529 1.6 drochner "\033[224z", /* F1 */
530 1.6 drochner "\033[225z",
531 1.6 drochner "\033[226z",
532 1.6 drochner "\033[227z",
533 1.6 drochner "\033[228z",
534 1.6 drochner "\033[229z",
535 1.6 drochner "\033[230z",
536 1.6 drochner "\033[231z",
537 1.6 drochner "\033[232z",
538 1.6 drochner "\033[233z", /* F10 */
539 1.6 drochner };
540 1.6 drochner
541 1.6 drochner int
542 1.21 martin wsemul_sun_translate(void *cookie, keysym_t in, const char **out)
543 1.6 drochner {
544 1.6 drochner static char c;
545 1.6 drochner
546 1.6 drochner if (KS_GROUP(in) == KS_GROUP_Keypad && (in & 0x80) == 0) {
547 1.6 drochner c = in & 0xff; /* turn into ASCII */
548 1.6 drochner *out = &c;
549 1.6 drochner return (1);
550 1.6 drochner }
551 1.6 drochner
552 1.6 drochner if (in >= KS_f1 && in <= KS_f10) {
553 1.6 drochner *out = sun_fkeys[in - KS_f1];
554 1.6 drochner return (6);
555 1.6 drochner }
556 1.6 drochner if (in >= KS_F1 && in <= KS_F10) {
557 1.6 drochner *out = sun_fkeys[in - KS_F1];
558 1.6 drochner return (6);
559 1.6 drochner }
560 1.6 drochner if (in >= KS_KP_F1 && in <= KS_KP_F4) {
561 1.6 drochner *out = sun_fkeys[in - KS_KP_F1];
562 1.6 drochner return (6);
563 1.6 drochner }
564 1.6 drochner
565 1.6 drochner switch (in) {
566 1.16 junyoung case KS_Home:
567 1.16 junyoung case KS_KP_Home:
568 1.16 junyoung case KS_KP_Begin:
569 1.6 drochner *out = "\033[214z";
570 1.6 drochner return (6);
571 1.16 junyoung case KS_Prior:
572 1.16 junyoung case KS_KP_Prior:
573 1.6 drochner *out = "\033[216z";
574 1.6 drochner return (6);
575 1.16 junyoung case KS_Next:
576 1.16 junyoung case KS_KP_Next:
577 1.6 drochner *out = "\033[222z";
578 1.6 drochner return (6);
579 1.16 junyoung case KS_Up:
580 1.16 junyoung case KS_KP_Up:
581 1.6 drochner *out = "\033[A";
582 1.6 drochner return (3);
583 1.16 junyoung case KS_Down:
584 1.16 junyoung case KS_KP_Down:
585 1.6 drochner *out = "\033[B";
586 1.6 drochner return (3);
587 1.16 junyoung case KS_Left:
588 1.16 junyoung case KS_KP_Left:
589 1.6 drochner *out = "\033[D";
590 1.6 drochner return (3);
591 1.16 junyoung case KS_Right:
592 1.16 junyoung case KS_KP_Right:
593 1.6 drochner *out = "\033[C";
594 1.6 drochner return (3);
595 1.16 junyoung case KS_KP_Delete:
596 1.6 drochner *out = "\177";
597 1.6 drochner return (1);
598 1.6 drochner }
599 1.6 drochner return (0);
600 1.1 drochner }
601 1.1 drochner
602 1.1 drochner void
603 1.14 veego wsemul_sun_detach(void *cookie, u_int *crowp, u_int *ccolp)
604 1.1 drochner {
605 1.1 drochner struct wsemul_sun_emuldata *edp = cookie;
606 1.1 drochner
607 1.1 drochner *crowp = edp->crow;
608 1.1 drochner *ccolp = edp->ccol;
609 1.1 drochner if (edp != &wsemul_sun_console_emuldata)
610 1.1 drochner free(edp, M_DEVBUF);
611 1.10 drochner }
612 1.10 drochner
613 1.10 drochner void
614 1.13 augustss wsemul_sun_resetop(void *cookie, enum wsemul_resetops op)
615 1.10 drochner {
616 1.10 drochner struct wsemul_sun_emuldata *edp = cookie;
617 1.10 drochner
618 1.10 drochner switch (op) {
619 1.10 drochner case WSEMUL_RESET:
620 1.10 drochner edp->state = SUN_EMUL_STATE_NORMAL;
621 1.10 drochner edp->scrolldist = 1;
622 1.10 drochner edp->rendflags = 0;
623 1.10 drochner edp->curattr = edp->defattr;
624 1.10 drochner break;
625 1.10 drochner case WSEMUL_CLEARSCREEN:
626 1.10 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
627 1.10 drochner edp->defattr);
628 1.10 drochner edp->ccol = edp->crow = 0;
629 1.10 drochner (*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
630 1.10 drochner break;
631 1.10 drochner default:
632 1.10 drochner break;
633 1.10 drochner }
634 1.1 drochner }
635