wsemul_sun.c revision 1.12 1 1.12 jdolecek /* $NetBSD: wsemul_sun.c,v 1.12 2001/02/21 23:12:58 jdolecek 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.12 jdolecek __KERNEL_RCSID(0, "$NetBSD: wsemul_sun.c,v 1.12 2001/02/21 23:12:58 jdolecek 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.3 drochner #include "opt_wskernattr.h"
51 1.3 drochner
52 1.1 drochner void *wsemul_sun_cnattach __P((const struct wsscreen_descr *, void *,
53 1.3 drochner int, int, long));
54 1.1 drochner void *wsemul_sun_attach __P((int console, const struct wsscreen_descr *,
55 1.3 drochner void *, int, int, void *, long));
56 1.3 drochner void wsemul_sun_output __P((void *cookie, const u_char *data, u_int count,
57 1.3 drochner int));
58 1.6 drochner int wsemul_sun_translate __P((void *cookie, keysym_t, char **));
59 1.1 drochner void wsemul_sun_detach __P((void *cookie, u_int *crowp, u_int *ccolp));
60 1.10 drochner void wsemul_sun_resetop __P((void *, enum wsemul_resetops));
61 1.1 drochner
62 1.1 drochner const struct wsemul_ops wsemul_sun_ops = {
63 1.1 drochner "sun",
64 1.1 drochner wsemul_sun_cnattach,
65 1.1 drochner wsemul_sun_attach,
66 1.1 drochner wsemul_sun_output,
67 1.6 drochner wsemul_sun_translate,
68 1.1 drochner wsemul_sun_detach,
69 1.10 drochner wsemul_sun_resetop
70 1.1 drochner };
71 1.1 drochner
72 1.1 drochner #define SUN_EMUL_STATE_NORMAL 0 /* normal processing */
73 1.1 drochner #define SUN_EMUL_STATE_HAVEESC 1 /* seen start of ctl seq */
74 1.1 drochner #define SUN_EMUL_STATE_CONTROL 2 /* processing ctl seq */
75 1.1 drochner
76 1.1 drochner #define SUN_EMUL_NARGS 2 /* max # of args to a command */
77 1.1 drochner
78 1.1 drochner struct wsemul_sun_emuldata {
79 1.1 drochner const struct wsdisplay_emulops *emulops;
80 1.1 drochner void *emulcookie;
81 1.1 drochner void *cbcookie;
82 1.3 drochner int scrcapabilities;
83 1.1 drochner u_int nrows, ncols, crow, ccol;
84 1.1 drochner
85 1.3 drochner u_int state; /* processing state */
86 1.3 drochner u_int args[SUN_EMUL_NARGS]; /* command args, if CONTROL */
87 1.3 drochner u_int scrolldist; /* distance to scroll */
88 1.3 drochner long defattr; /* default attribute (rendition) */
89 1.3 drochner long bowattr; /* attribute for reversed mode */
90 1.3 drochner int rendflags;
91 1.3 drochner #define REND_BOW 1
92 1.3 drochner #define REND_SO 2
93 1.3 drochner long curattr; /* currently used attribute */
94 1.3 drochner long kernattr; /* attribute for kernel output */
95 1.3 drochner #ifdef DIAGNOSTIC
96 1.3 drochner int console;
97 1.3 drochner #endif
98 1.1 drochner };
99 1.1 drochner
100 1.1 drochner static u_int wsemul_sun_output_normal __P((struct wsemul_sun_emuldata *,
101 1.3 drochner u_char, int));
102 1.1 drochner static u_int wsemul_sun_output_haveesc __P((struct wsemul_sun_emuldata *,
103 1.1 drochner u_char));
104 1.1 drochner static u_int wsemul_sun_output_control __P((struct wsemul_sun_emuldata *,
105 1.1 drochner u_char));
106 1.1 drochner static void wsemul_sun_control __P((struct wsemul_sun_emuldata *, u_char));
107 1.1 drochner
108 1.1 drochner struct wsemul_sun_emuldata wsemul_sun_console_emuldata;
109 1.1 drochner
110 1.1 drochner /* some useful utility macros */
111 1.1 drochner #define ARG(n) (edp->args[(n)])
112 1.1 drochner #define NORMALIZE_ARG(n) (ARG(n) ? ARG(n) : 1)
113 1.1 drochner #define COLS_LEFT (edp->ncols - edp->ccol - 1)
114 1.1 drochner #define ROWS_LEFT (edp->nrows - edp->crow - 1)
115 1.1 drochner
116 1.1 drochner void *
117 1.3 drochner wsemul_sun_cnattach(type, cookie, ccol, crow, defattr)
118 1.1 drochner const struct wsscreen_descr *type;
119 1.1 drochner void *cookie;
120 1.1 drochner int ccol, crow;
121 1.3 drochner long defattr;
122 1.1 drochner {
123 1.1 drochner struct wsemul_sun_emuldata *edp;
124 1.3 drochner int res;
125 1.1 drochner
126 1.1 drochner edp = &wsemul_sun_console_emuldata;
127 1.1 drochner
128 1.1 drochner edp->emulops = type->textops;
129 1.1 drochner edp->emulcookie = cookie;
130 1.3 drochner edp->scrcapabilities = type->capabilities;
131 1.1 drochner edp->nrows = type->nrows;
132 1.1 drochner edp->ncols = type->ncols;
133 1.1 drochner edp->crow = crow;
134 1.1 drochner edp->ccol = ccol;
135 1.4 drochner edp->curattr = edp->defattr = defattr;
136 1.3 drochner #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
137 1.3 drochner defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
138 1.3 drochner #ifndef WS_KERNEL_FG
139 1.3 drochner #define WS_KERNEL_FG WSCOL_WHITE
140 1.3 drochner #endif
141 1.3 drochner #ifndef WS_KERNEL_BG
142 1.3 drochner #define WS_KERNEL_BG WSCOL_BLACK
143 1.3 drochner #endif
144 1.3 drochner #ifndef WS_KERNEL_COLATTR
145 1.3 drochner #define WS_KERNEL_COLATTR 0
146 1.3 drochner #endif
147 1.3 drochner #ifndef WS_KERNEL_MONOATTR
148 1.3 drochner #define WS_KERNEL_MONOATTR 0
149 1.3 drochner #endif
150 1.3 drochner if (type->capabilities & WSSCREEN_WSCOLORS)
151 1.3 drochner res = (*edp->emulops->alloc_attr)(cookie,
152 1.3 drochner WS_KERNEL_FG, WS_KERNEL_BG,
153 1.3 drochner WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
154 1.3 drochner &edp->kernattr);
155 1.3 drochner else
156 1.3 drochner res = (*edp->emulops->alloc_attr)(cookie, 0, 0,
157 1.3 drochner WS_KERNEL_MONOATTR,
158 1.3 drochner &edp->kernattr);
159 1.3 drochner if (res)
160 1.3 drochner #else
161 1.3 drochner res = 0; /* XXX gcc */
162 1.3 drochner #endif
163 1.3 drochner edp->kernattr = defattr;
164 1.3 drochner
165 1.1 drochner edp->cbcookie = NULL;
166 1.1 drochner
167 1.1 drochner edp->state = SUN_EMUL_STATE_NORMAL;
168 1.1 drochner edp->scrolldist = 1;
169 1.3 drochner #ifdef DIAGNOSTIC
170 1.3 drochner edp->console = 1;
171 1.3 drochner #endif
172 1.1 drochner return (edp);
173 1.1 drochner }
174 1.1 drochner
175 1.1 drochner void *
176 1.3 drochner wsemul_sun_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
177 1.1 drochner int console;
178 1.1 drochner const struct wsscreen_descr *type;
179 1.1 drochner void *cookie;
180 1.1 drochner int ccol, crow;
181 1.1 drochner void *cbcookie;
182 1.3 drochner long defattr;
183 1.1 drochner {
184 1.1 drochner struct wsemul_sun_emuldata *edp;
185 1.1 drochner
186 1.3 drochner if (console) {
187 1.1 drochner edp = &wsemul_sun_console_emuldata;
188 1.3 drochner #ifdef DIAGNOSTIC
189 1.3 drochner KASSERT(edp->console == 1);
190 1.3 drochner #endif
191 1.3 drochner } else {
192 1.1 drochner edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
193 1.1 drochner
194 1.1 drochner edp->emulops = type->textops;
195 1.1 drochner edp->emulcookie = cookie;
196 1.3 drochner edp->scrcapabilities = type->capabilities;
197 1.1 drochner edp->nrows = type->nrows;
198 1.1 drochner edp->ncols = type->ncols;
199 1.1 drochner edp->crow = crow;
200 1.1 drochner edp->ccol = ccol;
201 1.3 drochner edp->defattr = defattr;
202 1.1 drochner
203 1.1 drochner edp->state = SUN_EMUL_STATE_NORMAL;
204 1.1 drochner edp->scrolldist = 1;
205 1.3 drochner #ifdef DIAGNOSTIC
206 1.3 drochner edp->console = 0;
207 1.3 drochner #endif
208 1.1 drochner }
209 1.1 drochner
210 1.1 drochner edp->cbcookie = cbcookie;
211 1.1 drochner
212 1.3 drochner /* XXX This assumes that the default attribute is wob. */
213 1.3 drochner if ((!(edp->scrcapabilities & WSSCREEN_WSCOLORS) ||
214 1.3 drochner (*edp->emulops->alloc_attr)(edp->emulcookie,
215 1.3 drochner WSCOL_BLACK, WSCOL_WHITE,
216 1.3 drochner WSATTR_WSCOLORS,
217 1.3 drochner &edp->bowattr)) &&
218 1.3 drochner (!(edp->scrcapabilities & WSSCREEN_REVERSE) ||
219 1.3 drochner (*edp->emulops->alloc_attr)(edp->emulcookie, 0, 0,
220 1.3 drochner WSATTR_REVERSE,
221 1.3 drochner &edp->bowattr)))
222 1.3 drochner edp->bowattr = edp->defattr;
223 1.3 drochner
224 1.3 drochner edp->curattr = edp->defattr;
225 1.3 drochner edp->rendflags = 0;
226 1.3 drochner
227 1.1 drochner return (edp);
228 1.1 drochner }
229 1.1 drochner
230 1.1 drochner static inline u_int
231 1.3 drochner wsemul_sun_output_normal(edp, c, kernel)
232 1.1 drochner struct wsemul_sun_emuldata *edp;
233 1.1 drochner u_char c;
234 1.3 drochner int kernel;
235 1.1 drochner {
236 1.1 drochner u_int newstate = SUN_EMUL_STATE_NORMAL;
237 1.1 drochner u_int n;
238 1.1 drochner
239 1.1 drochner switch (c) {
240 1.1 drochner case ASCII_BEL: /* "Bell (BEL)" */
241 1.1 drochner wsdisplay_emulbell(edp->cbcookie);
242 1.1 drochner break;
243 1.1 drochner
244 1.1 drochner case ASCII_BS: /* "Backspace (BS)" */
245 1.1 drochner if (edp->ccol > 0)
246 1.1 drochner edp->ccol--;
247 1.1 drochner break;
248 1.1 drochner
249 1.1 drochner case ASCII_CR: /* "Return (CR)" */
250 1.1 drochner edp->ccol = 0;
251 1.1 drochner break;
252 1.1 drochner
253 1.1 drochner case ASCII_HT: /* "Tab (TAB)" */
254 1.2 drochner n = min(8 - (edp->ccol & 7), COLS_LEFT);
255 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
256 1.3 drochner edp->ccol, n,
257 1.3 drochner kernel ? edp->kernattr : edp->curattr);
258 1.1 drochner edp->ccol += n;
259 1.1 drochner break;
260 1.1 drochner
261 1.7 drochner case ASCII_FF: /* "Form Feed (FF)" */
262 1.3 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
263 1.3 drochner kernel ? edp->kernattr : edp->curattr);
264 1.3 drochner /* XXX possible in kernel output? */
265 1.1 drochner edp->ccol = 0;
266 1.1 drochner edp->crow = 0;
267 1.1 drochner break;
268 1.1 drochner
269 1.1 drochner case ASCII_VT: /* "Reverse Line Feed" */
270 1.1 drochner if (edp->crow > 0)
271 1.1 drochner edp->crow--;
272 1.1 drochner break;
273 1.1 drochner
274 1.1 drochner case ASCII_ESC: /* "Escape (ESC)" */
275 1.12 jdolecek if (kernel) {
276 1.12 jdolecek printf("wsemul_sun_output_normal: ESC in kernel output ignored\n");
277 1.12 jdolecek break; /* ignore the ESC */
278 1.12 jdolecek }
279 1.12 jdolecek
280 1.1 drochner if (edp->state == SUN_EMUL_STATE_NORMAL) {
281 1.1 drochner newstate = SUN_EMUL_STATE_HAVEESC;
282 1.1 drochner break;
283 1.1 drochner }
284 1.1 drochner /* special case: fall through, we're printing one out */
285 1.1 drochner /* FALLTHRU */
286 1.1 drochner
287 1.1 drochner default: /* normal character */
288 1.8 drochner (*edp->emulops->putchar)(edp->emulcookie, edp->crow, edp->ccol,
289 1.8 drochner c, kernel ? edp->kernattr : edp->curattr);
290 1.1 drochner edp->ccol++;
291 1.1 drochner
292 1.1 drochner /* if cur col is still on cur line, done. */
293 1.1 drochner if (edp->ccol < edp->ncols)
294 1.1 drochner break;
295 1.1 drochner
296 1.1 drochner /* wrap the column around. */
297 1.1 drochner edp->ccol = 0;
298 1.1 drochner
299 1.1 drochner /* FALLTHRU */
300 1.1 drochner
301 1.1 drochner case ASCII_LF: /* "Line Feed (LF)" */
302 1.1 drochner /* if the cur line isn't the last, incr and leave. */
303 1.1 drochner if (edp->crow < edp->nrows - 1) {
304 1.1 drochner edp->crow++;
305 1.1 drochner break;
306 1.1 drochner }
307 1.1 drochner
308 1.1 drochner /*
309 1.1 drochner * if we're in wrap-around mode, go to the first
310 1.1 drochner * line and clear it.
311 1.1 drochner */
312 1.1 drochner if (edp->scrolldist == 0) {
313 1.1 drochner edp->crow = 0;
314 1.3 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, 1,
315 1.3 drochner edp->curattr);
316 1.1 drochner break;
317 1.1 drochner }
318 1.1 drochner
319 1.1 drochner /* scroll by the scrolling distance. */
320 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie, edp->scrolldist, 0,
321 1.1 drochner edp->nrows - edp->scrolldist);
322 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
323 1.3 drochner edp->nrows - edp->scrolldist, edp->scrolldist,
324 1.3 drochner edp->curattr);
325 1.1 drochner edp->crow -= edp->scrolldist - 1;
326 1.1 drochner break;
327 1.1 drochner }
328 1.1 drochner
329 1.1 drochner return (newstate);
330 1.1 drochner }
331 1.1 drochner
332 1.1 drochner static inline u_int
333 1.1 drochner wsemul_sun_output_haveesc(edp, c)
334 1.1 drochner struct wsemul_sun_emuldata *edp;
335 1.1 drochner u_char c;
336 1.1 drochner {
337 1.1 drochner u_int newstate;
338 1.1 drochner
339 1.1 drochner switch (c) {
340 1.1 drochner case '[': /* continuation of multi-char sequence */
341 1.9 augustss memset(edp->args, 0, sizeof (edp->args));
342 1.1 drochner newstate = SUN_EMUL_STATE_CONTROL;
343 1.1 drochner break;
344 1.1 drochner
345 1.1 drochner default:
346 1.1 drochner /* spit out the escape char (???), then the new character */
347 1.3 drochner wsemul_sun_output_normal(edp, ASCII_ESC, 0); /* ??? */
348 1.3 drochner newstate = wsemul_sun_output_normal(edp, c, 0);
349 1.1 drochner break;
350 1.1 drochner }
351 1.1 drochner
352 1.1 drochner return (newstate);
353 1.1 drochner }
354 1.1 drochner
355 1.1 drochner static inline void
356 1.1 drochner wsemul_sun_control(edp, c)
357 1.1 drochner struct wsemul_sun_emuldata *edp;
358 1.1 drochner u_char c;
359 1.1 drochner {
360 1.1 drochner u_int n, src, dst;
361 1.1 drochner
362 1.1 drochner switch (c) {
363 1.1 drochner case '@': /* "Insert Character (ICH)" */
364 1.1 drochner n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
365 1.1 drochner src = edp->ccol;
366 1.1 drochner dst = edp->ccol + n;
367 1.1 drochner if (dst < edp->ncols) {
368 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
369 1.1 drochner src, dst, edp->ncols - dst);
370 1.1 drochner }
371 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
372 1.3 drochner src, dst - src, edp->curattr);
373 1.1 drochner break;
374 1.1 drochner
375 1.1 drochner case 'A': /* "Cursor Up (CUU)" */
376 1.1 drochner edp->crow -= min(NORMALIZE_ARG(0), edp->crow);
377 1.1 drochner break;
378 1.1 drochner
379 1.5 drochner case 'E': /* "Cursor Next Line (CNL)" */
380 1.5 drochner edp->ccol = 0;
381 1.5 drochner /* FALLTHRU */
382 1.1 drochner case 'B': /* "Cursor Down (CUD)" */
383 1.1 drochner edp->crow += min(NORMALIZE_ARG(0), ROWS_LEFT);
384 1.1 drochner break;
385 1.1 drochner
386 1.1 drochner case 'C': /* "Cursor Forward (CUF)" */
387 1.1 drochner edp->ccol += min(NORMALIZE_ARG(0), COLS_LEFT);
388 1.1 drochner break;
389 1.1 drochner
390 1.1 drochner case 'D': /* "Cursor Backward (CUB)" */
391 1.1 drochner edp->ccol -= min(NORMALIZE_ARG(0), edp->ccol);
392 1.1 drochner break;
393 1.1 drochner
394 1.1 drochner case 'f': /* "Horizontal And Vertical Position (HVP)" */
395 1.1 drochner case 'H': /* "Cursor Position (CUP)" */
396 1.1 drochner edp->crow = min(NORMALIZE_ARG(1), edp->nrows) - 1;
397 1.1 drochner edp->ccol = min(NORMALIZE_ARG(0), edp->ncols) - 1;
398 1.1 drochner break;
399 1.1 drochner
400 1.1 drochner case 'J': /* "Erase in Display (ED)" */
401 1.1 drochner if (ROWS_LEFT > 0) {
402 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
403 1.3 drochner edp->crow + 1, ROWS_LEFT, edp->curattr);
404 1.1 drochner }
405 1.1 drochner /* FALLTHRU */
406 1.1 drochner case 'K': /* "Erase in Line (EL)" */
407 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
408 1.3 drochner edp->ccol, COLS_LEFT + 1, edp->curattr);
409 1.1 drochner break;
410 1.1 drochner
411 1.1 drochner case 'L': /* "Insert Line (IL)" */
412 1.1 drochner n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
413 1.1 drochner src = edp->crow;
414 1.1 drochner dst = edp->crow + n;
415 1.1 drochner if (dst < edp->nrows) {
416 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
417 1.1 drochner src, dst, edp->nrows - dst);
418 1.1 drochner }
419 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
420 1.3 drochner src, dst - src, edp->curattr);
421 1.1 drochner break;
422 1.1 drochner
423 1.1 drochner case 'M': /* "Delete Line (DL)" */
424 1.1 drochner n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
425 1.1 drochner src = edp->crow + n;
426 1.1 drochner dst = edp->crow;
427 1.1 drochner if (src < edp->nrows) {
428 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
429 1.1 drochner src, dst, edp->nrows - src);
430 1.1 drochner }
431 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
432 1.3 drochner dst + edp->nrows - src, src - dst, edp->curattr);
433 1.1 drochner break;
434 1.1 drochner
435 1.1 drochner case 'P': /* "Delete Character (DCH)" */
436 1.1 drochner n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
437 1.1 drochner src = edp->ccol + n;
438 1.1 drochner dst = edp->ccol;
439 1.1 drochner if (src < edp->ncols) {
440 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
441 1.1 drochner src, dst, edp->ncols - src);
442 1.1 drochner }
443 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
444 1.3 drochner dst + edp->ncols - src, src - dst, edp->curattr);
445 1.1 drochner break;
446 1.1 drochner
447 1.1 drochner case 'm': /* "Select Graphic Rendition (SGR)" */
448 1.3 drochner if (ARG(0))
449 1.3 drochner edp->rendflags |= REND_SO;
450 1.3 drochner else
451 1.3 drochner edp->rendflags &= ~REND_SO;
452 1.3 drochner goto setattr;
453 1.1 drochner
454 1.1 drochner case 'p': /* "Black On White (SUNBOW)" */
455 1.3 drochner edp->rendflags |= REND_BOW;
456 1.3 drochner goto setattr;
457 1.1 drochner
458 1.1 drochner case 'q': /* "White On Black (SUNWOB)" */
459 1.3 drochner edp->rendflags &= ~REND_BOW;
460 1.3 drochner goto setattr;
461 1.1 drochner
462 1.1 drochner case 'r': /* "Set Scrolling (SUNSCRL)" */
463 1.2 drochner edp->scrolldist = min(ARG(0), edp->nrows);
464 1.1 drochner break;
465 1.1 drochner
466 1.1 drochner case 's': /* "Reset Terminal Emulator (SUNRESET)" */
467 1.1 drochner edp->scrolldist = 1;
468 1.3 drochner edp->rendflags = 0;
469 1.3 drochner setattr:
470 1.3 drochner if (((edp->rendflags & REND_BOW) != 0) ^
471 1.3 drochner ((edp->rendflags & REND_SO) != 0))
472 1.3 drochner edp->curattr = edp->bowattr;
473 1.3 drochner else
474 1.3 drochner edp->curattr = edp->defattr;
475 1.1 drochner break;
476 1.1 drochner }
477 1.1 drochner }
478 1.1 drochner
479 1.1 drochner static inline u_int
480 1.1 drochner wsemul_sun_output_control(edp, c)
481 1.1 drochner struct wsemul_sun_emuldata *edp;
482 1.1 drochner u_char c;
483 1.1 drochner {
484 1.1 drochner u_int newstate = SUN_EMUL_STATE_CONTROL;
485 1.1 drochner u_int i;
486 1.1 drochner
487 1.1 drochner switch (c) {
488 1.1 drochner case '0': case '1': case '2': case '3': case '4': /* argument digit */
489 1.1 drochner case '5': case '6': case '7': case '8': case '9':
490 1.1 drochner edp->args[0] = (edp->args[0] * 10) + (c - '0');
491 1.1 drochner break;
492 1.1 drochner
493 1.1 drochner case ';': /* argument terminator */
494 1.1 drochner for (i = 1; i < SUN_EMUL_NARGS; i++)
495 1.1 drochner edp->args[i] = edp->args[i - 1];
496 1.1 drochner edp->args[0] = 0;
497 1.1 drochner break;
498 1.1 drochner
499 1.1 drochner default: /* end of escape sequence */
500 1.1 drochner wsemul_sun_control(edp, c);
501 1.1 drochner newstate = SUN_EMUL_STATE_NORMAL;
502 1.1 drochner break;
503 1.1 drochner }
504 1.1 drochner return (newstate);
505 1.1 drochner }
506 1.1 drochner
507 1.1 drochner void
508 1.3 drochner wsemul_sun_output(cookie, data, count, kernel)
509 1.1 drochner void *cookie;
510 1.1 drochner const u_char *data;
511 1.1 drochner u_int count;
512 1.3 drochner int kernel;
513 1.1 drochner {
514 1.1 drochner struct wsemul_sun_emuldata *edp = cookie;
515 1.1 drochner u_int newstate;
516 1.1 drochner
517 1.3 drochner #ifdef DIAGNOSTIC
518 1.3 drochner if (kernel && !edp->console)
519 1.3 drochner panic("wsemul_sun_output: kernel output, not console");
520 1.3 drochner #endif
521 1.3 drochner
522 1.1 drochner /* XXX */
523 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
524 1.1 drochner for (; count > 0; data++, count--) {
525 1.3 drochner if (kernel) {
526 1.3 drochner wsemul_sun_output_normal(edp, *data, 1);
527 1.3 drochner continue;
528 1.3 drochner }
529 1.1 drochner switch (edp->state) {
530 1.1 drochner case SUN_EMUL_STATE_NORMAL:
531 1.1 drochner /* XXX SCAN INPUT FOR NEWLINES, DO PRESCROLLING */
532 1.3 drochner newstate = wsemul_sun_output_normal(edp, *data, 0);
533 1.1 drochner break;
534 1.1 drochner case SUN_EMUL_STATE_HAVEESC:
535 1.1 drochner newstate = wsemul_sun_output_haveesc(edp, *data);
536 1.1 drochner break;
537 1.1 drochner case SUN_EMUL_STATE_CONTROL:
538 1.1 drochner newstate = wsemul_sun_output_control(edp, *data);
539 1.1 drochner break;
540 1.1 drochner default:
541 1.1 drochner #ifdef DIAGNOSTIC
542 1.1 drochner panic("wsemul_sun: invalid state %d\n", edp->state);
543 1.1 drochner #endif
544 1.1 drochner /* try to recover, if things get screwed up... */
545 1.3 drochner newstate = wsemul_sun_output_normal(edp, *data, 0);
546 1.1 drochner break;
547 1.1 drochner }
548 1.1 drochner edp->state = newstate;
549 1.1 drochner }
550 1.1 drochner /* XXX */
551 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
552 1.6 drochner }
553 1.6 drochner
554 1.6 drochner static char *sun_fkeys[] = {
555 1.6 drochner "\033[224z", /* F1 */
556 1.6 drochner "\033[225z",
557 1.6 drochner "\033[226z",
558 1.6 drochner "\033[227z",
559 1.6 drochner "\033[228z",
560 1.6 drochner "\033[229z",
561 1.6 drochner "\033[230z",
562 1.6 drochner "\033[231z",
563 1.6 drochner "\033[232z",
564 1.6 drochner "\033[233z", /* F10 */
565 1.6 drochner };
566 1.6 drochner
567 1.6 drochner int
568 1.6 drochner wsemul_sun_translate(cookie, in, out)
569 1.6 drochner void *cookie;
570 1.6 drochner keysym_t in;
571 1.6 drochner char **out;
572 1.6 drochner {
573 1.6 drochner static char c;
574 1.6 drochner
575 1.6 drochner if (KS_GROUP(in) == KS_GROUP_Keypad && (in & 0x80) == 0) {
576 1.6 drochner c = in & 0xff; /* turn into ASCII */
577 1.6 drochner *out = &c;
578 1.6 drochner return (1);
579 1.6 drochner }
580 1.6 drochner
581 1.6 drochner if (in >= KS_f1 && in <= KS_f10) {
582 1.6 drochner *out = sun_fkeys[in - KS_f1];
583 1.6 drochner return (6);
584 1.6 drochner }
585 1.6 drochner if (in >= KS_F1 && in <= KS_F10) {
586 1.6 drochner *out = sun_fkeys[in - KS_F1];
587 1.6 drochner return (6);
588 1.6 drochner }
589 1.6 drochner if (in >= KS_KP_F1 && in <= KS_KP_F4) {
590 1.6 drochner *out = sun_fkeys[in - KS_KP_F1];
591 1.6 drochner return (6);
592 1.6 drochner }
593 1.6 drochner
594 1.6 drochner switch (in) {
595 1.6 drochner case KS_Home:
596 1.6 drochner case KS_KP_Home:
597 1.6 drochner case KS_KP_Begin:
598 1.6 drochner *out = "\033[214z";
599 1.6 drochner return (6);
600 1.6 drochner case KS_Prior:
601 1.6 drochner case KS_KP_Prior:
602 1.6 drochner *out = "\033[216z";
603 1.6 drochner return (6);
604 1.6 drochner case KS_Next:
605 1.6 drochner case KS_KP_Next:
606 1.6 drochner *out = "\033[222z";
607 1.6 drochner return (6);
608 1.6 drochner case KS_Up:
609 1.6 drochner case KS_KP_Up:
610 1.6 drochner *out = "\033[A";
611 1.6 drochner return (3);
612 1.6 drochner case KS_Down:
613 1.6 drochner case KS_KP_Down:
614 1.6 drochner *out = "\033[B";
615 1.6 drochner return (3);
616 1.6 drochner case KS_Left:
617 1.6 drochner case KS_KP_Left:
618 1.6 drochner *out = "\033[D";
619 1.6 drochner return (3);
620 1.6 drochner case KS_Right:
621 1.6 drochner case KS_KP_Right:
622 1.6 drochner *out = "\033[C";
623 1.6 drochner return (3);
624 1.6 drochner case KS_KP_Delete:
625 1.6 drochner *out = "\177";
626 1.6 drochner return (1);
627 1.6 drochner }
628 1.6 drochner return (0);
629 1.1 drochner }
630 1.1 drochner
631 1.1 drochner void
632 1.1 drochner wsemul_sun_detach(cookie, crowp, ccolp)
633 1.1 drochner void *cookie;
634 1.1 drochner u_int *crowp, *ccolp;
635 1.1 drochner {
636 1.1 drochner struct wsemul_sun_emuldata *edp = cookie;
637 1.1 drochner
638 1.1 drochner *crowp = edp->crow;
639 1.1 drochner *ccolp = edp->ccol;
640 1.1 drochner if (edp != &wsemul_sun_console_emuldata)
641 1.1 drochner free(edp, M_DEVBUF);
642 1.10 drochner }
643 1.10 drochner
644 1.10 drochner void
645 1.10 drochner wsemul_sun_resetop(cookie, op)
646 1.10 drochner void *cookie;
647 1.10 drochner enum wsemul_resetops op;
648 1.10 drochner {
649 1.10 drochner struct wsemul_sun_emuldata *edp = cookie;
650 1.10 drochner
651 1.10 drochner switch (op) {
652 1.10 drochner case WSEMUL_RESET:
653 1.10 drochner edp->state = SUN_EMUL_STATE_NORMAL;
654 1.10 drochner edp->scrolldist = 1;
655 1.10 drochner edp->rendflags = 0;
656 1.10 drochner edp->curattr = edp->defattr;
657 1.10 drochner break;
658 1.10 drochner case WSEMUL_CLEARSCREEN:
659 1.10 drochner (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
660 1.10 drochner edp->defattr);
661 1.10 drochner edp->ccol = edp->crow = 0;
662 1.10 drochner (*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
663 1.10 drochner break;
664 1.10 drochner default:
665 1.10 drochner break;
666 1.10 drochner }
667 1.1 drochner }
668