Home | History | Annotate | Line # | Download | only in rcons
rcons_subr.c revision 1.1
      1  1.1  pk /*	$NetBSD: rcons_subr.c,v 1.1 1995/09/17 19:56:41 pk 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.1  pk #else
     51  1.1  pk #include <sys/types.h>
     52  1.1  pk #include "myfbdevice.h"
     53  1.1  pk #endif
     54  1.1  pk 
     55  1.1  pk #include <dev/rcons/rcons.h>
     56  1.1  pk #include <dev/rcons/raster.h>
     57  1.1  pk 
     58  1.1  pk void rcons_text(struct rconsole *, char *, int);
     59  1.1  pk void rcons_pctrl(struct rconsole *, int);
     60  1.1  pk void rcons_esc(struct rconsole *, int);
     61  1.1  pk void rcons_doesc(struct rconsole *, int);
     62  1.1  pk void rcons_cursor(struct rconsole *);
     63  1.1  pk void rcons_invert(struct rconsole *, int);
     64  1.1  pk void rcons_clear2eop(struct rconsole *);
     65  1.1  pk void rcons_clear2eol(struct rconsole *);
     66  1.1  pk void rcons_scroll(struct rconsole *, int);
     67  1.1  pk void rcons_delchar(struct rconsole *, int);
     68  1.1  pk void rcons_delline(struct rconsole *, int);
     69  1.1  pk void rcons_insertchar(struct rconsole *, int);
     70  1.1  pk void rcons_insertline(struct rconsole *, int);
     71  1.1  pk 
     72  1.1  pk extern void rcons_bell(struct rconsole *);
     73  1.1  pk 
     74  1.1  pk #define RCONS_ISPRINT(c) ((c) >= ' ' && (c) <= '~')
     75  1.1  pk #define RCONS_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
     76  1.1  pk 
     77  1.1  pk /* Output (or at least handle) a string sent to the console */
     78  1.1  pk void
     79  1.1  pk rcons_puts(rc, str, n)
     80  1.1  pk 	register struct rconsole *rc;
     81  1.1  pk 	register char *str;
     82  1.1  pk 	register int n;
     83  1.1  pk {
     84  1.1  pk 	register int c, i, j;
     85  1.1  pk 	register char *cp;
     86  1.1  pk 
     87  1.1  pk 	/* Jump scroll */
     88  1.1  pk 	/* XXX maybe this should be an option? */
     89  1.1  pk 	if ((rc->rc_bits & FB_INESC) == 0) {
     90  1.1  pk 		/* Count newlines up to an escape sequence */
     91  1.1  pk 		i = 0;
     92  1.1  pk 		j = 0;
     93  1.1  pk 		for (cp = str; j++ < n && *cp != '\033'; ++cp) {
     94  1.1  pk 			if (*cp == '\n')
     95  1.1  pk 				++i;
     96  1.1  pk 			else if (*cp == '\013')
     97  1.1  pk 				--i;
     98  1.1  pk 		}
     99  1.1  pk 
    100  1.1  pk 		/* Only jump scroll two or more rows */
    101  1.1  pk 		if (*rc->rc_row + i >= rc->rc_maxrow + 1) {
    102  1.1  pk 			/* Erase the cursor (if necessary) */
    103  1.1  pk 			if (rc->rc_bits & FB_CURSOR)
    104  1.1  pk 				rcons_cursor(rc);
    105  1.1  pk 
    106  1.1  pk 			rcons_scroll(rc, i);
    107  1.1  pk 		}
    108  1.1  pk 	}
    109  1.1  pk 
    110  1.1  pk 	/* Process characters */
    111  1.1  pk 	while (--n >= 0) {
    112  1.1  pk 		c = *str;
    113  1.1  pk 		if (c == '\033') {
    114  1.1  pk 			/* Start an escape (perhaps aborting one in progress) */
    115  1.1  pk 			rc->rc_bits |= FB_INESC | FB_P0_DEFAULT | FB_P1_DEFAULT;
    116  1.1  pk 			rc->rc_bits &= ~(FB_P0 | FB_P1);
    117  1.1  pk 
    118  1.1  pk 			/* Most parameters default to 1 */
    119  1.1  pk 			rc->rc_p0 = rc->rc_p1 = 1;
    120  1.1  pk 		} else if (rc->rc_bits & FB_INESC) {
    121  1.1  pk 			rcons_esc(rc, c);
    122  1.1  pk 		} else {
    123  1.1  pk 			/* Erase the cursor (if necessary) */
    124  1.1  pk 			if (rc->rc_bits & FB_CURSOR)
    125  1.1  pk 				rcons_cursor(rc);
    126  1.1  pk 
    127  1.1  pk 			/* Display the character */
    128  1.1  pk 			if (RCONS_ISPRINT(c)) {
    129  1.1  pk 				/* Try to output as much as possible */
    130  1.1  pk 				j = rc->rc_maxcol - (*rc->rc_col + 1);
    131  1.1  pk 				if (j > n)
    132  1.1  pk 					j = n;
    133  1.1  pk 				for (i = 1; i < j && RCONS_ISPRINT(str[i]); ++i)
    134  1.1  pk 					continue;
    135  1.1  pk 				rcons_text(rc, str, i);
    136  1.1  pk 				--i;
    137  1.1  pk 				str += i;
    138  1.1  pk 				n -= i;
    139  1.1  pk 			} else
    140  1.1  pk 				rcons_pctrl(rc, c);
    141  1.1  pk 		}
    142  1.1  pk 		++str;
    143  1.1  pk 	}
    144  1.1  pk 	/* Redraw the cursor (if necessary) */
    145  1.1  pk 	if ((rc->rc_bits & FB_CURSOR) == 0)
    146  1.1  pk 		rcons_cursor(rc);
    147  1.1  pk }
    148  1.1  pk 
    149  1.1  pk /* Actually write a string to the frame buffer */
    150  1.1  pk void
    151  1.1  pk rcons_text(rc, str, n)
    152  1.1  pk 	register struct rconsole *rc;
    153  1.1  pk 	register char *str;
    154  1.1  pk 	register int n;
    155  1.1  pk {
    156  1.1  pk 	register int x, y, op;
    157  1.1  pk 
    158  1.1  pk 	x = *rc->rc_col * rc->rc_font->width + rc->rc_xorigin;
    159  1.1  pk 	y = *rc->rc_row * rc->rc_font->height +
    160  1.1  pk 	    rc->rc_font_ascent + rc->rc_yorigin;
    161  1.1  pk 	op = RAS_SRC;
    162  1.1  pk 	if (((rc->rc_bits & FB_STANDOUT) != 0) ^
    163  1.1  pk 	    ((rc->rc_bits & FB_INVERT) != 0))
    164  1.1  pk 		op = RAS_NOT(op);
    165  1.1  pk 	raster_textn(rc->rc_sp, x, y, op, rc->rc_font, str, n);
    166  1.1  pk 	*rc->rc_col += n;
    167  1.1  pk 	if (*rc->rc_col >= rc->rc_maxcol) {
    168  1.1  pk 		*rc->rc_col = 0;
    169  1.1  pk 		(*rc->rc_row)++;
    170  1.1  pk 	}
    171  1.1  pk 	if (*rc->rc_row >= rc->rc_maxrow)
    172  1.1  pk 		rcons_scroll(rc, 1);
    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.1  pk 	register struct rconsole *rc;
    179  1.1  pk 	register int c;
    180  1.1  pk {
    181  1.1  pk 
    182  1.1  pk 	switch (c) {
    183  1.1  pk 
    184  1.1  pk 	case '\r':	/* Carriage return */
    185  1.1  pk 		*rc->rc_col = 0;
    186  1.1  pk 		break;
    187  1.1  pk 
    188  1.1  pk 	case '\b':	/* Backspace */
    189  1.1  pk 		if (*rc->rc_col > 0)
    190  1.1  pk 			(*rc->rc_col)--;
    191  1.1  pk 		break;
    192  1.1  pk 
    193  1.1  pk 	case '\013':	/* Vertical tab */
    194  1.1  pk 		if (*rc->rc_row > 0)
    195  1.1  pk 			(*rc->rc_row)--;
    196  1.1  pk 		break;
    197  1.1  pk 
    198  1.1  pk 	case '\f':	/* Formfeed */
    199  1.1  pk 		*rc->rc_row = *rc->rc_col = 0;
    200  1.1  pk 		rcons_clear2eop(rc);
    201  1.1  pk 		break;
    202  1.1  pk 
    203  1.1  pk 	case '\n':	/* Linefeed */
    204  1.1  pk 		(*rc->rc_row)++;
    205  1.1  pk 		if (*rc->rc_row >= rc->rc_maxrow)
    206  1.1  pk 			rcons_scroll(rc, 1);
    207  1.1  pk 		break;
    208  1.1  pk 
    209  1.1  pk 	case '\007':	/* Bell */
    210  1.1  pk 		rcons_bell(rc);
    211  1.1  pk 		break;
    212  1.1  pk 
    213  1.1  pk 	case '\t':	/* Horizontal tab */
    214  1.1  pk 		*rc->rc_col = (*rc->rc_col + 8) & ~7;
    215  1.1  pk 		if (*rc->rc_col >= rc->rc_maxcol)
    216  1.1  pk 			*rc->rc_col = rc->rc_maxcol - 1;
    217  1.1  pk 		break;
    218  1.1  pk 	}
    219  1.1  pk }
    220  1.1  pk 
    221  1.1  pk /* Handle the next character in an escape sequence */
    222  1.1  pk void
    223  1.1  pk rcons_esc(rc, c)
    224  1.1  pk 	register struct rconsole *rc;
    225  1.1  pk 	register int c;
    226  1.1  pk {
    227  1.1  pk 
    228  1.1  pk 	if (c == '[') {
    229  1.1  pk 		/* Parameter 0 */
    230  1.1  pk 		rc->rc_bits &= ~FB_P1;
    231  1.1  pk 		rc->rc_bits |= FB_P0;
    232  1.1  pk 	} else if (c == ';') {
    233  1.1  pk 		/* Parameter 1 */
    234  1.1  pk 		rc->rc_bits &= ~FB_P0;
    235  1.1  pk 		rc->rc_bits |= FB_P1;
    236  1.1  pk 	} else if (RCONS_ISDIGIT(c)) {
    237  1.1  pk 		/* Add a digit to a parameter */
    238  1.1  pk 		if (rc->rc_bits & FB_P0) {
    239  1.1  pk 			/* Parameter 0 */
    240  1.1  pk 			if (rc->rc_bits & FB_P0_DEFAULT) {
    241  1.1  pk 				rc->rc_bits &= ~FB_P0_DEFAULT;
    242  1.1  pk 				rc->rc_p0 = 0;
    243  1.1  pk 			}
    244  1.1  pk 			rc->rc_p0 *= 10;
    245  1.1  pk 			rc->rc_p0 += c - '0';
    246  1.1  pk 		} else if (rc->rc_bits & FB_P1) {
    247  1.1  pk 			/* Parameter 1 */
    248  1.1  pk 			if (rc->rc_bits & FB_P1_DEFAULT) {
    249  1.1  pk 				rc->rc_bits &= ~FB_P1_DEFAULT;
    250  1.1  pk 				rc->rc_p1 = 0;
    251  1.1  pk 			}
    252  1.1  pk 			rc->rc_p1 *= 10;
    253  1.1  pk 			rc->rc_p1 += c - '0';
    254  1.1  pk 		}
    255  1.1  pk 	} else {
    256  1.1  pk 		/* Erase the cursor (if necessary) */
    257  1.1  pk 		if (rc->rc_bits & FB_CURSOR)
    258  1.1  pk 			rcons_cursor(rc);
    259  1.1  pk 
    260  1.1  pk 		/* Process the completed escape sequence */
    261  1.1  pk 		rcons_doesc(rc, c);
    262  1.1  pk 		rc->rc_bits &= ~FB_INESC;
    263  1.1  pk 	}
    264  1.1  pk }
    265  1.1  pk 
    266  1.1  pk /* Process a complete escape sequence */
    267  1.1  pk void
    268  1.1  pk rcons_doesc(rc, c)
    269  1.1  pk 	register struct rconsole *rc;
    270  1.1  pk 	register int c;
    271  1.1  pk {
    272  1.1  pk 
    273  1.1  pk #ifdef notdef
    274  1.1  pk 	/* XXX add escape sequence to enable visual (and audible) bell */
    275  1.1  pk 	rc->rc_bits = FB_VISBELL;
    276  1.1  pk #endif
    277  1.1  pk 
    278  1.1  pk 	switch (c) {
    279  1.1  pk 
    280  1.1  pk 	case '@':
    281  1.1  pk 		/* Insert Character (ICH) */
    282  1.1  pk 		rcons_insertchar(rc, rc->rc_p0);
    283  1.1  pk 		break;
    284  1.1  pk 
    285  1.1  pk 	case 'A':
    286  1.1  pk 		/* Cursor Up (CUU) */
    287  1.1  pk 		*rc->rc_row -= rc->rc_p0;
    288  1.1  pk 		if (*rc->rc_row < 0)
    289  1.1  pk 			*rc->rc_row = 0;
    290  1.1  pk 		break;
    291  1.1  pk 
    292  1.1  pk 	case 'B':
    293  1.1  pk 		/* Cursor Down (CUD) */
    294  1.1  pk 		*rc->rc_row += rc->rc_p0;
    295  1.1  pk 		if (*rc->rc_row >= rc->rc_maxrow)
    296  1.1  pk 			*rc->rc_row = rc->rc_maxrow - 1;
    297  1.1  pk 		break;
    298  1.1  pk 
    299  1.1  pk 	case 'C':
    300  1.1  pk 		/* Cursor Forward (CUF) */
    301  1.1  pk 		*rc->rc_col += rc->rc_p0;
    302  1.1  pk 		if (*rc->rc_col >= rc->rc_maxcol)
    303  1.1  pk 			*rc->rc_col = rc->rc_maxcol - 1;
    304  1.1  pk 		break;
    305  1.1  pk 
    306  1.1  pk 	case 'D':
    307  1.1  pk 		/* Cursor Backward (CUB) */
    308  1.1  pk 		*rc->rc_col -= rc->rc_p0;
    309  1.1  pk 		if (*rc->rc_col < 0)
    310  1.1  pk 			*rc->rc_col = 0;
    311  1.1  pk 		break;
    312  1.1  pk 
    313  1.1  pk 	case 'E':
    314  1.1  pk 		/* Cursor Next Line (CNL) */
    315  1.1  pk 		*rc->rc_col = 0;
    316  1.1  pk 		*rc->rc_row += rc->rc_p0;
    317  1.1  pk 		if (*rc->rc_row >= rc->rc_maxrow)
    318  1.1  pk 			*rc->rc_row = rc->rc_maxrow - 1;
    319  1.1  pk 		break;
    320  1.1  pk 
    321  1.1  pk 	case 'f':
    322  1.1  pk 		/* Horizontal And Vertical Position (HVP) */
    323  1.1  pk 	case 'H':
    324  1.1  pk 		/* Cursor Position (CUP) */
    325  1.1  pk 		*rc->rc_col = rc->rc_p1 - 1;
    326  1.1  pk 		if (*rc->rc_col < 0)
    327  1.1  pk 			*rc->rc_col = 0;
    328  1.1  pk 		else if (*rc->rc_col >= rc->rc_maxcol)
    329  1.1  pk 			*rc->rc_col = rc->rc_maxcol - 1;
    330  1.1  pk 
    331  1.1  pk 		*rc->rc_row = rc->rc_p0 - 1;
    332  1.1  pk 		if (*rc->rc_row < 0)
    333  1.1  pk 			*rc->rc_row = 0;
    334  1.1  pk 		else if (*rc->rc_row >= rc->rc_maxrow)
    335  1.1  pk 			*rc->rc_row = rc->rc_maxrow - 1;
    336  1.1  pk 		break;
    337  1.1  pk 
    338  1.1  pk 	case 'J':
    339  1.1  pk 		/* Erase in Display (ED) */
    340  1.1  pk 		rcons_clear2eop(rc);
    341  1.1  pk 		break;
    342  1.1  pk 
    343  1.1  pk 	case 'K':
    344  1.1  pk 		/* Erase in Line (EL) */
    345  1.1  pk 		rcons_clear2eol(rc);
    346  1.1  pk 		break;
    347  1.1  pk 
    348  1.1  pk 	case 'L':
    349  1.1  pk 		/* Insert Line (IL) */
    350  1.1  pk 		rcons_insertline(rc, rc->rc_p0);
    351  1.1  pk 		break;
    352  1.1  pk 
    353  1.1  pk 	case 'M':
    354  1.1  pk 		/* Delete Line (DL) */
    355  1.1  pk 		rcons_delline(rc, rc->rc_p0);
    356  1.1  pk 		break;
    357  1.1  pk 
    358  1.1  pk 	case 'P':
    359  1.1  pk 		/* Delete Character (DCH) */
    360  1.1  pk 		rcons_delchar(rc, rc->rc_p0);
    361  1.1  pk 		break;
    362  1.1  pk 
    363  1.1  pk 	case 'm':
    364  1.1  pk 		/* Select Graphic Rendition (SGR); */
    365  1.1  pk 		/* (defaults to zero) */
    366  1.1  pk 		if (rc->rc_bits & FB_P0_DEFAULT)
    367  1.1  pk 			rc->rc_p0 = 0;
    368  1.1  pk 		if (rc->rc_p0)
    369  1.1  pk 			rc->rc_bits |= FB_STANDOUT;
    370  1.1  pk 		else
    371  1.1  pk 			rc->rc_bits &= ~FB_STANDOUT;
    372  1.1  pk 		break;
    373  1.1  pk 
    374  1.1  pk 	case 'p':
    375  1.1  pk 		/* Black On White (SUNBOW) */
    376  1.1  pk 		rcons_invert(rc, 0);
    377  1.1  pk 		break;
    378  1.1  pk 
    379  1.1  pk 	case 'q':
    380  1.1  pk 		/* White On Black (SUNWOB) */
    381  1.1  pk 		rcons_invert(rc, 1);
    382  1.1  pk 		break;
    383  1.1  pk 
    384  1.1  pk 	case 'r':
    385  1.1  pk 		/* Set scrolling (SUNSCRL) */
    386  1.1  pk 		/* (defaults to zero) */
    387  1.1  pk 		if (rc->rc_bits & FB_P0_DEFAULT)
    388  1.1  pk 			rc->rc_p0 = 0;
    389  1.1  pk 		/* XXX not implemented yet */
    390  1.1  pk 		rc->rc_scroll = rc->rc_p0;
    391  1.1  pk 		break;
    392  1.1  pk 
    393  1.1  pk 	case 's':
    394  1.1  pk 		/* Reset terminal emulator (SUNRESET) */
    395  1.1  pk 		rc->rc_bits &= ~FB_STANDOUT;
    396  1.1  pk 		rc->rc_scroll = 0;
    397  1.1  pk 		if (rc->rc_bits & FB_INVERT)
    398  1.1  pk 			rcons_invert(rc, 0);
    399  1.1  pk 		break;
    400  1.1  pk 	}
    401  1.1  pk }
    402  1.1  pk 
    403  1.1  pk /* Paint (or unpaint) the cursor */
    404  1.1  pk void
    405  1.1  pk rcons_cursor(rc)
    406  1.1  pk 	register struct rconsole *rc;
    407  1.1  pk {
    408  1.1  pk 	register int x, y;
    409  1.1  pk 
    410  1.1  pk 	x = *rc->rc_col * rc->rc_font->width + rc->rc_xorigin;
    411  1.1  pk 	y = *rc->rc_row * rc->rc_font->height + rc->rc_yorigin;
    412  1.1  pk 	raster_op(rc->rc_sp, x, y,
    413  1.1  pk #ifdef notdef
    414  1.1  pk 	    /* XXX This is the right way but too slow */
    415  1.1  pk 	    rc->rc_font->chars[(int)' '].r->width,
    416  1.1  pk 	    rc->rc_font->chars[(int)' '].r->height,
    417  1.1  pk #else
    418  1.1  pk 	    rc->rc_font->width, rc->rc_font->height,
    419  1.1  pk #endif
    420  1.1  pk 	    RAS_INVERT, (struct raster *) 0, 0, 0);
    421  1.1  pk 	rc->rc_bits ^= FB_CURSOR;
    422  1.1  pk }
    423  1.1  pk 
    424  1.1  pk /* Possibly change to SUNWOB or SUNBOW mode */
    425  1.1  pk void
    426  1.1  pk rcons_invert(rc, wob)
    427  1.1  pk 	struct rconsole *rc;
    428  1.1  pk 	int wob;
    429  1.1  pk {
    430  1.1  pk 	if (((rc->rc_bits & FB_INVERT) != 0) ^ wob) {
    431  1.1  pk 		/* Invert the display */
    432  1.1  pk 		raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
    433  1.1  pk 		    RAS_INVERT, (struct raster *) 0, 0, 0);
    434  1.1  pk 
    435  1.1  pk 		/* Swap things around */
    436  1.1  pk 		rc->rc_ras_blank = RAS_NOT(rc->rc_ras_blank);
    437  1.1  pk 		rc->rc_bits ^= FB_INVERT;
    438  1.1  pk 	}
    439  1.1  pk }
    440  1.1  pk 
    441  1.1  pk /* Clear to the end of the page */
    442  1.1  pk void
    443  1.1  pk rcons_clear2eop(rc)
    444  1.1  pk 	register struct rconsole *rc;
    445  1.1  pk {
    446  1.1  pk 	register int y;
    447  1.1  pk 
    448  1.1  pk 	if (*rc->rc_col == 0 && *rc->rc_row == 0) {
    449  1.1  pk 		/* Clear the entire frame buffer */
    450  1.1  pk 		raster_op(rc->rc_sp, 0, 0,
    451  1.1  pk 		    rc->rc_sp->width, rc->rc_sp->height,
    452  1.1  pk 		    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    453  1.1  pk 	} else {
    454  1.1  pk 		/* Only clear what needs to be cleared */
    455  1.1  pk 		rcons_clear2eol(rc);
    456  1.1  pk 		y = (*rc->rc_row + 1) * rc->rc_font->height;
    457  1.1  pk 
    458  1.1  pk 		raster_op(rc->rc_sp, rc->rc_xorigin, rc->rc_yorigin + y,
    459  1.1  pk 		    rc->rc_emuwidth, rc->rc_emuheight - y,
    460  1.1  pk 		    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    461  1.1  pk 	}
    462  1.1  pk }
    463  1.1  pk 
    464  1.1  pk /* Clear to the end of the line */
    465  1.1  pk void
    466  1.1  pk rcons_clear2eol(rc)
    467  1.1  pk 	register struct rconsole *rc;
    468  1.1  pk {
    469  1.1  pk 	register int x;
    470  1.1  pk 
    471  1.1  pk 	x = *rc->rc_col * rc->rc_font->width;
    472  1.1  pk 
    473  1.1  pk 	raster_op(rc->rc_sp,
    474  1.1  pk 	    rc->rc_xorigin + x,
    475  1.1  pk 	    *rc->rc_row * rc->rc_font->height + rc->rc_yorigin,
    476  1.1  pk 	    rc->rc_emuwidth - x, rc->rc_font->height,
    477  1.1  pk 	    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    478  1.1  pk }
    479  1.1  pk 
    480  1.1  pk /* Scroll up one line */
    481  1.1  pk void
    482  1.1  pk rcons_scroll(rc, n)
    483  1.1  pk 	register struct rconsole *rc;
    484  1.1  pk 	register int n;
    485  1.1  pk {
    486  1.1  pk 	register int ydiv;
    487  1.1  pk 
    488  1.1  pk 	/* Can't scroll more than the whole screen */
    489  1.1  pk 	if (n > rc->rc_maxrow)
    490  1.1  pk 		n = rc->rc_maxrow;
    491  1.1  pk 
    492  1.1  pk 	/* Calculate new row */
    493  1.1  pk 	*rc->rc_row -= n;
    494  1.1  pk 	if (*rc->rc_row < 0)
    495  1.1  pk 		*rc->rc_row  = 0;
    496  1.1  pk 
    497  1.1  pk 	/* Calculate number of pixels to scroll */
    498  1.1  pk 	ydiv = rc->rc_font->height * n;
    499  1.1  pk 
    500  1.1  pk 	raster_op(rc->rc_sp, rc->rc_xorigin, rc->rc_yorigin,
    501  1.1  pk 	    rc->rc_emuwidth, rc->rc_emuheight - ydiv,
    502  1.1  pk 	    RAS_SRC, rc->rc_sp, rc->rc_xorigin, ydiv + rc->rc_yorigin);
    503  1.1  pk 
    504  1.1  pk 	raster_op(rc->rc_sp,
    505  1.1  pk 	    rc->rc_xorigin, rc->rc_yorigin + rc->rc_emuheight - ydiv,
    506  1.1  pk 	    rc->rc_emuwidth, ydiv, rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    507  1.1  pk }
    508  1.1  pk 
    509  1.1  pk /* Delete characters */
    510  1.1  pk void
    511  1.1  pk rcons_delchar(rc, n)
    512  1.1  pk 	register struct rconsole *rc;
    513  1.1  pk 	register int n;
    514  1.1  pk {
    515  1.1  pk 	register int tox, fromx, y, width;
    516  1.1  pk 
    517  1.1  pk 	/* Can't delete more chars than there are */
    518  1.1  pk 	if (n > rc->rc_maxcol - *rc->rc_col)
    519  1.1  pk 		n = rc->rc_maxcol - *rc->rc_col;
    520  1.1  pk 
    521  1.1  pk 	fromx = (*rc->rc_col + n) * rc->rc_font->width;
    522  1.1  pk 	tox = *rc->rc_col * rc->rc_font->width;
    523  1.1  pk 	y = *rc->rc_row * rc->rc_font->height;
    524  1.1  pk 	width = n * rc->rc_font->width;
    525  1.1  pk 
    526  1.1  pk 	raster_op(rc->rc_sp, tox + rc->rc_xorigin, y + rc->rc_yorigin,
    527  1.1  pk 	    rc->rc_emuwidth - fromx, rc->rc_font->height,
    528  1.1  pk 	    RAS_SRC, rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin);
    529  1.1  pk 
    530  1.1  pk 	raster_op(rc->rc_sp,
    531  1.1  pk 	    rc->rc_emuwidth - width + rc->rc_xorigin, y + rc->rc_yorigin,
    532  1.1  pk 	    width, rc->rc_font->height,
    533  1.1  pk 	    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    534  1.1  pk }
    535  1.1  pk 
    536  1.1  pk /* Delete a number of lines */
    537  1.1  pk void
    538  1.1  pk rcons_delline(rc, n)
    539  1.1  pk 	register struct rconsole *rc;
    540  1.1  pk 	register int n;
    541  1.1  pk {
    542  1.1  pk 	register int fromy, toy, height;
    543  1.1  pk 
    544  1.1  pk 	/* Can't delete more lines than there are */
    545  1.1  pk 	if (n > rc->rc_maxrow - *rc->rc_row)
    546  1.1  pk 		n = rc->rc_maxrow - *rc->rc_row;
    547  1.1  pk 
    548  1.1  pk 	fromy = (*rc->rc_row + n) * rc->rc_font->height;
    549  1.1  pk 	toy = *rc->rc_row * rc->rc_font->height;
    550  1.1  pk 	height = rc->rc_font->height * n;
    551  1.1  pk 
    552  1.1  pk 	raster_op(rc->rc_sp, rc->rc_xorigin, toy + rc->rc_yorigin,
    553  1.1  pk 	    rc->rc_emuwidth, rc->rc_emuheight - fromy, RAS_SRC,
    554  1.1  pk 	    rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin);
    555  1.1  pk 
    556  1.1  pk 	raster_op(rc->rc_sp,
    557  1.1  pk 	    rc->rc_xorigin, rc->rc_emuheight - height + rc->rc_yorigin,
    558  1.1  pk 	    rc->rc_emuwidth, height,
    559  1.1  pk 	    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    560  1.1  pk }
    561  1.1  pk 
    562  1.1  pk /* Insert some characters */
    563  1.1  pk void
    564  1.1  pk rcons_insertchar(rc, n)
    565  1.1  pk 	register struct rconsole *rc;
    566  1.1  pk 	register int n;
    567  1.1  pk {
    568  1.1  pk 	register int tox, fromx, y;
    569  1.1  pk 
    570  1.1  pk 	/* Can't insert more chars than can fit */
    571  1.1  pk 	if (n > rc->rc_maxcol - *rc->rc_col)
    572  1.1  pk 		n = rc->rc_maxcol - *rc->rc_col;
    573  1.1  pk 
    574  1.1  pk 	tox = (*rc->rc_col + n) * rc->rc_font->width;
    575  1.1  pk 	fromx = *rc->rc_col * rc->rc_font->width;
    576  1.1  pk 	y = *rc->rc_row * rc->rc_font->height;
    577  1.1  pk 
    578  1.1  pk 	raster_op(rc->rc_sp, tox + rc->rc_xorigin, y + rc->rc_yorigin,
    579  1.1  pk 	    rc->rc_emuwidth - tox, rc->rc_font->height,
    580  1.1  pk 	    RAS_SRC, rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin);
    581  1.1  pk 
    582  1.1  pk 	raster_op(rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin,
    583  1.1  pk 	    rc->rc_font->width * n, rc->rc_font->height,
    584  1.1  pk 	    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    585  1.1  pk }
    586  1.1  pk 
    587  1.1  pk /* Insert some lines */
    588  1.1  pk void
    589  1.1  pk rcons_insertline(rc, n)
    590  1.1  pk 	register struct rconsole *rc;
    591  1.1  pk 	register int n;
    592  1.1  pk {
    593  1.1  pk 	register int fromy, toy;
    594  1.1  pk 
    595  1.1  pk 	/* Can't insert more lines than can fit */
    596  1.1  pk 	if (n > rc->rc_maxrow - *rc->rc_row)
    597  1.1  pk 		n = rc->rc_maxrow - *rc->rc_row;
    598  1.1  pk 
    599  1.1  pk 	toy = (*rc->rc_row + n) * rc->rc_font->height;
    600  1.1  pk 	fromy = *rc->rc_row * rc->rc_font->height;
    601  1.1  pk 
    602  1.1  pk 	raster_op(rc->rc_sp, rc->rc_xorigin, toy + rc->rc_yorigin,
    603  1.1  pk 	    rc->rc_emuwidth, rc->rc_emuheight - toy,
    604  1.1  pk 	    RAS_SRC, rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin);
    605  1.1  pk 
    606  1.1  pk 	raster_op(rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin,
    607  1.1  pk 	    rc->rc_emuwidth, rc->rc_font->height * n,
    608  1.1  pk 	    rc->rc_ras_blank, (struct raster *) 0, 0, 0);
    609  1.1  pk }
    610