wsemul_vt100.c revision 1.51 1 1.51 christos /* $NetBSD: wsemul_vt100.c,v 1.51 2023/07/16 17:43:50 christos 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 *
16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 drochner *
27 1.1 drochner */
28 1.16 lukem
29 1.16 lukem #include <sys/cdefs.h>
30 1.51 christos __KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.51 2023/07/16 17:43:50 christos Exp $");
31 1.26 jmmv
32 1.37 pooka #ifdef _KERNEL_OPT
33 1.26 jmmv #include "opt_wsmsgattrs.h"
34 1.37 pooka #endif
35 1.1 drochner
36 1.1 drochner #include <sys/param.h>
37 1.1 drochner #include <sys/systm.h>
38 1.1 drochner #include <sys/time.h>
39 1.1 drochner #include <sys/malloc.h>
40 1.1 drochner #include <sys/fcntl.h>
41 1.1 drochner
42 1.1 drochner #include <dev/wscons/wsconsio.h>
43 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
44 1.1 drochner #include <dev/wscons/wsemulvar.h>
45 1.1 drochner #include <dev/wscons/wsemul_vt100var.h>
46 1.1 drochner #include <dev/wscons/ascii.h>
47 1.1 drochner
48 1.49 uwe static void *wsemul_vt100_cnattach(const struct wsscreen_descr *, void *,
49 1.49 uwe int, int, long);
50 1.49 uwe static void *wsemul_vt100_attach(int console, const struct wsscreen_descr *,
51 1.49 uwe void *, int, int, void *, long);
52 1.49 uwe static void wsemul_vt100_output(void *cookie, const u_char *data, u_int count,
53 1.49 uwe int kernel);
54 1.49 uwe static void wsemul_vt100_detach(void *cookie, u_int *crowp, u_int *ccolp);
55 1.49 uwe static void wsemul_vt100_resetop(void *, enum wsemul_resetops);
56 1.26 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
57 1.26 jmmv static void wsemul_vt100_getmsgattrs(void *, struct wsdisplay_msgattrs *);
58 1.26 jmmv static void wsemul_vt100_setmsgattrs(void *, const struct wsscreen_descr *,
59 1.26 jmmv const struct wsdisplay_msgattrs *);
60 1.26 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
61 1.38 macallan static void wsemul_vt100_resize(void *, const struct wsscreen_descr *);
62 1.1 drochner
63 1.1 drochner const struct wsemul_ops wsemul_vt100_ops = {
64 1.40 maya .name = "vt100",
65 1.40 maya .cnattach = wsemul_vt100_cnattach,
66 1.40 maya .attach = wsemul_vt100_attach,
67 1.40 maya .output = wsemul_vt100_output,
68 1.40 maya .translate = wsemul_vt100_translate,
69 1.40 maya .detach = wsemul_vt100_detach,
70 1.40 maya .reset = wsemul_vt100_resetop,
71 1.26 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
72 1.40 maya .getmsgattrs = wsemul_vt100_getmsgattrs,
73 1.40 maya .setmsgattrs = wsemul_vt100_setmsgattrs,
74 1.26 jmmv #else
75 1.40 maya .getmsgattrs = NULL,
76 1.40 maya .setmsgattrs = NULL,
77 1.26 jmmv #endif
78 1.38 macallan .resize = wsemul_vt100_resize
79 1.1 drochner };
80 1.1 drochner
81 1.49 uwe static struct wsemul_vt100_emuldata wsemul_vt100_console_emuldata;
82 1.1 drochner
83 1.15 augustss static void wsemul_vt100_init(struct wsemul_vt100_emuldata *,
84 1.15 augustss const struct wsscreen_descr *,
85 1.15 augustss void *, int, int, long);
86 1.15 augustss
87 1.15 augustss static void wsemul_vt100_output_normal(struct wsemul_vt100_emuldata *,
88 1.15 augustss u_char, int);
89 1.15 augustss static void wsemul_vt100_output_c0c1(struct wsemul_vt100_emuldata *,
90 1.15 augustss u_char, int);
91 1.21 sommerfe static void wsemul_vt100_nextline(struct wsemul_vt100_emuldata *);
92 1.15 augustss typedef u_int vt100_handler(struct wsemul_vt100_emuldata *, u_char);
93 1.21 sommerfe
94 1.1 drochner static vt100_handler
95 1.1 drochner wsemul_vt100_output_esc,
96 1.1 drochner wsemul_vt100_output_csi,
97 1.1 drochner wsemul_vt100_output_scs94,
98 1.1 drochner wsemul_vt100_output_scs94_percent,
99 1.1 drochner wsemul_vt100_output_scs96,
100 1.1 drochner wsemul_vt100_output_scs96_percent,
101 1.3 drochner wsemul_vt100_output_esc_hash,
102 1.1 drochner wsemul_vt100_output_esc_spc,
103 1.1 drochner wsemul_vt100_output_string,
104 1.1 drochner wsemul_vt100_output_string_esc,
105 1.1 drochner wsemul_vt100_output_dcs,
106 1.1 drochner wsemul_vt100_output_dcs_dollar;
107 1.1 drochner
108 1.1 drochner #define VT100_EMUL_STATE_NORMAL 0 /* normal processing */
109 1.1 drochner #define VT100_EMUL_STATE_ESC 1 /* got ESC */
110 1.1 drochner #define VT100_EMUL_STATE_CSI 2 /* got CSI (ESC[) */
111 1.3 drochner #define VT100_EMUL_STATE_SCS94 3 /* got ESC{()*+} */
112 1.3 drochner #define VT100_EMUL_STATE_SCS94_PERCENT 4 /* got ESC{()*+}% */
113 1.3 drochner #define VT100_EMUL_STATE_SCS96 5 /* got ESC{-./} */
114 1.3 drochner #define VT100_EMUL_STATE_SCS96_PERCENT 6 /* got ESC{-./}% */
115 1.3 drochner #define VT100_EMUL_STATE_ESC_HASH 7 /* got ESC# */
116 1.3 drochner #define VT100_EMUL_STATE_ESC_SPC 8 /* got ESC<SPC> */
117 1.3 drochner #define VT100_EMUL_STATE_STRING 9 /* waiting for ST (ESC\) */
118 1.3 drochner #define VT100_EMUL_STATE_STRING_ESC 10 /* waiting for ST, got ESC */
119 1.3 drochner #define VT100_EMUL_STATE_DCS 11 /* got DCS (ESC P) */
120 1.3 drochner #define VT100_EMUL_STATE_DCS_DOLLAR 12 /* got DCS<p>$ */
121 1.1 drochner
122 1.49 uwe static vt100_handler *vt100_output[] = {
123 1.1 drochner wsemul_vt100_output_esc,
124 1.1 drochner wsemul_vt100_output_csi,
125 1.1 drochner wsemul_vt100_output_scs94,
126 1.1 drochner wsemul_vt100_output_scs94_percent,
127 1.1 drochner wsemul_vt100_output_scs96,
128 1.1 drochner wsemul_vt100_output_scs96_percent,
129 1.3 drochner wsemul_vt100_output_esc_hash,
130 1.1 drochner wsemul_vt100_output_esc_spc,
131 1.1 drochner wsemul_vt100_output_string,
132 1.1 drochner wsemul_vt100_output_string_esc,
133 1.1 drochner wsemul_vt100_output_dcs,
134 1.1 drochner wsemul_vt100_output_dcs_dollar,
135 1.1 drochner };
136 1.1 drochner
137 1.1 drochner static void
138 1.27 perry wsemul_vt100_init(struct wsemul_vt100_emuldata *edp,
139 1.15 augustss const struct wsscreen_descr *type, void *cookie, int ccol, int crow,
140 1.15 augustss long defattr)
141 1.1 drochner {
142 1.32 drochner struct vt100base_data *vd = &edp->bd;
143 1.26 jmmv int error;
144 1.26 jmmv
145 1.32 drochner vd->emulops = type->textops;
146 1.32 drochner vd->emulcookie = cookie;
147 1.32 drochner vd->scrcapabilities = type->capabilities;
148 1.32 drochner vd->nrows = type->nrows;
149 1.32 drochner vd->ncols = type->ncols;
150 1.32 drochner vd->crow = crow;
151 1.32 drochner vd->ccol = ccol;
152 1.26 jmmv
153 1.26 jmmv /* The underlying driver has already allocated a default and simple
154 1.26 jmmv * attribute for us, which is stored in defattr. We try to set the
155 1.26 jmmv * values specified by the kernel options below, but in case of
156 1.26 jmmv * failure we fallback to the value given by the driver. */
157 1.26 jmmv
158 1.26 jmmv if (type->capabilities & WSSCREEN_WSCOLORS) {
159 1.32 drochner vd->msgattrs.default_attrs = WS_DEFAULT_COLATTR |
160 1.26 jmmv WSATTR_WSCOLORS;
161 1.32 drochner vd->msgattrs.default_bg = WS_DEFAULT_BG;
162 1.32 drochner vd->msgattrs.default_fg = WS_DEFAULT_FG;
163 1.26 jmmv
164 1.32 drochner vd->msgattrs.kernel_attrs = WS_KERNEL_COLATTR |
165 1.26 jmmv WSATTR_WSCOLORS;
166 1.32 drochner vd->msgattrs.kernel_bg = WS_KERNEL_BG;
167 1.32 drochner vd->msgattrs.kernel_fg = WS_KERNEL_FG;
168 1.26 jmmv } else {
169 1.32 drochner vd->msgattrs.default_attrs = WS_DEFAULT_MONOATTR;
170 1.32 drochner vd->msgattrs.default_bg = vd->msgattrs.default_fg = 0;
171 1.26 jmmv
172 1.32 drochner vd->msgattrs.kernel_attrs = WS_KERNEL_MONOATTR;
173 1.32 drochner vd->msgattrs.kernel_bg = vd->msgattrs.kernel_fg = 0;
174 1.26 jmmv }
175 1.26 jmmv
176 1.32 drochner error = (*vd->emulops->allocattr)(cookie,
177 1.32 drochner vd->msgattrs.default_fg,
178 1.32 drochner vd->msgattrs.default_bg,
179 1.32 drochner vd->msgattrs.default_attrs,
180 1.32 drochner &vd->defattr);
181 1.26 jmmv if (error) {
182 1.32 drochner vd->defattr = defattr;
183 1.26 jmmv /* XXX This assumes the driver has allocated white on black
184 1.26 jmmv * XXX as the default attribute, which is not always true.
185 1.26 jmmv * XXX Maybe we need an emulop that, given an attribute,
186 1.26 jmmv * XXX (defattr) returns its flags and colors? */
187 1.32 drochner vd->msgattrs.default_attrs = 0;
188 1.32 drochner vd->msgattrs.default_bg = WSCOL_BLACK;
189 1.32 drochner vd->msgattrs.default_fg = WSCOL_WHITE;
190 1.26 jmmv } else {
191 1.32 drochner if (vd->emulops->replaceattr != NULL)
192 1.32 drochner (*vd->emulops->replaceattr)(cookie, defattr,
193 1.32 drochner vd->defattr);
194 1.26 jmmv }
195 1.26 jmmv
196 1.26 jmmv #if defined(WS_KERNEL_CUSTOMIZED)
197 1.26 jmmv /* Set up kernel colors, in case they were customized by the user;
198 1.26 jmmv * otherwise default to the colors specified for the console.
199 1.26 jmmv * In case of failure, we use console colors too; we can assume
200 1.26 jmmv * they are good as they have been previously allocated and
201 1.26 jmmv * verified. */
202 1.32 drochner error = (*vd->emulops->allocattr)(cookie,
203 1.32 drochner vd->msgattrs.kernel_fg,
204 1.32 drochner vd->msgattrs.kernel_bg,
205 1.32 drochner vd->msgattrs.kernel_attrs,
206 1.26 jmmv &edp->kernattr);
207 1.26 jmmv if (error)
208 1.26 jmmv #endif
209 1.32 drochner edp->kernattr = vd->defattr;
210 1.1 drochner }
211 1.1 drochner
212 1.49 uwe static void *
213 1.15 augustss wsemul_vt100_cnattach(const struct wsscreen_descr *type, void *cookie,
214 1.15 augustss int ccol, int crow, long defattr)
215 1.1 drochner {
216 1.1 drochner struct wsemul_vt100_emuldata *edp;
217 1.32 drochner struct vt100base_data *vd;
218 1.1 drochner
219 1.1 drochner edp = &wsemul_vt100_console_emuldata;
220 1.32 drochner vd = &edp->bd;
221 1.1 drochner wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
222 1.1 drochner #ifdef DIAGNOSTIC
223 1.1 drochner edp->console = 1;
224 1.1 drochner #endif
225 1.32 drochner vd->cbcookie = NULL;
226 1.1 drochner
227 1.32 drochner vd->tabs = 0;
228 1.32 drochner vd->dblwid = 0;
229 1.32 drochner vd->dw = 0;
230 1.32 drochner vd->dcsarg = 0;
231 1.3 drochner edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = 0;
232 1.3 drochner edp->nrctab = 0;
233 1.1 drochner wsemul_vt100_reset(edp);
234 1.43 christos return edp;
235 1.1 drochner }
236 1.1 drochner
237 1.49 uwe static void *
238 1.15 augustss wsemul_vt100_attach(int console, const struct wsscreen_descr *type,
239 1.15 augustss void *cookie, int ccol, int crow, void *cbcookie, long defattr)
240 1.1 drochner {
241 1.1 drochner struct wsemul_vt100_emuldata *edp;
242 1.32 drochner struct vt100base_data *vd;
243 1.1 drochner
244 1.1 drochner if (console) {
245 1.1 drochner edp = &wsemul_vt100_console_emuldata;
246 1.1 drochner KASSERT(edp->console == 1);
247 1.1 drochner } else {
248 1.1 drochner edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
249 1.1 drochner wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
250 1.1 drochner #ifdef DIAGNOSTIC
251 1.1 drochner edp->console = 0;
252 1.1 drochner #endif
253 1.1 drochner }
254 1.32 drochner vd = &edp->bd;
255 1.32 drochner vd->cbcookie = cbcookie;
256 1.1 drochner
257 1.46 chs vd->tabs = malloc(1024, M_DEVBUF, M_WAITOK);
258 1.46 chs vd->dblwid = malloc(1024, M_DEVBUF, M_WAITOK|M_ZERO);
259 1.32 drochner vd->dw = 0;
260 1.46 chs vd->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_WAITOK);
261 1.46 chs edp->isolatin1tab = malloc(128 * sizeof(int), M_DEVBUF, M_WAITOK);
262 1.46 chs edp->decgraphtab = malloc(128 * sizeof(int), M_DEVBUF, M_WAITOK);
263 1.46 chs edp->dectechtab = malloc(128 * sizeof(int), M_DEVBUF, M_WAITOK);
264 1.46 chs edp->nrctab = malloc(128 * sizeof(int), M_DEVBUF, M_WAITOK);
265 1.3 drochner vt100_initchartables(edp);
266 1.1 drochner wsemul_vt100_reset(edp);
267 1.43 christos return edp;
268 1.1 drochner }
269 1.1 drochner
270 1.49 uwe static void
271 1.15 augustss wsemul_vt100_detach(void *cookie, u_int *crowp, u_int *ccolp)
272 1.1 drochner {
273 1.1 drochner struct wsemul_vt100_emuldata *edp = cookie;
274 1.32 drochner struct vt100base_data *vd = &edp->bd;
275 1.1 drochner
276 1.32 drochner *crowp = vd->crow;
277 1.32 drochner *ccolp = vd->ccol;
278 1.3 drochner #define f(ptr) if (ptr) {free(ptr, M_DEVBUF); ptr = 0;}
279 1.32 drochner f(vd->tabs)
280 1.32 drochner f(vd->dblwid)
281 1.32 drochner f(vd->dcsarg)
282 1.3 drochner f(edp->isolatin1tab)
283 1.3 drochner f(edp->decgraphtab)
284 1.3 drochner f(edp->dectechtab)
285 1.3 drochner f(edp->nrctab)
286 1.3 drochner #undef f
287 1.1 drochner if (edp != &wsemul_vt100_console_emuldata)
288 1.1 drochner free(edp, M_DEVBUF);
289 1.9 drochner }
290 1.9 drochner
291 1.38 macallan static void
292 1.38 macallan wsemul_vt100_resize(void * cookie, const struct wsscreen_descr *type)
293 1.38 macallan {
294 1.38 macallan struct wsemul_vt100_emuldata *edp = cookie;
295 1.38 macallan
296 1.50 riastrad /* XXX match malloc size in wsemul_vt100_attach */
297 1.50 riastrad KASSERT(type->nrows >= 0);
298 1.50 riastrad KASSERT(type->ncols >= 0);
299 1.50 riastrad KASSERT(type->nrows <= 1024);
300 1.50 riastrad KASSERT(type->ncols <= 1024);
301 1.50 riastrad
302 1.50 riastrad edp->bd.nrows = MAX(0, MIN(type->nrows, 1024));
303 1.50 riastrad edp->bd.ncols = MAX(0, MIN(type->ncols, 1024));
304 1.38 macallan wsemul_vt100_reset(edp);
305 1.38 macallan wsemul_vt100_resetop(cookie, WSEMUL_CLEARSCREEN);
306 1.38 macallan }
307 1.38 macallan
308 1.49 uwe static void
309 1.15 augustss wsemul_vt100_resetop(void *cookie, enum wsemul_resetops op)
310 1.9 drochner {
311 1.9 drochner struct wsemul_vt100_emuldata *edp = cookie;
312 1.32 drochner struct vt100base_data *vd = &edp->bd;
313 1.9 drochner
314 1.9 drochner switch (op) {
315 1.9 drochner case WSEMUL_RESET:
316 1.9 drochner wsemul_vt100_reset(edp);
317 1.9 drochner break;
318 1.9 drochner case WSEMUL_SYNCFONT:
319 1.9 drochner vt100_initchartables(edp);
320 1.10 drochner break;
321 1.10 drochner case WSEMUL_CLEARSCREEN:
322 1.32 drochner wsemul_vt100_ed(vd, 2);
323 1.32 drochner vd->ccol = vd->crow = 0;
324 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie,
325 1.32 drochner vd->flags & VTFL_CURSORON, 0, 0);
326 1.10 drochner break;
327 1.10 drochner default:
328 1.9 drochner break;
329 1.9 drochner }
330 1.1 drochner }
331 1.1 drochner
332 1.1 drochner void
333 1.15 augustss wsemul_vt100_reset(struct wsemul_vt100_emuldata *edp)
334 1.1 drochner {
335 1.32 drochner struct vt100base_data *vd = &edp->bd;
336 1.1 drochner int i;
337 1.1 drochner
338 1.1 drochner edp->state = VT100_EMUL_STATE_NORMAL;
339 1.32 drochner vd->flags = VTFL_DECAWM | VTFL_CURSORON;
340 1.32 drochner vd->bkgdattr = vd->curattr = vd->defattr;
341 1.32 drochner vd->attrflags = vd->msgattrs.default_attrs;
342 1.32 drochner vd->fgcol = vd->msgattrs.default_fg;
343 1.32 drochner vd->bgcol = vd->msgattrs.default_bg;
344 1.32 drochner vd->scrreg_startrow = 0;
345 1.32 drochner vd->scrreg_nrows = vd->nrows;
346 1.32 drochner if (vd->tabs) {
347 1.32 drochner memset(vd->tabs, 0, vd->ncols);
348 1.32 drochner for (i = 8; i < vd->ncols; i += 8)
349 1.32 drochner vd->tabs[i] = 1;
350 1.1 drochner }
351 1.32 drochner vd->dcspos = 0;
352 1.32 drochner vd->dcstype = 0;
353 1.3 drochner edp->chartab_G[0] = 0;
354 1.3 drochner edp->chartab_G[1] = edp->nrctab; /* ??? */
355 1.3 drochner edp->chartab_G[2] = edp->isolatin1tab;
356 1.3 drochner edp->chartab_G[3] = edp->isolatin1tab;
357 1.3 drochner edp->chartab0 = 0;
358 1.3 drochner edp->chartab1 = 2;
359 1.3 drochner edp->sschartab = 0;
360 1.1 drochner }
361 1.1 drochner
362 1.1 drochner /*
363 1.1 drochner * now all the state machine bits
364 1.1 drochner */
365 1.1 drochner
366 1.21 sommerfe /*
367 1.21 sommerfe * Move the cursor to the next line if possible. If the cursor is at
368 1.21 sommerfe * the bottom of the scroll area, then scroll it up. If the cursor is
369 1.21 sommerfe * at the bottom of the screen then don't move it down.
370 1.21 sommerfe */
371 1.7 drochner static void
372 1.21 sommerfe wsemul_vt100_nextline(struct wsemul_vt100_emuldata *edp)
373 1.21 sommerfe {
374 1.32 drochner struct vt100base_data *vd = &edp->bd;
375 1.32 drochner
376 1.32 drochner if (ROWS_BELOW(vd) == 0) {
377 1.21 sommerfe /* Bottom of the scroll region. */
378 1.32 drochner wsemul_vt100_scrollup(vd, 1);
379 1.21 sommerfe } else {
380 1.32 drochner if ((vd->crow+1) < vd->nrows)
381 1.21 sommerfe /* Cursor not at the bottom of the screen. */
382 1.32 drochner vd->crow++;
383 1.32 drochner CHECK_DW(vd);
384 1.21 sommerfe }
385 1.27 perry }
386 1.21 sommerfe
387 1.22 sommerfe static void
388 1.15 augustss wsemul_vt100_output_normal(struct wsemul_vt100_emuldata *edp, u_char c,
389 1.15 augustss int kernel)
390 1.1 drochner {
391 1.32 drochner struct vt100base_data *vd = &edp->bd;
392 1.7 drochner u_int *ct, dc;
393 1.7 drochner
394 1.32 drochner if ((vd->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
395 1.7 drochner (VTFL_LASTCHAR | VTFL_DECAWM)) {
396 1.21 sommerfe wsemul_vt100_nextline(edp);
397 1.32 drochner vd->ccol = 0;
398 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
399 1.7 drochner }
400 1.7 drochner
401 1.7 drochner if (c & 0x80) {
402 1.7 drochner c &= 0x7f;
403 1.7 drochner ct = edp->chartab_G[edp->chartab1];
404 1.7 drochner } else {
405 1.7 drochner if (edp->sschartab) {
406 1.7 drochner ct = edp->chartab_G[edp->sschartab];
407 1.7 drochner edp->sschartab = 0;
408 1.7 drochner } else
409 1.7 drochner ct = edp->chartab_G[edp->chartab0];
410 1.7 drochner }
411 1.7 drochner dc = (ct ? ct[c] : c);
412 1.7 drochner
413 1.32 drochner if ((vd->flags & VTFL_INSERTMODE) && COLS_LEFT(vd))
414 1.32 drochner COPYCOLS(vd, vd->ccol, vd->ccol + 1, COLS_LEFT(vd));
415 1.7 drochner
416 1.32 drochner (*vd->emulops->putchar)(vd->emulcookie, vd->crow,
417 1.32 drochner vd->ccol << vd->dw, dc,
418 1.32 drochner kernel ? edp->kernattr : vd->curattr);
419 1.7 drochner
420 1.32 drochner if (COLS_LEFT(vd))
421 1.32 drochner vd->ccol++;
422 1.7 drochner else
423 1.32 drochner vd->flags |= VTFL_LASTCHAR;
424 1.7 drochner }
425 1.7 drochner
426 1.7 drochner static void
427 1.27 perry wsemul_vt100_output_c0c1(struct wsemul_vt100_emuldata *edp, u_char c,
428 1.15 augustss int kernel)
429 1.7 drochner {
430 1.32 drochner struct vt100base_data *vd = &edp->bd;
431 1.7 drochner u_int n;
432 1.1 drochner
433 1.1 drochner switch (c) {
434 1.19 junyoung case ASCII_NUL:
435 1.19 junyoung default:
436 1.1 drochner /* ignore */
437 1.1 drochner break;
438 1.19 junyoung case ASCII_BEL:
439 1.47 christos if (edp->state == VT100_EMUL_STATE_STRING) {
440 1.47 christos /* acts as an equivalent to the ``ESC \'' string end */
441 1.47 christos wsemul_vt100_handle_dcs(vd);
442 1.47 christos edp->state = VT100_EMUL_STATE_NORMAL;
443 1.47 christos } else {
444 1.47 christos wsdisplay_emulbell(vd->cbcookie);
445 1.47 christos }
446 1.1 drochner break;
447 1.19 junyoung case ASCII_BS:
448 1.32 drochner if (vd->ccol > 0) {
449 1.32 drochner vd->ccol--;
450 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
451 1.1 drochner }
452 1.1 drochner break;
453 1.19 junyoung case ASCII_CR:
454 1.32 drochner vd->ccol = 0;
455 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
456 1.1 drochner break;
457 1.19 junyoung case ASCII_HT:
458 1.32 drochner if (vd->tabs) {
459 1.32 drochner if (!COLS_LEFT(vd))
460 1.1 drochner break;
461 1.32 drochner for (n = vd->ccol + 1; n < NCOLS(vd) - 1; n++)
462 1.32 drochner if (vd->tabs[n])
463 1.1 drochner break;
464 1.1 drochner } else {
465 1.45 riastrad n = vd->ccol + uimin(8 - (vd->ccol & 7), COLS_LEFT(vd));
466 1.1 drochner }
467 1.32 drochner vd->ccol = n;
468 1.1 drochner break;
469 1.19 junyoung case ASCII_SO: /* LS1 */
470 1.3 drochner edp->chartab0 = 1;
471 1.3 drochner break;
472 1.19 junyoung case ASCII_SI: /* LS0 */
473 1.3 drochner edp->chartab0 = 0;
474 1.1 drochner break;
475 1.19 junyoung case ASCII_ESC:
476 1.14 jdolecek if (kernel) {
477 1.43 christos printf("%s: ESC in kernel output ignored\n", __func__);
478 1.14 jdolecek break; /* ignore the ESC */
479 1.14 jdolecek }
480 1.14 jdolecek
481 1.7 drochner if (edp->state == VT100_EMUL_STATE_STRING) {
482 1.7 drochner /* might be a string end */
483 1.7 drochner edp->state = VT100_EMUL_STATE_STRING_ESC;
484 1.7 drochner } else {
485 1.7 drochner /* XXX cancel current escape sequence */
486 1.7 drochner edp->state = VT100_EMUL_STATE_ESC;
487 1.7 drochner }
488 1.1 drochner break;
489 1.1 drochner #if 0
490 1.19 junyoung case CSI: /* 8-bit */
491 1.7 drochner /* XXX cancel current escape sequence */
492 1.1 drochner edp->nargs = 0;
493 1.8 augustss memset(edp->args, 0, sizeof (edp->args));
494 1.3 drochner edp->modif1 = edp->modif2 = '\0';
495 1.7 drochner edp->state = VT100_EMUL_STATE_CSI;
496 1.1 drochner break;
497 1.19 junyoung case DCS: /* 8-bit */
498 1.7 drochner /* XXX cancel current escape sequence */
499 1.1 drochner edp->nargs = 0;
500 1.8 augustss memset(edp->args, 0, sizeof (edp->args));
501 1.7 drochner edp->state = VT100_EMUL_STATE_DCS;
502 1.1 drochner break;
503 1.19 junyoung case ST: /* string end 8-bit */
504 1.7 drochner /* XXX only in VT100_EMUL_STATE_STRING */
505 1.47 christos wsemul_vt100_handle_dcs(vd);
506 1.43 christos edp->state = VT100_EMUL_STATE_NORMAL;
507 1.43 christos break;
508 1.1 drochner #endif
509 1.19 junyoung case ASCII_LF:
510 1.19 junyoung case ASCII_VT:
511 1.19 junyoung case ASCII_FF:
512 1.21 sommerfe wsemul_vt100_nextline(edp);
513 1.1 drochner break;
514 1.1 drochner }
515 1.1 drochner }
516 1.1 drochner
517 1.1 drochner static u_int
518 1.15 augustss wsemul_vt100_output_esc(struct wsemul_vt100_emuldata *edp, u_char c)
519 1.1 drochner {
520 1.32 drochner struct vt100base_data *vd = &edp->bd;
521 1.3 drochner int i;
522 1.1 drochner
523 1.1 drochner switch (c) {
524 1.19 junyoung case '[': /* CSI */
525 1.32 drochner vd->nargs = 0;
526 1.32 drochner memset(vd->args, 0, sizeof (vd->args));
527 1.32 drochner vd->modif1 = vd->modif2 = '\0';
528 1.43 christos return VT100_EMUL_STATE_CSI;
529 1.19 junyoung case '7': /* DECSC */
530 1.32 drochner vd->flags |= VTFL_SAVEDCURS;
531 1.32 drochner edp->savedcursor_row = vd->crow;
532 1.32 drochner edp->savedcursor_col = vd->ccol;
533 1.32 drochner edp->savedattr = vd->curattr;
534 1.32 drochner edp->savedbkgdattr = vd->bkgdattr;
535 1.32 drochner edp->savedattrflags = vd->attrflags;
536 1.32 drochner edp->savedfgcol = vd->fgcol;
537 1.32 drochner edp->savedbgcol = vd->bgcol;
538 1.3 drochner for (i = 0; i < 4; i++)
539 1.3 drochner edp->savedchartab_G[i] = edp->chartab_G[i];
540 1.3 drochner edp->savedchartab0 = edp->chartab0;
541 1.3 drochner edp->savedchartab1 = edp->chartab1;
542 1.1 drochner break;
543 1.19 junyoung case '8': /* DECRC */
544 1.32 drochner if ((vd->flags & VTFL_SAVEDCURS) == 0)
545 1.24 christos break;
546 1.32 drochner vd->crow = edp->savedcursor_row;
547 1.32 drochner vd->ccol = edp->savedcursor_col;
548 1.32 drochner vd->curattr = edp->savedattr;
549 1.32 drochner vd->bkgdattr = edp->savedbkgdattr;
550 1.32 drochner vd->attrflags = edp->savedattrflags;
551 1.32 drochner vd->fgcol = edp->savedfgcol;
552 1.32 drochner vd->bgcol = edp->savedbgcol;
553 1.3 drochner for (i = 0; i < 4; i++)
554 1.3 drochner edp->chartab_G[i] = edp->savedchartab_G[i];
555 1.3 drochner edp->chartab0 = edp->savedchartab0;
556 1.3 drochner edp->chartab1 = edp->savedchartab1;
557 1.1 drochner break;
558 1.19 junyoung case '=': /* DECKPAM application mode */
559 1.32 drochner vd->flags |= VTFL_APPLKEYPAD;
560 1.1 drochner break;
561 1.19 junyoung case '>': /* DECKPNM numeric mode */
562 1.32 drochner vd->flags &= ~VTFL_APPLKEYPAD;
563 1.1 drochner break;
564 1.19 junyoung case 'E': /* NEL */
565 1.32 drochner vd->ccol = 0;
566 1.1 drochner /* FALLTHRU */
567 1.19 junyoung case 'D': /* IND */
568 1.21 sommerfe wsemul_vt100_nextline(edp);
569 1.1 drochner break;
570 1.19 junyoung case 'H': /* HTS */
571 1.32 drochner KASSERT(vd->tabs != 0);
572 1.32 drochner vd->tabs[vd->ccol] = 1;
573 1.1 drochner break;
574 1.19 junyoung case '~': /* LS1R */
575 1.3 drochner edp->chartab1 = 1;
576 1.3 drochner break;
577 1.19 junyoung case 'n': /* LS2 */
578 1.3 drochner edp->chartab0 = 2;
579 1.3 drochner break;
580 1.19 junyoung case '}': /* LS2R */
581 1.3 drochner edp->chartab1 = 2;
582 1.3 drochner break;
583 1.19 junyoung case 'o': /* LS3 */
584 1.3 drochner edp->chartab0 = 3;
585 1.3 drochner break;
586 1.19 junyoung case '|': /* LS3R */
587 1.3 drochner edp->chartab1 = 3;
588 1.1 drochner break;
589 1.19 junyoung case 'N': /* SS2 */
590 1.3 drochner edp->sschartab = 2;
591 1.3 drochner break;
592 1.19 junyoung case 'O': /* SS3 */
593 1.3 drochner edp->sschartab = 3;
594 1.1 drochner break;
595 1.19 junyoung case 'M': /* RI */
596 1.32 drochner if (ROWS_ABOVE(vd) > 0) {
597 1.32 drochner vd->crow--;
598 1.32 drochner CHECK_DW(vd);
599 1.1 drochner break;
600 1.1 drochner }
601 1.32 drochner wsemul_vt100_scrolldown(vd, 1);
602 1.1 drochner break;
603 1.19 junyoung case 'P': /* DCS */
604 1.32 drochner vd->nargs = 0;
605 1.32 drochner memset(vd->args, 0, sizeof (vd->args));
606 1.43 christos return VT100_EMUL_STATE_DCS;
607 1.19 junyoung case 'c': /* RIS */
608 1.1 drochner wsemul_vt100_reset(edp);
609 1.32 drochner wsemul_vt100_ed(vd, 2);
610 1.32 drochner vd->ccol = vd->crow = 0;
611 1.1 drochner break;
612 1.19 junyoung case '(': case ')': case '*': case '+': /* SCS */
613 1.3 drochner edp->designating = c - '(';
614 1.43 christos return VT100_EMUL_STATE_SCS94;
615 1.19 junyoung case '-': case '.': case '/': /* SCS */
616 1.3 drochner edp->designating = c - '-' + 1;
617 1.43 christos return VT100_EMUL_STATE_SCS96;
618 1.19 junyoung case '#':
619 1.43 christos return VT100_EMUL_STATE_ESC_HASH;
620 1.19 junyoung case ' ': /* 7/8 bit */
621 1.43 christos return VT100_EMUL_STATE_ESC_SPC;
622 1.19 junyoung case ']': /* OSC operating system command */
623 1.19 junyoung case '^': /* PM privacy message */
624 1.19 junyoung case '_': /* APC application program command */
625 1.1 drochner /* ignored */
626 1.43 christos return VT100_EMUL_STATE_STRING;
627 1.19 junyoung case '<': /* exit VT52 mode - ignored */
628 1.1 drochner break;
629 1.19 junyoung default:
630 1.1 drochner #ifdef VT100_PRINTUNKNOWN
631 1.51 christos printf("%s: ESC%c unknown\n", __func__, c);
632 1.1 drochner #endif
633 1.1 drochner break;
634 1.1 drochner }
635 1.43 christos return VT100_EMUL_STATE_NORMAL;
636 1.1 drochner }
637 1.1 drochner
638 1.1 drochner static u_int
639 1.15 augustss wsemul_vt100_output_scs94(struct wsemul_vt100_emuldata *edp, u_char c)
640 1.1 drochner {
641 1.1 drochner switch (c) {
642 1.19 junyoung case '%': /* probably DEC supplemental graphic */
643 1.43 christos return VT100_EMUL_STATE_SCS94_PERCENT;
644 1.19 junyoung case 'A': /* british / national */
645 1.3 drochner edp->chartab_G[edp->designating] = edp->nrctab;
646 1.3 drochner break;
647 1.19 junyoung case 'B': /* ASCII */
648 1.3 drochner edp->chartab_G[edp->designating] = 0;
649 1.3 drochner break;
650 1.19 junyoung case '<': /* user preferred supplemental */
651 1.3 drochner /* XXX not really "user" preferred */
652 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
653 1.3 drochner break;
654 1.19 junyoung case '0': /* DEC special graphic */
655 1.3 drochner edp->chartab_G[edp->designating] = edp->decgraphtab;
656 1.3 drochner break;
657 1.19 junyoung case '>': /* DEC tech */
658 1.3 drochner edp->chartab_G[edp->designating] = edp->dectechtab;
659 1.1 drochner break;
660 1.19 junyoung default:
661 1.1 drochner #ifdef VT100_PRINTUNKNOWN
662 1.51 christos printf("%s: ESC%c%c unknown\n", __func__,
663 1.51 christos edp->designating + '(', c);
664 1.1 drochner #endif
665 1.1 drochner break;
666 1.1 drochner }
667 1.43 christos return VT100_EMUL_STATE_NORMAL;
668 1.1 drochner }
669 1.1 drochner
670 1.1 drochner static u_int
671 1.15 augustss wsemul_vt100_output_scs94_percent(struct wsemul_vt100_emuldata *edp, u_char c)
672 1.1 drochner {
673 1.1 drochner switch (c) {
674 1.19 junyoung case '5': /* DEC supplemental graphic */
675 1.3 drochner /* XXX there are differences */
676 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
677 1.1 drochner break;
678 1.19 junyoung default:
679 1.1 drochner #ifdef VT100_PRINTUNKNOWN
680 1.51 christos printf("%s: ESC%c%%%c unknown\n",
681 1.51 christos __func__, edp->designating + '(', c);
682 1.1 drochner #endif
683 1.1 drochner break;
684 1.1 drochner }
685 1.43 christos return VT100_EMUL_STATE_NORMAL;
686 1.1 drochner }
687 1.1 drochner
688 1.1 drochner static u_int
689 1.15 augustss wsemul_vt100_output_scs96(struct wsemul_vt100_emuldata *edp, u_char c)
690 1.1 drochner {
691 1.3 drochner int nrc;
692 1.1 drochner
693 1.1 drochner switch (c) {
694 1.31 snj case '%': /* probably portuguese */
695 1.43 christos return VT100_EMUL_STATE_SCS96_PERCENT;
696 1.19 junyoung case 'A': /* ISO-latin-1 supplemental */
697 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
698 1.3 drochner break;
699 1.19 junyoung case '4': /* dutch */
700 1.3 drochner nrc = 1;
701 1.3 drochner goto setnrc;
702 1.19 junyoung case '5': case 'C': /* finnish */
703 1.3 drochner nrc = 2;
704 1.3 drochner goto setnrc;
705 1.19 junyoung case 'R': /* french */
706 1.3 drochner nrc = 3;
707 1.3 drochner goto setnrc;
708 1.19 junyoung case 'Q': /* french canadian */
709 1.3 drochner nrc = 4;
710 1.3 drochner goto setnrc;
711 1.19 junyoung case 'K': /* german */
712 1.3 drochner nrc = 5;
713 1.3 drochner goto setnrc;
714 1.19 junyoung case 'Y': /* italian */
715 1.3 drochner nrc = 6;
716 1.3 drochner goto setnrc;
717 1.19 junyoung case 'E': case '6': /* norwegian / danish */
718 1.3 drochner nrc = 7;
719 1.3 drochner goto setnrc;
720 1.19 junyoung case 'Z': /* spanish */
721 1.3 drochner nrc = 9;
722 1.3 drochner goto setnrc;
723 1.19 junyoung case '7': case 'H': /* swedish */
724 1.3 drochner nrc = 10;
725 1.3 drochner goto setnrc;
726 1.19 junyoung case '=': /* swiss */
727 1.3 drochner nrc = 11;
728 1.3 drochner setnrc:
729 1.3 drochner vt100_setnrc(edp, nrc); /* what table ??? */
730 1.1 drochner break;
731 1.19 junyoung default:
732 1.1 drochner #ifdef VT100_PRINTUNKNOWN
733 1.51 christos printf("%s: ESC%c%c unknown\n",
734 1.51 christos __func__, edp->designating + '-' - 1, c);
735 1.1 drochner #endif
736 1.1 drochner break;
737 1.1 drochner }
738 1.43 christos return VT100_EMUL_STATE_NORMAL;
739 1.1 drochner }
740 1.1 drochner
741 1.1 drochner static u_int
742 1.15 augustss wsemul_vt100_output_scs96_percent(struct wsemul_vt100_emuldata *edp, u_char c)
743 1.1 drochner {
744 1.1 drochner switch (c) {
745 1.31 snj case '6': /* portuguese */
746 1.3 drochner vt100_setnrc(edp, 8);
747 1.1 drochner break;
748 1.19 junyoung default:
749 1.1 drochner #ifdef VT100_PRINTUNKNOWN
750 1.51 christos printf("%s: ESC%c%%%c unknown\n",
751 1.51 christos __func__, edp->designating + '-', c);
752 1.1 drochner #endif
753 1.1 drochner break;
754 1.1 drochner }
755 1.43 christos return VT100_EMUL_STATE_NORMAL;
756 1.1 drochner }
757 1.1 drochner
758 1.1 drochner static u_int
759 1.30 christos wsemul_vt100_output_esc_spc(struct wsemul_vt100_emuldata *edp,
760 1.29 christos u_char c)
761 1.1 drochner {
762 1.1 drochner switch (c) {
763 1.19 junyoung case 'F': /* 7-bit controls */
764 1.19 junyoung case 'G': /* 8-bit controls */
765 1.1 drochner #ifdef VT100_PRINTNOTIMPL
766 1.51 christos printf("%s: ESC<SPC>%c ignored\n", __func__, c);
767 1.1 drochner #endif
768 1.1 drochner break;
769 1.19 junyoung default:
770 1.1 drochner #ifdef VT100_PRINTUNKNOWN
771 1.51 christos printf("%s: ESC<SPC>%c unknown\n", __func__, c);
772 1.1 drochner #endif
773 1.1 drochner break;
774 1.1 drochner }
775 1.43 christos return VT100_EMUL_STATE_NORMAL;
776 1.1 drochner }
777 1.1 drochner
778 1.1 drochner static u_int
779 1.15 augustss wsemul_vt100_output_string(struct wsemul_vt100_emuldata *edp, u_char c)
780 1.1 drochner {
781 1.32 drochner struct vt100base_data *vd = &edp->bd;
782 1.32 drochner
783 1.32 drochner if (vd->dcstype && vd->dcspos < DCS_MAXLEN)
784 1.32 drochner vd->dcsarg[vd->dcspos++] = c;
785 1.43 christos return VT100_EMUL_STATE_STRING;
786 1.1 drochner }
787 1.1 drochner
788 1.1 drochner static u_int
789 1.15 augustss wsemul_vt100_output_string_esc(struct wsemul_vt100_emuldata *edp, u_char c)
790 1.1 drochner {
791 1.32 drochner struct vt100base_data *vd = &edp->bd;
792 1.32 drochner
793 1.1 drochner if (c == '\\') { /* ST complete */
794 1.32 drochner wsemul_vt100_handle_dcs(vd);
795 1.43 christos return VT100_EMUL_STATE_NORMAL;
796 1.1 drochner } else
797 1.43 christos return VT100_EMUL_STATE_STRING;
798 1.1 drochner }
799 1.1 drochner
800 1.1 drochner static u_int
801 1.15 augustss wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c)
802 1.1 drochner {
803 1.32 drochner struct vt100base_data *vd = &edp->bd;
804 1.1 drochner
805 1.1 drochner switch (c) {
806 1.19 junyoung case '0': case '1': case '2': case '3': case '4':
807 1.19 junyoung case '5': case '6': case '7': case '8': case '9':
808 1.1 drochner /* argument digit */
809 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS - 1)
810 1.1 drochner break;
811 1.32 drochner vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
812 1.1 drochner (c - '0');
813 1.1 drochner break;
814 1.19 junyoung default:
815 1.32 drochner vd->nargs++;
816 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS) {
817 1.1 drochner #ifdef VT100_DEBUG
818 1.51 christos printf("%s: too many arguments\n", __func__);
819 1.1 drochner #endif
820 1.32 drochner vd->nargs = VT100_EMUL_NARGS;
821 1.1 drochner }
822 1.51 christos if (c == ';') /* argument terminator */
823 1.51 christos break;
824 1.1 drochner switch (c) {
825 1.19 junyoung case '$':
826 1.43 christos return VT100_EMUL_STATE_DCS_DOLLAR;
827 1.19 junyoung case '{': /* DECDLD soft charset */
828 1.19 junyoung case '!': /* DECRQUPSS user preferred supplemental set */
829 1.1 drochner /* 'u' must follow - need another state */
830 1.19 junyoung case '|': /* DECUDK program F6..F20 */
831 1.1 drochner #ifdef VT100_PRINTNOTIMPL
832 1.51 christos printf("%s: DCS%c ignored\n", __func__, c);
833 1.1 drochner #endif
834 1.1 drochner break;
835 1.19 junyoung default:
836 1.1 drochner #ifdef VT100_PRINTUNKNOWN
837 1.51 christos printf("%s: DCS%c (%d, %d) unknown\n",
838 1.51 christos __func__, c, ARG(vd, 0), ARG(vd, 1));
839 1.1 drochner #endif
840 1.1 drochner break;
841 1.1 drochner }
842 1.44 martin return VT100_EMUL_STATE_STRING;
843 1.1 drochner }
844 1.1 drochner
845 1.43 christos return VT100_EMUL_STATE_DCS;
846 1.1 drochner }
847 1.1 drochner
848 1.1 drochner static u_int
849 1.15 augustss wsemul_vt100_output_dcs_dollar(struct wsemul_vt100_emuldata *edp, u_char c)
850 1.1 drochner {
851 1.32 drochner struct vt100base_data *vd = &edp->bd;
852 1.32 drochner
853 1.1 drochner switch (c) {
854 1.19 junyoung case 'p': /* DECRSTS terminal state restore */
855 1.19 junyoung case 'q': /* DECRQSS control function request */
856 1.1 drochner #ifdef VT100_PRINTNOTIMPL
857 1.51 christos printf("%s: DCS$%c ignored\n", __func__, c);
858 1.1 drochner #endif
859 1.1 drochner break;
860 1.19 junyoung case 't': /* DECRSPS restore presentation state */
861 1.32 drochner switch (ARG(vd, 0)) {
862 1.19 junyoung case 0: /* error */
863 1.1 drochner break;
864 1.19 junyoung case 1: /* cursor information restore */
865 1.1 drochner #ifdef VT100_PRINTNOTIMPL
866 1.51 christos printf("%s: DCS1$t ignored\n", __func__);
867 1.1 drochner #endif
868 1.1 drochner break;
869 1.19 junyoung case 2: /* tab stop restore */
870 1.32 drochner vd->dcspos = 0;
871 1.32 drochner vd->dcstype = DCSTYPE_TABRESTORE;
872 1.1 drochner break;
873 1.19 junyoung default:
874 1.1 drochner #ifdef VT100_PRINTUNKNOWN
875 1.51 christos printf("%s: DCS%d$t unknown\n", __func__, ARG(vd, 0));
876 1.1 drochner #endif
877 1.1 drochner break;
878 1.1 drochner }
879 1.1 drochner break;
880 1.19 junyoung default:
881 1.1 drochner #ifdef VT100_PRINTUNKNOWN
882 1.51 christos printf("%s: DCS$%c (%d, %d) unknown\n",
883 1.51 christos __func__, c, ARG(vd, 0), ARG(vd, 1));
884 1.1 drochner #endif
885 1.1 drochner break;
886 1.1 drochner }
887 1.43 christos return VT100_EMUL_STATE_STRING;
888 1.1 drochner }
889 1.1 drochner
890 1.1 drochner static u_int
891 1.15 augustss wsemul_vt100_output_esc_hash(struct wsemul_vt100_emuldata *edp, u_char c)
892 1.1 drochner {
893 1.32 drochner struct vt100base_data *vd = &edp->bd;
894 1.23 drochner int i, j;
895 1.1 drochner
896 1.1 drochner switch (c) {
897 1.19 junyoung case '5': /* DECSWL single width, single height */
898 1.32 drochner if (vd->dw) {
899 1.32 drochner for (i = 0; i < vd->ncols / 2; i++)
900 1.32 drochner (*vd->emulops->copycols)(vd->emulcookie,
901 1.32 drochner vd->crow,
902 1.3 drochner 2 * i, i, 1);
903 1.32 drochner (*vd->emulops->erasecols)(vd->emulcookie, vd->crow,
904 1.32 drochner i, vd->ncols - i,
905 1.32 drochner vd->bkgdattr);
906 1.32 drochner vd->dblwid[vd->crow] = 0;
907 1.32 drochner vd->dw = 0;
908 1.1 drochner }
909 1.1 drochner break;
910 1.19 junyoung case '6': /* DECDWL double width, single height */
911 1.19 junyoung case '3': /* DECDHL double width, double height, top half */
912 1.19 junyoung case '4': /* DECDHL double width, double height, bottom half */
913 1.32 drochner if (!vd->dw) {
914 1.32 drochner for (i = vd->ncols / 2 - 1; i >= 0; i--)
915 1.32 drochner (*vd->emulops->copycols)(vd->emulcookie,
916 1.32 drochner vd->crow,
917 1.3 drochner i, 2 * i, 1);
918 1.32 drochner for (i = 0; i < vd->ncols / 2; i++)
919 1.32 drochner (*vd->emulops->erasecols)(vd->emulcookie,
920 1.32 drochner vd->crow,
921 1.3 drochner 2 * i + 1, 1,
922 1.32 drochner vd->bkgdattr);
923 1.32 drochner vd->dblwid[vd->crow] = 1;
924 1.32 drochner vd->dw = 1;
925 1.32 drochner if (vd->ccol > (vd->ncols >> 1) - 1)
926 1.32 drochner vd->ccol = (vd->ncols >> 1) - 1;
927 1.3 drochner }
928 1.1 drochner break;
929 1.23 drochner case '8': /* DECALN */
930 1.32 drochner for (i = 0; i < vd->nrows; i++)
931 1.32 drochner for (j = 0; j < vd->ncols; j++)
932 1.32 drochner (*vd->emulops->putchar)(vd->emulcookie, i, j,
933 1.32 drochner 'E', vd->curattr);
934 1.32 drochner vd->ccol = 0;
935 1.32 drochner vd->crow = 0;
936 1.1 drochner break;
937 1.19 junyoung default:
938 1.1 drochner #ifdef VT100_PRINTUNKNOWN
939 1.51 christos printf("%s: ESC#%c unknown\n", __func__, c);
940 1.1 drochner #endif
941 1.1 drochner break;
942 1.1 drochner }
943 1.43 christos return VT100_EMUL_STATE_NORMAL;
944 1.1 drochner }
945 1.1 drochner
946 1.1 drochner static u_int
947 1.15 augustss wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c)
948 1.1 drochner {
949 1.32 drochner struct vt100base_data *vd = &edp->bd;
950 1.1 drochner
951 1.1 drochner switch (c) {
952 1.19 junyoung case '0': case '1': case '2': case '3': case '4':
953 1.19 junyoung case '5': case '6': case '7': case '8': case '9':
954 1.1 drochner /* argument digit */
955 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS - 1)
956 1.1 drochner break;
957 1.32 drochner vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
958 1.1 drochner (c - '0');
959 1.1 drochner break;
960 1.19 junyoung case '?': /* DEC specific */
961 1.19 junyoung case '>': /* DA query */
962 1.32 drochner vd->modif1 = c;
963 1.1 drochner break;
964 1.19 junyoung case '!':
965 1.19 junyoung case '"':
966 1.19 junyoung case '$':
967 1.19 junyoung case '&':
968 1.32 drochner vd->modif2 = c;
969 1.1 drochner break;
970 1.51 christos default: /* end of escape sequence, argument terminator */
971 1.32 drochner vd->nargs++;
972 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS) {
973 1.1 drochner #ifdef VT100_DEBUG
974 1.51 christos printf("%s: too many arguments\n", __func__);
975 1.1 drochner #endif
976 1.32 drochner vd->nargs = VT100_EMUL_NARGS;
977 1.1 drochner }
978 1.51 christos if (c == ';') /* argument terminator */
979 1.51 christos break;
980 1.32 drochner wsemul_vt100_handle_csi(vd, c);
981 1.43 christos return VT100_EMUL_STATE_NORMAL;
982 1.1 drochner }
983 1.43 christos return VT100_EMUL_STATE_CSI;
984 1.1 drochner }
985 1.1 drochner
986 1.49 uwe static void
987 1.15 augustss wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
988 1.1 drochner {
989 1.1 drochner struct wsemul_vt100_emuldata *edp = cookie;
990 1.32 drochner struct vt100base_data *vd = &edp->bd;
991 1.1 drochner
992 1.1 drochner #ifdef DIAGNOSTIC
993 1.1 drochner if (kernel && !edp->console)
994 1.43 christos panic("%s: kernel output, not console", __func__);
995 1.1 drochner #endif
996 1.1 drochner
997 1.32 drochner if (vd->flags & VTFL_CURSORON)
998 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie, 0,
999 1.32 drochner vd->crow, vd->ccol << vd->dw);
1000 1.1 drochner for (; count > 0; data++, count--) {
1001 1.7 drochner if ((*data & 0x7f) < 0x20) {
1002 1.7 drochner wsemul_vt100_output_c0c1(edp, *data, kernel);
1003 1.7 drochner continue;
1004 1.7 drochner }
1005 1.1 drochner if (edp->state == VT100_EMUL_STATE_NORMAL || kernel) {
1006 1.7 drochner wsemul_vt100_output_normal(edp, *data, kernel);
1007 1.1 drochner continue;
1008 1.1 drochner }
1009 1.43 christos int state = edp->state - 1;
1010 1.43 christos KASSERT(state < __arraycount(vt100_output));
1011 1.43 christos edp->state = vt100_output[state](edp, *data);
1012 1.1 drochner }
1013 1.32 drochner if (vd->flags & VTFL_CURSORON)
1014 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie, 1,
1015 1.43 christos vd->crow, vd->ccol << vd->dw);
1016 1.1 drochner }
1017 1.26 jmmv
1018 1.26 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
1019 1.26 jmmv static void
1020 1.26 jmmv wsemul_vt100_getmsgattrs(void *cookie, struct wsdisplay_msgattrs *ma)
1021 1.26 jmmv {
1022 1.26 jmmv struct wsemul_vt100_emuldata *edp = cookie;
1023 1.35 drochner struct vt100base_data *vd = &edp->bd;
1024 1.26 jmmv
1025 1.32 drochner *ma = vd->msgattrs;
1026 1.26 jmmv }
1027 1.26 jmmv
1028 1.26 jmmv static void
1029 1.26 jmmv wsemul_vt100_setmsgattrs(void *cookie, const struct wsscreen_descr *type,
1030 1.26 jmmv const struct wsdisplay_msgattrs *ma)
1031 1.26 jmmv {
1032 1.26 jmmv int error;
1033 1.26 jmmv long tmp;
1034 1.26 jmmv struct wsemul_vt100_emuldata *edp = cookie;
1035 1.35 drochner struct vt100base_data *vd = &edp->bd;
1036 1.26 jmmv
1037 1.32 drochner vd->msgattrs = *ma;
1038 1.26 jmmv if (type->capabilities & WSSCREEN_WSCOLORS) {
1039 1.32 drochner vd->msgattrs.default_attrs |= WSATTR_WSCOLORS;
1040 1.32 drochner vd->msgattrs.kernel_attrs |= WSATTR_WSCOLORS;
1041 1.26 jmmv } else {
1042 1.32 drochner vd->msgattrs.default_bg = vd->msgattrs.kernel_bg = 0;
1043 1.32 drochner vd->msgattrs.default_fg = vd->msgattrs.kernel_fg = 0;
1044 1.26 jmmv }
1045 1.26 jmmv
1046 1.32 drochner error = (*vd->emulops->allocattr)(vd->emulcookie,
1047 1.32 drochner vd->msgattrs.default_fg,
1048 1.32 drochner vd->msgattrs.default_bg,
1049 1.32 drochner vd->msgattrs.default_attrs,
1050 1.26 jmmv &tmp);
1051 1.36 mrg #ifndef VT100_DEBUG
1052 1.36 mrg __USE(error);
1053 1.36 mrg #else
1054 1.26 jmmv if (error)
1055 1.51 christos printf("%s: failed to allocate attribute for default "
1056 1.51 christos "messages\n", __func__);
1057 1.26 jmmv else
1058 1.26 jmmv #endif
1059 1.26 jmmv {
1060 1.32 drochner if (vd->curattr == vd->defattr) {
1061 1.32 drochner vd->bkgdattr = vd->curattr = tmp;
1062 1.32 drochner vd->attrflags = vd->msgattrs.default_attrs;
1063 1.32 drochner vd->bgcol = vd->msgattrs.default_bg;
1064 1.32 drochner vd->fgcol = vd->msgattrs.default_fg;
1065 1.26 jmmv } else {
1066 1.26 jmmv edp->savedbkgdattr = edp->savedattr = tmp;
1067 1.32 drochner edp->savedattrflags = vd->msgattrs.default_attrs;
1068 1.32 drochner edp->savedbgcol = vd->msgattrs.default_bg;
1069 1.32 drochner edp->savedfgcol = vd->msgattrs.default_fg;
1070 1.26 jmmv }
1071 1.32 drochner if (vd->emulops->replaceattr != NULL)
1072 1.32 drochner (*vd->emulops->replaceattr)(vd->emulcookie,
1073 1.32 drochner vd->defattr, tmp);
1074 1.32 drochner vd->defattr = tmp;
1075 1.26 jmmv }
1076 1.26 jmmv
1077 1.32 drochner error = (*vd->emulops->allocattr)(vd->emulcookie,
1078 1.32 drochner vd->msgattrs.kernel_fg,
1079 1.32 drochner vd->msgattrs.kernel_bg,
1080 1.32 drochner vd->msgattrs.kernel_attrs,
1081 1.26 jmmv &tmp);
1082 1.26 jmmv #ifdef VT100_DEBUG
1083 1.26 jmmv if (error)
1084 1.51 christos printf("%s: failed to allocate attribute for kernel "
1085 1.51 christos "messages\n", __func__);
1086 1.26 jmmv else
1087 1.26 jmmv #endif
1088 1.26 jmmv {
1089 1.32 drochner if (vd->emulops->replaceattr != NULL)
1090 1.32 drochner (*vd->emulops->replaceattr)(vd->emulcookie,
1091 1.26 jmmv edp->kernattr, tmp);
1092 1.26 jmmv edp->kernattr = tmp;
1093 1.26 jmmv }
1094 1.26 jmmv }
1095 1.26 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
1096