wsemul_vt100_subr.c revision 1.1 1 1.1 drochner /* $NetBSD: wsemul_vt100_subr.c,v 1.1 1998/06/20 19:17:47 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.1 drochner #define MODE_SET 33
48 1.1 drochner #define MODE_RESET 44
49 1.1 drochner #define MODE_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.1 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.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
71 1.1 drochner edp->scrreg_startrow + help, n,
72 1.1 drochner edp->curattr);
73 1.1 drochner }
74 1.1 drochner
75 1.1 drochner /*
76 1.1 drochner * scroll down within scrolling region
77 1.1 drochner */
78 1.1 drochner void
79 1.1 drochner wsemul_vt100_scrolldown(edp, n)
80 1.1 drochner struct wsemul_vt100_emuldata *edp;
81 1.1 drochner int n;
82 1.1 drochner {
83 1.1 drochner int help;
84 1.1 drochner
85 1.1 drochner if (n > edp->scrreg_nrows)
86 1.1 drochner n = edp->scrreg_nrows;
87 1.1 drochner
88 1.1 drochner help = edp->scrreg_nrows - n;
89 1.1 drochner if (help > 0)
90 1.1 drochner (*edp->emulops->copyrows)(edp->emulcookie,
91 1.1 drochner edp->scrreg_startrow,
92 1.1 drochner edp->scrreg_startrow + n,
93 1.1 drochner help);
94 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
95 1.1 drochner edp->scrreg_startrow, n,
96 1.1 drochner edp->curattr);
97 1.1 drochner }
98 1.1 drochner
99 1.1 drochner /*
100 1.1 drochner * erase in display
101 1.1 drochner */
102 1.1 drochner void
103 1.1 drochner wsemul_vt100_ed(edp, arg)
104 1.1 drochner struct wsemul_vt100_emuldata *edp;
105 1.1 drochner int arg;
106 1.1 drochner {
107 1.1 drochner int n;
108 1.1 drochner
109 1.1 drochner switch (arg) {
110 1.1 drochner case 0: /* cursor to end */
111 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
112 1.1 drochner edp->ccol, COLS_LEFT + 1,
113 1.1 drochner edp->curattr);
114 1.1 drochner n = edp->nrows - edp->crow - 1;
115 1.1 drochner if (n > 0) {
116 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
117 1.1 drochner edp->crow + 1, n,
118 1.1 drochner edp->curattr);
119 1.1 drochner }
120 1.1 drochner break;
121 1.1 drochner case 1: /* beginning to cursor */
122 1.1 drochner if (edp->crow > 0) {
123 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
124 1.1 drochner 0, edp->crow,
125 1.1 drochner edp->curattr);
126 1.1 drochner }
127 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
128 1.1 drochner 0, edp->ccol + 1,
129 1.1 drochner edp->curattr);
130 1.1 drochner break;
131 1.1 drochner case 2: /* complete display */
132 1.1 drochner (*edp->emulops->eraserows)(edp->emulcookie,
133 1.1 drochner 0, edp->nrows,
134 1.1 drochner edp->curattr);
135 1.1 drochner break;
136 1.1 drochner default:
137 1.1 drochner #ifdef VT100_PRINTUNKNOWN
138 1.1 drochner printf("ed(%d) unknown\n", arg);
139 1.1 drochner #endif
140 1.1 drochner break;
141 1.1 drochner }
142 1.1 drochner }
143 1.1 drochner
144 1.1 drochner /*
145 1.1 drochner * erase in line
146 1.1 drochner */
147 1.1 drochner void
148 1.1 drochner wsemul_vt100_el(edp, arg)
149 1.1 drochner struct wsemul_vt100_emuldata *edp;
150 1.1 drochner int arg;
151 1.1 drochner {
152 1.1 drochner switch (arg) {
153 1.1 drochner case 0: /* cursor to end */
154 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
155 1.1 drochner edp->ccol, COLS_LEFT + 1,
156 1.1 drochner edp->curattr);
157 1.1 drochner break;
158 1.1 drochner case 1: /* beginning to cursor */
159 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
160 1.1 drochner 0, edp->ccol + 1,
161 1.1 drochner edp->curattr);
162 1.1 drochner break;
163 1.1 drochner case 2: /* complete line */
164 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
165 1.1 drochner 0, edp->ncols,
166 1.1 drochner edp->curattr);
167 1.1 drochner break;
168 1.1 drochner default:
169 1.1 drochner #ifdef VT100_PRINTUNKNOWN
170 1.1 drochner printf("el(%d) unknown\n", arg);
171 1.1 drochner #endif
172 1.1 drochner break;
173 1.1 drochner }
174 1.1 drochner }
175 1.1 drochner
176 1.1 drochner /*
177 1.1 drochner * handle commands after CSI (ESC[)
178 1.1 drochner */
179 1.1 drochner void
180 1.1 drochner wsemul_vt100_handle_csi(edp, c)
181 1.1 drochner struct wsemul_vt100_emuldata *edp;
182 1.1 drochner u_char c;
183 1.1 drochner {
184 1.1 drochner int n, help, flags, fgcol, bgcol;
185 1.1 drochner long attr;
186 1.1 drochner
187 1.1 drochner switch (c) {
188 1.1 drochner case '@': /* ICH insert character VT300 only */
189 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
190 1.1 drochner help = edp->ncols - (edp->ccol + n);
191 1.1 drochner if (help > 0)
192 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
193 1.1 drochner edp->ccol, edp->ccol + n,
194 1.1 drochner help);
195 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
196 1.1 drochner edp->ccol, n, edp->curattr);
197 1.1 drochner break;
198 1.1 drochner case 'A': /* CUU */
199 1.1 drochner edp->crow -= min(DEF1_ARG(0), ROWS_ABOVE);
200 1.1 drochner break;
201 1.1 drochner case 'B': /* CUD */
202 1.1 drochner edp->crow += min(DEF1_ARG(0), ROWS_BELOW);
203 1.1 drochner break;
204 1.1 drochner case 'C': /* CUF */
205 1.1 drochner edp->ccol += min(DEF1_ARG(0), COLS_LEFT);
206 1.1 drochner break;
207 1.1 drochner case 'D': /* CUB */
208 1.1 drochner edp->ccol -= min(DEF1_ARG(0), edp->ccol);
209 1.1 drochner edp->flags &= ~VTFL_LASTCHAR;
210 1.1 drochner break;
211 1.1 drochner case 'H': /* CUP */
212 1.1 drochner case 'f': /* HVP */
213 1.1 drochner if (edp->flags & VTFL_DECOM)
214 1.1 drochner edp->crow = edp->scrreg_startrow +
215 1.1 drochner min(DEF1_ARG(0), edp->scrreg_nrows) - 1;
216 1.1 drochner else
217 1.1 drochner edp->crow = min(DEF1_ARG(0), edp->nrows) - 1;
218 1.1 drochner edp->ccol = min(DEF1_ARG(1), edp->ncols) - 1;
219 1.1 drochner edp->flags &= ~VTFL_LASTCHAR;
220 1.1 drochner break;
221 1.1 drochner case 'J': /* ED erase in display */
222 1.1 drochner wsemul_vt100_ed(edp, ARG(0));
223 1.1 drochner break;
224 1.1 drochner case 'K': /* EL erase in line */
225 1.1 drochner wsemul_vt100_el(edp, ARG(0));
226 1.1 drochner break;
227 1.1 drochner case 'L': /* IL insert line */
228 1.1 drochner case 'M': /* DL delete line */
229 1.1 drochner n = min(DEF1_ARG(0), ROWS_BELOW + 1);
230 1.1 drochner {
231 1.1 drochner int savscrstartrow, savscrnrows;
232 1.1 drochner savscrstartrow = edp->scrreg_startrow;
233 1.1 drochner savscrnrows = edp->scrreg_nrows;
234 1.1 drochner edp->scrreg_nrows -= ROWS_ABOVE;
235 1.1 drochner edp->scrreg_startrow = edp->crow;
236 1.1 drochner if (c == 'L')
237 1.1 drochner wsemul_vt100_scrolldown(edp, n);
238 1.1 drochner else
239 1.1 drochner wsemul_vt100_scrollup(edp, n);
240 1.1 drochner edp->scrreg_startrow = savscrstartrow;
241 1.1 drochner edp->scrreg_nrows = savscrnrows;
242 1.1 drochner }
243 1.1 drochner break;
244 1.1 drochner case 'P': /* DCH delete character */
245 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
246 1.1 drochner help = edp->ncols - (edp->ccol + n);
247 1.1 drochner if (help > 0)
248 1.1 drochner (*edp->emulops->copycols)(edp->emulcookie, edp->crow,
249 1.1 drochner edp->ccol + n, edp->ccol,
250 1.1 drochner help);
251 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
252 1.1 drochner edp->ncols - n, n, edp->curattr);
253 1.1 drochner break;
254 1.1 drochner case 'X': /* ECH erase character */
255 1.1 drochner n = min(DEF1_ARG(0), COLS_LEFT + 1);
256 1.1 drochner (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
257 1.1 drochner edp->ccol, n,
258 1.1 drochner edp->curattr);
259 1.1 drochner break;
260 1.1 drochner case 'c': /* DA primary */
261 1.1 drochner if (ARG(0) == 0)
262 1.1 drochner wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1,
263 1.1 drochner sizeof(WSEMUL_VT_ID1));
264 1.1 drochner break;
265 1.1 drochner case 'g': /* TBC */
266 1.1 drochner KASSERT(edp->tabs != 0);
267 1.1 drochner switch (ARG(0)) {
268 1.1 drochner case 0:
269 1.1 drochner edp->tabs[edp->ccol] = 0;
270 1.1 drochner break;
271 1.1 drochner case 3:
272 1.1 drochner bzero(edp->tabs, edp->ncols);
273 1.1 drochner break;
274 1.1 drochner default:
275 1.1 drochner #ifdef VT100_PRINTUNKNOWN
276 1.1 drochner printf("CSI%dg unknown\n", ARG(0));
277 1.1 drochner #endif
278 1.1 drochner break;
279 1.1 drochner }
280 1.1 drochner break;
281 1.1 drochner case 'h': /* SM */
282 1.1 drochner vt100_setmode(edp, ARG(0), 0);
283 1.1 drochner break;
284 1.1 drochner case 'i': /* MC printer controller mode */
285 1.1 drochner switch (ARG(0)) {
286 1.1 drochner case 0: /* print screen */
287 1.1 drochner break;
288 1.1 drochner case 4: /* off */
289 1.1 drochner case 5: /* on */
290 1.1 drochner break;
291 1.1 drochner default:
292 1.1 drochner #ifdef VT100_PRINTUNKNOWN
293 1.1 drochner printf("CSI%di unknown\n", ARG(0));
294 1.1 drochner #endif
295 1.1 drochner break;
296 1.1 drochner }
297 1.1 drochner break;
298 1.1 drochner case 'l': /* RM */
299 1.1 drochner vt100_resetmode(edp, ARG(0), 0);
300 1.1 drochner break;
301 1.1 drochner case 'm': /* SGR select graphic rendition */
302 1.1 drochner flags = edp->attrflags;
303 1.1 drochner fgcol = edp->fgcol;
304 1.1 drochner bgcol = edp->bgcol;
305 1.1 drochner for (n = 0; n < edp->nargs; n++) {
306 1.1 drochner switch (ARG(n)) {
307 1.1 drochner case 0: /* reset */
308 1.1 drochner edp->attrflags = 0;
309 1.1 drochner edp->fgcol = WSCOL_WHITE;
310 1.1 drochner edp->bgcol = WSCOL_BLACK;
311 1.1 drochner if (n == edp->nargs - 1) {
312 1.1 drochner edp->curattr = edp->defattr;
313 1.1 drochner return;
314 1.1 drochner }
315 1.1 drochner break;
316 1.1 drochner case 1: /* bold */
317 1.1 drochner flags |= WSATTR_HILIT;
318 1.1 drochner break;
319 1.1 drochner case 4: /* underline */
320 1.1 drochner flags |= WSATTR_UNDERLINE;
321 1.1 drochner break;
322 1.1 drochner case 5: /* blink */
323 1.1 drochner flags |= WSATTR_BLINK;
324 1.1 drochner break;
325 1.1 drochner case 7: /* reverse */
326 1.1 drochner flags |= WSATTR_REVERSE;
327 1.1 drochner break;
328 1.1 drochner case 22: /* ~bold VT300 only */
329 1.1 drochner flags &= ~WSATTR_HILIT;
330 1.1 drochner break;
331 1.1 drochner case 24: /* ~underline VT300 only */
332 1.1 drochner flags &= ~WSATTR_UNDERLINE;
333 1.1 drochner break;
334 1.1 drochner case 25: /* ~blink VT300 only */
335 1.1 drochner flags &= ~WSATTR_BLINK;
336 1.1 drochner break;
337 1.1 drochner case 27: /* ~reverse VT300 only */
338 1.1 drochner flags &= ~WSATTR_REVERSE;
339 1.1 drochner break;
340 1.1 drochner case 30: case 31: case 32: case 33:
341 1.1 drochner case 34: case 35: case 36: case 37:
342 1.1 drochner /* fg color */
343 1.1 drochner flags |= WSATTR_WSCOLORS;
344 1.1 drochner fgcol = ARG(n) - 30;
345 1.1 drochner break;
346 1.1 drochner case 40: case 41: case 42: case 43:
347 1.1 drochner case 44: case 45: case 46: case 47:
348 1.1 drochner /* bg color */
349 1.1 drochner flags |= WSATTR_WSCOLORS;
350 1.1 drochner bgcol = ARG(n) - 40;
351 1.1 drochner break;
352 1.1 drochner default:
353 1.1 drochner #ifdef VT100_PRINTUNKNOWN
354 1.1 drochner printf("CSI%dm unknown\n", ARG(n));
355 1.1 drochner #endif
356 1.1 drochner }
357 1.1 drochner }
358 1.1 drochner if (vt100_selectattribute(edp, flags, fgcol, bgcol, &attr)) {
359 1.1 drochner #ifdef VT100_DEBUG
360 1.1 drochner printf("error allocating attr %d/%d/%x\n",
361 1.1 drochner fgcol, bgcol, flags);
362 1.1 drochner #endif
363 1.1 drochner } else {
364 1.1 drochner edp->curattr = attr;
365 1.1 drochner edp->attrflags = flags;
366 1.1 drochner edp->fgcol = fgcol;
367 1.1 drochner edp->bgcol = bgcol;
368 1.1 drochner }
369 1.1 drochner break;
370 1.1 drochner case 'n': /* reports */
371 1.1 drochner switch (ARG(0)) {
372 1.1 drochner case 5: /* DSR operating status */
373 1.1 drochner /* 0 = OK, 3 = malfunction */
374 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4);
375 1.1 drochner break;
376 1.1 drochner case 6: { /* DSR cursor position report */
377 1.1 drochner char buf[20];
378 1.1 drochner int row;
379 1.1 drochner if (edp->flags & VTFL_DECOM)
380 1.1 drochner row = ROWS_ABOVE;
381 1.1 drochner else
382 1.1 drochner row = edp->crow;
383 1.1 drochner n = sprintf(buf, "\033[%d;%dR",
384 1.1 drochner row + 1, edp->ccol + 1);
385 1.1 drochner wsdisplay_emulinput(edp->cbcookie, buf, n);
386 1.1 drochner }
387 1.1 drochner break;
388 1.1 drochner case 15: /* DSR printer status */
389 1.1 drochner /* 13 = no printer, 10 = ready, 11 = not ready */
390 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?13n", 6);
391 1.1 drochner break;
392 1.1 drochner case 25: /* UDK status - VT300 only */
393 1.1 drochner /* 20 = locked, 21 = unlocked */
394 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?21n", 6);
395 1.1 drochner break;
396 1.1 drochner case 26: /* keyboard dialect */
397 1.1 drochner /* 1 = north american , 7 = german */
398 1.1 drochner wsdisplay_emulinput(edp->cbcookie, "\033[?27;1n", 8);
399 1.1 drochner break;
400 1.1 drochner default:
401 1.1 drochner #ifdef VT100_PRINTUNKNOWN
402 1.1 drochner printf("CSI%dn unknown\n", ARG(0));
403 1.1 drochner #endif
404 1.1 drochner break;
405 1.1 drochner }
406 1.1 drochner break;
407 1.1 drochner case 'r': /* DECSTBM set top/bottom margins */
408 1.1 drochner if (ARG(0) == 0 && ARG(1) == 0) {
409 1.1 drochner edp->scrreg_startrow = 0;
410 1.1 drochner edp->scrreg_nrows = edp->nrows;
411 1.1 drochner } else {
412 1.1 drochner edp->scrreg_startrow = min(DEF1_ARG(0),
413 1.1 drochner edp->nrows) - 1;
414 1.1 drochner edp->scrreg_nrows = min(DEF1_ARG(1), edp->nrows) -
415 1.1 drochner edp->scrreg_startrow;
416 1.1 drochner }
417 1.1 drochner edp->crow = ((edp->flags & VTFL_DECOM) ?
418 1.1 drochner edp->scrreg_startrow : 0);
419 1.1 drochner edp->ccol = 0;
420 1.1 drochner break;
421 1.1 drochner case 'y':
422 1.1 drochner switch (ARG(0)) {
423 1.1 drochner case 4: /* DECTST invoke confidence test */
424 1.1 drochner /* ignore */
425 1.1 drochner break;
426 1.1 drochner default:
427 1.1 drochner #ifdef VT100_PRINTUNKNOWN
428 1.1 drochner printf("CSI%dy unknown\n", ARG(0));
429 1.1 drochner #endif
430 1.1 drochner break;
431 1.1 drochner }
432 1.1 drochner break;
433 1.1 drochner default:
434 1.1 drochner #ifdef VT100_PRINTUNKNOWN
435 1.1 drochner printf("CSI%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
436 1.1 drochner #endif
437 1.1 drochner }
438 1.1 drochner }
439 1.1 drochner
440 1.1 drochner /*
441 1.1 drochner * handle commands after CSI?
442 1.1 drochner */
443 1.1 drochner void
444 1.1 drochner wsemul_vt100_handle_csi_qm(edp, c)
445 1.1 drochner struct wsemul_vt100_emuldata *edp;
446 1.1 drochner u_char c;
447 1.1 drochner {
448 1.1 drochner switch (c) {
449 1.1 drochner case 'J': /* DECSED selective erase in display */
450 1.1 drochner wsemul_vt100_ed(edp, ARG(0));
451 1.1 drochner break;
452 1.1 drochner case 'K': /* DECSEL selective erase in line */
453 1.1 drochner wsemul_vt100_el(edp, ARG(0));
454 1.1 drochner break;
455 1.1 drochner case 'h': /* SM, DEC private */
456 1.1 drochner vt100_setmode(edp, ARG(0), 1);
457 1.1 drochner break;
458 1.1 drochner case 'i': /* MC printer controller mode */
459 1.1 drochner switch (ARG(0)) {
460 1.1 drochner case 1: /* print cursor line */
461 1.1 drochner case 4: /* off */
462 1.1 drochner case 5: /* on */
463 1.1 drochner #ifdef VT100_PRINTNOTIMPL
464 1.1 drochner printf("CSI?%di ignored\n", ARG(0));
465 1.1 drochner #endif
466 1.1 drochner break;
467 1.1 drochner default:
468 1.1 drochner #ifdef VT100_PRINTUNKNOWN
469 1.1 drochner printf("CSI?%di unknown\n", ARG(0));
470 1.1 drochner #endif
471 1.1 drochner break;
472 1.1 drochner }
473 1.1 drochner break;
474 1.1 drochner case 'l': /* RM, DEC private */
475 1.1 drochner vt100_resetmode(edp, ARG(0), 1);
476 1.1 drochner break;
477 1.1 drochner default:
478 1.1 drochner #ifdef VT100_PRINTUNKNOWN
479 1.1 drochner printf("CSI?%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
480 1.1 drochner #endif
481 1.1 drochner break;
482 1.1 drochner }
483 1.1 drochner }
484 1.1 drochner
485 1.1 drochner /*
486 1.1 drochner * get an attribute from the graphics driver,
487 1.1 drochner * try to find replacements if the desired appearance
488 1.1 drochner * is not supported
489 1.1 drochner */
490 1.1 drochner static int
491 1.1 drochner vt100_selectattribute(edp, flags, fgcol, bgcol, attr)
492 1.1 drochner struct wsemul_vt100_emuldata *edp;
493 1.1 drochner int flags, fgcol, bgcol;
494 1.1 drochner long *attr;
495 1.1 drochner {
496 1.1 drochner if ((flags & WSATTR_HILIT) &&
497 1.1 drochner !(edp->scrcapabilities & WSSCREEN_HILIT)) {
498 1.1 drochner flags &= ~WSATTR_HILIT;
499 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
500 1.1 drochner fgcol = WSCOL_RED;
501 1.1 drochner flags |= WSATTR_WSCOLORS;
502 1.1 drochner } else {
503 1.1 drochner #ifdef VT100_DEBUG
504 1.1 drochner printf("bold ignored (impossible)\n");
505 1.1 drochner #endif
506 1.1 drochner }
507 1.1 drochner }
508 1.1 drochner if ((flags & WSATTR_UNDERLINE) &&
509 1.1 drochner !(edp->scrcapabilities & WSSCREEN_UNDERLINE)) {
510 1.1 drochner flags &= ~WSATTR_UNDERLINE;
511 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
512 1.1 drochner bgcol = WSCOL_BROWN;
513 1.1 drochner flags &= ~WSATTR_UNDERLINE;
514 1.1 drochner flags |= WSATTR_WSCOLORS;
515 1.1 drochner } else {
516 1.1 drochner #ifdef VT100_DEBUG
517 1.1 drochner printf("underline ignored (impossible)\n");
518 1.1 drochner #endif
519 1.1 drochner }
520 1.1 drochner }
521 1.1 drochner if ((flags & WSATTR_BLINK) &&
522 1.1 drochner !(edp->scrcapabilities & WSSCREEN_BLINK)) {
523 1.1 drochner flags &= ~WSATTR_BLINK;
524 1.1 drochner #ifdef VT100_DEBUG
525 1.1 drochner printf("blink ignored (impossible)\n");
526 1.1 drochner #endif
527 1.1 drochner }
528 1.1 drochner if ((flags & WSATTR_REVERSE) &&
529 1.1 drochner !(edp->scrcapabilities & WSSCREEN_REVERSE)) {
530 1.1 drochner flags &= ~WSATTR_REVERSE;
531 1.1 drochner if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
532 1.1 drochner int help;
533 1.1 drochner help = bgcol;
534 1.1 drochner bgcol = fgcol;
535 1.1 drochner fgcol = help;
536 1.1 drochner flags |= WSATTR_WSCOLORS;
537 1.1 drochner } else {
538 1.1 drochner #ifdef VT100_DEBUG
539 1.1 drochner printf("reverse ignored (impossible)\n");
540 1.1 drochner #endif
541 1.1 drochner }
542 1.1 drochner }
543 1.1 drochner if ((flags & WSATTR_WSCOLORS) &&
544 1.1 drochner !(edp->scrcapabilities & WSSCREEN_WSCOLORS)) {
545 1.1 drochner flags &= ~WSATTR_WSCOLORS;
546 1.1 drochner #ifdef VT100_DEBUG
547 1.1 drochner printf("colors ignored (impossible)\n");
548 1.1 drochner #endif
549 1.1 drochner }
550 1.1 drochner return ((*edp->emulops->alloc_attr)(edp->emulcookie,
551 1.1 drochner fgcol, bgcol, flags,
552 1.1 drochner attr));
553 1.1 drochner }
554 1.1 drochner
555 1.1 drochner /*
556 1.1 drochner * handle device control sequences if the main state machine
557 1.1 drochner * told so by setting edp->dcstype to a nonzero value
558 1.1 drochner */
559 1.1 drochner void
560 1.1 drochner wsemul_vt100_handle_dcs(edp)
561 1.1 drochner struct wsemul_vt100_emuldata *edp;
562 1.1 drochner {
563 1.1 drochner int i, pos;
564 1.1 drochner
565 1.1 drochner switch (edp->dcstype) {
566 1.1 drochner case 0: /* not handled */
567 1.1 drochner return;
568 1.1 drochner case DCSTYPE_TABRESTORE:
569 1.1 drochner KASSERT(edp->tabs != 0);
570 1.1 drochner bzero(edp->tabs, edp->ncols);
571 1.1 drochner pos = 0;
572 1.1 drochner for (i = 0; i < edp->dcspos; i++) {
573 1.1 drochner char c = edp->dcsarg[i];
574 1.1 drochner switch (c) {
575 1.1 drochner case '0': case '1': case '2': case '3': case '4':
576 1.1 drochner case '5': case '6': case '7': case '8': case '9':
577 1.1 drochner pos = pos * 10 + (edp->dcsarg[i] - '0');
578 1.1 drochner break;
579 1.1 drochner case '/':
580 1.1 drochner if (pos > 0)
581 1.1 drochner edp->tabs[pos - 1] = 1;
582 1.1 drochner pos = 0;
583 1.1 drochner break;
584 1.1 drochner default:
585 1.1 drochner #ifdef VT100_PRINTUNKNOWN
586 1.1 drochner printf("unknown char %c in DCS\n", c);
587 1.1 drochner #endif
588 1.1 drochner }
589 1.1 drochner }
590 1.1 drochner if (pos > 0)
591 1.1 drochner edp->tabs[pos - 1] = 1;
592 1.1 drochner break;
593 1.1 drochner default:
594 1.1 drochner panic("wsemul_vt100_handle_dcs: bad type %d", edp->dcstype);
595 1.1 drochner }
596 1.1 drochner edp->dcstype = 0;
597 1.1 drochner }
598 1.1 drochner
599 1.1 drochner static int
600 1.1 drochner vt100_ansimode(edp, nr, op)
601 1.1 drochner struct wsemul_vt100_emuldata *edp;
602 1.1 drochner int nr, op;
603 1.1 drochner {
604 1.1 drochner int res = 0; /* default: unknown */
605 1.1 drochner
606 1.1 drochner switch (nr) {
607 1.1 drochner case 2: /* KAM keyboard locked/unlocked */
608 1.1 drochner break;
609 1.1 drochner case 3: /* CRM control representation */
610 1.1 drochner break;
611 1.1 drochner case 4: /* IRM insert/replace characters */
612 1.1 drochner if (op == MODE_SET)
613 1.1 drochner edp->flags |= VTFL_INSERTMODE;
614 1.1 drochner else if (op == MODE_RESET)
615 1.1 drochner edp->flags &= ~VTFL_INSERTMODE;
616 1.1 drochner res = ((edp->flags & VTFL_INSERTMODE) ? 1 : 2);
617 1.1 drochner break;
618 1.1 drochner case 10: /* HEM horizontal editing (permanently reset) */
619 1.1 drochner res = 4;
620 1.1 drochner break;
621 1.1 drochner case 12: /* SRM local echo off/on */
622 1.1 drochner res = 4; /* permanently reset ??? */
623 1.1 drochner break;
624 1.1 drochner case 20: /* LNM newline = newline/linefeed */
625 1.1 drochner break;
626 1.1 drochner default:
627 1.1 drochner #ifdef VT100_PRINTUNKNOWN
628 1.1 drochner printf("ANSI mode %d unknown\n", nr);
629 1.1 drochner #endif
630 1.1 drochner }
631 1.1 drochner return (res);
632 1.1 drochner }
633 1.1 drochner
634 1.1 drochner static int
635 1.1 drochner vt100_decmode(edp, nr, op)
636 1.1 drochner struct wsemul_vt100_emuldata *edp;
637 1.1 drochner int nr, op;
638 1.1 drochner {
639 1.1 drochner int res = 0; /* default: unknown */
640 1.1 drochner
641 1.1 drochner switch (nr) {
642 1.1 drochner case 1: /* DECCKM application/nomal cursor keys */
643 1.1 drochner if (op == MODE_SET)
644 1.1 drochner edp->flags |= VTFL_APPLCURSOR;
645 1.1 drochner else if (op == MODE_RESET)
646 1.1 drochner edp->flags &= ~VTFL_APPLCURSOR;
647 1.1 drochner res = ((edp->flags & VTFL_APPLCURSOR) ? 1 : 2);
648 1.1 drochner break;
649 1.1 drochner case 2: /* DECANM ANSI vt100/vt52 */
650 1.1 drochner res = 3; /* permanently set ??? */
651 1.1 drochner break;
652 1.1 drochner case 3: /* DECCOLM 132/80 cols */
653 1.1 drochner case 4: /* DECSCLM smooth/jump scroll */
654 1.1 drochner case 5: /* DECSCNM light/dark background */
655 1.1 drochner res = 4; /* all permanently reset ??? */
656 1.1 drochner break;
657 1.1 drochner case 6: /* DECOM move within/outside margins */
658 1.1 drochner if (op == MODE_SET)
659 1.1 drochner edp->flags |= VTFL_DECOM;
660 1.1 drochner else if (op == MODE_RESET)
661 1.1 drochner edp->flags &= ~VTFL_DECOM;
662 1.1 drochner res = ((edp->flags & VTFL_DECOM) ? 1 : 2);
663 1.1 drochner break;
664 1.1 drochner case 7: /* DECAWM autowrap */
665 1.1 drochner if (op == MODE_SET)
666 1.1 drochner edp->flags |= VTFL_DECAWM;
667 1.1 drochner else if (op == MODE_RESET)
668 1.1 drochner edp->flags &= ~VTFL_DECAWM;
669 1.1 drochner res = ((edp->flags & VTFL_DECAWM) ? 1 : 2);
670 1.1 drochner break;
671 1.1 drochner case 8: /* DECARM keyboard autorepeat */
672 1.1 drochner break;
673 1.1 drochner case 18: /* DECPFF print form feed */
674 1.1 drochner break;
675 1.1 drochner case 19: /* DECPEX printer extent: screen/scrolling region */
676 1.1 drochner break;
677 1.1 drochner case 25: /* DECTCEM text cursor on/off */
678 1.1 drochner if (op == MODE_SET || op == MODE_RESET) {
679 1.1 drochner edp->flags = (edp->flags & ~VTFL_CURSORON) |
680 1.1 drochner ((op == MODE_SET) ? VTFL_CURSORON : 0);
681 1.1 drochner (*edp->emulops->cursor)(edp->emulcookie,
682 1.1 drochner (op == MODE_SET),
683 1.1 drochner edp->crow, edp->ccol);
684 1.1 drochner }
685 1.1 drochner res = ((edp->flags & VTFL_CURSORON) ? 1 : 2);
686 1.1 drochner break;
687 1.1 drochner case 42: /* DECNRCM use 7-bit NRC /
688 1.1 drochner 7/8 bit from DEC multilingual or ISO-latin-1*/
689 1.1 drochner break;
690 1.1 drochner case 66: /* DECNKM numeric keypad */
691 1.1 drochner break;
692 1.1 drochner case 68: /* DECKBUM keyboard usage data processing/typewriter */
693 1.1 drochner break;
694 1.1 drochner default:
695 1.1 drochner #ifdef VT100_PRINTUNKNOWN
696 1.1 drochner printf("DEC mode %d unknown\n", nr);
697 1.1 drochner #endif
698 1.1 drochner break;
699 1.1 drochner }
700 1.1 drochner return (res);
701 1.1 drochner }
702 1.1 drochner
703 1.1 drochner void
704 1.1 drochner vt100_setmode(edp, nr, decmode)
705 1.1 drochner struct wsemul_vt100_emuldata *edp;
706 1.1 drochner int nr, decmode;
707 1.1 drochner {
708 1.1 drochner if (decmode)
709 1.1 drochner vt100_decmode(edp, nr, MODE_SET);
710 1.1 drochner else
711 1.1 drochner vt100_ansimode(edp, nr, MODE_SET);
712 1.1 drochner }
713 1.1 drochner
714 1.1 drochner void
715 1.1 drochner vt100_resetmode(edp, nr, decmode)
716 1.1 drochner struct wsemul_vt100_emuldata *edp;
717 1.1 drochner int nr, decmode;
718 1.1 drochner {
719 1.1 drochner if (decmode)
720 1.1 drochner vt100_decmode(edp, nr, MODE_RESET);
721 1.1 drochner else
722 1.1 drochner vt100_ansimode(edp, nr, MODE_RESET);
723 1.1 drochner }
724 1.1 drochner
725 1.1 drochner void
726 1.1 drochner vt100_reportmode(edp, nr, decmode)
727 1.1 drochner struct wsemul_vt100_emuldata *edp;
728 1.1 drochner int nr, decmode;
729 1.1 drochner {
730 1.1 drochner char buf[20];
731 1.1 drochner int res, n;
732 1.1 drochner
733 1.1 drochner if (decmode)
734 1.1 drochner res = vt100_decmode(edp, nr, MODE_REPORT);
735 1.1 drochner else
736 1.1 drochner res = vt100_ansimode(edp, nr, MODE_REPORT);
737 1.1 drochner
738 1.1 drochner n = sprintf(buf, "\033[%s%d;%d$y", (decmode ? "?" : ""), nr, res);
739 1.1 drochner wsdisplay_emulinput(edp->cbcookie, buf, n);
740 1.1 drochner }
741