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