wsemul_vt100_subr.c revision 1.3 1 1.3 drochner /* $NetBSD: wsemul_vt100_subr.c,v 1.3 1998/06/29 21:14:40 drochner Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1998
5 1.1 drochner * Matthias Drochner. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner * 3. All advertising materials mentioning features or use of this software
16 1.1 drochner * must display the following acknowledgement:
17 1.1 drochner * This product includes software developed for the NetBSD Project
18 1.1 drochner * by Matthias Drochner.
19 1.1 drochner * 4. The name of the author may not be used to endorse or promote products
20 1.1 drochner * derived from this software without specific prior written permission.
21 1.1 drochner *
22 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 drochner *
33 1.1 drochner */
34 1.1 drochner
35 1.1 drochner #include <sys/param.h>
36 1.1 drochner #include <sys/systm.h>
37 1.1 drochner
38 1.1 drochner #include <dev/wscons/wsksymvar.h>
39 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
40 1.1 drochner #include <dev/wscons/wsemulvar.h>
41 1.1 drochner #include <dev/wscons/wsemul_vt100var.h>
42 1.1 drochner
43 1.1 drochner static int vt100_selectattribute __P((struct wsemul_vt100_emuldata *,
44 1.1 drochner int, int, int, long *));
45 1.1 drochner static int vt100_ansimode __P((struct wsemul_vt100_emuldata *, int, int));
46 1.1 drochner static int vt100_decmode __P((struct wsemul_vt100_emuldata *, int, int));
47 1.2 drochner #define VTMODE_SET 33
48 1.2 drochner #define VTMODE_RESET 44
49 1.2 drochner #define VTMODE_REPORT 55
50 1.1 drochner
51 1.1 drochner /*
52 1.1 drochner * scroll up within scrolling region
53 1.1 drochner */
54 1.1 drochner void
55 1.1 drochner wsemul_vt100_scrollup(edp, n)
56 1.1 drochner struct wsemul_vt100_emuldata *edp;
57 1.1 drochner int n;
58 1.1 drochner {
59 1.1 drochner int help;
60 1.1 drochner
61 1.1 drochner if (n > edp->scrreg_nrows)
62 1.1 drochner n = edp->scrreg_nrows;
63 1.1 drochner
64 1.1 drochner help = edp->scrreg_nrows - n;
65 1.2 drochner if (help > 0) {
66 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
67 1.1 drochner edp->scrreg_startrow + n,
68 1.1 drochner edp->scrreg_startrow,
69 1.1 drochner help);
70 1.2 drochner if (edp->dblwid)
71 1.2 drochner bcopy(&edp->dblwid[edp->scrreg_startrow + n],
72 1.2 drochner &edp->dblwid[edp->scrreg_startrow],
73 1.2 drochner help);
74 1.2 drochner }
75 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
76 1.1 drochner edp->scrreg_startrow + help, n,
77 1.2 drochner edp->defattr);
78 1.2 drochner if (edp->dblwid)
79 1.2 drochner bzero(&edp->dblwid[edp->scrreg_startrow + help], n);
80 1.2 drochner CHECK_DW;
81 1.1 drochner }
82 1.1 drochner
83 1.1 drochner /*
84 1.1 drochner * scroll down within scrolling region
85 1.1 drochner */
86 1.1 drochner void
87 1.1 drochner wsemul_vt100_scrolldown(edp, n)
88 1.1 drochner struct wsemul_vt100_emuldata *edp;
89 1.1 drochner int n;
90 1.1 drochner {
91 1.1 drochner int help;
92 1.1 drochner
93 1.1 drochner if (n > edp->scrreg_nrows)
94 1.1 drochner n = edp->scrreg_nrows;
95 1.1 drochner
96 1.1 drochner help = edp->scrreg_nrows - n;
97 1.2 drochner if (help > 0) {
98 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
99 1.1 drochner edp->scrreg_startrow,
100 1.1 drochner edp->scrreg_startrow + n,
101 1.1 drochner help);
102 1.2 drochner if (edp->dblwid)
103 1.2 drochner bcopy(&edp->dblwid[edp->scrreg_startrow],
104 1.2 drochner &edp->dblwid[edp->scrreg_startrow + n],
105 1.2 drochner help);
106 1.2 drochner }
107 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
108 1.1 drochner edp->scrreg_startrow, n,
109 1.2 drochner edp->defattr);
110 1.2 drochner if (edp->dblwid)
111 1.2 drochner bzero(&edp->dblwid[edp->scrreg_startrow], n);
112 1.2 drochner CHECK_DW;
113 1.1 drochner }
114 1.1 drochner
115 1.1 drochner /*
116 1.1 drochner * erase in display
117 1.1 drochner */
118 1.1 drochner void
119 1.1 drochner wsemul_vt100_ed(edp, arg)
120 1.1 drochner struct wsemul_vt100_emuldata *edp;
121 1.1 drochner int arg;
122 1.1 drochner {
123 1.1 drochner int n;
124 1.1 drochner
125 1.1 drochner switch (arg) {
126 1.1 drochner case 0: /* cursor to end */
127 1.2 drochner ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->defattr);
128 1.1 drochner n = edp->nrows - edp->crow - 1;
129 1.1 drochner if (n > 0) {
130 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
131 1.1 drochner edp->crow + 1, n,
132 1.2 drochner edp->defattr);
133 1.2 drochner if (edp->dblwid)
134 1.2 drochner bzero(&edp->dblwid[edp->crow + 1], n);
135 1.1 drochner }
136 1.1 drochner break;
137 1.1 drochner case 1: /* beginning to cursor */
138 1.1 drochner if (edp->crow > 0) {
139 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
140 1.1 drochner 0, edp->crow,
141 1.2 drochner edp->defattr);
142 1.2 drochner if (edp->dblwid)
143 1.2 drochner bzero(&edp->dblwid[0], edp->crow);
144 1.1 drochner }
145 1.2 drochner ERASECOLS(0, edp->ccol + 1, edp->defattr);
146 1.1 drochner break;
147 1.1 drochner case 2: /* complete display */
148 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
149 1.1 drochner 0, edp->nrows,
150 1.2 drochner edp->defattr);
151 1.2 drochner if (edp->dblwid)
152 1.2 drochner bzero(&edp->dblwid[0], edp->nrows);
153 1.1 drochner break;
154 1.1 drochner default:
155 1.1 drochner #ifdef VT100_PRINTUNKNOWN
156 1.1 drochner printf("ed(%d) unknown\n", arg);
157 1.1 drochner #endif
158 1.1 drochner break;
159 1.1 drochner }
160 1.2 drochner CHECK_DW;
161 1.1 drochner }
162 1.1 drochner
163 1.1 drochner /*
164 1.1 drochner * erase in line
165 1.1 drochner */
166 1.1 drochner void
167 1.1 drochner wsemul_vt100_el(edp, arg)
168 1.1 drochner struct wsemul_vt100_emuldata *edp;
169 1.1 drochner int arg;
170 1.1 drochner {
171 1.1 drochner switch (arg) {
172 1.1 drochner case 0: /* cursor to end */
173 1.2 drochner ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->defattr);
174 1.1 drochner break;
175 1.1 drochner case 1: /* beginning to cursor */
176 1.2 drochner ERASECOLS(0, edp->ccol + 1, edp->defattr);
177 1.1 drochner break;
178 1.1 drochner case 2: /* complete line */
179 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
180 1.1 drochner 0, edp->ncols,
181 1.2 drochner edp->defattr);
182 1.1 drochner break;
183 1.1 drochner default:
184 1.1 drochner #ifdef VT100_PRINTUNKNOWN
185 1.1 drochner printf("el(%d) unknown\n", arg);
186 1.1 drochner #endif
187 1.1 drochner break;
188 1.1 drochner }
189 1.1 drochner }
190 1.1 drochner
191 1.1 drochner /*
192 1.1 drochner * handle commands after CSI (ESC[)
193 1.1 drochner */
194 1.1 drochner void
195 1.1 drochner wsemul_vt100_handle_csi(edp, c)
196 1.1 drochner struct wsemul_vt100_emuldata *edp;
197 1.1 drochner u_char c;
198 1.1 drochner {
199 1.1 drochner int n, help, flags, fgcol, bgcol;
200 1.1 drochner long attr;
201 1.1 drochner
202 1.2 drochner #define A3(a, b, c) (((a) << 16) | ((b) << 8) | (c))
203 1.2 drochner switch (A3(edp->modif1, edp->modif2, c)) {
204 1.2 drochner case A3('>', '\0', 'c'): /* DA secondary */
205 1.2 drochner wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID2,
206 1.2 drochner sizeof(WSEMUL_VT_ID2));
207 1.2 drochner break;
208 1.2 drochner
209 1.2 drochner case A3('\0', '\0', 'J'): /* ED selective erase in display */
210 1.2 drochner case A3('?', '\0', 'J'): /* DECSED selective erase in display */
211 1.2 drochner wsemul_vt100_ed(edp, ARG(0));
212 1.2 drochner break;
213 1.2 drochner case A3('\0', '\0', 'K'): /* EL selective erase in line */
214 1.2 drochner case A3('?', '\0', 'K'): /* DECSEL selective erase in line */
215 1.2 drochner wsemul_vt100_el(edp, ARG(0));
216 1.2 drochner break;
217 1.2 drochner case A3('\0', '\0', 'h'): /* SM */
218 1.2 drochner for (n = 0; n < edp->nargs; n++)
219 1.2 drochner vt100_ansimode(edp, ARG(n), VTMODE_SET);
220 1.2 drochner break;
221 1.2 drochner case A3('?', '\0', 'h'): /* DECSM */
222 1.2 drochner for (n = 0; n < edp->nargs; n++)
223 1.2 drochner vt100_decmode(edp, ARG(n), VTMODE_SET);
224 1.2 drochner break;
225 1.2 drochner case A3('\0', '\0', 'l'): /* RM */
226 1.2 drochner for (n = 0; n < edp->nargs; n++)
227 1.2 drochner vt100_ansimode(edp, ARG(n), VTMODE_RESET);
228 1.2 drochner break;;
229 1.2 drochner case A3('?', '\0', 'l'): /* DECRM */
230 1.2 drochner for (n = 0; n < edp->nargs; n++)
231 1.2 drochner vt100_decmode(edp, ARG(n), VTMODE_RESET);
232 1.2 drochner break;;
233 1.2 drochner case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */
234 1.2 drochner vt100_ansimode(edp, ARG(0), VTMODE_REPORT);
235 1.2 drochner break;
236 1.2 drochner case A3('?', '$', 'p'): /* DECRQM request mode DEC */
237 1.2 drochner vt100_decmode(edp, ARG(0), VTMODE_REPORT);
238 1.2 drochner break;
239 1.2 drochner case A3('\0', '\0', 'i'): /* MC printer controller mode */
240 1.2 drochner case A3('?', '\0', 'i'): /* MC printer controller mode */
241 1.2 drochner switch (ARG(0)) {
242 1.2 drochner case 0: /* print screen */
243 1.2 drochner case 1: /* print cursor line */
244 1.2 drochner case 4: /* off */
245 1.2 drochner case 5: /* on */
246 1.2 drochner #ifdef VT100_PRINTNOTIMPL
247 1.2 drochner printf("CSI%di ignored\n", ARG(0));
248 1.2 drochner #endif
249 1.2 drochner break;
250 1.2 drochner default:
251 1.2 drochner #ifdef VT100_PRINTUNKNOWN
252 1.2 drochner printf("CSI%di unknown\n", ARG(0));
253 1.2 drochner #endif
254 1.2 drochner break;
255 1.2 drochner }
256 1.2 drochner break;
257 1.2 drochner
258 1.2 drochner #define A2(a, b) (((a) << 8) | (b))
259 1.2 drochner case A2('!', 'p'): /* DECSTR soft reset VT300 only */
260 1.2 drochner wsemul_vt100_reset(edp);
261 1.2 drochner break;
262 1.2 drochner
263 1.2 drochner case A2('"', 'p'): /* DECSCL */
264 1.2 drochner switch (ARG(0)) {
265 1.2 drochner case 61: /* VT100 mode (no further arguments!) */
266 1.2 drochner break;
267 1.2 drochner case 62:
268 1.2 drochner case 63: /* VT300 mode */
269 1.2 drochner break;
270 1.2 drochner default:
271 1.2 drochner #ifdef VT100_PRINTUNKNOWN
272 1.2 drochner printf("CSI%d\"p unknown\n", ARG(0));
273 1.2 drochner #endif
274 1.2 drochner break;
275 1.2 drochner }
276 1.2 drochner switch (ARG(1)) {
277 1.2 drochner case 0:
278 1.2 drochner case 2: /* 8-bit controls */
279 1.2 drochner #ifdef VT100_PRINTNOTIMPL
280 1.2 drochner printf("CSI%d;%d\"p ignored\n", ARG(0), ARG(1));
281 1.2 drochner #endif
282 1.2 drochner break;
283 1.2 drochner case 1: /* 7-bit controls */
284 1.2 drochner break;
285 1.2 drochner default:
286 1.2 drochner #ifdef VT100_PRINTUNKNOWN
287 1.2 drochner printf("CSI%d;%d\"p unknown\n", ARG(0), ARG(1));
288 1.2 drochner #endif
289 1.2 drochner break;
290 1.2 drochner }
291 1.2 drochner break;
292 1.2 drochner case A2('"', 'q'): /* DECSCA select character attribute VT300 */
293 1.2 drochner switch (ARG(0)) {
294 1.2 drochner case 0:
295 1.2 drochner case 1: /* erasable */
296 1.2 drochner break;
297 1.2 drochner case 2: /* not erasable */
298 1.2 drochner #ifdef VT100_PRINTNOTIMPL
299 1.2 drochner printf("CSI2\"q ignored\n");
300 1.2 drochner #endif
301 1.2 drochner break;
302 1.2 drochner default:
303 1.2 drochner #ifdef VT100_PRINTUNKNOWN
304 1.2 drochner printf("CSI%d\"q unknown\n", ARG(0));
305 1.2 drochner #endif
306 1.2 drochner break;
307 1.2 drochner }
308 1.2 drochner break;
309 1.2 drochner
310 1.2 drochner case A2('$', 'u'): /* DECRQTSR request terminal status report */
311 1.2 drochner switch (ARG(0)) {
312 1.2 drochner case 0: /* ignored */
313 1.2 drochner break;
314 1.2 drochner case 1: /* terminal state report */
315 1.2 drochner #ifdef VT100_PRINTNOTIMPL
316 1.2 drochner printf("CSI1$u ignored\n");
317 1.2 drochner #endif
318 1.2 drochner break;
319 1.2 drochner default:
320 1.2 drochner #ifdef VT100_PRINTUNKNOWN
321 1.2 drochner printf("CSI%d$u unknown\n", ARG(0));
322 1.2 drochner #endif
323 1.2 drochner break;
324 1.2 drochner }
325 1.2 drochner break;
326 1.2 drochner case A2('$', 'w'): /* DECRQPSR request presentation status report
327 1.2 drochner (VT300 only) */
328 1.2 drochner switch (ARG(0)) {
329 1.2 drochner case 0: /* error */
330 1.2 drochner break;
331 1.2 drochner case 1: /* cursor information report */
332 1.2 drochner #ifdef VT100_PRINTNOTIMPL
333 1.2 drochner printf("CSI1$w ignored\n");
334 1.2 drochner #endif
335 1.2 drochner break;
336 1.2 drochner case 2: /* tab stop report */
337 1.2 drochner {
338 1.3 drochner int i, n, ps = 0;
339 1.2 drochner char buf[20];
340 1.2 drochner KASSERT(edp->tabs != 0);
341 1.2 drochner wsdisplay_emulinput(edp->cbcookie, "\033P2$u", 5);
342 1.2 drochner for (i = 0; i < edp->ncols; i++)
343 1.2 drochner if (edp->tabs[i]) {
344 1.2 drochner n = sprintf(buf, "%s%d",
345 1.3 drochner (ps ? "/" : ""), i + 1);
346 1.2 drochner wsdisplay_emulinput(edp->cbcookie,
347 1.2 drochner buf, n);
348 1.3 drochner ps = 1;
349 1.2 drochner }
350 1.2 drochner }
351 1.2 drochner wsdisplay_emulinput(edp->cbcookie, "\033\\", 2);
352 1.2 drochner break;
353 1.2 drochner default:
354 1.2 drochner #ifdef VT100_PRINTUNKNOWN
355 1.2 drochner printf("CSI%d$w unknown\n", ARG(0));
356 1.2 drochner #endif
357 1.2 drochner break;
358 1.2 drochner }
359 1.2 drochner break;
360 1.2 drochner case A2('$', '}'): /* DECSASD select active status display */
361 1.2 drochner switch (ARG(0)) {
362 1.2 drochner case 0: /* main display */
363 1.2 drochner case 1: /* status line */
364 1.2 drochner #ifdef VT100_PRINTNOTIMPL
365 1.2 drochner printf("CSI%d$} ignored\n", ARG(0));
366 1.2 drochner #endif
367 1.2 drochner break;
368 1.2 drochner default:
369 1.2 drochner #ifdef VT100_PRINTUNKNOWN
370 1.2 drochner printf("CSI%d$} unknown\n", ARG(0));
371 1.2 drochner #endif
372 1.2 drochner break;
373 1.2 drochner }
374 1.2 drochner break;
375 1.2 drochner case A2('$', '~'): /* DECSSDD select status line type */
376 1.2 drochner switch (ARG(0)) {
377 1.2 drochner case 0: /* none */
378 1.2 drochner case 1: /* indicator */
379 1.2 drochner case 2: /* host-writable */
380 1.2 drochner #ifdef VT100_PRINTNOTIMPL
381 1.2 drochner printf("CSI%d$~ ignored\n", ARG(0));
382 1.2 drochner #endif
383 1.2 drochner break;
384 1.2 drochner default:
385 1.2 drochner #ifdef VT100_PRINTUNKNOWN
386 1.2 drochner printf("CSI%d$~ unknown\n", ARG(0));
387 1.2 drochner #endif
388 1.2 drochner break;
389 1.2 drochner }
390 1.2 drochner break;
391 1.2 drochner
392 1.2 drochner case A2('&', 'u'): /* DECRQUPSS request user preferred
393 1.2 drochner supplemental set */
394 1.2 drochner wsdisplay_emulinput(edp->emulcookie, "\033P0!u%5\033\\", 9);
395 1.2 drochner break;
396 1.2 drochner
397 1.1 drochner case '@': /* ICH insert character VT300 only */
398 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
399 1.2 drochner help = NCOLS - (edp->ccol + n);
400 1.1 drochner if (help > 0)
401 1.2 drochner COPYCOLS(edp->ccol, edp->ccol + n, help);
402 1.2 drochner ERASECOLS(edp->ccol, n, edp->defattr);
403 1.1 drochner break;
404 1.1 drochner case 'A': /* CUU */
405 1.1 drochner edp->crow -= min(DEF1_ARG(0), ROWS_ABOVE);
406 1.2 drochner CHECK_DW;
407 1.1 drochner break;
408 1.1 drochner case 'B': /* CUD */
409 1.1 drochner edp->crow += min(DEF1_ARG(0), ROWS_BELOW);
410 1.2 drochner CHECK_DW;
411 1.1 drochner break;
412 1.1 drochner case 'C': /* CUF */
413 1.1 drochner edp->ccol += min(DEF1_ARG(0), COLS_LEFT);
414 1.1 drochner break;
415 1.1 drochner case 'D': /* CUB */
416 1.1 drochner edp->ccol -= min(DEF1_ARG(0), edp->ccol);
417 1.1 drochner edp->flags &= ~VTFL_LASTCHAR;
418 1.1 drochner break;
419 1.1 drochner case 'H': /* CUP */
420 1.1 drochner case 'f': /* HVP */
421 1.1 drochner if (edp->flags & VTFL_DECOM)
422 1.1 drochner edp->crow = edp->scrreg_startrow +
423 1.1 drochner min(DEF1_ARG(0), edp->scrreg_nrows) - 1;
424 1.1 drochner else
425 1.1 drochner edp->crow = min(DEF1_ARG(0), edp->nrows) - 1;
426 1.2 drochner CHECK_DW;
427 1.2 drochner edp->ccol = min(DEF1_ARG(1), NCOLS) - 1;
428 1.1 drochner edp->flags &= ~VTFL_LASTCHAR;
429 1.1 drochner break;
430 1.1 drochner case 'L': /* IL insert line */
431 1.1 drochner case 'M': /* DL delete line */
432 1.1 drochner n = min(DEF1_ARG(0), ROWS_BELOW + 1);
433 1.1 drochner {
434 1.2 drochner int savscrstartrow, savscrnrows;
435 1.2 drochner savscrstartrow = edp->scrreg_startrow;
436 1.2 drochner savscrnrows = edp->scrreg_nrows;
437 1.2 drochner edp->scrreg_nrows -= ROWS_ABOVE;
438 1.2 drochner edp->scrreg_startrow = edp->crow;
439 1.2 drochner if (c == 'L')
440 1.2 drochner wsemul_vt100_scrolldown(edp, n);
441 1.2 drochner else
442 1.2 drochner wsemul_vt100_scrollup(edp, n);
443 1.2 drochner edp->scrreg_startrow = savscrstartrow;
444 1.2 drochner edp->scrreg_nrows = savscrnrows;
445 1.1 drochner }
446 1.1 drochner break;
447 1.1 drochner case 'P': /* DCH delete character */
448 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
449 1.2 drochner help = NCOLS - (edp->ccol + n);
450 1.1 drochner if (help > 0)
451 1.2 drochner COPYCOLS(edp->ccol + n, edp->ccol, help);
452 1.2 drochner ERASECOLS(NCOLS - n, n, edp->defattr);
453 1.1 drochner break;
454 1.1 drochner case 'X': /* ECH erase character */
455 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
456 1.2 drochner ERASECOLS(edp->ccol, n, edp->defattr);
457 1.1 drochner break;
458 1.1 drochner case 'c': /* DA primary */
459 1.1 drochner if (ARG(0) == 0)
460 1.1 drochner wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1,
461 1.1 drochner sizeof(WSEMUL_VT_ID1));
462 1.1 drochner break;
463 1.1 drochner case 'g': /* TBC */
464 1.1 drochner KASSERT(edp->tabs != 0);
465 1.1 drochner switch (ARG(0)) {
466 1.1 drochner case 0:
467 1.1 drochner edp->tabs[edp->ccol] = 0;
468 1.1 drochner break;
469 1.1 drochner case 3:
470 1.1 drochner bzero(edp->tabs, edp->ncols);
471 1.1 drochner break;
472 1.1 drochner default:
473 1.1 drochner #ifdef VT100_PRINTUNKNOWN
474 1.1 drochner printf("CSI%dg unknown\n", ARG(0));
475 1.1 drochner #endif
476 1.1 drochner break;
477 1.1 drochner }
478 1.1 drochner break;
479 1.1 drochner case 'm': /* SGR select graphic rendition */
480 1.1 drochner flags = edp->attrflags;
481 1.1 drochner fgcol = edp->fgcol;
482 1.1 drochner bgcol = edp->bgcol;
483 1.1 drochner for (n = 0; n < edp->nargs; n++) {
484 1.1 drochner switch (ARG(n)) {
485 1.1 drochner case 0: /* reset */
486 1.2 drochner attr = edp->defattr;
487 1.2 drochner flags = 0;
488 1.2 drochner fgcol = WSCOL_WHITE;
489 1.2 drochner bgcol = WSCOL_BLACK;
490 1.1 drochner if (n == edp->nargs - 1) {
491 1.2 drochner edp->curattr = attr;
492 1.2 drochner edp->attrflags = flags;
493 1.2 drochner edp->fgcol = fgcol;
494 1.2 drochner edp->bgcol = bgcol;
495 1.1 drochner return;
496 1.1 drochner }
497 1.1 drochner break;
498 1.1 drochner case 1: /* bold */
499 1.1 drochner flags |= WSATTR_HILIT;
500 1.1 drochner break;
501 1.1 drochner case 4: /* underline */
502 1.1 drochner flags |= WSATTR_UNDERLINE;
503 1.1 drochner break;
504 1.1 drochner case 5: /* blink */
505 1.1 drochner flags |= WSATTR_BLINK;
506 1.1 drochner break;
507 1.1 drochner case 7: /* reverse */
508 1.1 drochner flags |= WSATTR_REVERSE;
509 1.1 drochner break;
510 1.1 drochner case 22: /* ~bold VT300 only */
511 1.1 drochner flags &= ~WSATTR_HILIT;
512 1.1 drochner break;
513 1.1 drochner case 24: /* ~underline VT300 only */
514 1.1 drochner flags &= ~WSATTR_UNDERLINE;
515 1.1 drochner break;
516 1.1 drochner case 25: /* ~blink VT300 only */
517 1.1 drochner flags &= ~WSATTR_BLINK;
518 1.1 drochner break;
519 1.1 drochner case 27: /* ~reverse VT300 only */
520 1.1 drochner flags &= ~WSATTR_REVERSE;
521 1.1 drochner break;
522 1.1 drochner case 30: case 31: case 32: case 33:
523 1.1 drochner case 34: case 35: case 36: case 37:
524 1.1 drochner /* fg color */
525 1.1 drochner flags |= WSATTR_WSCOLORS;
526 1.1 drochner fgcol = ARG(n) - 30;
527 1.1 drochner break;
528 1.1 drochner case 40: case 41: case 42: case 43:
529 1.1 drochner case 44: case 45: case 46: case 47:
530 1.1 drochner /* bg color */
531 1.1 drochner flags |= WSATTR_WSCOLORS;
532 1.1 drochner bgcol = ARG(n) - 40;
533 1.1 drochner break;
534 1.1 drochner default:
535 1.1 drochner #ifdef VT100_PRINTUNKNOWN
536 1.1 drochner printf("CSI%dm unknown\n", ARG(n));
537 1.1 drochner #endif
538 1.1 drochner }
539 1.1 drochner }
540 1.1 drochner if (vt100_selectattribute(edp, flags, fgcol, bgcol, &attr)) {
541 1.1 drochner #ifdef VT100_DEBUG
542 1.1 drochner printf("error allocating attr %d/%d/%x\n",
543 1.1 drochner fgcol, bgcol, flags);
544 1.1 drochner #endif
545 1.1 drochner } else {
546 1.1 drochner edp->curattr = attr;
547 1.1 drochner edp->attrflags = flags;
548 1.1 drochner edp->fgcol = fgcol;
549 1.1 drochner edp->bgcol = bgcol;
550 1.1 drochner }
551 1.1 drochner break;
552 1.1 drochner case 'n': /* reports */
553 1.1 drochner switch (ARG(0)) {
554 1.1 drochner case 5: /* DSR operating status */
555 1.1 drochner /* 0 = OK, 3 = malfunction */
556 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4);
557 1.1 drochner break;
558 1.1 drochner case 6: { /* DSR cursor position report */
559 1.1 drochner char buf[20];
560 1.1 drochner int row;
561 1.1 drochner if (edp->flags & VTFL_DECOM)
562 1.1 drochner row = ROWS_ABOVE;
563 1.1 drochner else
564 1.1 drochner row = edp->crow;
565 1.1 drochner n = sprintf(buf, "\033[%d;%dR",
566 1.1 drochner row + 1, edp->ccol + 1);
567 1.1 drochner wsdisplay_emulinput(edp->cbcookie, buf, n);
568 1.1 drochner }
569 1.1 drochner break;
570 1.1 drochner case 15: /* DSR printer status */
571 1.1 drochner /* 13 = no printer, 10 = ready, 11 = not ready */
572 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?13n", 6);
573 1.1 drochner break;
574 1.1 drochner case 25: /* UDK status - VT300 only */
575 1.1 drochner /* 20 = locked, 21 = unlocked */
576 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?21n", 6);
577 1.1 drochner break;
578 1.1 drochner case 26: /* keyboard dialect */
579 1.1 drochner /* 1 = north american , 7 = german */
580 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?27;1n", 8);
581 1.1 drochner break;
582 1.1 drochner default:
583 1.1 drochner #ifdef VT100_PRINTUNKNOWN
584 1.1 drochner printf("CSI%dn unknown\n", ARG(0));
585 1.1 drochner #endif
586 1.1 drochner break;
587 1.1 drochner }
588 1.1 drochner break;
589 1.1 drochner case 'r': /* DECSTBM set top/bottom margins */
590 1.1 drochner if (ARG(0) == 0 && ARG(1) == 0) {
591 1.1 drochner edp->scrreg_startrow = 0;
592 1.1 drochner edp->scrreg_nrows = edp->nrows;
593 1.1 drochner } else {
594 1.1 drochner edp->scrreg_startrow = min(DEF1_ARG(0),
595 1.1 drochner edp->nrows) - 1;
596 1.1 drochner edp->scrreg_nrows = min(DEF1_ARG(1), edp->nrows) -
597 1.1 drochner edp->scrreg_startrow;
598 1.1 drochner }
599 1.1 drochner edp->crow = ((edp->flags & VTFL_DECOM) ?
600 1.1 drochner edp->scrreg_startrow : 0);
601 1.1 drochner edp->ccol = 0;
602 1.1 drochner break;
603 1.1 drochner case 'y':
604 1.1 drochner switch (ARG(0)) {
605 1.1 drochner case 4: /* DECTST invoke confidence test */
606 1.1 drochner /* ignore */
607 1.1 drochner break;
608 1.1 drochner default:
609 1.1 drochner #ifdef VT100_PRINTUNKNOWN
610 1.1 drochner printf("CSI%dy unknown\n", ARG(0));
611 1.1 drochner #endif
612 1.1 drochner break;
613 1.1 drochner }
614 1.1 drochner break;
615 1.1 drochner default:
616 1.1 drochner #ifdef VT100_PRINTUNKNOWN
617 1.1 drochner printf("CSI%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
618 1.1 drochner #endif
619 1.1 drochner }
620 1.1 drochner }
621 1.1 drochner
622 1.1 drochner /*
623 1.1 drochner * get an attribute from the graphics driver,
624 1.1 drochner * try to find replacements if the desired appearance
625 1.1 drochner * is not supported
626 1.1 drochner */
627 1.1 drochner static int
628 1.1 drochner vt100_selectattribute(edp, flags, fgcol, bgcol, attr)
629 1.1 drochner struct wsemul_vt100_emuldata *edp;
630 1.1 drochner int flags, fgcol, bgcol;
631 1.1 drochner long *attr;
632 1.1 drochner {
633 1.1 drochner if ((flags & WSATTR_HILIT) &&
634 1.1 drochner !(edp->scrcapabilities & WSSCREEN_HILIT)) {
635 1.1 drochner flags &= ~WSATTR_HILIT;
636 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
637 1.1 drochner fgcol = WSCOL_RED;
638 1.1 drochner flags |= WSATTR_WSCOLORS;
639 1.1 drochner } else {
640 1.1 drochner #ifdef VT100_DEBUG
641 1.1 drochner printf("bold ignored (impossible)\n");
642 1.1 drochner #endif
643 1.1 drochner }
644 1.1 drochner }
645 1.1 drochner if ((flags & WSATTR_UNDERLINE) &&
646 1.1 drochner !(edp->scrcapabilities & WSSCREEN_UNDERLINE)) {
647 1.1 drochner flags &= ~WSATTR_UNDERLINE;
648 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
649 1.1 drochner bgcol = WSCOL_BROWN;
650 1.1 drochner flags &= ~WSATTR_UNDERLINE;
651 1.1 drochner flags |= WSATTR_WSCOLORS;
652 1.1 drochner } else {
653 1.1 drochner #ifdef VT100_DEBUG
654 1.1 drochner printf("underline ignored (impossible)\n");
655 1.1 drochner #endif
656 1.1 drochner }
657 1.1 drochner }
658 1.1 drochner if ((flags & WSATTR_BLINK) &&
659 1.1 drochner !(edp->scrcapabilities & WSSCREEN_BLINK)) {
660 1.1 drochner flags &= ~WSATTR_BLINK;
661 1.1 drochner #ifdef VT100_DEBUG
662 1.1 drochner printf("blink ignored (impossible)\n");
663 1.1 drochner #endif
664 1.1 drochner }
665 1.1 drochner if ((flags & WSATTR_REVERSE) &&
666 1.1 drochner !(edp->scrcapabilities & WSSCREEN_REVERSE)) {
667 1.1 drochner flags &= ~WSATTR_REVERSE;
668 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
669 1.1 drochner int help;
670 1.1 drochner help = bgcol;
671 1.1 drochner bgcol = fgcol;
672 1.1 drochner fgcol = help;
673 1.1 drochner flags |= WSATTR_WSCOLORS;
674 1.1 drochner } else {
675 1.1 drochner #ifdef VT100_DEBUG
676 1.1 drochner printf("reverse ignored (impossible)\n");
677 1.1 drochner #endif
678 1.1 drochner }
679 1.1 drochner }
680 1.1 drochner if ((flags & WSATTR_WSCOLORS) &&
681 1.1 drochner !(edp->scrcapabilities & WSSCREEN_WSCOLORS)) {
682 1.1 drochner flags &= ~WSATTR_WSCOLORS;
683 1.1 drochner #ifdef VT100_DEBUG
684 1.1 drochner printf("colors ignored (impossible)\n");
685 1.1 drochner #endif
686 1.1 drochner }
687 1.1 drochner return ((*edp->emulops->alloc_attr)(edp->emulcookie,
688 1.1 drochner fgcol, bgcol, flags,
689 1.1 drochner attr));
690 1.1 drochner }
691 1.1 drochner
692 1.1 drochner /*
693 1.1 drochner * handle device control sequences if the main state machine
694 1.1 drochner * told so by setting edp->dcstype to a nonzero value
695 1.1 drochner */
696 1.1 drochner void
697 1.1 drochner wsemul_vt100_handle_dcs(edp)
698 1.1 drochner struct wsemul_vt100_emuldata *edp;
699 1.1 drochner {
700 1.1 drochner int i, pos;
701 1.1 drochner
702 1.1 drochner switch (edp->dcstype) {
703 1.1 drochner case 0: /* not handled */
704 1.1 drochner return;
705 1.1 drochner case DCSTYPE_TABRESTORE:
706 1.1 drochner KASSERT(edp->tabs != 0);
707 1.1 drochner bzero(edp->tabs, edp->ncols);
708 1.1 drochner pos = 0;
709 1.1 drochner for (i = 0; i < edp->dcspos; i++) {
710 1.1 drochner char c = edp->dcsarg[i];
711 1.1 drochner switch (c) {
712 1.1 drochner case '0': case '1': case '2': case '3': case '4':
713 1.1 drochner case '5': case '6': case '7': case '8': case '9':
714 1.1 drochner pos = pos * 10 + (edp->dcsarg[i] - '0');
715 1.1 drochner break;
716 1.1 drochner case '/':
717 1.1 drochner if (pos > 0)
718 1.1 drochner edp->tabs[pos - 1] = 1;
719 1.1 drochner pos = 0;
720 1.1 drochner break;
721 1.1 drochner default:
722 1.1 drochner #ifdef VT100_PRINTUNKNOWN
723 1.1 drochner printf("unknown char %c in DCS\n", c);
724 1.1 drochner #endif
725 1.1 drochner }
726 1.1 drochner }
727 1.1 drochner if (pos > 0)
728 1.1 drochner edp->tabs[pos - 1] = 1;
729 1.1 drochner break;
730 1.1 drochner default:
731 1.1 drochner panic("wsemul_vt100_handle_dcs: bad type %d", edp->dcstype);
732 1.1 drochner }
733 1.1 drochner edp->dcstype = 0;
734 1.1 drochner }
735 1.1 drochner
736 1.1 drochner static int
737 1.1 drochner vt100_ansimode(edp, nr, op)
738 1.1 drochner struct wsemul_vt100_emuldata *edp;
739 1.1 drochner int nr, op;
740 1.1 drochner {
741 1.1 drochner int res = 0; /* default: unknown */
742 1.1 drochner
743 1.1 drochner switch (nr) {
744 1.1 drochner case 2: /* KAM keyboard locked/unlocked */
745 1.1 drochner break;
746 1.1 drochner case 3: /* CRM control representation */
747 1.1 drochner break;
748 1.1 drochner case 4: /* IRM insert/replace characters */
749 1.2 drochner if (op == VTMODE_SET)
750 1.1 drochner edp->flags |= VTFL_INSERTMODE;
751 1.2 drochner else if (op == VTMODE_RESET)
752 1.1 drochner edp->flags &= ~VTFL_INSERTMODE;
753 1.1 drochner res = ((edp->flags & VTFL_INSERTMODE) ? 1 : 2);
754 1.1 drochner break;
755 1.1 drochner case 10: /* HEM horizontal editing (permanently reset) */
756 1.1 drochner res = 4;
757 1.1 drochner break;
758 1.1 drochner case 12: /* SRM local echo off/on */
759 1.1 drochner res = 4; /* permanently reset ??? */
760 1.1 drochner break;
761 1.1 drochner case 20: /* LNM newline = newline/linefeed */
762 1.1 drochner break;
763 1.1 drochner default:
764 1.1 drochner #ifdef VT100_PRINTUNKNOWN
765 1.1 drochner printf("ANSI mode %d unknown\n", nr);
766 1.1 drochner #endif
767 1.1 drochner }
768 1.1 drochner return (res);
769 1.1 drochner }
770 1.1 drochner
771 1.1 drochner static int
772 1.1 drochner vt100_decmode(edp, nr, op)
773 1.1 drochner struct wsemul_vt100_emuldata *edp;
774 1.1 drochner int nr, op;
775 1.1 drochner {
776 1.1 drochner int res = 0; /* default: unknown */
777 1.1 drochner
778 1.1 drochner switch (nr) {
779 1.1 drochner case 1: /* DECCKM application/nomal cursor keys */
780 1.2 drochner if (op == VTMODE_SET)
781 1.1 drochner edp->flags |= VTFL_APPLCURSOR;
782 1.2 drochner else if (op == VTMODE_RESET)
783 1.1 drochner edp->flags &= ~VTFL_APPLCURSOR;
784 1.1 drochner res = ((edp->flags & VTFL_APPLCURSOR) ? 1 : 2);
785 1.1 drochner break;
786 1.1 drochner case 2: /* DECANM ANSI vt100/vt52 */
787 1.1 drochner res = 3; /* permanently set ??? */
788 1.1 drochner break;
789 1.1 drochner case 3: /* DECCOLM 132/80 cols */
790 1.1 drochner case 4: /* DECSCLM smooth/jump scroll */
791 1.1 drochner case 5: /* DECSCNM light/dark background */
792 1.1 drochner res = 4; /* all permanently reset ??? */
793 1.1 drochner break;
794 1.1 drochner case 6: /* DECOM move within/outside margins */
795 1.2 drochner if (op == VTMODE_SET)
796 1.1 drochner edp->flags |= VTFL_DECOM;
797 1.2 drochner else if (op == VTMODE_RESET)
798 1.1 drochner edp->flags &= ~VTFL_DECOM;
799 1.1 drochner res = ((edp->flags & VTFL_DECOM) ? 1 : 2);
800 1.1 drochner break;
801 1.1 drochner case 7: /* DECAWM autowrap */
802 1.2 drochner if (op == VTMODE_SET)
803 1.1 drochner edp->flags |= VTFL_DECAWM;
804 1.2 drochner else if (op == VTMODE_RESET)
805 1.1 drochner edp->flags &= ~VTFL_DECAWM;
806 1.1 drochner res = ((edp->flags & VTFL_DECAWM) ? 1 : 2);
807 1.1 drochner break;
808 1.1 drochner case 8: /* DECARM keyboard autorepeat */
809 1.1 drochner break;
810 1.1 drochner case 18: /* DECPFF print form feed */
811 1.1 drochner break;
812 1.1 drochner case 19: /* DECPEX printer extent: screen/scrolling region */
813 1.1 drochner break;
814 1.1 drochner case 25: /* DECTCEM text cursor on/off */
815 1.2 drochner if (op == VTMODE_SET || op == VTMODE_RESET) {
816 1.1 drochner edp->flags = (edp->flags & ~VTFL_CURSORON) |
817 1.2 drochner ((op == VTMODE_SET) ? VTFL_CURSORON : 0);
818 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie,
819 1.2 drochner (op == VTMODE_SET),
820 1.1 drochner edp->crow, edp->ccol);
821 1.1 drochner }
822 1.1 drochner res = ((edp->flags & VTFL_CURSORON) ? 1 : 2);
823 1.1 drochner break;
824 1.1 drochner case 42: /* DECNRCM use 7-bit NRC /
825 1.1 drochner 7/8 bit from DEC multilingual or ISO-latin-1*/
826 1.2 drochner if (op == VTMODE_SET)
827 1.2 drochner edp->flags |= VTFL_NATCHARSET;
828 1.2 drochner else if (op == VTMODE_RESET)
829 1.2 drochner edp->flags &= ~VTFL_NATCHARSET;
830 1.2 drochner res = ((edp->flags & VTFL_NATCHARSET) ? 1 : 2);
831 1.1 drochner break;
832 1.1 drochner case 66: /* DECNKM numeric keypad */
833 1.1 drochner break;
834 1.1 drochner case 68: /* DECKBUM keyboard usage data processing/typewriter */
835 1.1 drochner break;
836 1.1 drochner default:
837 1.1 drochner #ifdef VT100_PRINTUNKNOWN
838 1.1 drochner printf("DEC mode %d unknown\n", nr);
839 1.1 drochner #endif
840 1.1 drochner break;
841 1.1 drochner }
842 1.1 drochner return (res);
843 1.1 drochner }
844