Home | History | Annotate | Line # | Download | only in wscons
wscons_rops.c revision 1.4
      1 /* $NetBSD: wscons_rops.c,v 1.4 1998/06/26 21:12:49 drochner 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(id, on, row, col)
     60 	void *id;
     61 	int on, row, col;
     62 {
     63 	register struct rcons *rc = id;
     64 	register int x, y;
     65 
     66 	/* turn the cursor off */
     67 	if (!on) {
     68 		/* make sure it's on */
     69 		if ((rc->rc_bits & RC_CURSOR) == 0)
     70 			return;
     71 
     72 		row = *rc->rc_crowp;
     73 		col = *rc->rc_ccolp;
     74 	} else {
     75 		/* unpaint the old copy. */
     76 		*rc->rc_crowp = row;
     77 		*rc->rc_ccolp = col;
     78 	}
     79 
     80 	x = col * rc->rc_font->width + rc->rc_xorigin;
     81 	y = row * rc->rc_font->height + rc->rc_yorigin;
     82 
     83 	raster_op(rc->rc_sp, x, y,
     84 #ifdef notdef
     85 	    /* XXX This is the right way but too slow */
     86 	    rc->rc_font->chars[(int)' '].r->width,
     87 	    rc->rc_font->chars[(int)' '].r->height,
     88 #else
     89 	    rc->rc_font->width, rc->rc_font->height,
     90 #endif
     91 	    RAS_INVERT,
     92 	    (struct raster *) 0, 0, 0);
     93 
     94 	rc->rc_bits ^= RC_CURSOR;
     95 }
     96 
     97 unsigned int
     98 rcons_mapchar(id, uni)
     99 	void *id;
    100 	int uni;
    101 {
    102 	if (uni < 128)
    103 		return (uni);
    104 	return (0);
    105 }
    106 
    107 /*
    108  * Actually write a string to the frame buffer.
    109  */
    110 void
    111 rcons_putchar(id, row, col, uc, attr)
    112 	void *id;
    113 	int row, col;
    114 	u_int uc;
    115 	long attr;
    116 {
    117 	struct rcons *rc = id;
    118 	register int x, y, op;
    119 	u_char help;
    120 
    121 	x = col * rc->rc_font->width + rc->rc_xorigin;
    122 	y = row * rc->rc_font->height + rc->rc_font_ascent + rc->rc_yorigin;
    123 
    124 	op = RAS_SRC;
    125 	if ((attr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    126 		op = RAS_NOT(op);
    127 	help = uc & 0xff;
    128 	raster_textn(rc->rc_sp, x, y, op, rc->rc_font, &help, 1);
    129 }
    130 
    131 /*
    132  * Possibly change to white-on-black or black-on-white modes.
    133  */
    134 void
    135 rcons_invert(id, inverted)
    136 	void *id;
    137 	int inverted;
    138 {
    139 	struct rcons *rc = id;
    140 
    141 	if (((rc->rc_bits & RC_INVERT) != 0) ^ inverted) {
    142 		/* Invert the display */
    143 		raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
    144 		    RAS_INVERT, (struct raster *) 0, 0, 0);
    145 
    146 		/* Swap things around */
    147 		rc->rc_bits ^= RC_INVERT;
    148 	}
    149 }
    150 
    151 /*
    152  * Copy columns (characters) in a row (line).
    153  */
    154 void
    155 rcons_copycols(id, row, srccol, dstcol, ncols)
    156 	void *id;
    157 	int row, srccol, dstcol, ncols;
    158 {
    159 	struct rcons *rc = id;
    160 	int y, srcx, dstx, nx;
    161 
    162 	y = rc->rc_yorigin + rc->rc_font->height * row;
    163 	srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
    164 	dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
    165 	nx = rc->rc_font->width * ncols;
    166 
    167 	raster_op(rc->rc_sp, dstx, y,
    168 	    nx, rc->rc_font->height, RAS_SRC,
    169 	    rc->rc_sp, srcx, y);
    170 }
    171 
    172 /*
    173  * Clear columns (characters) in a row (line).
    174  */
    175 void
    176 rcons_erasecols(id, row, startcol, ncols, fillattr)
    177 	void *id;
    178 	int row, startcol, ncols;
    179 	long fillattr;
    180 {
    181 	struct rcons *rc = id;
    182 	int y, startx, nx, op;
    183 
    184 	y = rc->rc_yorigin + rc->rc_font->height * row;
    185 	startx = rc->rc_xorigin + rc->rc_font->width * startcol;
    186 	nx = rc->rc_font->width * ncols;
    187 
    188 	op = RAS_CLEAR;
    189 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    190 		op = RAS_NOT(op);
    191 	raster_op(rc->rc_sp, startx, y,
    192 	    nx, rc->rc_font->height, op,
    193 	    (struct raster *) 0, 0, 0);
    194 }
    195 
    196 /*
    197  * Copy rows (lines).
    198  */
    199 void
    200 rcons_copyrows(id, srcrow, dstrow, nrows)
    201 	void *id;
    202 	int srcrow, dstrow, nrows;
    203 {
    204 	struct rcons *rc = id;
    205 	int srcy, dsty, ny;
    206 
    207 	srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
    208 	dsty = rc->rc_yorigin + rc->rc_font->height * dstrow;
    209 	ny = rc->rc_font->height * nrows;
    210 
    211 	raster_op(rc->rc_sp, rc->rc_xorigin, dsty,
    212 	    rc->rc_raswidth, ny, RAS_SRC,
    213 	    rc->rc_sp, rc->rc_xorigin, srcy);
    214 }
    215 
    216 /*
    217  * Erase rows (lines).
    218  */
    219 void
    220 rcons_eraserows(id, startrow, nrows, fillattr)
    221 	void *id;
    222 	int startrow, nrows;
    223 	long fillattr;
    224 {
    225 	struct rcons *rc = id;
    226 	int starty, ny, op;
    227 
    228 	starty = rc->rc_yorigin + rc->rc_font->height * startrow;
    229 	ny = rc->rc_font->height * nrows;
    230 
    231 	op = RAS_CLEAR;
    232 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    233 		op = RAS_NOT(op);
    234 	raster_op(rc->rc_sp, rc->rc_xorigin, starty,
    235 	    rc->rc_raswidth, ny, op,
    236 	    (struct raster *) 0, 0, 0);
    237 }
    238 
    239 int
    240 rcons_alloc_attr(id, fg, bg, flags, attrp)
    241 	void *id;
    242 	int fg, bg, flags;
    243 	long *attrp;
    244 {
    245 	if (flags & (WSATTR_HILIT | WSATTR_BLINK |
    246 		     WSATTR_UNDERLINE | WSATTR_WSCOLORS))
    247 		return (EINVAL);
    248 	if (flags & WSATTR_REVERSE)
    249 		*attrp = 1;
    250 	else
    251 		*attrp = 0;
    252 	return (0);
    253 }
    254