1 /* $NetBSD: rasops1.c,v 1.18 2008/04/28 20:23:56 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: rasops1.c,v 1.18 2008/04/28 20:23:56 martin Exp $"); 34 35 #include "opt_rasops.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/time.h> 40 #include <machine/endian.h> 41 42 #include <dev/wscons/wsdisplayvar.h> 43 #include <dev/wscons/wsconsio.h> 44 #include <dev/rasops/rasops.h> 45 #include <dev/rasops/rasops_masks.h> 46 47 static void rasops1_copycols(void *, int, int, int, int); 48 static void rasops1_erasecols(void *, int, int, int, long); 49 static void rasops1_do_cursor(struct rasops_info *); 50 static void rasops1_putchar(void *, int, int col, u_int, long); 51 #ifndef RASOPS_SMALL 52 static void rasops1_putchar8(void *, int, int col, u_int, long); 53 static void rasops1_putchar16(void *, int, int col, u_int, long); 54 #endif 55 56 /* 57 * Initialize rasops_info struct for this colordepth. 58 */ 59 void 60 rasops1_init(ri) 61 struct rasops_info *ri; 62 { 63 64 switch (ri->ri_font->fontwidth) { 65 #ifndef RASOPS_SMALL 66 case 8: 67 ri->ri_ops.putchar = rasops1_putchar8; 68 break; 69 case 16: 70 ri->ri_ops.putchar = rasops1_putchar16; 71 break; 72 #endif 73 default: 74 ri->ri_ops.putchar = rasops1_putchar; 75 break; 76 } 77 78 if ((ri->ri_font->fontwidth & 7) != 0) { 79 ri->ri_ops.erasecols = rasops1_erasecols; 80 ri->ri_ops.copycols = rasops1_copycols; 81 ri->ri_do_cursor = rasops1_do_cursor; 82 } 83 } 84 85 /* 86 * Paint a single character. This is the generic version, this is ugly. 87 */ 88 static void 89 rasops1_putchar(cookie, row, col, uc, attr) 90 void *cookie; 91 int row, col; 92 u_int uc; 93 long attr; 94 { 95 u_int fs, rs, fb, bg, fg, lmask, rmask; 96 u_int32_t height, width; 97 struct rasops_info *ri; 98 int32_t *rp; 99 u_char *fr; 100 101 ri = (struct rasops_info *)cookie; 102 103 #ifdef RASOPS_CLIPPING 104 /* Catches 'row < 0' case too */ 105 if ((unsigned)row >= (unsigned)ri->ri_rows) 106 return; 107 108 if ((unsigned)col >= (unsigned)ri->ri_cols) 109 return; 110 #endif 111 112 col *= ri->ri_font->fontwidth; 113 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 114 height = ri->ri_font->fontheight; 115 width = ri->ri_font->fontwidth; 116 col = col & 31; 117 rs = ri->ri_stride; 118 119 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 120 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 121 122 /* If fg and bg match this becomes a space character */ 123 if (fg == bg || uc == ' ') { 124 uc = (u_int)-1; 125 fr = 0; /* shutup gcc */ 126 fs = 0; /* shutup gcc */ 127 } else { 128 uc -= ri->ri_font->firstchar; 129 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 130 fs = ri->ri_font->stride; 131 } 132 133 /* Single word, one mask */ 134 if ((col + width) <= 32) { 135 rmask = rasops_pmask[col][width]; 136 lmask = ~rmask; 137 138 if (uc == (u_int)-1) { 139 bg &= rmask; 140 141 while (height--) { 142 *rp = (*rp & lmask) | bg; 143 DELTA(rp, rs, int32_t *); 144 } 145 } else { 146 /* NOT fontbits if bg is white */ 147 if (bg) { 148 while (height--) { 149 fb = ~(fr[3] | (fr[2] << 8) | 150 (fr[1] << 16) | (fr[0] << 24)); 151 *rp = (*rp & lmask) 152 | (MBE(fb >> col) & rmask); 153 154 fr += fs; 155 DELTA(rp, rs, int32_t *); 156 } 157 } else { 158 while (height--) { 159 fb = (fr[3] | (fr[2] << 8) | 160 (fr[1] << 16) | (fr[0] << 24)); 161 *rp = (*rp & lmask) 162 | (MBE(fb >> col) & rmask); 163 164 fr += fs; 165 DELTA(rp, rs, int32_t *); 166 } 167 } 168 } 169 170 /* Do underline */ 171 if ((attr & 1) != 0) { 172 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 173 *rp = (*rp & lmask) | (fg & rmask); 174 } 175 } else { 176 lmask = ~rasops_lmask[col]; 177 rmask = ~rasops_rmask[(col + width) & 31]; 178 179 if (uc == (u_int)-1) { 180 width = bg & ~rmask; 181 bg = bg & ~lmask; 182 183 while (height--) { 184 rp[0] = (rp[0] & lmask) | bg; 185 rp[1] = (rp[1] & rmask) | width; 186 DELTA(rp, rs, int32_t *); 187 } 188 } else { 189 width = 32 - col; 190 191 /* NOT fontbits if bg is white */ 192 if (bg) { 193 while (height--) { 194 fb = ~(fr[3] | (fr[2] << 8) | 195 (fr[1] << 16) | (fr[0] << 24)); 196 197 rp[0] = (rp[0] & lmask) 198 | MBE((u_int)fb >> col); 199 200 rp[1] = (rp[1] & rmask) 201 | (MBE((u_int)fb << width) & ~rmask); 202 203 fr += fs; 204 DELTA(rp, rs, int32_t *); 205 } 206 } else { 207 while (height--) { 208 fb = (fr[3] | (fr[2] << 8) | 209 (fr[1] << 16) | (fr[0] << 24)); 210 211 rp[0] = (rp[0] & lmask) 212 | MBE(fb >> col); 213 214 rp[1] = (rp[1] & rmask) 215 | (MBE(fb << width) & ~rmask); 216 217 fr += fs; 218 DELTA(rp, rs, int32_t *); 219 } 220 } 221 } 222 223 /* Do underline */ 224 if ((attr & 1) != 0) { 225 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 226 rp[0] = (rp[0] & lmask) | (fg & ~lmask); 227 rp[1] = (rp[1] & rmask) | (fg & ~rmask); 228 } 229 } 230 } 231 232 #ifndef RASOPS_SMALL 233 /* 234 * Paint a single character. This is for 8-pixel wide fonts. 235 */ 236 static void 237 rasops1_putchar8(cookie, row, col, uc, attr) 238 void *cookie; 239 int row, col; 240 u_int uc; 241 long attr; 242 { 243 int height, fs, rs, bg, fg; 244 struct rasops_info *ri; 245 u_char *fr, *rp; 246 247 ri = (struct rasops_info *)cookie; 248 249 #ifdef RASOPS_CLIPPING 250 /* Catches 'row < 0' case too */ 251 if ((unsigned)row >= (unsigned)ri->ri_rows) 252 return; 253 254 if ((unsigned)col >= (unsigned)ri->ri_cols) 255 return; 256 #endif 257 258 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 259 height = ri->ri_font->fontheight; 260 rs = ri->ri_stride; 261 262 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 263 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 264 265 /* If fg and bg match this becomes a space character */ 266 if (fg == bg || uc == ' ') { 267 while (height--) { 268 *rp = bg; 269 rp += rs; 270 } 271 } else { 272 uc -= ri->ri_font->firstchar; 273 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 274 fs = ri->ri_font->stride; 275 276 /* NOT fontbits if bg is white */ 277 if (bg) { 278 while (height--) { 279 *rp = ~*fr; 280 fr += fs; 281 rp += rs; 282 } 283 } else { 284 while (height--) { 285 *rp = *fr; 286 fr += fs; 287 rp += rs; 288 } 289 } 290 291 } 292 293 /* Do underline */ 294 if ((attr & 1) != 0) 295 rp[-(ri->ri_stride << 1)] = fg; 296 } 297 298 /* 299 * Paint a single character. This is for 16-pixel wide fonts. 300 */ 301 static void 302 rasops1_putchar16(cookie, row, col, uc, attr) 303 void *cookie; 304 int row, col; 305 u_int uc; 306 long attr; 307 { 308 int height, fs, rs, bg, fg; 309 struct rasops_info *ri; 310 u_char *fr, *rp; 311 312 ri = (struct rasops_info *)cookie; 313 314 #ifdef RASOPS_CLIPPING 315 /* Catches 'row < 0' case too */ 316 if ((unsigned)row >= (unsigned)ri->ri_rows) 317 return; 318 319 if ((unsigned)col >= (unsigned)ri->ri_cols) 320 return; 321 #endif 322 323 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 324 height = ri->ri_font->fontheight; 325 rs = ri->ri_stride; 326 327 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 328 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0]; 329 330 /* If fg and bg match this becomes a space character */ 331 if (fg == bg || uc == ' ') { 332 while (height--) { 333 *(int16_t *)rp = bg; 334 rp += rs; 335 } 336 } else { 337 uc -= ri->ri_font->firstchar; 338 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 339 fs = ri->ri_font->stride; 340 341 /* NOT fontbits if bg is white */ 342 if (bg) { 343 while (height--) { 344 rp[0] = ~fr[0]; 345 rp[1] = ~fr[1]; 346 fr += fs; 347 rp += rs; 348 } 349 } else { 350 while (height--) { 351 rp[0] = fr[0]; 352 rp[1] = fr[1]; 353 fr += fs; 354 rp += rs; 355 } 356 } 357 } 358 359 /* Do underline */ 360 if ((attr & 1) != 0) 361 *(int16_t *)(rp - (ri->ri_stride << 1)) = fg; 362 } 363 #endif /* !RASOPS_SMALL */ 364 365 /* 366 * Grab routines common to depths where (bpp < 8) 367 */ 368 #define NAME(ident) rasops1_##ident 369 #define PIXEL_SHIFT 0 370 371 #include <dev/rasops/rasops_bitops.h> 372