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