Home | History | Annotate | Line # | Download | only in wscons
wscons_rops.c revision 1.3
      1 /* $NetBSD: wscons_rops.c,v 1.3 1998/06/20 21:52:50 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 /*
     98  * Actually write a string to the frame buffer.
     99  */
    100 void
    101 rcons_putchar(id, row, col, uc, attr)
    102 	void *id;
    103 	int row, col;
    104 	u_int uc;
    105 	long attr;
    106 {
    107 	struct rcons *rc = id;
    108 	register int x, y, op;
    109 	u_char help;
    110 
    111 	x = col * rc->rc_font->width + rc->rc_xorigin;
    112 	y = row * rc->rc_font->height + rc->rc_font_ascent + rc->rc_yorigin;
    113 
    114 	op = RAS_SRC;
    115 	if ((attr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    116 		op = RAS_NOT(op);
    117 	help = uc & 0xff;
    118 	raster_textn(rc->rc_sp, x, y, op, rc->rc_font, &help, 1);
    119 }
    120 
    121 /*
    122  * Possibly change to white-on-black or black-on-white modes.
    123  */
    124 void
    125 rcons_invert(id, inverted)
    126 	void *id;
    127 	int inverted;
    128 {
    129 	struct rcons *rc = id;
    130 
    131 	if (((rc->rc_bits & RC_INVERT) != 0) ^ inverted) {
    132 		/* Invert the display */
    133 		raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height,
    134 		    RAS_INVERT, (struct raster *) 0, 0, 0);
    135 
    136 		/* Swap things around */
    137 		rc->rc_bits ^= RC_INVERT;
    138 	}
    139 }
    140 
    141 /*
    142  * Copy columns (characters) in a row (line).
    143  */
    144 void
    145 rcons_copycols(id, row, srccol, dstcol, ncols)
    146 	void *id;
    147 	int row, srccol, dstcol, ncols;
    148 {
    149 	struct rcons *rc = id;
    150 	int y, srcx, dstx, nx;
    151 
    152 	y = rc->rc_yorigin + rc->rc_font->height * row;
    153 	srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
    154 	dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
    155 	nx = rc->rc_font->width * ncols;
    156 
    157 	raster_op(rc->rc_sp, dstx, y,
    158 	    nx, rc->rc_font->height, RAS_SRC,
    159 	    rc->rc_sp, srcx, y);
    160 }
    161 
    162 /*
    163  * Clear columns (characters) in a row (line).
    164  */
    165 void
    166 rcons_erasecols(id, row, startcol, ncols, fillattr)
    167 	void *id;
    168 	int row, startcol, ncols;
    169 	long fillattr;
    170 {
    171 	struct rcons *rc = id;
    172 	int y, startx, nx, op;
    173 
    174 	y = rc->rc_yorigin + rc->rc_font->height * row;
    175 	startx = rc->rc_xorigin + rc->rc_font->width * startcol;
    176 	nx = rc->rc_font->width * ncols;
    177 
    178 	op = RAS_CLEAR;
    179 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    180 		op = RAS_NOT(op);
    181 	raster_op(rc->rc_sp, startx, y,
    182 	    nx, rc->rc_font->height, op,
    183 	    (struct raster *) 0, 0, 0);
    184 }
    185 
    186 /*
    187  * Copy rows (lines).
    188  */
    189 void
    190 rcons_copyrows(id, srcrow, dstrow, nrows)
    191 	void *id;
    192 	int srcrow, dstrow, nrows;
    193 {
    194 	struct rcons *rc = id;
    195 	int srcy, dsty, ny;
    196 
    197 	srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
    198 	dsty = rc->rc_yorigin + rc->rc_font->height * dstrow;
    199 	ny = rc->rc_font->height * nrows;
    200 
    201 	raster_op(rc->rc_sp, rc->rc_xorigin, dsty,
    202 	    rc->rc_raswidth, ny, RAS_SRC,
    203 	    rc->rc_sp, rc->rc_xorigin, srcy);
    204 }
    205 
    206 /*
    207  * Erase rows (lines).
    208  */
    209 void
    210 rcons_eraserows(id, startrow, nrows, fillattr)
    211 	void *id;
    212 	int startrow, nrows;
    213 	long fillattr;
    214 {
    215 	struct rcons *rc = id;
    216 	int starty, ny, op;
    217 
    218 	starty = rc->rc_yorigin + rc->rc_font->height * startrow;
    219 	ny = rc->rc_font->height * nrows;
    220 
    221 	op = RAS_CLEAR;
    222 	if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0))
    223 		op = RAS_NOT(op);
    224 	raster_op(rc->rc_sp, rc->rc_xorigin, starty,
    225 	    rc->rc_raswidth, ny, op,
    226 	    (struct raster *) 0, 0, 0);
    227 }
    228 
    229 int
    230 rcons_alloc_attr(id, fg, bg, flags, attrp)
    231 	void *id;
    232 	int fg, bg, flags;
    233 	long *attrp;
    234 {
    235 	if (flags & (WSATTR_HILIT | WSATTR_BLINK |
    236 		     WSATTR_UNDERLINE | WSATTR_WSCOLORS))
    237 		return (EINVAL);
    238 	if (flags & WSATTR_REVERSE)
    239 		*attrp = 1;
    240 	else
    241 		*attrp = 0;
    242 	return (0);
    243 }
    244