rcons_subr.c revision 1.4 1 1.4 ad /* $NetBSD: rcons_subr.c,v 1.4 1999/04/22 00:46:36 ad Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1991, 1993
5 1.1 pk * The Regents of the University of California. All rights reserved.
6 1.1 pk *
7 1.1 pk * This software was developed by the Computer Systems Engineering group
8 1.1 pk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 pk * contributed to Berkeley.
10 1.1 pk *
11 1.1 pk * All advertising materials mentioning features or use of this software
12 1.1 pk * must display the following acknowledgement:
13 1.1 pk * This product includes software developed by the University of
14 1.1 pk * California, Lawrence Berkeley Laboratory.
15 1.1 pk *
16 1.1 pk * Redistribution and use in source and binary forms, with or without
17 1.1 pk * modification, are permitted provided that the following conditions
18 1.1 pk * are met:
19 1.1 pk * 1. Redistributions of source code must retain the above copyright
20 1.1 pk * notice, this list of conditions and the following disclaimer.
21 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 pk * notice, this list of conditions and the following disclaimer in the
23 1.1 pk * documentation and/or other materials provided with the distribution.
24 1.1 pk * 3. All advertising materials mentioning features or use of this software
25 1.1 pk * must display the following acknowledgement:
26 1.1 pk * This product includes software developed by the University of
27 1.1 pk * California, Berkeley and its contributors.
28 1.1 pk * 4. Neither the name of the University nor the names of its contributors
29 1.1 pk * may be used to endorse or promote products derived from this software
30 1.1 pk * without specific prior written permission.
31 1.1 pk *
32 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 pk * SUCH DAMAGE.
43 1.1 pk *
44 1.1 pk * @(#)rcons_subr.c 8.1 (Berkeley) 6/11/93
45 1.1 pk */
46 1.1 pk
47 1.1 pk #ifdef _KERNEL
48 1.1 pk #include <sys/param.h>
49 1.1 pk #include <sys/device.h>
50 1.3 ad #include <sys/systm.h>
51 1.1 pk #else
52 1.1 pk #include <sys/types.h>
53 1.1 pk #include "myfbdevice.h"
54 1.1 pk #endif
55 1.1 pk
56 1.1 pk #include <dev/rcons/rcons.h>
57 1.3 ad #include <dev/wscons/wsdisplayvar.h>
58 1.1 pk
59 1.1 pk extern void rcons_bell(struct rconsole *);
60 1.1 pk
61 1.4 ad #if 0
62 1.2 pk #define RCONS_ISPRINT(c) ((((c) >= ' ') && ((c) <= '~')) || ((c) > 160))
63 1.4 ad #else
64 1.4 ad #define RCONS_ISPRINT(c) (((((c) >= ' ') && ((c) <= '~'))) || ((c) > 127))
65 1.4 ad #endif
66 1.1 pk #define RCONS_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
67 1.1 pk
68 1.3 ad /* Initalize our operations set */
69 1.3 ad void
70 1.3 ad rcons_init_ops(rc)
71 1.3 ad struct rconsole *rc;
72 1.3 ad {
73 1.3 ad u_int ch;
74 1.3 ad long tmp;
75 1.3 ad int i;
76 1.3 ad
77 1.3 ad i = (sizeof(rc->rc_charmap) / sizeof(rc->rc_charmap[0])) - 1;
78 1.3 ad
79 1.3 ad for (; i >= 0; i--) {
80 1.3 ad rc->rc_ops->mapchar(rc->rc_cookie, i, &ch);
81 1.3 ad rc->rc_charmap[i] = ch;
82 1.3 ad }
83 1.3 ad
84 1.4 ad /* Determine which attributes the device supports. */
85 1.3 ad rc->rc_fgcolor = RASTERCONSOLE_FGCOL;
86 1.3 ad rc->rc_bgcolor = RASTERCONSOLE_BGCOL;
87 1.3 ad rc->rc_supwsflg = 0;
88 1.3 ad
89 1.3 ad for (i = 1; i < 256; i <<= 1)
90 1.3 ad if (rc->rc_ops->alloc_attr(rc->rc_cookie, 0, 0, i, &tmp) == 0)
91 1.3 ad rc->rc_supwsflg |= i;
92 1.3 ad
93 1.3 ad /* Allocate kernel output attribute */
94 1.3 ad rc->rc_wsflg = WSATTR_HILIT;
95 1.3 ad rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
96 1.3 ad rc->rc_kern_attr = rc->rc_attr;
97 1.3 ad
98 1.3 ad rc->rc_wsflg = 0;
99 1.3 ad rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
100 1.3 ad }
101 1.3 ad
102 1.1 pk /* Output (or at least handle) a string sent to the console */
103 1.1 pk void
104 1.1 pk rcons_puts(rc, str, n)
105 1.3 ad struct rconsole *rc;
106 1.3 ad unsigned char *str;
107 1.3 ad int n;
108 1.1 pk {
109 1.3 ad int c, i, j;
110 1.3 ad unsigned char *cp;
111 1.1 pk
112 1.1 pk /* Jump scroll */
113 1.1 pk /* XXX maybe this should be an option? */
114 1.1 pk if ((rc->rc_bits & FB_INESC) == 0) {
115 1.1 pk /* Count newlines up to an escape sequence */
116 1.1 pk i = 0;
117 1.1 pk j = 0;
118 1.1 pk for (cp = str; j++ < n && *cp != '\033'; ++cp) {
119 1.1 pk if (*cp == '\n')
120 1.1 pk ++i;
121 1.1 pk else if (*cp == '\013')
122 1.1 pk --i;
123 1.1 pk }
124 1.1 pk
125 1.1 pk /* Only jump scroll two or more rows */
126 1.3 ad if (rc->rc_row + i > rc->rc_maxrow + 1) {
127 1.1 pk /* Erase the cursor (if necessary) */
128 1.1 pk if (rc->rc_bits & FB_CURSOR)
129 1.1 pk rcons_cursor(rc);
130 1.1 pk
131 1.1 pk rcons_scroll(rc, i);
132 1.1 pk }
133 1.1 pk }
134 1.1 pk
135 1.1 pk /* Process characters */
136 1.1 pk while (--n >= 0) {
137 1.1 pk c = *str;
138 1.1 pk if (c == '\033') {
139 1.1 pk /* Start an escape (perhaps aborting one in progress) */
140 1.1 pk rc->rc_bits |= FB_INESC | FB_P0_DEFAULT | FB_P1_DEFAULT;
141 1.1 pk rc->rc_bits &= ~(FB_P0 | FB_P1);
142 1.1 pk
143 1.1 pk /* Most parameters default to 1 */
144 1.1 pk rc->rc_p0 = rc->rc_p1 = 1;
145 1.1 pk } else if (rc->rc_bits & FB_INESC) {
146 1.1 pk rcons_esc(rc, c);
147 1.1 pk } else {
148 1.1 pk /* Erase the cursor (if necessary) */
149 1.1 pk if (rc->rc_bits & FB_CURSOR)
150 1.1 pk rcons_cursor(rc);
151 1.1 pk
152 1.1 pk /* Display the character */
153 1.1 pk if (RCONS_ISPRINT(c)) {
154 1.1 pk /* Try to output as much as possible */
155 1.3 ad j = rc->rc_maxcol - rc->rc_col;
156 1.1 pk if (j > n)
157 1.1 pk j = n;
158 1.1 pk for (i = 1; i < j && RCONS_ISPRINT(str[i]); ++i)
159 1.1 pk continue;
160 1.1 pk rcons_text(rc, str, i);
161 1.1 pk --i;
162 1.1 pk str += i;
163 1.1 pk n -= i;
164 1.1 pk } else
165 1.1 pk rcons_pctrl(rc, c);
166 1.1 pk }
167 1.1 pk ++str;
168 1.1 pk }
169 1.1 pk /* Redraw the cursor (if necessary) */
170 1.1 pk if ((rc->rc_bits & FB_CURSOR) == 0)
171 1.1 pk rcons_cursor(rc);
172 1.1 pk }
173 1.1 pk
174 1.1 pk
175 1.1 pk /* Handle a control character sent to the console */
176 1.1 pk void
177 1.1 pk rcons_pctrl(rc, c)
178 1.3 ad struct rconsole *rc;
179 1.3 ad int c;
180 1.1 pk {
181 1.1 pk
182 1.1 pk switch (c) {
183 1.1 pk case '\r': /* Carriage return */
184 1.3 ad rc->rc_col = 0;
185 1.1 pk break;
186 1.1 pk
187 1.1 pk case '\b': /* Backspace */
188 1.3 ad if (rc->rc_col > 0)
189 1.3 ad (rc->rc_col)--;
190 1.1 pk break;
191 1.1 pk
192 1.3 ad case '\v': /* Vertical tab */
193 1.3 ad if (rc->rc_row > 0)
194 1.3 ad (rc->rc_row)--;
195 1.1 pk break;
196 1.1 pk
197 1.1 pk case '\f': /* Formfeed */
198 1.3 ad rc->rc_row = rc->rc_col = 0;
199 1.1 pk rcons_clear2eop(rc);
200 1.1 pk break;
201 1.1 pk
202 1.1 pk case '\n': /* Linefeed */
203 1.3 ad (rc->rc_row)++;
204 1.3 ad if (rc->rc_row >= rc->rc_maxrow)
205 1.1 pk rcons_scroll(rc, 1);
206 1.1 pk break;
207 1.1 pk
208 1.3 ad case '\a': /* Bell */
209 1.1 pk rcons_bell(rc);
210 1.1 pk break;
211 1.1 pk
212 1.1 pk case '\t': /* Horizontal tab */
213 1.3 ad rc->rc_col = (rc->rc_col + 8) & ~7;
214 1.3 ad if (rc->rc_col >= rc->rc_maxcol)
215 1.3 ad rc->rc_col = rc->rc_maxcol;
216 1.1 pk break;
217 1.1 pk }
218 1.1 pk }
219 1.1 pk
220 1.1 pk /* Handle the next character in an escape sequence */
221 1.1 pk void
222 1.1 pk rcons_esc(rc, c)
223 1.3 ad struct rconsole *rc;
224 1.3 ad int c;
225 1.1 pk {
226 1.1 pk
227 1.1 pk if (c == '[') {
228 1.1 pk /* Parameter 0 */
229 1.1 pk rc->rc_bits &= ~FB_P1;
230 1.1 pk rc->rc_bits |= FB_P0;
231 1.1 pk } else if (c == ';') {
232 1.1 pk /* Parameter 1 */
233 1.1 pk rc->rc_bits &= ~FB_P0;
234 1.1 pk rc->rc_bits |= FB_P1;
235 1.1 pk } else if (RCONS_ISDIGIT(c)) {
236 1.1 pk /* Add a digit to a parameter */
237 1.1 pk if (rc->rc_bits & FB_P0) {
238 1.1 pk /* Parameter 0 */
239 1.1 pk if (rc->rc_bits & FB_P0_DEFAULT) {
240 1.1 pk rc->rc_bits &= ~FB_P0_DEFAULT;
241 1.1 pk rc->rc_p0 = 0;
242 1.1 pk }
243 1.1 pk rc->rc_p0 *= 10;
244 1.1 pk rc->rc_p0 += c - '0';
245 1.1 pk } else if (rc->rc_bits & FB_P1) {
246 1.1 pk /* Parameter 1 */
247 1.1 pk if (rc->rc_bits & FB_P1_DEFAULT) {
248 1.1 pk rc->rc_bits &= ~FB_P1_DEFAULT;
249 1.1 pk rc->rc_p1 = 0;
250 1.1 pk }
251 1.1 pk rc->rc_p1 *= 10;
252 1.1 pk rc->rc_p1 += c - '0';
253 1.1 pk }
254 1.1 pk } else {
255 1.1 pk /* Erase the cursor (if necessary) */
256 1.1 pk if (rc->rc_bits & FB_CURSOR)
257 1.1 pk rcons_cursor(rc);
258 1.1 pk
259 1.1 pk /* Process the completed escape sequence */
260 1.1 pk rcons_doesc(rc, c);
261 1.1 pk rc->rc_bits &= ~FB_INESC;
262 1.1 pk }
263 1.1 pk }
264 1.1 pk
265 1.3 ad
266 1.3 ad /* Handle an SGR (Select Graphic Rendition) escape */
267 1.3 ad void
268 1.3 ad rcons_sgresc(rc, c)
269 1.3 ad struct rconsole *rc;
270 1.3 ad int c;
271 1.3 ad {
272 1.3 ad
273 1.3 ad switch (c) {
274 1.3 ad /* Clear all attributes || End underline */
275 1.3 ad case 0:
276 1.3 ad rc->rc_wsflg = 0;
277 1.3 ad rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
278 1.3 ad break;
279 1.3 ad
280 1.3 ad /* ANSI foreground color */
281 1.3 ad case 30: case 31: case 32: case 33:
282 1.3 ad case 34: case 35: case 36: case 37:
283 1.3 ad rcons_setcolor(rc, c - 30, rc->rc_bgcolor);
284 1.3 ad break;
285 1.3 ad
286 1.3 ad /* ANSI background color */
287 1.3 ad case 40: case 41: case 42: case 43:
288 1.3 ad case 44: case 45: case 46: case 47:
289 1.3 ad rcons_setcolor(rc, rc->rc_fgcolor, c - 40);
290 1.3 ad break;
291 1.3 ad
292 1.3 ad /* Begin reverse */
293 1.3 ad case 7:
294 1.3 ad rc->rc_wsflg |= WSATTR_REVERSE;
295 1.3 ad rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
296 1.3 ad break;
297 1.3 ad
298 1.3 ad /* Begin bold */
299 1.3 ad case 1:
300 1.3 ad rc->rc_wsflg |= WSATTR_HILIT;
301 1.3 ad rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
302 1.3 ad break;
303 1.3 ad
304 1.3 ad /* Begin underline */
305 1.3 ad case 4:
306 1.3 ad rc->rc_wsflg |= WSATTR_UNDERLINE;
307 1.3 ad rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
308 1.3 ad break;
309 1.3 ad }
310 1.3 ad }
311 1.3 ad
312 1.3 ad
313 1.1 pk /* Process a complete escape sequence */
314 1.1 pk void
315 1.1 pk rcons_doesc(rc, c)
316 1.3 ad struct rconsole *rc;
317 1.3 ad int c;
318 1.1 pk {
319 1.1 pk
320 1.1 pk #ifdef notdef
321 1.1 pk /* XXX add escape sequence to enable visual (and audible) bell */
322 1.1 pk rc->rc_bits = FB_VISBELL;
323 1.1 pk #endif
324 1.1 pk
325 1.1 pk switch (c) {
326 1.1 pk
327 1.1 pk case '@':
328 1.1 pk /* Insert Character (ICH) */
329 1.1 pk rcons_insertchar(rc, rc->rc_p0);
330 1.1 pk break;
331 1.1 pk
332 1.1 pk case 'A':
333 1.1 pk /* Cursor Up (CUU) */
334 1.3 ad rc->rc_row -= rc->rc_p0;
335 1.3 ad if (rc->rc_row < 0)
336 1.3 ad rc->rc_row = 0;
337 1.1 pk break;
338 1.1 pk
339 1.1 pk case 'B':
340 1.1 pk /* Cursor Down (CUD) */
341 1.3 ad rc->rc_row += rc->rc_p0;
342 1.3 ad if (rc->rc_row >= rc->rc_maxrow)
343 1.3 ad rc->rc_row = rc->rc_maxrow - 1;
344 1.1 pk break;
345 1.1 pk
346 1.1 pk case 'C':
347 1.1 pk /* Cursor Forward (CUF) */
348 1.3 ad rc->rc_col += rc->rc_p0;
349 1.3 ad if (rc->rc_col >= rc->rc_maxcol)
350 1.3 ad rc->rc_col = rc->rc_maxcol - 1;
351 1.1 pk break;
352 1.1 pk
353 1.1 pk case 'D':
354 1.1 pk /* Cursor Backward (CUB) */
355 1.3 ad rc->rc_col -= rc->rc_p0;
356 1.3 ad if (rc->rc_col < 0)
357 1.3 ad rc->rc_col = 0;
358 1.1 pk break;
359 1.1 pk
360 1.1 pk case 'E':
361 1.1 pk /* Cursor Next Line (CNL) */
362 1.3 ad rc->rc_col = 0;
363 1.3 ad rc->rc_row += rc->rc_p0;
364 1.3 ad if (rc->rc_row >= rc->rc_maxrow)
365 1.3 ad rc->rc_row = rc->rc_maxrow - 1;
366 1.1 pk break;
367 1.1 pk
368 1.1 pk case 'f':
369 1.1 pk /* Horizontal And Vertical Position (HVP) */
370 1.1 pk case 'H':
371 1.1 pk /* Cursor Position (CUP) */
372 1.3 ad rc->rc_col = rc->rc_p1 - 1;
373 1.3 ad if (rc->rc_col < 0)
374 1.3 ad rc->rc_col = 0;
375 1.3 ad else if (rc->rc_col >= rc->rc_maxcol)
376 1.3 ad rc->rc_col = rc->rc_maxcol - 1;
377 1.3 ad
378 1.3 ad rc->rc_row = rc->rc_p0 - 1;
379 1.3 ad if (rc->rc_row < 0)
380 1.3 ad rc->rc_row = 0;
381 1.3 ad else if (rc->rc_row >= rc->rc_maxrow)
382 1.3 ad rc->rc_row = rc->rc_maxrow - 1;
383 1.1 pk break;
384 1.1 pk
385 1.1 pk case 'J':
386 1.1 pk /* Erase in Display (ED) */
387 1.1 pk rcons_clear2eop(rc);
388 1.1 pk break;
389 1.1 pk
390 1.1 pk case 'K':
391 1.1 pk /* Erase in Line (EL) */
392 1.1 pk rcons_clear2eol(rc);
393 1.1 pk break;
394 1.1 pk
395 1.1 pk case 'L':
396 1.1 pk /* Insert Line (IL) */
397 1.1 pk rcons_insertline(rc, rc->rc_p0);
398 1.1 pk break;
399 1.1 pk
400 1.1 pk case 'M':
401 1.1 pk /* Delete Line (DL) */
402 1.1 pk rcons_delline(rc, rc->rc_p0);
403 1.1 pk break;
404 1.1 pk
405 1.1 pk case 'P':
406 1.1 pk /* Delete Character (DCH) */
407 1.1 pk rcons_delchar(rc, rc->rc_p0);
408 1.1 pk break;
409 1.1 pk
410 1.1 pk case 'm':
411 1.3 ad /* Select Graphic Rendition (SGR) */
412 1.1 pk /* (defaults to zero) */
413 1.1 pk if (rc->rc_bits & FB_P0_DEFAULT)
414 1.1 pk rc->rc_p0 = 0;
415 1.3 ad
416 1.3 ad if (rc->rc_bits & FB_P1_DEFAULT)
417 1.3 ad rc->rc_p1 = 0;
418 1.3 ad
419 1.3 ad rcons_sgresc(rc, rc->rc_p0);
420 1.3 ad
421 1.3 ad if (rc->rc_bits & FB_P1)
422 1.3 ad rcons_sgresc(rc, rc->rc_p1);
423 1.3 ad
424 1.1 pk break;
425 1.1 pk
426 1.1 pk case 'p':
427 1.1 pk /* Black On White (SUNBOW) */
428 1.1 pk rcons_invert(rc, 0);
429 1.1 pk break;
430 1.1 pk
431 1.1 pk case 'q':
432 1.1 pk /* White On Black (SUNWOB) */
433 1.1 pk rcons_invert(rc, 1);
434 1.1 pk break;
435 1.1 pk
436 1.1 pk case 'r':
437 1.1 pk /* Set scrolling (SUNSCRL) */
438 1.1 pk /* (defaults to zero) */
439 1.1 pk if (rc->rc_bits & FB_P0_DEFAULT)
440 1.1 pk rc->rc_p0 = 0;
441 1.1 pk /* XXX not implemented yet */
442 1.1 pk rc->rc_scroll = rc->rc_p0;
443 1.1 pk break;
444 1.1 pk
445 1.1 pk case 's':
446 1.1 pk /* Reset terminal emulator (SUNRESET) */
447 1.3 ad rc->rc_wsflg = 0;
448 1.1 pk rc->rc_scroll = 0;
449 1.3 ad rc->rc_bits &= ~FB_NO_CURSOR;
450 1.3 ad rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
451 1.3 ad
452 1.1 pk if (rc->rc_bits & FB_INVERT)
453 1.1 pk rcons_invert(rc, 0);
454 1.1 pk break;
455 1.3 ad #ifdef notyet
456 1.3 ad /*
457 1.3 ad * XXX following two read \E[?25h and \E[?25l. rcons
458 1.3 ad * can't currently handle the '?'.
459 1.3 ad */
460 1.3 ad case 'h':
461 1.3 ad /* Normal/very visible cursor */
462 1.3 ad if (rc->rc_p0 == 25) {
463 1.3 ad rc->rc_bits &= ~FB_NO_CURSOR;
464 1.3 ad
465 1.3 ad if (rc->rc_bits & FB_CURSOR) {
466 1.3 ad rc->rc_bits ^= FB_CURSOR;
467 1.3 ad rcons_cursor(rc);
468 1.3 ad }
469 1.3 ad }
470 1.3 ad break;
471 1.3 ad
472 1.3 ad case 'l':
473 1.3 ad /* Invisible cursor */
474 1.3 ad if (rc->rc_p0 == 25 && (rc->rc_bits & FB_NO_CURSOR) == 0) {
475 1.3 ad if (rc->rc_bits & FB_CURSOR)
476 1.3 ad rcons_cursor(rc);
477 1.3 ad
478 1.3 ad rc->rc_bits |= FB_NO_CURSOR;
479 1.3 ad }
480 1.3 ad break;
481 1.3 ad #endif
482 1.1 pk }
483 1.1 pk }
484 1.1 pk
485 1.3 ad /* Set ANSI colors */
486 1.3 ad void
487 1.3 ad rcons_setcolor(rc, fg, bg)
488 1.3 ad struct rconsole *rc;
489 1.3 ad int fg, bg;
490 1.3 ad {
491 1.3 ad int flg;
492 1.3 ad
493 1.3 ad if (fg > WSCOL_WHITE || fg < 0)
494 1.3 ad return;
495 1.3 ad
496 1.3 ad if (bg > WSCOL_WHITE || bg < 0)
497 1.3 ad return;
498 1.3 ad
499 1.3 ad #ifdef RASTERCONS_WONB
500 1.3 ad flg = bg;
501 1.3 ad bg = fg;
502 1.3 ad fg = flg;
503 1.3 ad #endif
504 1.3 ad
505 1.3 ad /* Emulate WSATTR_REVERSE attribute if it's not supported */
506 1.3 ad if ((rc->rc_wsflg & WSATTR_REVERSE) &&
507 1.3 ad !(rc->rc_supwsflg & WSATTR_REVERSE)) {
508 1.3 ad flg = bg;
509 1.3 ad bg = fg;
510 1.3 ad fg = flg;
511 1.3 ad }
512 1.3 ad
513 1.3 ad /* Mask out unsupported flags and get attribute */
514 1.3 ad flg = rc->rc_wsflg & rc->rc_supwsflg;
515 1.3 ad rc->rc_bgcolor = bg;
516 1.3 ad rc->rc_fgcolor = fg;
517 1.3 ad rc->rc_ops->alloc_attr(rc->rc_cookie, fg, bg, flg, &rc->rc_attr);
518 1.3 ad }
519 1.3 ad
520 1.3 ad
521 1.3 ad /* Actually write a string to the frame buffer */
522 1.3 ad void
523 1.3 ad rcons_text(rc, str, n)
524 1.3 ad struct rconsole *rc;
525 1.3 ad unsigned char *str;
526 1.3 ad int n;
527 1.3 ad {
528 1.3 ad u_int uc;
529 1.3 ad
530 1.3 ad while (n--) {
531 1.3 ad uc = rc->rc_charmap[*str++ & 255];
532 1.3 ad rc->rc_ops->putchar(rc->rc_cookie, rc->rc_row, rc->rc_col++,
533 1.3 ad uc, rc->rc_attr);
534 1.3 ad }
535 1.3 ad
536 1.3 ad if (rc->rc_col >= rc->rc_maxcol) {
537 1.3 ad rc->rc_col = 0;
538 1.3 ad rc->rc_row++;
539 1.3 ad }
540 1.3 ad
541 1.3 ad if (rc->rc_row >= rc->rc_maxrow)
542 1.3 ad rcons_scroll(rc, 1);
543 1.3 ad }
544 1.3 ad
545 1.1 pk /* Paint (or unpaint) the cursor */
546 1.1 pk void
547 1.1 pk rcons_cursor(rc)
548 1.3 ad struct rconsole *rc;
549 1.1 pk {
550 1.1 pk rc->rc_bits ^= FB_CURSOR;
551 1.3 ad
552 1.3 ad if (rc->rc_bits & FB_NO_CURSOR)
553 1.3 ad return;
554 1.3 ad
555 1.3 ad rc->rc_ops->cursor(rc->rc_cookie, rc->rc_bits & FB_CURSOR,
556 1.3 ad rc->rc_row, rc->rc_col);
557 1.1 pk }
558 1.1 pk
559 1.1 pk /* Possibly change to SUNWOB or SUNBOW mode */
560 1.1 pk void
561 1.1 pk rcons_invert(rc, wob)
562 1.1 pk struct rconsole *rc;
563 1.1 pk int wob;
564 1.1 pk {
565 1.3 ad
566 1.3 ad rc->rc_bits ^= FB_INVERT;
567 1.3 ad /* XXX how do we do we invert the framebuffer?? */
568 1.1 pk }
569 1.1 pk
570 1.1 pk /* Clear to the end of the page */
571 1.1 pk void
572 1.1 pk rcons_clear2eop(rc)
573 1.3 ad struct rconsole *rc;
574 1.1 pk {
575 1.3 ad if (rc->rc_col || rc->rc_row) {
576 1.1 pk rcons_clear2eol(rc);
577 1.1 pk
578 1.3 ad if (rc->rc_row < (rc->rc_maxrow - 1))
579 1.3 ad rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_row + 1,
580 1.3 ad rc->rc_maxrow, rc->rc_attr);
581 1.3 ad } else
582 1.3 ad rc->rc_ops->eraserows(rc->rc_cookie, 0, rc->rc_maxrow,
583 1.3 ad rc->rc_attr);
584 1.1 pk }
585 1.1 pk
586 1.1 pk /* Clear to the end of the line */
587 1.1 pk void
588 1.1 pk rcons_clear2eol(rc)
589 1.3 ad struct rconsole *rc;
590 1.1 pk {
591 1.3 ad rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row, rc->rc_col,
592 1.3 ad rc->rc_maxcol - rc->rc_col, rc->rc_attr);
593 1.3 ad }
594 1.1 pk
595 1.1 pk
596 1.3 ad /* Scroll up */
597 1.1 pk void
598 1.1 pk rcons_scroll(rc, n)
599 1.3 ad struct rconsole *rc;
600 1.3 ad int n;
601 1.1 pk {
602 1.1 pk /* Can't scroll more than the whole screen */
603 1.1 pk if (n > rc->rc_maxrow)
604 1.1 pk n = rc->rc_maxrow;
605 1.1 pk
606 1.1 pk /* Calculate new row */
607 1.3 ad rc->rc_row -= n;
608 1.3 ad
609 1.3 ad if (rc->rc_row < 0)
610 1.3 ad rc->rc_row = 0;
611 1.3 ad
612 1.3 ad rc->rc_ops->copyrows(rc->rc_cookie, n, 0, rc->rc_maxrow - n);
613 1.3 ad rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_maxrow - n, n, rc->rc_attr);
614 1.1 pk }
615 1.1 pk
616 1.1 pk /* Delete characters */
617 1.1 pk void
618 1.1 pk rcons_delchar(rc, n)
619 1.3 ad struct rconsole *rc;
620 1.3 ad int n;
621 1.1 pk {
622 1.1 pk /* Can't delete more chars than there are */
623 1.3 ad if (n > rc->rc_maxcol - rc->rc_col)
624 1.3 ad n = rc->rc_maxcol - rc->rc_col;
625 1.3 ad
626 1.3 ad rc->rc_ops->copycols(rc->rc_cookie, rc->rc_row, rc->rc_col + n,
627 1.3 ad rc->rc_col, rc->rc_maxcol - rc->rc_col - n);
628 1.1 pk
629 1.3 ad rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row,
630 1.3 ad rc->rc_maxcol - n, n, rc->rc_attr);
631 1.1 pk }
632 1.1 pk
633 1.1 pk /* Delete a number of lines */
634 1.1 pk void
635 1.1 pk rcons_delline(rc, n)
636 1.3 ad struct rconsole *rc;
637 1.3 ad int n;
638 1.1 pk {
639 1.3 ad /* Can't delete more lines than there are */
640 1.3 ad if (n > rc->rc_maxrow - rc->rc_row)
641 1.3 ad n = rc->rc_maxrow - rc->rc_row;
642 1.1 pk
643 1.3 ad rc->rc_ops->copyrows(rc->rc_cookie, rc->rc_row + n, rc->rc_row,
644 1.3 ad rc->rc_maxrow - rc->rc_row - n);
645 1.1 pk
646 1.3 ad rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_maxrow - n, n,
647 1.3 ad rc->rc_attr);
648 1.1 pk }
649 1.1 pk
650 1.1 pk /* Insert some characters */
651 1.1 pk void
652 1.1 pk rcons_insertchar(rc, n)
653 1.3 ad struct rconsole *rc;
654 1.3 ad int n;
655 1.1 pk {
656 1.1 pk /* Can't insert more chars than can fit */
657 1.3 ad if (n > rc->rc_maxcol - rc->rc_col)
658 1.3 ad n = rc->rc_maxcol - rc->rc_col - 1;
659 1.3 ad
660 1.3 ad rc->rc_ops->copycols(rc->rc_cookie, rc->rc_row, rc->rc_col,
661 1.3 ad rc->rc_col + n, rc->rc_maxcol - rc->rc_col - n - 1);
662 1.1 pk
663 1.3 ad rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row, rc->rc_col,
664 1.3 ad n, rc->rc_attr);
665 1.1 pk }
666 1.1 pk
667 1.1 pk /* Insert some lines */
668 1.1 pk void
669 1.1 pk rcons_insertline(rc, n)
670 1.3 ad struct rconsole *rc;
671 1.3 ad int n;
672 1.1 pk {
673 1.1 pk /* Can't insert more lines than can fit */
674 1.3 ad if (n > rc->rc_maxrow - rc->rc_row)
675 1.3 ad n = rc->rc_maxrow - rc->rc_row;
676 1.1 pk
677 1.3 ad rc->rc_ops->copyrows(rc->rc_cookie, rc->rc_row, rc->rc_row + n,
678 1.3 ad rc->rc_maxrow - rc->rc_row - n);
679 1.1 pk
680 1.3 ad rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_row, n,
681 1.3 ad rc->rc_attr);
682 1.1 pk }
683 1.3 ad
684 1.3 ad /* end of rcons_subr.c */
685