1 /* $NetBSD: rasops2.c,v 1.4 1999/10/23 23:14:14 ad 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 Andy 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 "opt_rasops.h" 40 #include <sys/cdefs.h> 41 __KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.4 1999/10/23 23:14:14 ad Exp $"); 42 43 #include <sys/types.h> 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/time.h> 47 #include <machine/endian.h> 48 49 #include <dev/wscons/wsdisplayvar.h> 50 #include <dev/wscons/wsconsio.h> 51 #include <dev/rasops/rasops.h> 52 #include <dev/rasops/rasops_masks.h> 53 54 static void rasops2_copycols __P((void *, int, int, int, int)); 55 static void rasops2_erasecols __P((void *, int, int, int, long)); 56 static void rasops2_do_cursor __P((struct rasops_info *)); 57 static void rasops2_putchar __P((void *, int, int col, u_int, long)); 58 #ifndef RASOPS_SMALL 59 static void rasops2_putchar8 __P((void *, int, int col, u_int, long)); 60 static void rasops2_putchar12 __P((void *, int, int col, u_int, long)); 61 static void rasops2_putchar16 __P((void *, int, int col, u_int, long)); 62 static void rasops2_makestamp __P((struct rasops_info *, long)); 63 #endif 64 65 /* 66 * 4x1 stamp for optimized character blitting 67 */ 68 static int8_t stamp[16]; 69 static long stamp_attr; 70 static int stamp_mutex; /* XXX see note in README */ 71 72 /* 73 * Initialize rasops_info struct for this colordepth. 74 */ 75 void 76 rasops2_init(ri) 77 struct rasops_info *ri; 78 { 79 80 switch (ri->ri_font->fontwidth) { 81 #ifndef RASOPS_SMALL 82 case 8: 83 ri->ri_ops.putchar = rasops2_putchar8; 84 break; 85 case 12: 86 ri->ri_ops.putchar = rasops2_putchar12; 87 break; 88 case 16: 89 ri->ri_ops.putchar = rasops2_putchar16; 90 break; 91 #endif /* !RASOPS_SMALL */ 92 default: 93 panic("fontwidth not 8/12/16 or RASOPS_SMALL - fixme!"); 94 ri->ri_ops.putchar = rasops2_putchar; 95 break; 96 } 97 98 if ((ri->ri_font->fontwidth & 3) != 0) { 99 ri->ri_ops.erasecols = rasops2_erasecols; 100 ri->ri_ops.copycols = rasops2_copycols; 101 ri->ri_do_cursor = rasops2_do_cursor; 102 } 103 } 104 105 #ifdef notyet 106 /* 107 * Paint a single character. This is the generic version, this is ugly. 108 */ 109 static void 110 rasops2_putchar(cookie, row, col, uc, attr) 111 void *cookie; 112 int row, col; 113 u_int uc; 114 long attr; 115 { 116 int height, width, fs, rs, fb, bg, fg, lmask, rmask; 117 struct rasops_info *ri; 118 int32_t *rp; 119 u_char *fr; 120 121 ri = (struct rasops_info *)cookie; 122 123 #ifdef RASOPS_CLIPPING 124 /* Catches 'row < 0' case too */ 125 if ((unsigned)row >= (unsigned)ri->ri_rows) 126 return; 127 128 if ((unsigned)col >= (unsigned)ri->ri_cols) 129 return; 130 #endif 131 132 width = ri->ri_font->fontwidth << 1; 133 height = ri->ri_font->fontheight; 134 col *= width; 135 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 136 col = col & 31; 137 rs = ri->ri_stride; 138 139 bg = ri->ri_devcmap[(attr >> 16) & 15]; 140 fg = ri->ri_devcmap[(attr >> 24) & 15]; 141 142 /* If fg and bg match this becomes a space character */ 143 if (fg == bg || uc == ' ') { 144 uc = (u_int)-1; 145 fr = 0; /* shutup gcc */ 146 fs = 0; /* shutup gcc */ 147 } else { 148 uc -= ri->ri_font->firstchar; 149 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 150 fs = ri->ri_font->stride; 151 } 152 153 /* Single word, one mask */ 154 if ((col + width) <= 32) { 155 rmask = rasops_pmask[col][width]; 156 lmask = ~rmask; 157 158 if (uc == (u_int)-1) { 159 bg &= rmask; 160 161 while (height--) { 162 *rp = (*rp & lmask) | bg; 163 DELTA(rp, rs, int32_t *); 164 } 165 } else { 166 while (height--) { 167 /* get bits, mask */ 168 /* compose sl */ 169 /* mask sl */ 170 /* put word */ 171 } 172 } 173 174 /* Do underline */ 175 if (attr & 1) { 176 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 177 *rp = (*rp & lmask) | (fg & rmask); 178 } 179 } else { 180 lmask = ~rasops_lmask[col]; 181 rmask = ~rasops_rmask[(col + width) & 31]; 182 183 if (uc == (u_int)-1) { 184 bg = bg & ~lmask; 185 width = bg & ~rmask; 186 187 while (height--) { 188 rp[0] = (rp[0] & lmask) | bg; 189 rp[1] = (rp[1] & rmask) | width; 190 DELTA(rp, rs, int32_t *); 191 } 192 } else { 193 width = 32 - col; 194 195 /* NOT fontbits if bg is white */ 196 while (height--) { 197 fb = ~(fr[3] | (fr[2] << 8) | 198 (fr[1] << 16) | (fr[0] << 24)); 199 200 rp[0] = (rp[0] & lmask) 201 | MBE((u_int)fb >> col); 202 203 rp[1] = (rp[1] & rmask) 204 | (MBE((u_int)fb << width) & ~rmask); 205 206 fr += fs; 207 DELTA(rp, rs, int32_t *); 208 } 209 } 210 211 /* Do underline */ 212 if (attr & 1) { 213 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 214 rp[0] = (rp[0] & lmask) | (fg & ~lmask); 215 rp[1] = (rp[1] & rmask) | (fg & ~rmask); 216 } 217 } 218 } 219 #endif 220 221 /* 222 * Put a single character. This is the generic version. 223 */ 224 static void 225 rasops2_putchar(cookie, row, col, uc, attr) 226 void *cookie; 227 int row, col; 228 u_int uc; 229 long attr; 230 { 231 232 /* XXX punt */ 233 } 234 235 #ifndef RASOPS_SMALL 236 /* 237 * Recompute the blitting stamp. 238 */ 239 static void 240 rasops2_makestamp(ri, attr) 241 struct rasops_info *ri; 242 long attr; 243 { 244 int i, fg, bg; 245 246 fg = ri->ri_devcmap[(attr >> 24) & 15] & 3; 247 bg = ri->ri_devcmap[(attr >> 16) & 15] & 3; 248 stamp_attr = attr; 249 250 for (i = 0; i < 16; i++) { 251 stamp[i] = (i & 1 ? fg : bg); 252 stamp[i] |= (i & 2 ? fg : bg) << 2; 253 stamp[i] |= (i & 4 ? fg : bg) << 4; 254 stamp[i] |= (i & 8 ? fg : bg) << 6; 255 } 256 } 257 258 /* 259 * Put a single character. This is for 8-pixel wide fonts. 260 */ 261 static void 262 rasops2_putchar8(cookie, row, col, uc, attr) 263 void *cookie; 264 int row, col; 265 u_int uc; 266 long attr; 267 { 268 struct rasops_info *ri; 269 int height, fs, rs; 270 u_char *fr, *rp; 271 272 /* Can't risk remaking the stamp if it's already in use */ 273 if (stamp_mutex++) { 274 stamp_mutex--; 275 rasops2_putchar(cookie, row, col, uc, attr); 276 return; 277 } 278 279 ri = (struct rasops_info *)cookie; 280 281 #ifdef RASOPS_CLIPPING 282 /* Catches 'row < 0' case too */ 283 if ((unsigned)row >= (unsigned)ri->ri_rows) { 284 stamp_mutex--; 285 return; 286 } 287 288 if ((unsigned)col >= (unsigned)ri->ri_cols) { 289 stamp_mutex--; 290 return; 291 } 292 #endif 293 294 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 295 height = ri->ri_font->fontheight; 296 rs = ri->ri_stride; 297 298 /* Recompute stamp? */ 299 if (attr != stamp_attr) 300 rasops2_makestamp(ri, attr); 301 302 if (uc == ' ') { 303 while (height--) { 304 *(int16_t *)rp = stamp[0]; 305 rp += rs; 306 } 307 } else { 308 uc -= ri->ri_font->firstchar; 309 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 310 fs = ri->ri_font->stride; 311 312 while (height--) { 313 rp[0] = stamp[(*fr >> 4) & 15]; 314 rp[1] = stamp[*fr & 15]; 315 fr += fs; 316 rp += rs; 317 } 318 } 319 320 /* Do underline */ 321 if ((attr & 1) != 0) 322 *(int16_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 323 324 stamp_mutex--; 325 } 326 327 /* 328 * Put a single character. This is for 12-pixel wide fonts. 329 */ 330 static void 331 rasops2_putchar12(cookie, row, col, uc, attr) 332 void *cookie; 333 int row, col; 334 u_int uc; 335 long attr; 336 { 337 struct rasops_info *ri; 338 int height, fs, rs; 339 u_char *fr, *rp; 340 341 /* Can't risk remaking the stamp if it's already in use */ 342 if (stamp_mutex++) { 343 stamp_mutex--; 344 rasops2_putchar(cookie, row, col, uc, attr); 345 return; 346 } 347 348 ri = (struct rasops_info *)cookie; 349 350 #ifdef RASOPS_CLIPPING 351 /* Catches 'row < 0' case too */ 352 if ((unsigned)row >= (unsigned)ri->ri_rows) { 353 stamp_mutex--; 354 return; 355 } 356 357 if ((unsigned)col >= (unsigned)ri->ri_cols) { 358 stamp_mutex--; 359 return; 360 } 361 #endif 362 363 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 364 height = ri->ri_font->fontheight; 365 rs = ri->ri_stride; 366 367 /* Recompute stamp? */ 368 if (attr != stamp_attr) 369 rasops2_makestamp(ri, attr); 370 371 if (uc == ' ') { 372 while (height--) { 373 rp[0] = stamp[0]; 374 rp[1] = stamp[0]; 375 rp[2] = stamp[0]; 376 rp += rs; 377 } 378 } else { 379 uc -= ri->ri_font->firstchar; 380 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 381 fs = ri->ri_font->stride; 382 383 while (height--) { 384 rp[0] = stamp[(fr[0] >> 4) & 15]; 385 rp[1] = stamp[fr[0] & 15]; 386 rp[2] = stamp[(fr[1] >> 4) & 15]; 387 fr += fs; 388 rp += rs; 389 } 390 } 391 392 /* Do underline */ 393 if ((attr & 1) != 0) { 394 rp -= ri->ri_stride << 1; 395 rp[0] = stamp[15]; 396 rp[1] = stamp[15]; 397 rp[2] = stamp[15]; 398 } 399 400 stamp_mutex--; 401 } 402 403 /* 404 * Put a single character. This is for 16-pixel wide fonts. 405 */ 406 static void 407 rasops2_putchar16(cookie, row, col, uc, attr) 408 void *cookie; 409 int row, col; 410 u_int uc; 411 long attr; 412 { 413 struct rasops_info *ri; 414 int height, fs, rs; 415 u_char *fr, *rp; 416 417 /* Can't risk remaking the stamp if it's already in use */ 418 if (stamp_mutex++) { 419 stamp_mutex--; 420 rasops2_putchar(cookie, row, col, uc, attr); 421 return; 422 } 423 424 ri = (struct rasops_info *)cookie; 425 426 #ifdef RASOPS_CLIPPING 427 /* Catches 'row < 0' case too */ 428 if ((unsigned)row >= (unsigned)ri->ri_rows) { 429 stamp_mutex--; 430 return; 431 } 432 433 if ((unsigned)col >= (unsigned)ri->ri_cols) { 434 stamp_mutex--; 435 return; 436 } 437 #endif 438 439 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale; 440 height = ri->ri_font->fontheight; 441 rs = ri->ri_stride; 442 443 /* Recompute stamp? */ 444 if (attr != stamp_attr) 445 rasops2_makestamp(ri, attr); 446 447 if (uc == ' ') { 448 while (height--) { 449 *(int32_t *)rp = stamp[0]; 450 rp += rs; 451 } 452 } else { 453 uc -= ri->ri_font->firstchar; 454 fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale; 455 fs = ri->ri_font->stride; 456 457 while (height--) { 458 rp[0] = stamp[(fr[0] >> 4) & 15]; 459 rp[1] = stamp[fr[0] & 15]; 460 rp[2] = stamp[(fr[1] >> 4) & 15]; 461 rp[3] = stamp[fr[1] & 15]; 462 fr += fs; 463 rp += rs; 464 } 465 } 466 467 /* Do underline */ 468 if ((attr & 1) != 0) 469 *(int32_t *)(rp - (ri->ri_stride << 1)) = stamp[15]; 470 471 stamp_mutex--; 472 } 473 #endif /* !RASOPS_SMALL */ 474 475 /* 476 * Grab routines common to depths where (bpp < 8) 477 */ 478 #define NAME(ident) rasops2_##ident 479 #define PIXEL_SHIFT 1 480 481 #include <dev/rasops/rasops_bitops.h> 482