wsemul_vt100.c revision 1.49 1 1.49 uwe /* $NetBSD: wsemul_vt100.c,v 1.49 2022/01/02 23:46:21 uwe 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.49 uwe __KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.49 2022/01/02 23:46:21 uwe 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.38 macallan edp->bd.nrows = type->nrows;
297 1.38 macallan edp->bd.ncols = type->ncols;
298 1.38 macallan wsemul_vt100_reset(edp);
299 1.38 macallan wsemul_vt100_resetop(cookie, WSEMUL_CLEARSCREEN);
300 1.38 macallan }
301 1.38 macallan
302 1.49 uwe static void
303 1.15 augustss wsemul_vt100_resetop(void *cookie, enum wsemul_resetops op)
304 1.9 drochner {
305 1.9 drochner struct wsemul_vt100_emuldata *edp = cookie;
306 1.32 drochner struct vt100base_data *vd = &edp->bd;
307 1.9 drochner
308 1.9 drochner switch (op) {
309 1.9 drochner case WSEMUL_RESET:
310 1.9 drochner wsemul_vt100_reset(edp);
311 1.9 drochner break;
312 1.9 drochner case WSEMUL_SYNCFONT:
313 1.9 drochner vt100_initchartables(edp);
314 1.10 drochner break;
315 1.10 drochner case WSEMUL_CLEARSCREEN:
316 1.32 drochner wsemul_vt100_ed(vd, 2);
317 1.32 drochner vd->ccol = vd->crow = 0;
318 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie,
319 1.32 drochner vd->flags & VTFL_CURSORON, 0, 0);
320 1.10 drochner break;
321 1.10 drochner default:
322 1.9 drochner break;
323 1.9 drochner }
324 1.1 drochner }
325 1.1 drochner
326 1.1 drochner void
327 1.15 augustss wsemul_vt100_reset(struct wsemul_vt100_emuldata *edp)
328 1.1 drochner {
329 1.32 drochner struct vt100base_data *vd = &edp->bd;
330 1.1 drochner int i;
331 1.1 drochner
332 1.1 drochner edp->state = VT100_EMUL_STATE_NORMAL;
333 1.32 drochner vd->flags = VTFL_DECAWM | VTFL_CURSORON;
334 1.32 drochner vd->bkgdattr = vd->curattr = vd->defattr;
335 1.32 drochner vd->attrflags = vd->msgattrs.default_attrs;
336 1.32 drochner vd->fgcol = vd->msgattrs.default_fg;
337 1.32 drochner vd->bgcol = vd->msgattrs.default_bg;
338 1.32 drochner vd->scrreg_startrow = 0;
339 1.32 drochner vd->scrreg_nrows = vd->nrows;
340 1.32 drochner if (vd->tabs) {
341 1.32 drochner memset(vd->tabs, 0, vd->ncols);
342 1.32 drochner for (i = 8; i < vd->ncols; i += 8)
343 1.32 drochner vd->tabs[i] = 1;
344 1.1 drochner }
345 1.32 drochner vd->dcspos = 0;
346 1.32 drochner vd->dcstype = 0;
347 1.3 drochner edp->chartab_G[0] = 0;
348 1.3 drochner edp->chartab_G[1] = edp->nrctab; /* ??? */
349 1.3 drochner edp->chartab_G[2] = edp->isolatin1tab;
350 1.3 drochner edp->chartab_G[3] = edp->isolatin1tab;
351 1.3 drochner edp->chartab0 = 0;
352 1.3 drochner edp->chartab1 = 2;
353 1.3 drochner edp->sschartab = 0;
354 1.1 drochner }
355 1.1 drochner
356 1.1 drochner /*
357 1.1 drochner * now all the state machine bits
358 1.1 drochner */
359 1.1 drochner
360 1.21 sommerfe /*
361 1.21 sommerfe * Move the cursor to the next line if possible. If the cursor is at
362 1.21 sommerfe * the bottom of the scroll area, then scroll it up. If the cursor is
363 1.21 sommerfe * at the bottom of the screen then don't move it down.
364 1.21 sommerfe */
365 1.7 drochner static void
366 1.21 sommerfe wsemul_vt100_nextline(struct wsemul_vt100_emuldata *edp)
367 1.21 sommerfe {
368 1.32 drochner struct vt100base_data *vd = &edp->bd;
369 1.32 drochner
370 1.32 drochner if (ROWS_BELOW(vd) == 0) {
371 1.21 sommerfe /* Bottom of the scroll region. */
372 1.32 drochner wsemul_vt100_scrollup(vd, 1);
373 1.21 sommerfe } else {
374 1.32 drochner if ((vd->crow+1) < vd->nrows)
375 1.21 sommerfe /* Cursor not at the bottom of the screen. */
376 1.32 drochner vd->crow++;
377 1.32 drochner CHECK_DW(vd);
378 1.21 sommerfe }
379 1.27 perry }
380 1.21 sommerfe
381 1.22 sommerfe static void
382 1.15 augustss wsemul_vt100_output_normal(struct wsemul_vt100_emuldata *edp, u_char c,
383 1.15 augustss int kernel)
384 1.1 drochner {
385 1.32 drochner struct vt100base_data *vd = &edp->bd;
386 1.7 drochner u_int *ct, dc;
387 1.7 drochner
388 1.32 drochner if ((vd->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
389 1.7 drochner (VTFL_LASTCHAR | VTFL_DECAWM)) {
390 1.21 sommerfe wsemul_vt100_nextline(edp);
391 1.32 drochner vd->ccol = 0;
392 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
393 1.7 drochner }
394 1.7 drochner
395 1.7 drochner if (c & 0x80) {
396 1.7 drochner c &= 0x7f;
397 1.7 drochner ct = edp->chartab_G[edp->chartab1];
398 1.7 drochner } else {
399 1.7 drochner if (edp->sschartab) {
400 1.7 drochner ct = edp->chartab_G[edp->sschartab];
401 1.7 drochner edp->sschartab = 0;
402 1.7 drochner } else
403 1.7 drochner ct = edp->chartab_G[edp->chartab0];
404 1.7 drochner }
405 1.7 drochner dc = (ct ? ct[c] : c);
406 1.7 drochner
407 1.32 drochner if ((vd->flags & VTFL_INSERTMODE) && COLS_LEFT(vd))
408 1.32 drochner COPYCOLS(vd, vd->ccol, vd->ccol + 1, COLS_LEFT(vd));
409 1.7 drochner
410 1.32 drochner (*vd->emulops->putchar)(vd->emulcookie, vd->crow,
411 1.32 drochner vd->ccol << vd->dw, dc,
412 1.32 drochner kernel ? edp->kernattr : vd->curattr);
413 1.7 drochner
414 1.32 drochner if (COLS_LEFT(vd))
415 1.32 drochner vd->ccol++;
416 1.7 drochner else
417 1.32 drochner vd->flags |= VTFL_LASTCHAR;
418 1.7 drochner }
419 1.7 drochner
420 1.7 drochner static void
421 1.27 perry wsemul_vt100_output_c0c1(struct wsemul_vt100_emuldata *edp, u_char c,
422 1.15 augustss int kernel)
423 1.7 drochner {
424 1.32 drochner struct vt100base_data *vd = &edp->bd;
425 1.7 drochner u_int n;
426 1.1 drochner
427 1.1 drochner switch (c) {
428 1.19 junyoung case ASCII_NUL:
429 1.19 junyoung default:
430 1.1 drochner /* ignore */
431 1.1 drochner break;
432 1.19 junyoung case ASCII_BEL:
433 1.47 christos if (edp->state == VT100_EMUL_STATE_STRING) {
434 1.47 christos /* acts as an equivalent to the ``ESC \'' string end */
435 1.47 christos wsemul_vt100_handle_dcs(vd);
436 1.47 christos edp->state = VT100_EMUL_STATE_NORMAL;
437 1.47 christos } else {
438 1.47 christos wsdisplay_emulbell(vd->cbcookie);
439 1.47 christos }
440 1.1 drochner break;
441 1.19 junyoung case ASCII_BS:
442 1.32 drochner if (vd->ccol > 0) {
443 1.32 drochner vd->ccol--;
444 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
445 1.1 drochner }
446 1.1 drochner break;
447 1.19 junyoung case ASCII_CR:
448 1.32 drochner vd->ccol = 0;
449 1.32 drochner vd->flags &= ~VTFL_LASTCHAR;
450 1.1 drochner break;
451 1.19 junyoung case ASCII_HT:
452 1.32 drochner if (vd->tabs) {
453 1.32 drochner if (!COLS_LEFT(vd))
454 1.1 drochner break;
455 1.32 drochner for (n = vd->ccol + 1; n < NCOLS(vd) - 1; n++)
456 1.32 drochner if (vd->tabs[n])
457 1.1 drochner break;
458 1.1 drochner } else {
459 1.45 riastrad n = vd->ccol + uimin(8 - (vd->ccol & 7), COLS_LEFT(vd));
460 1.1 drochner }
461 1.32 drochner vd->ccol = n;
462 1.1 drochner break;
463 1.19 junyoung case ASCII_SO: /* LS1 */
464 1.3 drochner edp->chartab0 = 1;
465 1.3 drochner break;
466 1.19 junyoung case ASCII_SI: /* LS0 */
467 1.3 drochner edp->chartab0 = 0;
468 1.1 drochner break;
469 1.19 junyoung case ASCII_ESC:
470 1.14 jdolecek if (kernel) {
471 1.43 christos printf("%s: ESC in kernel output ignored\n", __func__);
472 1.14 jdolecek break; /* ignore the ESC */
473 1.14 jdolecek }
474 1.14 jdolecek
475 1.7 drochner if (edp->state == VT100_EMUL_STATE_STRING) {
476 1.7 drochner /* might be a string end */
477 1.7 drochner edp->state = VT100_EMUL_STATE_STRING_ESC;
478 1.7 drochner } else {
479 1.7 drochner /* XXX cancel current escape sequence */
480 1.7 drochner edp->state = VT100_EMUL_STATE_ESC;
481 1.7 drochner }
482 1.1 drochner break;
483 1.1 drochner #if 0
484 1.19 junyoung case CSI: /* 8-bit */
485 1.7 drochner /* XXX cancel current escape sequence */
486 1.1 drochner edp->nargs = 0;
487 1.8 augustss memset(edp->args, 0, sizeof (edp->args));
488 1.3 drochner edp->modif1 = edp->modif2 = '\0';
489 1.7 drochner edp->state = VT100_EMUL_STATE_CSI;
490 1.1 drochner break;
491 1.19 junyoung case DCS: /* 8-bit */
492 1.7 drochner /* XXX cancel current escape sequence */
493 1.1 drochner edp->nargs = 0;
494 1.8 augustss memset(edp->args, 0, sizeof (edp->args));
495 1.7 drochner edp->state = VT100_EMUL_STATE_DCS;
496 1.1 drochner break;
497 1.19 junyoung case ST: /* string end 8-bit */
498 1.7 drochner /* XXX only in VT100_EMUL_STATE_STRING */
499 1.47 christos wsemul_vt100_handle_dcs(vd);
500 1.43 christos edp->state = VT100_EMUL_STATE_NORMAL;
501 1.43 christos break;
502 1.1 drochner #endif
503 1.19 junyoung case ASCII_LF:
504 1.19 junyoung case ASCII_VT:
505 1.19 junyoung case ASCII_FF:
506 1.21 sommerfe wsemul_vt100_nextline(edp);
507 1.1 drochner break;
508 1.1 drochner }
509 1.1 drochner }
510 1.1 drochner
511 1.1 drochner static u_int
512 1.15 augustss wsemul_vt100_output_esc(struct wsemul_vt100_emuldata *edp, u_char c)
513 1.1 drochner {
514 1.32 drochner struct vt100base_data *vd = &edp->bd;
515 1.3 drochner int i;
516 1.1 drochner
517 1.1 drochner switch (c) {
518 1.19 junyoung case '[': /* CSI */
519 1.32 drochner vd->nargs = 0;
520 1.32 drochner memset(vd->args, 0, sizeof (vd->args));
521 1.32 drochner vd->modif1 = vd->modif2 = '\0';
522 1.43 christos return VT100_EMUL_STATE_CSI;
523 1.19 junyoung case '7': /* DECSC */
524 1.32 drochner vd->flags |= VTFL_SAVEDCURS;
525 1.32 drochner edp->savedcursor_row = vd->crow;
526 1.32 drochner edp->savedcursor_col = vd->ccol;
527 1.32 drochner edp->savedattr = vd->curattr;
528 1.32 drochner edp->savedbkgdattr = vd->bkgdattr;
529 1.32 drochner edp->savedattrflags = vd->attrflags;
530 1.32 drochner edp->savedfgcol = vd->fgcol;
531 1.32 drochner edp->savedbgcol = vd->bgcol;
532 1.3 drochner for (i = 0; i < 4; i++)
533 1.3 drochner edp->savedchartab_G[i] = edp->chartab_G[i];
534 1.3 drochner edp->savedchartab0 = edp->chartab0;
535 1.3 drochner edp->savedchartab1 = edp->chartab1;
536 1.1 drochner break;
537 1.19 junyoung case '8': /* DECRC */
538 1.32 drochner if ((vd->flags & VTFL_SAVEDCURS) == 0)
539 1.24 christos break;
540 1.32 drochner vd->crow = edp->savedcursor_row;
541 1.32 drochner vd->ccol = edp->savedcursor_col;
542 1.32 drochner vd->curattr = edp->savedattr;
543 1.32 drochner vd->bkgdattr = edp->savedbkgdattr;
544 1.32 drochner vd->attrflags = edp->savedattrflags;
545 1.32 drochner vd->fgcol = edp->savedfgcol;
546 1.32 drochner vd->bgcol = edp->savedbgcol;
547 1.3 drochner for (i = 0; i < 4; i++)
548 1.3 drochner edp->chartab_G[i] = edp->savedchartab_G[i];
549 1.3 drochner edp->chartab0 = edp->savedchartab0;
550 1.3 drochner edp->chartab1 = edp->savedchartab1;
551 1.1 drochner break;
552 1.19 junyoung case '=': /* DECKPAM application mode */
553 1.32 drochner vd->flags |= VTFL_APPLKEYPAD;
554 1.1 drochner break;
555 1.19 junyoung case '>': /* DECKPNM numeric mode */
556 1.32 drochner vd->flags &= ~VTFL_APPLKEYPAD;
557 1.1 drochner break;
558 1.19 junyoung case 'E': /* NEL */
559 1.32 drochner vd->ccol = 0;
560 1.1 drochner /* FALLTHRU */
561 1.19 junyoung case 'D': /* IND */
562 1.21 sommerfe wsemul_vt100_nextline(edp);
563 1.1 drochner break;
564 1.19 junyoung case 'H': /* HTS */
565 1.32 drochner KASSERT(vd->tabs != 0);
566 1.32 drochner vd->tabs[vd->ccol] = 1;
567 1.1 drochner break;
568 1.19 junyoung case '~': /* LS1R */
569 1.3 drochner edp->chartab1 = 1;
570 1.3 drochner break;
571 1.19 junyoung case 'n': /* LS2 */
572 1.3 drochner edp->chartab0 = 2;
573 1.3 drochner break;
574 1.19 junyoung case '}': /* LS2R */
575 1.3 drochner edp->chartab1 = 2;
576 1.3 drochner break;
577 1.19 junyoung case 'o': /* LS3 */
578 1.3 drochner edp->chartab0 = 3;
579 1.3 drochner break;
580 1.19 junyoung case '|': /* LS3R */
581 1.3 drochner edp->chartab1 = 3;
582 1.1 drochner break;
583 1.19 junyoung case 'N': /* SS2 */
584 1.3 drochner edp->sschartab = 2;
585 1.3 drochner break;
586 1.19 junyoung case 'O': /* SS3 */
587 1.3 drochner edp->sschartab = 3;
588 1.1 drochner break;
589 1.19 junyoung case 'M': /* RI */
590 1.32 drochner if (ROWS_ABOVE(vd) > 0) {
591 1.32 drochner vd->crow--;
592 1.32 drochner CHECK_DW(vd);
593 1.1 drochner break;
594 1.1 drochner }
595 1.32 drochner wsemul_vt100_scrolldown(vd, 1);
596 1.1 drochner break;
597 1.19 junyoung case 'P': /* DCS */
598 1.32 drochner vd->nargs = 0;
599 1.32 drochner memset(vd->args, 0, sizeof (vd->args));
600 1.43 christos return VT100_EMUL_STATE_DCS;
601 1.19 junyoung case 'c': /* RIS */
602 1.1 drochner wsemul_vt100_reset(edp);
603 1.32 drochner wsemul_vt100_ed(vd, 2);
604 1.32 drochner vd->ccol = vd->crow = 0;
605 1.1 drochner break;
606 1.19 junyoung case '(': case ')': case '*': case '+': /* SCS */
607 1.3 drochner edp->designating = c - '(';
608 1.43 christos return VT100_EMUL_STATE_SCS94;
609 1.19 junyoung case '-': case '.': case '/': /* SCS */
610 1.3 drochner edp->designating = c - '-' + 1;
611 1.43 christos return VT100_EMUL_STATE_SCS96;
612 1.19 junyoung case '#':
613 1.43 christos return VT100_EMUL_STATE_ESC_HASH;
614 1.19 junyoung case ' ': /* 7/8 bit */
615 1.43 christos return VT100_EMUL_STATE_ESC_SPC;
616 1.19 junyoung case ']': /* OSC operating system command */
617 1.19 junyoung case '^': /* PM privacy message */
618 1.19 junyoung case '_': /* APC application program command */
619 1.1 drochner /* ignored */
620 1.43 christos return VT100_EMUL_STATE_STRING;
621 1.19 junyoung case '<': /* exit VT52 mode - ignored */
622 1.1 drochner break;
623 1.19 junyoung default:
624 1.1 drochner #ifdef VT100_PRINTUNKNOWN
625 1.1 drochner printf("ESC%c unknown\n", c);
626 1.1 drochner #endif
627 1.1 drochner break;
628 1.1 drochner }
629 1.43 christos return VT100_EMUL_STATE_NORMAL;
630 1.1 drochner }
631 1.1 drochner
632 1.1 drochner static u_int
633 1.15 augustss wsemul_vt100_output_scs94(struct wsemul_vt100_emuldata *edp, u_char c)
634 1.1 drochner {
635 1.1 drochner switch (c) {
636 1.19 junyoung case '%': /* probably DEC supplemental graphic */
637 1.43 christos return VT100_EMUL_STATE_SCS94_PERCENT;
638 1.19 junyoung case 'A': /* british / national */
639 1.3 drochner edp->chartab_G[edp->designating] = edp->nrctab;
640 1.3 drochner break;
641 1.19 junyoung case 'B': /* ASCII */
642 1.3 drochner edp->chartab_G[edp->designating] = 0;
643 1.3 drochner break;
644 1.19 junyoung case '<': /* user preferred supplemental */
645 1.3 drochner /* XXX not really "user" preferred */
646 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
647 1.3 drochner break;
648 1.19 junyoung case '0': /* DEC special graphic */
649 1.3 drochner edp->chartab_G[edp->designating] = edp->decgraphtab;
650 1.3 drochner break;
651 1.19 junyoung case '>': /* DEC tech */
652 1.3 drochner edp->chartab_G[edp->designating] = edp->dectechtab;
653 1.1 drochner break;
654 1.19 junyoung default:
655 1.1 drochner #ifdef VT100_PRINTUNKNOWN
656 1.3 drochner printf("ESC%c%c unknown\n", edp->designating + '(', c);
657 1.1 drochner #endif
658 1.1 drochner break;
659 1.1 drochner }
660 1.43 christos return VT100_EMUL_STATE_NORMAL;
661 1.1 drochner }
662 1.1 drochner
663 1.1 drochner static u_int
664 1.15 augustss wsemul_vt100_output_scs94_percent(struct wsemul_vt100_emuldata *edp, u_char c)
665 1.1 drochner {
666 1.1 drochner switch (c) {
667 1.19 junyoung case '5': /* DEC supplemental graphic */
668 1.3 drochner /* XXX there are differences */
669 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
670 1.1 drochner break;
671 1.19 junyoung default:
672 1.1 drochner #ifdef VT100_PRINTUNKNOWN
673 1.3 drochner printf("ESC%c%%%c unknown\n", edp->designating + '(', c);
674 1.1 drochner #endif
675 1.1 drochner break;
676 1.1 drochner }
677 1.43 christos return VT100_EMUL_STATE_NORMAL;
678 1.1 drochner }
679 1.1 drochner
680 1.1 drochner static u_int
681 1.15 augustss wsemul_vt100_output_scs96(struct wsemul_vt100_emuldata *edp, u_char c)
682 1.1 drochner {
683 1.3 drochner int nrc;
684 1.1 drochner
685 1.1 drochner switch (c) {
686 1.31 snj case '%': /* probably portuguese */
687 1.43 christos return VT100_EMUL_STATE_SCS96_PERCENT;
688 1.19 junyoung case 'A': /* ISO-latin-1 supplemental */
689 1.3 drochner edp->chartab_G[edp->designating] = edp->isolatin1tab;
690 1.3 drochner break;
691 1.19 junyoung case '4': /* dutch */
692 1.3 drochner nrc = 1;
693 1.3 drochner goto setnrc;
694 1.19 junyoung case '5': case 'C': /* finnish */
695 1.3 drochner nrc = 2;
696 1.3 drochner goto setnrc;
697 1.19 junyoung case 'R': /* french */
698 1.3 drochner nrc = 3;
699 1.3 drochner goto setnrc;
700 1.19 junyoung case 'Q': /* french canadian */
701 1.3 drochner nrc = 4;
702 1.3 drochner goto setnrc;
703 1.19 junyoung case 'K': /* german */
704 1.3 drochner nrc = 5;
705 1.3 drochner goto setnrc;
706 1.19 junyoung case 'Y': /* italian */
707 1.3 drochner nrc = 6;
708 1.3 drochner goto setnrc;
709 1.19 junyoung case 'E': case '6': /* norwegian / danish */
710 1.3 drochner nrc = 7;
711 1.3 drochner goto setnrc;
712 1.19 junyoung case 'Z': /* spanish */
713 1.3 drochner nrc = 9;
714 1.3 drochner goto setnrc;
715 1.19 junyoung case '7': case 'H': /* swedish */
716 1.3 drochner nrc = 10;
717 1.3 drochner goto setnrc;
718 1.19 junyoung case '=': /* swiss */
719 1.3 drochner nrc = 11;
720 1.3 drochner setnrc:
721 1.3 drochner vt100_setnrc(edp, nrc); /* what table ??? */
722 1.1 drochner break;
723 1.19 junyoung default:
724 1.1 drochner #ifdef VT100_PRINTUNKNOWN
725 1.3 drochner printf("ESC%c%c unknown\n", edp->designating + '-' - 1, c);
726 1.1 drochner #endif
727 1.1 drochner break;
728 1.1 drochner }
729 1.43 christos return VT100_EMUL_STATE_NORMAL;
730 1.1 drochner }
731 1.1 drochner
732 1.1 drochner static u_int
733 1.15 augustss wsemul_vt100_output_scs96_percent(struct wsemul_vt100_emuldata *edp, u_char c)
734 1.1 drochner {
735 1.1 drochner switch (c) {
736 1.31 snj case '6': /* portuguese */
737 1.3 drochner vt100_setnrc(edp, 8);
738 1.1 drochner break;
739 1.19 junyoung default:
740 1.1 drochner #ifdef VT100_PRINTUNKNOWN
741 1.3 drochner printf("ESC%c%%%c unknown\n", edp->designating + '-', c);
742 1.1 drochner #endif
743 1.1 drochner break;
744 1.1 drochner }
745 1.43 christos return VT100_EMUL_STATE_NORMAL;
746 1.1 drochner }
747 1.1 drochner
748 1.1 drochner static u_int
749 1.30 christos wsemul_vt100_output_esc_spc(struct wsemul_vt100_emuldata *edp,
750 1.29 christos u_char c)
751 1.1 drochner {
752 1.1 drochner switch (c) {
753 1.19 junyoung case 'F': /* 7-bit controls */
754 1.19 junyoung case 'G': /* 8-bit controls */
755 1.1 drochner #ifdef VT100_PRINTNOTIMPL
756 1.1 drochner printf("ESC<SPC>%c ignored\n", c);
757 1.1 drochner #endif
758 1.1 drochner break;
759 1.19 junyoung default:
760 1.1 drochner #ifdef VT100_PRINTUNKNOWN
761 1.1 drochner printf("ESC<SPC>%c unknown\n", c);
762 1.1 drochner #endif
763 1.1 drochner break;
764 1.1 drochner }
765 1.43 christos return VT100_EMUL_STATE_NORMAL;
766 1.1 drochner }
767 1.1 drochner
768 1.1 drochner static u_int
769 1.15 augustss wsemul_vt100_output_string(struct wsemul_vt100_emuldata *edp, u_char c)
770 1.1 drochner {
771 1.32 drochner struct vt100base_data *vd = &edp->bd;
772 1.32 drochner
773 1.32 drochner if (vd->dcstype && vd->dcspos < DCS_MAXLEN)
774 1.32 drochner vd->dcsarg[vd->dcspos++] = c;
775 1.43 christos return VT100_EMUL_STATE_STRING;
776 1.1 drochner }
777 1.1 drochner
778 1.1 drochner static u_int
779 1.15 augustss wsemul_vt100_output_string_esc(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.1 drochner if (c == '\\') { /* ST complete */
784 1.32 drochner wsemul_vt100_handle_dcs(vd);
785 1.43 christos return VT100_EMUL_STATE_NORMAL;
786 1.1 drochner } else
787 1.43 christos return VT100_EMUL_STATE_STRING;
788 1.1 drochner }
789 1.1 drochner
790 1.1 drochner static u_int
791 1.15 augustss wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c)
792 1.1 drochner {
793 1.32 drochner struct vt100base_data *vd = &edp->bd;
794 1.1 drochner
795 1.1 drochner switch (c) {
796 1.19 junyoung case '0': case '1': case '2': case '3': case '4':
797 1.19 junyoung case '5': case '6': case '7': case '8': case '9':
798 1.1 drochner /* argument digit */
799 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS - 1)
800 1.1 drochner break;
801 1.32 drochner vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
802 1.1 drochner (c - '0');
803 1.1 drochner break;
804 1.19 junyoung case ';': /* argument terminator */
805 1.32 drochner vd->nargs++;
806 1.1 drochner break;
807 1.19 junyoung default:
808 1.32 drochner vd->nargs++;
809 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS) {
810 1.1 drochner #ifdef VT100_DEBUG
811 1.1 drochner printf("vt100: too many arguments\n");
812 1.1 drochner #endif
813 1.32 drochner vd->nargs = VT100_EMUL_NARGS;
814 1.1 drochner }
815 1.1 drochner switch (c) {
816 1.19 junyoung case '$':
817 1.43 christos return VT100_EMUL_STATE_DCS_DOLLAR;
818 1.19 junyoung case '{': /* DECDLD soft charset */
819 1.19 junyoung case '!': /* DECRQUPSS user preferred supplemental set */
820 1.1 drochner /* 'u' must follow - need another state */
821 1.19 junyoung case '|': /* DECUDK program F6..F20 */
822 1.1 drochner #ifdef VT100_PRINTNOTIMPL
823 1.1 drochner printf("DCS%c ignored\n", c);
824 1.1 drochner #endif
825 1.1 drochner break;
826 1.19 junyoung default:
827 1.1 drochner #ifdef VT100_PRINTUNKNOWN
828 1.32 drochner printf("DCS%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1));
829 1.1 drochner #endif
830 1.1 drochner break;
831 1.1 drochner }
832 1.44 martin return VT100_EMUL_STATE_STRING;
833 1.1 drochner }
834 1.1 drochner
835 1.43 christos return VT100_EMUL_STATE_DCS;
836 1.1 drochner }
837 1.1 drochner
838 1.1 drochner static u_int
839 1.15 augustss wsemul_vt100_output_dcs_dollar(struct wsemul_vt100_emuldata *edp, u_char c)
840 1.1 drochner {
841 1.32 drochner struct vt100base_data *vd = &edp->bd;
842 1.32 drochner
843 1.1 drochner switch (c) {
844 1.19 junyoung case 'p': /* DECRSTS terminal state restore */
845 1.19 junyoung case 'q': /* DECRQSS control function request */
846 1.1 drochner #ifdef VT100_PRINTNOTIMPL
847 1.1 drochner printf("DCS$%c ignored\n", c);
848 1.1 drochner #endif
849 1.1 drochner break;
850 1.19 junyoung case 't': /* DECRSPS restore presentation state */
851 1.32 drochner switch (ARG(vd, 0)) {
852 1.19 junyoung case 0: /* error */
853 1.1 drochner break;
854 1.19 junyoung case 1: /* cursor information restore */
855 1.1 drochner #ifdef VT100_PRINTNOTIMPL
856 1.1 drochner printf("DCS1$t ignored\n");
857 1.1 drochner #endif
858 1.1 drochner break;
859 1.19 junyoung case 2: /* tab stop restore */
860 1.32 drochner vd->dcspos = 0;
861 1.32 drochner vd->dcstype = DCSTYPE_TABRESTORE;
862 1.1 drochner break;
863 1.19 junyoung default:
864 1.1 drochner #ifdef VT100_PRINTUNKNOWN
865 1.32 drochner printf("DCS%d$t unknown\n", ARG(vd, 0));
866 1.1 drochner #endif
867 1.1 drochner break;
868 1.1 drochner }
869 1.1 drochner break;
870 1.19 junyoung default:
871 1.1 drochner #ifdef VT100_PRINTUNKNOWN
872 1.32 drochner printf("DCS$%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1));
873 1.1 drochner #endif
874 1.1 drochner break;
875 1.1 drochner }
876 1.43 christos return VT100_EMUL_STATE_STRING;
877 1.1 drochner }
878 1.1 drochner
879 1.1 drochner static u_int
880 1.15 augustss wsemul_vt100_output_esc_hash(struct wsemul_vt100_emuldata *edp, u_char c)
881 1.1 drochner {
882 1.32 drochner struct vt100base_data *vd = &edp->bd;
883 1.23 drochner int i, j;
884 1.1 drochner
885 1.1 drochner switch (c) {
886 1.19 junyoung case '5': /* DECSWL single width, single height */
887 1.32 drochner if (vd->dw) {
888 1.32 drochner for (i = 0; i < vd->ncols / 2; i++)
889 1.32 drochner (*vd->emulops->copycols)(vd->emulcookie,
890 1.32 drochner vd->crow,
891 1.3 drochner 2 * i, i, 1);
892 1.32 drochner (*vd->emulops->erasecols)(vd->emulcookie, vd->crow,
893 1.32 drochner i, vd->ncols - i,
894 1.32 drochner vd->bkgdattr);
895 1.32 drochner vd->dblwid[vd->crow] = 0;
896 1.32 drochner vd->dw = 0;
897 1.1 drochner }
898 1.1 drochner break;
899 1.19 junyoung case '6': /* DECDWL double width, single height */
900 1.19 junyoung case '3': /* DECDHL double width, double height, top half */
901 1.19 junyoung case '4': /* DECDHL double width, double height, bottom half */
902 1.32 drochner if (!vd->dw) {
903 1.32 drochner for (i = vd->ncols / 2 - 1; i >= 0; i--)
904 1.32 drochner (*vd->emulops->copycols)(vd->emulcookie,
905 1.32 drochner vd->crow,
906 1.3 drochner i, 2 * i, 1);
907 1.32 drochner for (i = 0; i < vd->ncols / 2; i++)
908 1.32 drochner (*vd->emulops->erasecols)(vd->emulcookie,
909 1.32 drochner vd->crow,
910 1.3 drochner 2 * i + 1, 1,
911 1.32 drochner vd->bkgdattr);
912 1.32 drochner vd->dblwid[vd->crow] = 1;
913 1.32 drochner vd->dw = 1;
914 1.32 drochner if (vd->ccol > (vd->ncols >> 1) - 1)
915 1.32 drochner vd->ccol = (vd->ncols >> 1) - 1;
916 1.3 drochner }
917 1.1 drochner break;
918 1.23 drochner case '8': /* DECALN */
919 1.32 drochner for (i = 0; i < vd->nrows; i++)
920 1.32 drochner for (j = 0; j < vd->ncols; j++)
921 1.32 drochner (*vd->emulops->putchar)(vd->emulcookie, i, j,
922 1.32 drochner 'E', vd->curattr);
923 1.32 drochner vd->ccol = 0;
924 1.32 drochner vd->crow = 0;
925 1.1 drochner break;
926 1.19 junyoung default:
927 1.1 drochner #ifdef VT100_PRINTUNKNOWN
928 1.1 drochner printf("ESC#%c unknown\n", c);
929 1.1 drochner #endif
930 1.1 drochner break;
931 1.1 drochner }
932 1.43 christos return VT100_EMUL_STATE_NORMAL;
933 1.1 drochner }
934 1.1 drochner
935 1.1 drochner static u_int
936 1.15 augustss wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c)
937 1.1 drochner {
938 1.32 drochner struct vt100base_data *vd = &edp->bd;
939 1.1 drochner
940 1.1 drochner switch (c) {
941 1.19 junyoung case '0': case '1': case '2': case '3': case '4':
942 1.19 junyoung case '5': case '6': case '7': case '8': case '9':
943 1.1 drochner /* argument digit */
944 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS - 1)
945 1.1 drochner break;
946 1.32 drochner vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
947 1.1 drochner (c - '0');
948 1.1 drochner break;
949 1.19 junyoung case ';': /* argument terminator */
950 1.32 drochner vd->nargs++;
951 1.1 drochner break;
952 1.19 junyoung case '?': /* DEC specific */
953 1.19 junyoung case '>': /* DA query */
954 1.32 drochner vd->modif1 = c;
955 1.1 drochner break;
956 1.19 junyoung case '!':
957 1.19 junyoung case '"':
958 1.19 junyoung case '$':
959 1.19 junyoung case '&':
960 1.32 drochner vd->modif2 = c;
961 1.1 drochner break;
962 1.19 junyoung default: /* end of escape sequence */
963 1.32 drochner vd->nargs++;
964 1.32 drochner if (vd->nargs > VT100_EMUL_NARGS) {
965 1.1 drochner #ifdef VT100_DEBUG
966 1.1 drochner printf("vt100: too many arguments\n");
967 1.1 drochner #endif
968 1.32 drochner vd->nargs = VT100_EMUL_NARGS;
969 1.1 drochner }
970 1.32 drochner wsemul_vt100_handle_csi(vd, c);
971 1.43 christos return VT100_EMUL_STATE_NORMAL;
972 1.1 drochner }
973 1.43 christos return VT100_EMUL_STATE_CSI;
974 1.1 drochner }
975 1.1 drochner
976 1.49 uwe static void
977 1.15 augustss wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
978 1.1 drochner {
979 1.1 drochner struct wsemul_vt100_emuldata *edp = cookie;
980 1.32 drochner struct vt100base_data *vd = &edp->bd;
981 1.1 drochner
982 1.1 drochner #ifdef DIAGNOSTIC
983 1.1 drochner if (kernel && !edp->console)
984 1.43 christos panic("%s: kernel output, not console", __func__);
985 1.1 drochner #endif
986 1.1 drochner
987 1.32 drochner if (vd->flags & VTFL_CURSORON)
988 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie, 0,
989 1.32 drochner vd->crow, vd->ccol << vd->dw);
990 1.1 drochner for (; count > 0; data++, count--) {
991 1.7 drochner if ((*data & 0x7f) < 0x20) {
992 1.7 drochner wsemul_vt100_output_c0c1(edp, *data, kernel);
993 1.7 drochner continue;
994 1.7 drochner }
995 1.1 drochner if (edp->state == VT100_EMUL_STATE_NORMAL || kernel) {
996 1.7 drochner wsemul_vt100_output_normal(edp, *data, kernel);
997 1.1 drochner continue;
998 1.1 drochner }
999 1.43 christos int state = edp->state - 1;
1000 1.43 christos KASSERT(state < __arraycount(vt100_output));
1001 1.43 christos edp->state = vt100_output[state](edp, *data);
1002 1.1 drochner }
1003 1.32 drochner if (vd->flags & VTFL_CURSORON)
1004 1.32 drochner (*vd->emulops->cursor)(vd->emulcookie, 1,
1005 1.43 christos vd->crow, vd->ccol << vd->dw);
1006 1.1 drochner }
1007 1.26 jmmv
1008 1.26 jmmv #ifdef WSDISPLAY_CUSTOM_OUTPUT
1009 1.26 jmmv static void
1010 1.26 jmmv wsemul_vt100_getmsgattrs(void *cookie, struct wsdisplay_msgattrs *ma)
1011 1.26 jmmv {
1012 1.26 jmmv struct wsemul_vt100_emuldata *edp = cookie;
1013 1.35 drochner struct vt100base_data *vd = &edp->bd;
1014 1.26 jmmv
1015 1.32 drochner *ma = vd->msgattrs;
1016 1.26 jmmv }
1017 1.26 jmmv
1018 1.26 jmmv static void
1019 1.26 jmmv wsemul_vt100_setmsgattrs(void *cookie, const struct wsscreen_descr *type,
1020 1.26 jmmv const struct wsdisplay_msgattrs *ma)
1021 1.26 jmmv {
1022 1.26 jmmv int error;
1023 1.26 jmmv long tmp;
1024 1.26 jmmv struct wsemul_vt100_emuldata *edp = cookie;
1025 1.35 drochner struct vt100base_data *vd = &edp->bd;
1026 1.26 jmmv
1027 1.32 drochner vd->msgattrs = *ma;
1028 1.26 jmmv if (type->capabilities & WSSCREEN_WSCOLORS) {
1029 1.32 drochner vd->msgattrs.default_attrs |= WSATTR_WSCOLORS;
1030 1.32 drochner vd->msgattrs.kernel_attrs |= WSATTR_WSCOLORS;
1031 1.26 jmmv } else {
1032 1.32 drochner vd->msgattrs.default_bg = vd->msgattrs.kernel_bg = 0;
1033 1.32 drochner vd->msgattrs.default_fg = vd->msgattrs.kernel_fg = 0;
1034 1.26 jmmv }
1035 1.26 jmmv
1036 1.32 drochner error = (*vd->emulops->allocattr)(vd->emulcookie,
1037 1.32 drochner vd->msgattrs.default_fg,
1038 1.32 drochner vd->msgattrs.default_bg,
1039 1.32 drochner vd->msgattrs.default_attrs,
1040 1.26 jmmv &tmp);
1041 1.36 mrg #ifndef VT100_DEBUG
1042 1.36 mrg __USE(error);
1043 1.36 mrg #else
1044 1.26 jmmv if (error)
1045 1.26 jmmv printf("vt100: failed to allocate attribute for default "
1046 1.26 jmmv "messages\n");
1047 1.26 jmmv else
1048 1.26 jmmv #endif
1049 1.26 jmmv {
1050 1.32 drochner if (vd->curattr == vd->defattr) {
1051 1.32 drochner vd->bkgdattr = vd->curattr = tmp;
1052 1.32 drochner vd->attrflags = vd->msgattrs.default_attrs;
1053 1.32 drochner vd->bgcol = vd->msgattrs.default_bg;
1054 1.32 drochner vd->fgcol = vd->msgattrs.default_fg;
1055 1.26 jmmv } else {
1056 1.26 jmmv edp->savedbkgdattr = edp->savedattr = tmp;
1057 1.32 drochner edp->savedattrflags = vd->msgattrs.default_attrs;
1058 1.32 drochner edp->savedbgcol = vd->msgattrs.default_bg;
1059 1.32 drochner edp->savedfgcol = vd->msgattrs.default_fg;
1060 1.26 jmmv }
1061 1.32 drochner if (vd->emulops->replaceattr != NULL)
1062 1.32 drochner (*vd->emulops->replaceattr)(vd->emulcookie,
1063 1.32 drochner vd->defattr, tmp);
1064 1.32 drochner vd->defattr = tmp;
1065 1.26 jmmv }
1066 1.26 jmmv
1067 1.32 drochner error = (*vd->emulops->allocattr)(vd->emulcookie,
1068 1.32 drochner vd->msgattrs.kernel_fg,
1069 1.32 drochner vd->msgattrs.kernel_bg,
1070 1.32 drochner vd->msgattrs.kernel_attrs,
1071 1.26 jmmv &tmp);
1072 1.26 jmmv #ifdef VT100_DEBUG
1073 1.26 jmmv if (error)
1074 1.26 jmmv printf("vt100: failed to allocate attribute for kernel "
1075 1.26 jmmv "messages\n");
1076 1.26 jmmv else
1077 1.26 jmmv #endif
1078 1.26 jmmv {
1079 1.32 drochner if (vd->emulops->replaceattr != NULL)
1080 1.32 drochner (*vd->emulops->replaceattr)(vd->emulcookie,
1081 1.26 jmmv edp->kernattr, tmp);
1082 1.26 jmmv edp->kernattr = tmp;
1083 1.26 jmmv }
1084 1.26 jmmv }
1085 1.26 jmmv #endif /* WSDISPLAY_CUSTOM_OUTPUT */
1086