This source file includes following definitions.
- wsemul_dumb_cnattach
- wsemul_dumb_attach
- wsemul_dumb_output
- wsemul_dumb_translate
- wsemul_dumb_detach
- wsemul_dumb_resetop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <sys/cdefs.h>
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/time.h>
39 #include <sys/malloc.h>
40 #include <sys/fcntl.h>
41
42 #include <dev/wscons/wsconsio.h>
43 #include <dev/wscons/wsdisplayvar.h>
44 #include <dev/wscons/wsemulvar.h>
45 #include <dev/wscons/ascii.h>
46
47 void *wsemul_dumb_cnattach(const struct wsscreen_descr *, void *,
48 int, int, long);
49 void *wsemul_dumb_attach(int console, const struct wsscreen_descr *,
50 void *, int, int, void *, long);
51 void wsemul_dumb_output(void *cookie, const u_char *data, u_int count,
52 int);
53 int wsemul_dumb_translate(void *cookie, keysym_t, char **);
54 void wsemul_dumb_detach(void *cookie, u_int *crowp, u_int *ccolp);
55 void wsemul_dumb_resetop(void *, enum wsemul_resetops);
56
57 const struct wsemul_ops wsemul_dumb_ops = {
58 "dumb",
59 wsemul_dumb_cnattach,
60 wsemul_dumb_attach,
61 wsemul_dumb_output,
62 wsemul_dumb_translate,
63 wsemul_dumb_detach,
64 wsemul_dumb_resetop
65 };
66
67 struct wsemul_dumb_emuldata {
68 const struct wsdisplay_emulops *emulops;
69 void *emulcookie;
70 void *cbcookie;
71 int crippled;
72 u_int nrows, ncols, crow, ccol;
73 long defattr;
74 };
75
76 struct wsemul_dumb_emuldata wsemul_dumb_console_emuldata;
77
78 void *
79 wsemul_dumb_cnattach(type, cookie, ccol, crow, defattr)
80 const struct wsscreen_descr *type;
81 void *cookie;
82 int ccol, crow;
83 long defattr;
84 {
85 struct wsemul_dumb_emuldata *edp;
86 const struct wsdisplay_emulops *emulops;
87
88 edp = &wsemul_dumb_console_emuldata;
89
90 edp->emulops = emulops = type->textops;
91 edp->emulcookie = cookie;
92 edp->nrows = type->nrows;
93 edp->ncols = type->ncols;
94 edp->crow = crow;
95 edp->ccol = ccol;
96 edp->defattr = defattr;
97 edp->cbcookie = NULL;
98 edp->crippled = emulops->cursor == NULL ||
99 emulops->copycols == NULL || emulops->copyrows == NULL ||
100 emulops->erasecols == NULL || emulops->eraserows == NULL;
101
102 return (edp);
103 }
104
105 void *
106 wsemul_dumb_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
107 int console;
108 const struct wsscreen_descr *type;
109 void *cookie;
110 int ccol, crow;
111 void *cbcookie;
112 long defattr;
113 {
114 struct wsemul_dumb_emuldata *edp;
115
116 if (console)
117 edp = &wsemul_dumb_console_emuldata;
118 else {
119 edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
120
121 edp->emulops = type->textops;
122 edp->emulcookie = cookie;
123 edp->nrows = type->nrows;
124 edp->ncols = type->ncols;
125 edp->crow = crow;
126 edp->ccol = ccol;
127 edp->defattr = defattr;
128 }
129
130 edp->cbcookie = cbcookie;
131
132 return (edp);
133 }
134
135 void
136 wsemul_dumb_output(cookie, data, count, kernel)
137 void *cookie;
138 const u_char *data;
139 u_int count;
140 int kernel;
141 {
142 struct wsemul_dumb_emuldata *edp = cookie;
143 u_char c;
144 int n;
145
146 if (edp->crippled) {
147 while (count-- > 0) {
148 c = *data++;
149
150 if (c == ASCII_BEL)
151 wsdisplay_emulbell(edp->cbcookie);
152 else
153 (*edp->emulops->putchar)(edp->emulcookie, 0,
154 0, c, 0);
155 }
156 return;
157 }
158
159
160 (*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
161 while (count-- > 0) {
162 c = *data++;
163
164 switch (c) {
165 case ASCII_BEL:
166 wsdisplay_emulbell(edp->cbcookie);
167 break;
168
169 case ASCII_BS:
170 if (edp->ccol > 0)
171 edp->ccol--;
172 break;
173
174 case ASCII_CR:
175 edp->ccol = 0;
176 break;
177
178 case ASCII_HT:
179 n = min(8 - (edp->ccol & 7),
180 edp->ncols - edp->ccol - 1);
181 (*edp->emulops->erasecols)(edp->emulcookie,
182 edp->crow, edp->ccol, n, edp->defattr);
183 edp->ccol += n;
184 break;
185
186 case ASCII_FF:
187 (*edp->emulops->eraserows)(edp->emulcookie, 0,
188 edp->nrows, edp->defattr);
189 edp->ccol = 0;
190 edp->crow = 0;
191 break;
192
193 case ASCII_VT:
194 if (edp->crow > 0)
195 edp->crow--;
196 break;
197
198 default:
199 (*edp->emulops->putchar)(edp->emulcookie, edp->crow,
200 edp->ccol, c, edp->defattr);
201 edp->ccol++;
202
203
204 if (edp->ccol < edp->ncols)
205 break;
206
207
208 edp->ccol = 0;
209
210
211
212 case ASCII_LF:
213
214 if (edp->crow < edp->nrows - 1) {
215 edp->crow++;
216 break;
217 }
218 n = 1;
219 (*edp->emulops->copyrows)(edp->emulcookie, n, 0,
220 edp->nrows - n);
221 (*edp->emulops->eraserows)(edp->emulcookie,
222 edp->nrows - n, n, edp->defattr);
223 edp->crow -= n - 1;
224 break;
225 }
226 }
227
228 (*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
229 }
230
231 int
232 wsemul_dumb_translate(cookie, in, out)
233 void *cookie;
234 keysym_t in;
235 char **out;
236 {
237 return (0);
238 }
239
240 void
241 wsemul_dumb_detach(cookie, crowp, ccolp)
242 void *cookie;
243 u_int *crowp, *ccolp;
244 {
245 struct wsemul_dumb_emuldata *edp = cookie;
246
247 *crowp = edp->crow;
248 *ccolp = edp->ccol;
249 if (edp != &wsemul_dumb_console_emuldata)
250 free(edp, M_DEVBUF);
251 }
252
253 void
254 wsemul_dumb_resetop(cookie, op)
255 void *cookie;
256 enum wsemul_resetops op;
257 {
258 struct wsemul_dumb_emuldata *edp = cookie;
259
260 if (edp->crippled)
261 return;
262
263 switch (op) {
264 case WSEMUL_CLEARSCREEN:
265 (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
266 edp->defattr);
267 edp->ccol = edp->crow = 0;
268 (*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
269 break;
270 default:
271 break;
272 }
273 }