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