Home | History | Annotate | Line # | Download | only in wscons
wscons_rops.c revision 1.7
      1 /* $NetBSD: wscons_rops.c,v 1.7 2001/10/13 15:56:15 augustss Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)rcons_subr.c	8.1 (Berkeley) 6/11/93
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/device.h>
     49 
     50 #include <dev/rcons/raster.h>
     51 #include <dev/wscons/wscons_raster.h>
     52 #include <dev/wscons/wsdisplayvar.h>
     53 
     54 /*
     55  * Paint (or unpaint) the cursor.
     56  * Pays no lip service to hardware cursors.
     57  */
     58 void
     59 rcons_cursor(void *id, int on, int row, int col)
     60 {
     61 	struct rcons *rc = id;
     62 	int x, y;
     63 
     64 	/* turn the cursor off */
     65 	if (!on) {
     66 		/* make sure it's on */
     67 		if ((rc->rc_bits & RC_CURSOR) == 0)
     68 			return;
     69 
     70 		row = *rc->rc_crowp;
     71 		col = *rc->rc_ccolp;
     72 	} else {
     73 		/* unpaint the old copy. */
     74 		*rc->rc_crowp = row;
     75 		*rc->rc_ccolp = col;
     76 	}
     77 
     78 	x = col * rc->rc_font->width + rc->rc_xorigin;
     79 	y = row * rc->rc_font->height + rc->rc_yorigin;
     80 
     81 	raster_op(rc->rc_sp, x, y,
     82 #ifdef notdef
     83 	    /* XXX This is the right way but too slow */
     84 	    rc->rc_font->chars[(int)' '].r->width,
     85 	    rc->rc_font->chars[(int)' '].r->height,
     86 #else
     87 	    rc->rc_font->width, rc->rc_font->height,
     88 #endif
     89 	    RAS_INVERT,
     90 	    (struct raster *) 0, 0, 0);
     91 
     92 	rc->rc_bits ^= RC_CURSOR;
     93 }
     94 
     95 int
     96 rcons_mapchar(void *id, int uni, unsigned int *index)
     97 {
     98 
     99 	if (uni < 128) {
    100 		*index = uni;
    101 		return (5);
    102 	}
    103 	*index = ' ';
    104 	return (0);
    105 }
    106 
    107 /*
    108  * Actually write a string to the frame buffer.
    109  */
    110 void
    111 rcons_putchar(void *id, int row, int col, u_int uc, long attr)
    112 {
    113 	struct rcons *rc = id;
    114 	int x, y, op;
    115 	u_char help;
    116 
    117 	x = col * rc->rc_font->width + rc->rc_xorigin;
    118 	y = row * rc->rc_font->height + rc->rc_font_ascent + rc->rc_yorigin;
    119 
    120 	op = RAS_SRC;
    121 	if ((attr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    122 		op = RAS_NOT(op);
    123 	help = uc & 0xff;
    124 	raster_textn(rc->rc_sp, x, y, op, rc->rc_font, &help, 1);
    125 }
    126 
    127 /*
    128  * Possibly change to white-on-black or black-on-white modes.
    129  */
    130 void
    131 rcons_invert(void *id, int inverted)
    132 {
    133 	struct rcons *rc = id;
    134 
    135 	if (((rc->rc_bits & RC_INVERT) != 0) ^ inverted) {
    136 		/* Invert the display */
    137 		raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
    138 		    RAS_INVERT, (struct raster *) 0, 0, 0);
    139 
    140 		/* Swap things around */
    141 		rc->rc_bits ^= RC_INVERT;
    142 	}
    143 }
    144 
    145 /*
    146  * Copy columns (characters) in a row (line).
    147  */
    148 void
    149 rcons_copycols(void *id, int row, int srccol, int dstcol, int ncols)
    150 {
    151 	struct rcons *rc = id;
    152 	int y, srcx, dstx, nx;
    153 
    154 	y = rc->rc_yorigin + rc->rc_font->height * row;
    155 	srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
    156 	dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
    157 	nx = rc->rc_font->width * ncols;
    158 
    159 	raster_op(rc->rc_sp, dstx, y,
    160 	    nx, rc->rc_font->height, RAS_SRC,
    161 	    rc->rc_sp, srcx, y);
    162 }
    163 
    164 /*
    165  * Clear columns (characters) in a row (line).
    166  */
    167 void
    168 rcons_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
    169 {
    170 	struct rcons *rc = id;
    171 	int y, startx, nx, op;
    172 
    173 	y = rc->rc_yorigin + rc->rc_font->height * row;
    174 	startx = rc->rc_xorigin + rc->rc_font->width * startcol;
    175 	nx = rc->rc_font->width * ncols;
    176 
    177 	op = RAS_CLEAR;
    178 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    179 		op = RAS_NOT(op);
    180 	raster_op(rc->rc_sp, startx, y,
    181 	    nx, rc->rc_font->height, op,
    182 	    (struct raster *) 0, 0, 0);
    183 }
    184 
    185 /*
    186  * Copy rows (lines).
    187  */
    188 void
    189 rcons_copyrows(void *id, int srcrow, int dstrow, int nrows)
    190 {
    191 	struct rcons *rc = id;
    192 	int srcy, dsty, ny;
    193 
    194 	srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
    195 	dsty = rc->rc_yorigin + rc->rc_font->height * dstrow;
    196 	ny = rc->rc_font->height * nrows;
    197 
    198 	raster_op(rc->rc_sp, rc->rc_xorigin, dsty,
    199 	    rc->rc_raswidth, ny, RAS_SRC,
    200 	    rc->rc_sp, rc->rc_xorigin, srcy);
    201 }
    202 
    203 /*
    204  * Erase rows (lines).
    205  */
    206 void
    207 rcons_eraserows(void *id, int startrow, int nrows, long fillattr)
    208 {
    209 	struct rcons *rc = id;
    210 	int starty, ny, op;
    211 
    212 	starty = rc->rc_yorigin + rc->rc_font->height * startrow;
    213 	ny = rc->rc_font->height * nrows;
    214 
    215 	op = RAS_CLEAR;
    216 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    217 		op = RAS_NOT(op);
    218 	raster_op(rc->rc_sp, rc->rc_xorigin, starty,
    219 	    rc->rc_raswidth, ny, op,
    220 	    (struct raster *) 0, 0, 0);
    221 }
    222 
    223 int
    224 rcons_alloc_attr(void *id, int fg, int bg, int flags, long *attrp)
    225 {
    226 	if (flags & (WSATTR_HILIT | WSATTR_BLINK |
    227 		     WSATTR_UNDERLINE | WSATTR_WSCOLORS))
    228 		return (EINVAL);
    229 	if (flags & WSATTR_REVERSE)
    230 		*attrp = 1;
    231 	else
    232 		*attrp = 0;
    233 	return (0);
    234 }
    235