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