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