Many enchancements to rcons to support ANSI color and all attributes

properly. All output now performed using a 'struct wsdisplay_emulops'.
This commit is contained in:
ad 1999-04-13 18:43:17 +00:00
parent a9ef1be75b
commit 8fe6730f9a
6 changed files with 387 additions and 348 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.1 1998/06/12 23:22:55 cgd Exp $
# $NetBSD: Makefile,v 1.2 1999/04/13 18:43:17 ad Exp $
INCSDIR= /usr/include/dev/rcons
INCS= raster.h rcons.h rcons_subr.h
INCS= raster.h rcons.h
.include <bsd.kinc.mk>

View File

@ -1,12 +1,11 @@
# $NetBSD: files.rcons,v 1.3 1999/03/27 00:07:58 dbj Exp $
# $NetBSD: files.rcons,v 1.4 1999/04/13 18:43:17 ad Exp $
#
# Configuration file for RASTER Console.
#
file dev/rcons/raster_op.c raster
file dev/rcons/raster_text.c raster
# rcons bit-depth options
defopt opt_rcons.h RCONS_2BPP RCONS_16BPP
file dev/rcons/raster_op.c rasterconsole | raster
file dev/rcons/raster_text.c rasterconsole | raster
file dev/rcons/rcons_kern.c rasterconsole
file dev/rcons/rcons_subr.c rasterconsole
defopt opt_rcons.h RASTERCONS_FGCOL RASTERCONS_BGCOL

View File

@ -1,4 +1,4 @@
/* $NetBSD: rcons.h,v 1.4 1996/03/14 19:02:32 christos Exp $ */
/* $NetBSD: rcons.h,v 1.5 1999/04/13 18:43:17 ad Exp $ */
/*
* Copyright (c) 1992, 1993
@ -43,72 +43,74 @@
*
* @(#)fbvar.h 8.1 (Berkeley) 6/11/93
*/
#ifndef _RCONS_H_
#define _RCONS_H_ 1
#include <dev/rcons/raster.h>
/* Default color values */
#include "opt_rcons.h"
#ifndef RASTERCONSOLE_FGCOL
#define RASTERCONSOLE_FGCOL WSCOL_WHITE
#endif
#ifndef RASTERCONSOLE_BGCOL
#define RASTERCONSOLE_BGCOL WSCOL_BLACK
#endif
/* Avoid dragging in dev/wscons/wsdisplayvar.h */
struct wsdisplay_emulops;
struct rconsole {
/* Raster console emulator state */
/* This section must be filled in by the framebugger device */
int rc_width;
int rc_height;
int rc_depth;
caddr_t rc_pixels; /* display RAM */
int rc_linebytes; /* bytes per display line */
int rc_maxrow; /* emulator height of screen */
int rc_maxcol; /* emulator width of screen */
u_int rc_maxrow; /* emulator height of screen */
u_int rc_maxcol; /* emulator width of screen */
void (*rc_bell)__P((int)); /* ring the bell */
/* The following two items may optionally be left zero */
int *rc_row; /* emulator row */
int *rc_col; /* emulator column */
struct wsdisplay_emulops *rc_ops;/* output ops */
void *rc_cookie; /* cookie thereof */
u_int rc_width; /* width in pixels */
u_int rc_height; /* height in pixels */
/* Bits maintained by the raster routines */
u_int rc_row; /* emulator row */
u_int rc_col; /* emulator column */
u_int rc_bits; /* see defines below */
int rc_ringing; /* bell currently ringing */
int rc_belldepth; /* audible bell depth */
int rc_scroll; /* stupid sun scroll mode */
int rc_p0; /* escape sequence parameter 0 */
int rc_p1; /* escape sequence parameter 1 */
int rc_emuwidth; /* emulator screen width */
int rc_emuheight; /* emulator screen height */
int rc_xorigin; /* x origin for first column */
int rc_yorigin; /* y origin for first row */
struct raster *rc_sp; /* frame buffer raster */
struct raster *rc_cursor; /* optional cursor */
int rc_ras_blank; /* current screen blank raster op */
struct raster_font *rc_font; /* font and related info */
int rc_fgcolor; /* current fg color */
int rc_bgcolor; /* current bg color */
long rc_attr; /* wscons text attribute */
long rc_kern_attr; /* kernel output attribute */
u_int rc_wsflg; /* wscons attribute flags */
u_int rc_supwsflg; /* supported attribute flags */
u_int rc_charmap[256]; /* ASCII->emulator char map */
};
#define FB_INESC 0x001 /* processing an escape sequence */
#define FB_STANDOUT 0x002 /* standout mode */
#ifdef notyet
#define FB_BOLD 0x? /* boldface mode */
#endif
#define FB_INVERT 0x008 /* white on black mode */
#define FB_VISBELL 0x010 /* visual bell */
#define FB_CURSOR 0x020 /* cursor is visible */
#define FB_VISBELL 0x002 /* visual bell */
#define FB_CURSOR 0x004 /* cursor is visible */
#define FB_INVERT 0x008 /* framebuffer inverted */
#define FB_NO_CURSOR 0x010 /* cursor is disabled */
#define FB_P0_DEFAULT 0x100 /* param 0 is defaulted */
#define FB_P1_DEFAULT 0x200 /* param 1 is defaulted */
#define FB_P0 0x400 /* working on param 0 */
#define FB_P1 0x800 /* working on param 1 */
/* rcons_kern.c */
void rcons_cnputc __P((int));
void rcons_bell __P((struct rconsole *));
void rcons_init __P((struct rconsole *));
/* rcons_subr.c */
void rcons_init_ops __P((struct rconsole *rc));
void rcons_puts __P((struct rconsole *, unsigned char *, int));
void rcons_text __P((struct rconsole *, unsigned char *, int));
void rcons_pctrl __P((struct rconsole *, int));
void rcons_esc __P((struct rconsole *, int));
void rcons_doesc __P((struct rconsole *, int));
void rcons_sgresc __P((struct rconsole *, int));
void rcons_init __P((struct rconsole *));
void rcons_text __P((struct rconsole *, unsigned char *, int));
void rcons_cursor __P((struct rconsole *));
void rcons_invert __P((struct rconsole *, int));
void rcons_clear2eop __P((struct rconsole *));
@ -118,3 +120,6 @@ void rcons_delchar __P((struct rconsole *, int));
void rcons_delline __P((struct rconsole *, int));
void rcons_insertchar __P((struct rconsole *, int));
void rcons_insertline __P((struct rconsole *, int));
void rcons_setcolor __P((struct rconsole *, int, int));
#endif /* !defined _RCONS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: rcons_kern.c,v 1.6 1996/10/13 01:38:31 christos Exp $ */
/* $NetBSD: rcons_kern.c,v 1.7 1999/04/13 18:43:17 ad Exp $ */
/*
* Copyright (c) 1991, 1993
@ -51,6 +51,7 @@
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/proc.h>
#include <dev/rcons/raster.h>
#include <dev/rcons/rcons.h>
@ -58,9 +59,7 @@ extern struct tty *fbconstty;
static void rcons_belltmr(void *);
#include "rcons_subr.h"
static struct rconsole *mydevicep;
static struct rconsole *mydevicep; /* XXX */
static void rcons_output __P((struct tty *));
void
@ -68,6 +67,11 @@ rcons_cnputc(c)
int c;
{
char buf[1];
long attr;
/* Swap in kernel attribute */
attr = mydevicep->rc_attr;
mydevicep->rc_attr = mydevicep->rc_kern_attr;
if (c == '\n')
rcons_puts(mydevicep, "\r\n", 2);
@ -75,13 +79,16 @@ rcons_cnputc(c)
buf[0] = c;
rcons_puts(mydevicep, buf, 1);
}
/* Swap out kernel attribute */
mydevicep->rc_attr = attr;
}
static void
rcons_output(tp)
register struct tty *tp;
struct tty *tp;
{
register int s, n;
int s, n;
char buf[OBUFSIZ];
s = spltty();
@ -114,16 +121,15 @@ rcons_output(tp)
/* Ring the console bell */
void
rcons_bell(rc)
register struct rconsole *rc;
struct rconsole *rc;
{
register int i, s;
int i, s;
if (rc->rc_bits & FB_VISBELL) {
/* invert the screen twice */
for (i = 0; i < 2; ++i)
raster_op(rc->rc_sp, 0, 0,
rc->rc_sp->width, rc->rc_sp->height,
RAS_INVERT, (struct raster *) 0, 0, 0);
i = ((rc->rc_bits & FB_INVERT) == 0);
rcons_invert(rc, i);
rcons_invert(rc, i ^ 1);
}
s = splhigh();
@ -145,8 +151,8 @@ static void
rcons_belltmr(p)
void *p;
{
register struct rconsole *rc = p;
register int s = splhigh(), i;
struct rconsole *rc = p;
int s = splhigh(), i;
if (rc->rc_ringing) {
rc->rc_ringing = 0;
@ -166,39 +172,13 @@ rcons_belltmr(p)
void
rcons_init(rc)
register struct rconsole *rc;
struct rconsole *rc;
{
/* XXX this should go away */
static struct raster xxxraster;
register struct raster *rp = rc->rc_sp = &xxxraster;
register struct winsize *ws;
register int i;
static int row, col;
struct winsize *ws;
mydevicep = rc;
/* XXX mostly duplicates of data in other places */
rp->width = rc->rc_width;
rp->height = rc->rc_height;
rp->depth = rc->rc_depth;
if (rc->rc_linebytes & 0x3) {
printf("rcons_init: linebytes assumption botched (0x%x)\n",
rc->rc_linebytes);
return;
}
rp->linelongs = rc->rc_linebytes >> 2;
rp->pixels = (u_int32_t *)rc->rc_pixels;
rc->rc_ras_blank = RAS_CLEAR;
/* Impose upper bounds on rc_max{row,col} */
i = rc->rc_height / rc->rc_font->height;
if (rc->rc_maxrow > i)
rc->rc_maxrow = i;
i = rc->rc_width / rc->rc_font->width;
if (rc->rc_maxcol > i)
rc->rc_maxcol = i;
/* Let the system know how big the console is */
ws = &fbconstty->t_winsize;
ws->ws_row = rc->rc_maxrow;
@ -206,47 +186,13 @@ rcons_init(rc)
ws->ws_xpixel = rc->rc_width;
ws->ws_ypixel = rc->rc_height;
/* Center emulator screen (but align x origin to 32 bits) */
rc->rc_xorigin =
((rc->rc_width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~0x1f;
rc->rc_yorigin =
(rc->rc_height - rc->rc_maxrow * rc->rc_font->height) / 2;
/* Emulator width and height used for scrolling */
rc->rc_emuwidth = rc->rc_maxcol * rc->rc_font->width;
if (rc->rc_emuwidth & 0x1f) {
/* Pad to 32 bits */
i = (rc->rc_emuwidth + 0x1f) & ~0x1f;
/* Make sure emulator width isn't too wide */
if (rc->rc_xorigin + i <= rc->rc_width)
rc->rc_emuwidth = i;
}
rc->rc_emuheight = rc->rc_maxrow * rc->rc_font->height;
#ifdef RASTERCONS_WONB
rc->rc_ras_blank = RAS_NOT(rc->rc_ras_blank);
rc->rc_bits |= FB_INVERT;
#endif
if (rc->rc_row == NULL || rc->rc_col == NULL) {
/*
* No address passed; use private copies
* go to LL corner and scroll.
*/
rc->rc_row = &row;
rc->rc_col = &col;
row = rc->rc_maxrow;
col = 0;
#if 0
rcons_clear2eop(rc); /* clear the display */
#endif
rcons_scroll(rc, 1);
rcons_cursor(rc); /* and draw the initial cursor */
} else {
/* Prom emulator cursor is currently visible */
rc->rc_bits |= FB_CURSOR;
}
/* Initialize operations set, clear screen and turn cursor on */
rcons_init_ops(rc);
rc->rc_col = 0;
rc->rc_row = 0;
rcons_clear2eop(rc);
rcons_cursor(rc);
/* Initialization done; hook us up */
fbconstty->t_oproc = rcons_output;
/*fbconstty->t_stop = (void (*)()) nullop;*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: rcons_subr.c,v 1.2 1995/10/04 23:57:26 pk Exp $ */
/* $NetBSD: rcons_subr.c,v 1.3 1999/04/13 18:43:17 ad Exp $ */
/*
* Copyright (c) 1991, 1993
@ -47,30 +47,66 @@
#ifdef _KERNEL
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#else
#include <sys/types.h>
#include "myfbdevice.h"
#endif
#include <dev/rcons/rcons.h>
#include <dev/rcons/raster.h>
#include "rcons_subr.h"
#include <dev/wscons/wsdisplayvar.h>
extern void rcons_bell(struct rconsole *);
#define RCONS_ISPRINT(c) ((((c) >= ' ') && ((c) <= '~')) || ((c) > 160))
#define RCONS_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
/* Initalize our operations set */
void
rcons_init_ops(rc)
struct rconsole *rc;
{
u_int ch;
long tmp;
int i;
i = (sizeof(rc->rc_charmap) / sizeof(rc->rc_charmap[0])) - 1;
for (; i >= 0; i--) {
rc->rc_ops->mapchar(rc->rc_cookie, i, &ch);
rc->rc_charmap[i] = ch;
}
/*
* Determine which attributes the device supports.
* XXX should determine exactly which _combinations_ work.
*/
rc->rc_fgcolor = RASTERCONSOLE_FGCOL;
rc->rc_bgcolor = RASTERCONSOLE_BGCOL;
rc->rc_supwsflg = 0;
for (i = 1; i < 256; i <<= 1)
if (rc->rc_ops->alloc_attr(rc->rc_cookie, 0, 0, i, &tmp) == 0)
rc->rc_supwsflg |= i;
/* Allocate kernel output attribute */
rc->rc_wsflg = WSATTR_HILIT;
rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
rc->rc_kern_attr = rc->rc_attr;
rc->rc_wsflg = 0;
rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
}
/* Output (or at least handle) a string sent to the console */
void
rcons_puts(rc, str, n)
register struct rconsole *rc;
register unsigned char *str;
register int n;
struct rconsole *rc;
unsigned char *str;
int n;
{
register int c, i, j;
register unsigned char *cp;
int c, i, j;
unsigned char *cp;
/* Jump scroll */
/* XXX maybe this should be an option? */
@ -86,7 +122,7 @@ rcons_puts(rc, str, n)
}
/* Only jump scroll two or more rows */
if (*rc->rc_row + i >= rc->rc_maxrow + 1) {
if (rc->rc_row + i > rc->rc_maxrow + 1) {
/* Erase the cursor (if necessary) */
if (rc->rc_bits & FB_CURSOR)
rcons_cursor(rc);
@ -115,7 +151,7 @@ rcons_puts(rc, str, n)
/* Display the character */
if (RCONS_ISPRINT(c)) {
/* Try to output as much as possible */
j = rc->rc_maxcol - (*rc->rc_col + 1);
j = rc->rc_maxcol - rc->rc_col;
if (j > n)
j = n;
for (i = 1; i < j && RCONS_ISPRINT(str[i]); ++i)
@ -134,74 +170,49 @@ rcons_puts(rc, str, n)
rcons_cursor(rc);
}
/* Actually write a string to the frame buffer */
void
rcons_text(rc, str, n)
register struct rconsole *rc;
register unsigned char *str;
register int n;
{
register int x, y, op;
x = *rc->rc_col * rc->rc_font->width + rc->rc_xorigin;
y = *rc->rc_row * rc->rc_font->height +
rc->rc_font->ascent + rc->rc_yorigin;
op = RAS_SRC;
if (((rc->rc_bits & FB_STANDOUT) != 0) ^
((rc->rc_bits & FB_INVERT) != 0))
op = RAS_NOT(op);
raster_textn(rc->rc_sp, x, y, op, rc->rc_font, str, n);
*rc->rc_col += n;
if (*rc->rc_col >= rc->rc_maxcol) {
*rc->rc_col = 0;
(*rc->rc_row)++;
}
if (*rc->rc_row >= rc->rc_maxrow)
rcons_scroll(rc, 1);
}
/* Handle a control character sent to the console */
void
rcons_pctrl(rc, c)
register struct rconsole *rc;
register int c;
struct rconsole *rc;
int c;
{
switch (c) {
case '\r': /* Carriage return */
*rc->rc_col = 0;
rc->rc_col = 0;
break;
case '\b': /* Backspace */
if (*rc->rc_col > 0)
(*rc->rc_col)--;
if (rc->rc_col > 0)
(rc->rc_col)--;
break;
case '\013': /* Vertical tab */
if (*rc->rc_row > 0)
(*rc->rc_row)--;
case '\v': /* Vertical tab */
if (rc->rc_row > 0)
(rc->rc_row)--;
break;
case '\f': /* Formfeed */
*rc->rc_row = *rc->rc_col = 0;
rc->rc_row = rc->rc_col = 0;
rcons_clear2eop(rc);
break;
case '\n': /* Linefeed */
(*rc->rc_row)++;
if (*rc->rc_row >= rc->rc_maxrow)
(rc->rc_row)++;
if (rc->rc_row >= rc->rc_maxrow)
rcons_scroll(rc, 1);
break;
case '\007': /* Bell */
case '\a': /* Bell */
rcons_bell(rc);
break;
case '\t': /* Horizontal tab */
*rc->rc_col = (*rc->rc_col + 8) & ~7;
if (*rc->rc_col >= rc->rc_maxcol)
*rc->rc_col = rc->rc_maxcol - 1;
rc->rc_col = (rc->rc_col + 8) & ~7;
if (rc->rc_col >= rc->rc_maxcol)
rc->rc_col = rc->rc_maxcol;
break;
}
}
@ -209,8 +220,8 @@ rcons_pctrl(rc, c)
/* Handle the next character in an escape sequence */
void
rcons_esc(rc, c)
register struct rconsole *rc;
register int c;
struct rconsole *rc;
int c;
{
if (c == '[') {
@ -251,11 +262,59 @@ rcons_esc(rc, c)
}
}
/* Handle an SGR (Select Graphic Rendition) escape */
void
rcons_sgresc(rc, c)
struct rconsole *rc;
int c;
{
switch (c) {
/* Clear all attributes || End underline */
case 0:
rc->rc_wsflg = 0;
rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
break;
/* ANSI foreground color */
case 30: case 31: case 32: case 33:
case 34: case 35: case 36: case 37:
rcons_setcolor(rc, c - 30, rc->rc_bgcolor);
break;
/* ANSI background color */
case 40: case 41: case 42: case 43:
case 44: case 45: case 46: case 47:
rcons_setcolor(rc, rc->rc_fgcolor, c - 40);
break;
/* Begin reverse */
case 7:
rc->rc_wsflg |= WSATTR_REVERSE;
rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
break;
/* Begin bold */
case 1:
rc->rc_wsflg |= WSATTR_HILIT;
rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
break;
/* Begin underline */
case 4:
rc->rc_wsflg |= WSATTR_UNDERLINE;
rcons_setcolor(rc, rc->rc_fgcolor, rc->rc_bgcolor);
break;
}
}
/* Process a complete escape sequence */
void
rcons_doesc(rc, c)
register struct rconsole *rc;
register int c;
struct rconsole *rc;
int c;
{
#ifdef notdef
@ -272,55 +331,55 @@ rcons_doesc(rc, c)
case 'A':
/* Cursor Up (CUU) */
*rc->rc_row -= rc->rc_p0;
if (*rc->rc_row < 0)
*rc->rc_row = 0;
rc->rc_row -= rc->rc_p0;
if (rc->rc_row < 0)
rc->rc_row = 0;
break;
case 'B':
/* Cursor Down (CUD) */
*rc->rc_row += rc->rc_p0;
if (*rc->rc_row >= rc->rc_maxrow)
*rc->rc_row = rc->rc_maxrow - 1;
rc->rc_row += rc->rc_p0;
if (rc->rc_row >= rc->rc_maxrow)
rc->rc_row = rc->rc_maxrow - 1;
break;
case 'C':
/* Cursor Forward (CUF) */
*rc->rc_col += rc->rc_p0;
if (*rc->rc_col >= rc->rc_maxcol)
*rc->rc_col = rc->rc_maxcol - 1;
rc->rc_col += rc->rc_p0;
if (rc->rc_col >= rc->rc_maxcol)
rc->rc_col = rc->rc_maxcol - 1;
break;
case 'D':
/* Cursor Backward (CUB) */
*rc->rc_col -= rc->rc_p0;
if (*rc->rc_col < 0)
*rc->rc_col = 0;
rc->rc_col -= rc->rc_p0;
if (rc->rc_col < 0)
rc->rc_col = 0;
break;
case 'E':
/* Cursor Next Line (CNL) */
*rc->rc_col = 0;
*rc->rc_row += rc->rc_p0;
if (*rc->rc_row >= rc->rc_maxrow)
*rc->rc_row = rc->rc_maxrow - 1;
rc->rc_col = 0;
rc->rc_row += rc->rc_p0;
if (rc->rc_row >= rc->rc_maxrow)
rc->rc_row = rc->rc_maxrow - 1;
break;
case 'f':
/* Horizontal And Vertical Position (HVP) */
case 'H':
/* Cursor Position (CUP) */
*rc->rc_col = rc->rc_p1 - 1;
if (*rc->rc_col < 0)
*rc->rc_col = 0;
else if (*rc->rc_col >= rc->rc_maxcol)
*rc->rc_col = rc->rc_maxcol - 1;
rc->rc_col = rc->rc_p1 - 1;
if (rc->rc_col < 0)
rc->rc_col = 0;
else if (rc->rc_col >= rc->rc_maxcol)
rc->rc_col = rc->rc_maxcol - 1;
*rc->rc_row = rc->rc_p0 - 1;
if (*rc->rc_row < 0)
*rc->rc_row = 0;
else if (*rc->rc_row >= rc->rc_maxrow)
*rc->rc_row = rc->rc_maxrow - 1;
rc->rc_row = rc->rc_p0 - 1;
if (rc->rc_row < 0)
rc->rc_row = 0;
else if (rc->rc_row >= rc->rc_maxrow)
rc->rc_row = rc->rc_maxrow - 1;
break;
case 'J':
@ -349,14 +408,19 @@ rcons_doesc(rc, c)
break;
case 'm':
/* Select Graphic Rendition (SGR); */
/* Select Graphic Rendition (SGR) */
/* (defaults to zero) */
if (rc->rc_bits & FB_P0_DEFAULT)
rc->rc_p0 = 0;
if (rc->rc_p0)
rc->rc_bits |= FB_STANDOUT;
else
rc->rc_bits &= ~FB_STANDOUT;
if (rc->rc_bits & FB_P1_DEFAULT)
rc->rc_p1 = 0;
rcons_sgresc(rc, rc->rc_p0);
if (rc->rc_bits & FB_P1)
rcons_sgresc(rc, rc->rc_p1);
break;
case 'p':
@ -380,33 +444,116 @@ rcons_doesc(rc, c)
case 's':
/* Reset terminal emulator (SUNRESET) */
rc->rc_bits &= ~FB_STANDOUT;
rc->rc_wsflg = 0;
rc->rc_scroll = 0;
rc->rc_bits &= ~FB_NO_CURSOR;
rcons_setcolor(rc, RASTERCONSOLE_FGCOL, RASTERCONSOLE_BGCOL);
if (rc->rc_bits & FB_INVERT)
rcons_invert(rc, 0);
break;
#ifdef notyet
/*
* XXX following two read \E[?25h and \E[?25l. rcons
* can't currently handle the '?'.
*/
case 'h':
/* Normal/very visible cursor */
if (rc->rc_p0 == 25) {
rc->rc_bits &= ~FB_NO_CURSOR;
if (rc->rc_bits & FB_CURSOR) {
rc->rc_bits ^= FB_CURSOR;
rcons_cursor(rc);
}
}
break;
case 'l':
/* Invisible cursor */
if (rc->rc_p0 == 25 && (rc->rc_bits & FB_NO_CURSOR) == 0) {
if (rc->rc_bits & FB_CURSOR)
rcons_cursor(rc);
rc->rc_bits |= FB_NO_CURSOR;
}
break;
#endif
}
}
/* Set ANSI colors */
void
rcons_setcolor(rc, fg, bg)
struct rconsole *rc;
int fg, bg;
{
int flg;
if (fg > WSCOL_WHITE || fg < 0)
return;
if (bg > WSCOL_WHITE || bg < 0)
return;
#ifdef RASTERCONS_WONB
flg = bg;
bg = fg;
fg = flg;
#endif
/* Emulate WSATTR_REVERSE attribute if it's not supported */
if ((rc->rc_wsflg & WSATTR_REVERSE) &&
!(rc->rc_supwsflg & WSATTR_REVERSE)) {
flg = bg;
bg = fg;
fg = flg;
}
/* Mask out unsupported flags and get attribute */
flg = rc->rc_wsflg & rc->rc_supwsflg;
rc->rc_bgcolor = bg;
rc->rc_fgcolor = fg;
rc->rc_ops->alloc_attr(rc->rc_cookie, fg, bg, flg, &rc->rc_attr);
}
/* Actually write a string to the frame buffer */
void
rcons_text(rc, str, n)
struct rconsole *rc;
unsigned char *str;
int n;
{
u_int uc;
while (n--) {
uc = rc->rc_charmap[*str++ & 255];
rc->rc_ops->putchar(rc->rc_cookie, rc->rc_row, rc->rc_col++,
uc, rc->rc_attr);
}
if (rc->rc_col >= rc->rc_maxcol) {
rc->rc_col = 0;
rc->rc_row++;
}
if (rc->rc_row >= rc->rc_maxrow)
rcons_scroll(rc, 1);
}
/* Paint (or unpaint) the cursor */
void
rcons_cursor(rc)
register struct rconsole *rc;
struct rconsole *rc;
{
register int x, y;
x = *rc->rc_col * rc->rc_font->width + rc->rc_xorigin;
y = *rc->rc_row * rc->rc_font->height + rc->rc_yorigin;
raster_op(rc->rc_sp, x, y,
#ifdef notdef
/* XXX This is the right way but too slow */
rc->rc_font->chars[(int)' '].r->width,
rc->rc_font->chars[(int)' '].r->height,
#else
rc->rc_font->width, rc->rc_font->height,
#endif
RAS_INVERT, (struct raster *) 0, 0, 0);
rc->rc_bits ^= FB_CURSOR;
if (rc->rc_bits & FB_NO_CURSOR)
return;
rc->rc_ops->cursor(rc->rc_cookie, rc->rc_bits & FB_CURSOR,
rc->rc_row, rc->rc_col);
}
/* Possibly change to SUNWOB or SUNBOW mode */
@ -415,183 +562,123 @@ rcons_invert(rc, wob)
struct rconsole *rc;
int wob;
{
if (((rc->rc_bits & FB_INVERT) != 0) ^ wob) {
/* Invert the display */
raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
RAS_INVERT, (struct raster *) 0, 0, 0);
/* Swap things around */
rc->rc_ras_blank = RAS_NOT(rc->rc_ras_blank);
rc->rc_bits ^= FB_INVERT;
}
rc->rc_bits ^= FB_INVERT;
/* XXX how do we do we invert the framebuffer?? */
}
/* Clear to the end of the page */
void
rcons_clear2eop(rc)
register struct rconsole *rc;
struct rconsole *rc;
{
register int y;
if (*rc->rc_col == 0 && *rc->rc_row == 0) {
/* Clear the entire frame buffer */
raster_op(rc->rc_sp, 0, 0,
rc->rc_sp->width, rc->rc_sp->height,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
} else {
/* Only clear what needs to be cleared */
if (rc->rc_col || rc->rc_row) {
rcons_clear2eol(rc);
y = (*rc->rc_row + 1) * rc->rc_font->height;
raster_op(rc->rc_sp, rc->rc_xorigin, rc->rc_yorigin + y,
rc->rc_emuwidth, rc->rc_emuheight - y,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
}
if (rc->rc_row < (rc->rc_maxrow - 1))
rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_row + 1,
rc->rc_maxrow, rc->rc_attr);
} else
rc->rc_ops->eraserows(rc->rc_cookie, 0, rc->rc_maxrow,
rc->rc_attr);
}
/* Clear to the end of the line */
void
rcons_clear2eol(rc)
register struct rconsole *rc;
struct rconsole *rc;
{
register int x;
x = *rc->rc_col * rc->rc_font->width;
raster_op(rc->rc_sp,
rc->rc_xorigin + x,
*rc->rc_row * rc->rc_font->height + rc->rc_yorigin,
rc->rc_emuwidth - x, rc->rc_font->height,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row, rc->rc_col,
rc->rc_maxcol - rc->rc_col, rc->rc_attr);
}
/* Scroll up one line */
/* Scroll up */
void
rcons_scroll(rc, n)
register struct rconsole *rc;
register int n;
struct rconsole *rc;
int n;
{
register int ydiv;
/* Can't scroll more than the whole screen */
if (n > rc->rc_maxrow)
n = rc->rc_maxrow;
/* Calculate new row */
*rc->rc_row -= n;
if (*rc->rc_row < 0)
*rc->rc_row = 0;
rc->rc_row -= n;
/* Calculate number of pixels to scroll */
ydiv = rc->rc_font->height * n;
if (rc->rc_row < 0)
rc->rc_row = 0;
raster_op(rc->rc_sp, rc->rc_xorigin, rc->rc_yorigin,
rc->rc_emuwidth, rc->rc_emuheight - ydiv,
RAS_SRC, rc->rc_sp, rc->rc_xorigin, ydiv + rc->rc_yorigin);
raster_op(rc->rc_sp,
rc->rc_xorigin, rc->rc_yorigin + rc->rc_emuheight - ydiv,
rc->rc_emuwidth, ydiv, rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->copyrows(rc->rc_cookie, n, 0, rc->rc_maxrow - n);
rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_maxrow - n, n, rc->rc_attr);
}
/* Delete characters */
void
rcons_delchar(rc, n)
register struct rconsole *rc;
register int n;
struct rconsole *rc;
int n;
{
register int tox, fromx, y, width;
/* Can't delete more chars than there are */
if (n > rc->rc_maxcol - *rc->rc_col)
n = rc->rc_maxcol - *rc->rc_col;
if (n > rc->rc_maxcol - rc->rc_col)
n = rc->rc_maxcol - rc->rc_col;
rc->rc_ops->copycols(rc->rc_cookie, rc->rc_row, rc->rc_col + n,
rc->rc_col, rc->rc_maxcol - rc->rc_col - n);
fromx = (*rc->rc_col + n) * rc->rc_font->width;
tox = *rc->rc_col * rc->rc_font->width;
y = *rc->rc_row * rc->rc_font->height;
width = n * rc->rc_font->width;
raster_op(rc->rc_sp, tox + rc->rc_xorigin, y + rc->rc_yorigin,
rc->rc_emuwidth - fromx, rc->rc_font->height,
RAS_SRC, rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin);
raster_op(rc->rc_sp,
rc->rc_emuwidth - width + rc->rc_xorigin, y + rc->rc_yorigin,
width, rc->rc_font->height,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row,
rc->rc_maxcol - n, n, rc->rc_attr);
}
/* Delete a number of lines */
void
rcons_delline(rc, n)
register struct rconsole *rc;
register int n;
struct rconsole *rc;
int n;
{
register int fromy, toy, height;
/* Can't delete more lines than there are */
if (n > rc->rc_maxrow - *rc->rc_row)
n = rc->rc_maxrow - *rc->rc_row;
if (n > rc->rc_maxrow - rc->rc_row)
n = rc->rc_maxrow - rc->rc_row;
fromy = (*rc->rc_row + n) * rc->rc_font->height;
toy = *rc->rc_row * rc->rc_font->height;
height = rc->rc_font->height * n;
rc->rc_ops->copyrows(rc->rc_cookie, rc->rc_row + n, rc->rc_row,
rc->rc_maxrow - rc->rc_row - n);
raster_op(rc->rc_sp, rc->rc_xorigin, toy + rc->rc_yorigin,
rc->rc_emuwidth, rc->rc_emuheight - fromy, RAS_SRC,
rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin);
raster_op(rc->rc_sp,
rc->rc_xorigin, rc->rc_emuheight - height + rc->rc_yorigin,
rc->rc_emuwidth, height,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_maxrow - n, n,
rc->rc_attr);
}
/* Insert some characters */
void
rcons_insertchar(rc, n)
register struct rconsole *rc;
register int n;
struct rconsole *rc;
int n;
{
register int tox, fromx, y;
/* Can't insert more chars than can fit */
if (n > rc->rc_maxcol - *rc->rc_col)
n = rc->rc_maxcol - *rc->rc_col;
if (n > rc->rc_maxcol - rc->rc_col)
n = rc->rc_maxcol - rc->rc_col - 1;
rc->rc_ops->copycols(rc->rc_cookie, rc->rc_row, rc->rc_col,
rc->rc_col + n, rc->rc_maxcol - rc->rc_col - n - 1);
tox = (*rc->rc_col + n) * rc->rc_font->width;
fromx = *rc->rc_col * rc->rc_font->width;
y = *rc->rc_row * rc->rc_font->height;
raster_op(rc->rc_sp, tox + rc->rc_xorigin, y + rc->rc_yorigin,
rc->rc_emuwidth - tox, rc->rc_font->height,
RAS_SRC, rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin);
raster_op(rc->rc_sp, fromx + rc->rc_xorigin, y + rc->rc_yorigin,
rc->rc_font->width * n, rc->rc_font->height,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->erasecols(rc->rc_cookie, rc->rc_row, rc->rc_col,
n, rc->rc_attr);
}
/* Insert some lines */
void
rcons_insertline(rc, n)
register struct rconsole *rc;
register int n;
struct rconsole *rc;
int n;
{
register int fromy, toy;
/* Can't insert more lines than can fit */
if (n > rc->rc_maxrow - *rc->rc_row)
n = rc->rc_maxrow - *rc->rc_row;
if (n > rc->rc_maxrow - rc->rc_row)
n = rc->rc_maxrow - rc->rc_row;
toy = (*rc->rc_row + n) * rc->rc_font->height;
fromy = *rc->rc_row * rc->rc_font->height;
rc->rc_ops->copyrows(rc->rc_cookie, rc->rc_row, rc->rc_row + n,
rc->rc_maxrow - rc->rc_row - n);
raster_op(rc->rc_sp, rc->rc_xorigin, toy + rc->rc_yorigin,
rc->rc_emuwidth, rc->rc_emuheight - toy,
RAS_SRC, rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin);
raster_op(rc->rc_sp, rc->rc_xorigin, fromy + rc->rc_yorigin,
rc->rc_emuwidth, rc->rc_font->height * n,
rc->rc_ras_blank, (struct raster *) 0, 0, 0);
rc->rc_ops->eraserows(rc->rc_cookie, rc->rc_row, n,
rc->rc_attr);
}
/* end of rcons_subr.c */

View File

@ -1,4 +1,6 @@
/* $NetBSD: rcons_subr.h,v 1.1 1995/10/04 23:57:28 pk Exp $ */
/* $NetBSD: rcons_subr.h,v 1.2 1999/04/13 18:43:17 ad Exp $ */
/* XXX this header is depreciated - do not use */
/*
* Copyright (c) 1991, 1993