1 /* $NetBSD: rasops4.c,v 1.3 2001/11/13 07:00:23 lukem 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.3 2001/11/13 07:00:23 lukem Exp $"); 41 42 #include "opt_rasops.h" 43 44 #include <sys/types.h> 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/time.h> 48 #include <machine/endian.h> 49 50 #include <dev/wscons/wsdisplayvar.h> 51 #include <dev/wscons/wsconsio.h> 52 #include <dev/rasops/rasops.h> 53 #include <dev/rasops/rasops_masks.h> 54 55 static void rasops4_copycols __P((void *, int, int, int, int)); 56 static void rasops4_erasecols __P((void *, int, int, int, long)); 57 static void rasops4_do_cursor __P((struct rasops_info *)); 58 static void rasops4_putchar __P((void *, int, int col, u_int, long)); 59 #ifndef RASOPS_SMALL 60 static void rasops4_putchar8 __P((void *, int, int col, u_int, long)); 61 static void rasops4_putchar12 __P((void *, int, int col, u_int, long)); 62 static void rasops4_putchar16 __P((void *, int, int col, u_int, long)); 63 static void rasops4_makestamp __P((struct rasops_info *, long)); 64 65 /* 66 * 4x1 stamp for optimized character blitting 67 */ 68 static u_int16_t stamp[16]; 69 static long stamp_attr; 70 static int stamp_mutex; /* XXX see note in README */ 71 #endif 72 73 /* 74 * Initialize rasops_info struct for this colordepth. 75 */ 76 void 77 rasops4_init(ri) 78 struct rasops_info *ri; 79 { 80 81 switch (ri->ri_font->fontwidth) { 82 #ifndef RASOPS_SMALL 83 case 8: 84 ri->ri_ops.putchar = rasops4_putchar8; 85 break; 86 case 12: 87 ri->ri_ops.putchar = rasops4_putchar12; 88 break; 89 case 16: 90 ri->ri_ops.putchar = rasops4_putchar16; 91 break; 92 #endif /* !RASOPS_SMALL */ 93 default: 94 panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!"); 95 ri->ri_ops.putchar = rasops4_putchar; 96 break; 97 } 98 99 if ((ri->ri_font->fontwidth & 1) != 0) { 100 ri->ri_ops.erasecols = rasops4_erasecols; 101 ri->ri_ops.copycols = rasops4_copycols; 102 ri->ri_do_cursor = rasops4_do_cursor; 103 } 104 } 105 106 #ifdef notyet 107 /* 108 * Paint a single character. This is the generic version, this is ugly. 109 */ 110 static void 111 rasops4_putchar(cookie, row, col, uc, attr) 112 void *cookie; 113 int row, col; 114 u_int uc; 115 long attr; 116 { 117 int height, width, fs, rs, fb, bg, fg, lmask, rmask; 118 struct rasops_info *ri; 119 int32_t *rp; 120 u_char *fr; 121 122 ri = (struct rasops_info *)cookie; 123 124 #ifdef RASOPS_CLIPPING 125 /* Catches 'row < 0' case too */ 126 if ((unsigned)row >= (unsigned)ri->ri_rows) 127 return; 128 129 if ((unsigned)col >= (unsigned)ri->ri_cols) 130 return; 131 #endif 132 133 width = ri->ri_font->fontwidth << 1; 134 height = ri->ri_font->fontheight; 135 col *= width; 136 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 137 col = col & 31; 138 rs = ri->ri_stride; 139 140 bg = ri->ri_devcmap[(attr >> 16) & 0xf]; 141 fg = ri->ri_devcmap[(attr >> 24) & 0xf]; 142 143 /* If fg and bg match this becomes a space character */ 144 if (fg == bg || uc == ' ') { 145 uc = (u_int)-1; 146 fr = 0; /* shutup gcc */ 147 fs = 0; /* shutup gcc */ 148 } else { 149 uc -= ri->ri_font->firstchar; 150 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 151 fs = ri->ri_font->stride; 152 } 153 154 /* Single word, one mask */ 155 if ((col + width) <= 32) { 156 rmask = rasops_pmask[col][width]; 157 lmask = ~rmask; 158 159 if (uc == (u_int)-1) { 160 bg &= rmask; 161 162 while (height--) { 163 *rp = (*rp & lmask) | bg; 164 DELTA(rp, rs, int32_t *); 165 } 166 } else { 167 while (height--) { 168 /* get bits, mask */ 169 /* compose sl */ 170 /* mask sl */ 171 /* put word */ 172 } 173 } 174 175 /* Do underline */ 176 if (attr & 1) { 177 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 178 *rp = (*rp & lmask) | (fg & rmask); 179 } 180 } else { 181 lmask = ~rasops_lmask[col]; 182 rmask = ~rasops_rmask[(col + width) & 31]; 183 184 if (uc == (u_int)-1) { 185 bg = bg & ~lmask; 186 width = bg & ~rmask; 187 188 while (height--) { 189 rp[0] = (rp[0] & lmask) | bg; 190 rp[1] = (rp[1] & rmask) | width; 191 DELTA(rp, rs, int32_t *); 192 } 193 } else { 194 width = 32 - col; 195 196 /* NOT fontbits if bg is white */ 197 while (height--) { 198 fb = ~(fr[3] | (fr[2] << 8) | 199 (fr[1] << 16) | (fr[0] << 24)); 200 201 rp[0] = (rp[0] & lmask) 202 | MBE((u_int)fb >> col); 203 204 rp[1] = (rp[1] & rmask) 205 | (MBE((u_int)fb << width) & ~rmask); 206 207 fr += fs; 208 DELTA(rp, rs, int32_t *); 209 } 210 } 211 212 /* Do underline */ 213 if (attr & 1) { 214 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 215 rp[0] = (rp[0] & lmask) | (fg & ~lmask); 216 rp[1] = (rp[1] & rmask) | (fg & ~rmask); 217 } 218 } 219 } 220 #endif 221 222 /* 223 * Put a single character. This is the generic version. 224 */ 225 static void 226 rasops4_putchar(cookie, row, col, uc, attr) 227 void *cookie; 228 int row, col; 229 u_int uc; 230 long attr; 231 { 232 233 /* XXX punt */ 234 } 235 236 #ifndef RASOPS_SMALL 237 /* 238 * Recompute the blitting stamp. 239 */ 240 static void 241 rasops4_makestamp(ri, attr) 242 struct rasops_info *ri; 243 long attr; 244 { 245 int i, fg, bg; 246 247 fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xf; 248 bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xf; 249 stamp_attr = attr; 250 251 for (i = 0; i < 16; i++) { 252 stamp[i] = (i & 1 ? fg : bg) << 8; 253 stamp[i] |= (i & 2 ? fg : bg) << 12; 254 stamp[i] |= (i & 4 ? fg : bg) << 0; 255 stamp[i] |= (i & 8 ? fg : bg) << 4; 256 } 257 } 258 259 /* 260 * Put a single character. This is for 8-pixel wide fonts. 261 */ 262 static void 263 rasops4_putchar8(cookie, row, col, uc, attr) 264 void *cookie; 265 int row, col; 266 u_int uc; 267 long attr; 268 { 269 struct rasops_info *ri; 270 int height, fs, rs; 271 u_char *fr; 272 u_int16_t *rp; 273 274 /* Can't risk remaking the stamp if it's already in use */ 275 if (stamp_mutex++) { 276 stamp_mutex--; 277 rasops4_putchar(cookie, row, col, uc, attr); 278 return; 279 } 280 281 ri = (struct rasops_info *)cookie; 282 283 #ifdef RASOPS_CLIPPING 284 /* Catches 'row < 0' case too */ 285 if ((unsigned)row >= (unsigned)ri->ri_rows) { 286 stamp_mutex--; 287 return; 288 } 289 290 if ((unsigned)col >= (unsigned)ri->ri_cols) { 291 stamp_mutex--; 292 return; 293 } 294 #endif 295 296 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale); 297 height = ri->ri_font->fontheight; 298 rs = ri->ri_stride / sizeof(*rp); 299 300 /* Recompute stamp? */ 301 if (attr != stamp_attr) 302 rasops4_makestamp(ri, attr); 303 304 if (uc == ' ') { 305 u_int16_t c = stamp[0]; 306 while (height--) { 307 rp[0] = c; 308 rp[1] = c; 309 rp += rs; 310 } 311 } else { 312 uc -= ri->ri_font->firstchar; 313 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 314 fs = ri->ri_font->stride; 315 316 while (height--) { 317 rp[0] = stamp[(*fr >> 4) & 0xf]; 318 rp[1] = stamp[*fr & 0xf]; 319 fr += fs; 320 rp += rs; 321 } 322 } 323 324 /* Do underline */ 325 if ((attr & 1) != 0) { 326 rp -= (rs << 1); 327 rp[0] = stamp[15]; 328 rp[1] = stamp[15]; 329 } 330 331 stamp_mutex--; 332 } 333 334 /* 335 * Put a single character. This is for 12-pixel wide fonts. 336 */ 337 static void 338 rasops4_putchar12(cookie, row, col, uc, attr) 339 void *cookie; 340 int row, col; 341 u_int uc; 342 long attr; 343 { 344 struct rasops_info *ri; 345 int height, fs, rs; 346 u_char *fr; 347 u_int16_t *rp; 348 349 /* Can't risk remaking the stamp if it's already in use */ 350 if (stamp_mutex++) { 351 stamp_mutex--; 352 rasops4_putchar(cookie, row, col, uc, attr); 353 return; 354 } 355 356 ri = (struct rasops_info *)cookie; 357 358 #ifdef RASOPS_CLIPPING 359 /* Catches 'row < 0' case too */ 360 if ((unsigned)row >= (unsigned)ri->ri_rows) { 361 stamp_mutex--; 362 return; 363 } 364 365 if ((unsigned)col >= (unsigned)ri->ri_cols) { 366 stamp_mutex--; 367 return; 368 } 369 #endif 370 371 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale); 372 height = ri->ri_font->fontheight; 373 rs = ri->ri_stride / sizeof(*rp); 374 375 /* Recompute stamp? */ 376 if (attr != stamp_attr) 377 rasops4_makestamp(ri, attr); 378 379 if (uc == ' ') { 380 u_int16_t c = stamp[0]; 381 while (height--) { 382 rp[0] = c; 383 rp[1] = c; 384 rp[2] = c; 385 rp += rs; 386 } 387 } else { 388 uc -= ri->ri_font->firstchar; 389 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 390 fs = ri->ri_font->stride; 391 392 while (height--) { 393 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 394 rp[1] = stamp[fr[0] & 0xf]; 395 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 396 fr += fs; 397 rp += rs; 398 } 399 } 400 401 /* Do underline */ 402 if ((attr & 1) != 0) { 403 rp -= (rs << 1); 404 rp[0] = stamp[15]; 405 rp[1] = stamp[15]; 406 rp[2] = stamp[15]; 407 } 408 409 stamp_mutex--; 410 } 411 412 /* 413 * Put a single character. This is for 16-pixel wide fonts. 414 */ 415 static void 416 rasops4_putchar16(cookie, row, col, uc, attr) 417 void *cookie; 418 int row, col; 419 u_int uc; 420 long attr; 421 { 422 struct rasops_info *ri; 423 int height, fs, rs; 424 u_char *fr; 425 u_int16_t *rp; 426 427 /* Can't risk remaking the stamp if it's already in use */ 428 if (stamp_mutex++) { 429 stamp_mutex--; 430 rasops4_putchar(cookie, row, col, uc, attr); 431 return; 432 } 433 434 ri = (struct rasops_info *)cookie; 435 436 #ifdef RASOPS_CLIPPING 437 /* Catches 'row < 0' case too */ 438 if ((unsigned)row >= (unsigned)ri->ri_rows) { 439 stamp_mutex--; 440 return; 441 } 442 443 if ((unsigned)col >= (unsigned)ri->ri_cols) { 444 stamp_mutex--; 445 return; 446 } 447 #endif 448 449 rp = (u_int16_t *)(ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale); 450 height = ri->ri_font->fontheight; 451 rs = ri->ri_stride / sizeof(*rp); 452 453 /* Recompute stamp? */ 454 if (attr != stamp_attr) 455 rasops4_makestamp(ri, attr); 456 457 if (uc == ' ') { 458 u_int16_t c = stamp[0]; 459 while (height--) { 460 rp[0] = c; 461 rp[1] = c; 462 rp[2] = c; 463 rp[3] = c; 464 rp += rs; 465 } 466 } else { 467 uc -= ri->ri_font->firstchar; 468 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 469 fs = ri->ri_font->stride; 470 471 while (height--) { 472 rp[0] = stamp[(fr[0] >> 4) & 0xf]; 473 rp[1] = stamp[fr[0] & 0xf]; 474 rp[2] = stamp[(fr[1] >> 4) & 0xf]; 475 rp[3] = stamp[fr[1] & 0xf]; 476 fr += fs; 477 rp += rs; 478 } 479 } 480 481 /* Do underline */ 482 if ((attr & 1) != 0) { 483 rp -= (rs << 1); 484 rp[0] = stamp[15]; 485 rp[1] = stamp[15]; 486 rp[2] = stamp[15]; 487 rp[3] = stamp[15]; 488 } 489 490 stamp_mutex--; 491 } 492 #endif /* !RASOPS_SMALL */ 493 494 /* 495 * Grab routines common to depths where (bpp < 8) 496 */ 497 #define NAME(ident) rasops4_##ident 498 #define PIXEL_SHIFT 3 499 500 #include <dev/rasops/rasops_bitops.h> 501