1 /* $NetBSD: wscons_rops.c,v 1.8 2001/11/13 06:17:46 lukem 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/cdefs.h> 48 __KERNEL_RCSID(0, "$NetBSD: wscons_rops.c,v 1.8 2001/11/13 06:17:46 lukem Exp $"); 49 50 #include <sys/param.h> 51 #include <sys/device.h> 52 53 #include <dev/rcons/raster.h> 54 #include <dev/wscons/wscons_raster.h> 55 #include <dev/wscons/wsdisplayvar.h> 56 57 /* 58 * Paint (or unpaint) the cursor. 59 * Pays no lip service to hardware cursors. 60 */ 61 void 62 rcons_cursor(void *id, int on, int row, int col) 63 { 64 struct rcons *rc = id; 65 int x, y; 66 67 /* turn the cursor off */ 68 if (!on) { 69 /* make sure it's on */ 70 if ((rc->rc_bits & RC_CURSOR) == 0) 71 return; 72 73 row = *rc->rc_crowp; 74 col = *rc->rc_ccolp; 75 } else { 76 /* unpaint the old copy. */ 77 *rc->rc_crowp = row; 78 *rc->rc_ccolp = col; 79 } 80 81 x = col * rc->rc_font->width + rc->rc_xorigin; 82 y = row * rc->rc_font->height + rc->rc_yorigin; 83 84 raster_op(rc->rc_sp, x, y, 85 #ifdef notdef 86 /* XXX This is the right way but too slow */ 87 rc->rc_font->chars[(int)' '].r->width, 88 rc->rc_font->chars[(int)' '].r->height, 89 #else 90 rc->rc_font->width, rc->rc_font->height, 91 #endif 92 RAS_INVERT, 93 (struct raster *) 0, 0, 0); 94 95 rc->rc_bits ^= RC_CURSOR; 96 } 97 98 int 99 rcons_mapchar(void *id, int uni, unsigned int *index) 100 { 101 102 if (uni < 128) { 103 *index = uni; 104 return (5); 105 } 106 *index = ' '; 107 return (0); 108 } 109 110 /* 111 * Actually write a string to the frame buffer. 112 */ 113 void 114 rcons_putchar(void *id, int row, int col, u_int uc, long attr) 115 { 116 struct rcons *rc = id; 117 int x, y, op; 118 u_char help; 119 120 x = col * rc->rc_font->width + rc->rc_xorigin; 121 y = row * rc->rc_font->height + rc->rc_font_ascent + rc->rc_yorigin; 122 123 op = RAS_SRC; 124 if ((attr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0)) 125 op = RAS_NOT(op); 126 help = uc & 0xff; 127 raster_textn(rc->rc_sp, x, y, op, rc->rc_font, &help, 1); 128 } 129 130 /* 131 * Possibly change to white-on-black or black-on-white modes. 132 */ 133 void 134 rcons_invert(void *id, int inverted) 135 { 136 struct rcons *rc = id; 137 138 if (((rc->rc_bits & RC_INVERT) != 0) ^ inverted) { 139 /* Invert the display */ 140 raster_op(rc->rc_sp, 0, 0, rc->rc_sp->width, rc->rc_sp->height, 141 RAS_INVERT, (struct raster *) 0, 0, 0); 142 143 /* Swap things around */ 144 rc->rc_bits ^= RC_INVERT; 145 } 146 } 147 148 /* 149 * Copy columns (characters) in a row (line). 150 */ 151 void 152 rcons_copycols(void *id, int row, int srccol, int dstcol, int ncols) 153 { 154 struct rcons *rc = id; 155 int y, srcx, dstx, nx; 156 157 y = rc->rc_yorigin + rc->rc_font->height * row; 158 srcx = rc->rc_xorigin + rc->rc_font->width * srccol; 159 dstx = rc->rc_xorigin + rc->rc_font->width * dstcol; 160 nx = rc->rc_font->width * ncols; 161 162 raster_op(rc->rc_sp, dstx, y, 163 nx, rc->rc_font->height, RAS_SRC, 164 rc->rc_sp, srcx, y); 165 } 166 167 /* 168 * Clear columns (characters) in a row (line). 169 */ 170 void 171 rcons_erasecols(void *id, int row, int startcol, int ncols, long fillattr) 172 { 173 struct rcons *rc = id; 174 int y, startx, nx, op; 175 176 y = rc->rc_yorigin + rc->rc_font->height * row; 177 startx = rc->rc_xorigin + rc->rc_font->width * startcol; 178 nx = rc->rc_font->width * ncols; 179 180 op = RAS_CLEAR; 181 if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0)) 182 op = RAS_NOT(op); 183 raster_op(rc->rc_sp, startx, y, 184 nx, rc->rc_font->height, op, 185 (struct raster *) 0, 0, 0); 186 } 187 188 /* 189 * Copy rows (lines). 190 */ 191 void 192 rcons_copyrows(void *id, int srcrow, int dstrow, int 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(void *id, int startrow, int nrows, long fillattr) 211 { 212 struct rcons *rc = id; 213 int starty, ny, op; 214 215 starty = rc->rc_yorigin + rc->rc_font->height * startrow; 216 ny = rc->rc_font->height * nrows; 217 218 op = RAS_CLEAR; 219 if ((fillattr != 0) ^ ((rc->rc_bits & RC_INVERT) != 0)) 220 op = RAS_NOT(op); 221 raster_op(rc->rc_sp, rc->rc_xorigin, starty, 222 rc->rc_raswidth, ny, op, 223 (struct raster *) 0, 0, 0); 224 } 225 226 int 227 rcons_alloc_attr(void *id, int fg, int bg, int flags, long *attrp) 228 { 229 if (flags & (WSATTR_HILIT | WSATTR_BLINK | 230 WSATTR_UNDERLINE | WSATTR_WSCOLORS)) 231 return (EINVAL); 232 if (flags & WSATTR_REVERSE) 233 *attrp = 1; 234 else 235 *attrp = 0; 236 return (0); 237 } 238