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