1 /* 2 * $Id: ite_cc.c,v 1.19 1994/06/15 19:06:11 chopps Exp $ 3 */ 4 5 #include "grfcc.h" 6 #if NGRFCC > 0 7 8 #include <sys/param.h> 9 #include <sys/conf.h> 10 #include <sys/proc.h> 11 #include <sys/device.h> 12 #include <sys/ioctl.h> 13 #include <sys/tty.h> 14 #include <sys/systm.h> 15 #include <sys/queue.h> 16 #include <sys/termios.h> 17 #include <dev/cons.h> 18 #include <machine/cpu.h> 19 #include <amiga/dev/itevar.h> 20 #include <amiga/dev/iteioctl.h> 21 #include <amiga/amiga/cc.h> 22 #include <amiga/amiga/device.h> 23 #include <amiga/dev/grfabs_reg.h> 24 #include <amiga/dev/grfioctl.h> 25 #include <amiga/dev/grfvar.h> 26 #include <amiga/dev/grf_ccreg.h> 27 #include <amiga/dev/viewioctl.h> 28 #include <amiga/dev/viewvar.h> 29 30 #ifndef KFONT_CUSTOM 31 #ifdef KFONT_8X11 32 #define kernel_font_width kernel_font_width_8x11 33 #define kernel_font_height kernel_font_height_8x11 34 #define kernel_font_baseline kernel_font_baseline_8x11 35 #define kernel_font_boldsmear kernel_font_boldsmear_8x11 36 #define kernel_font_lo kernel_font_lo_8x11 37 #define kernel_font_hi kernel_font_hi_8x11 38 #define kernel_font kernel_font_8x11 39 #define kernel_cursor kernel_cursor_8x11 40 #else 41 #define kernel_font_width kernel_font_width_8x8 42 #define kernel_font_height kernel_font_height_8x8 43 #define kernel_font_baseline kernel_font_baseline_8x8 44 #define kernel_font_boldsmear kernel_font_boldsmear_8x8 45 #define kernel_font_lo kernel_font_lo_8x8 46 #define kernel_font_hi kernel_font_hi_8x8 47 #define kernel_font kernel_font_8x8 48 #define kernel_cursor kernel_cursor_8x8 49 #endif 50 #endif 51 52 extern u_char kernel_font_width, kernel_font_height, kernel_font_baseline; 53 extern short kernel_font_boldsmear; 54 extern u_char kernel_font_lo, kernel_font_hi; 55 extern u_char kernel_font[], kernel_cursor[]; 56 57 /* 58 * This is what ip->priv points to; 59 * it contains local variables for custom-chip ites. 60 */ 61 struct ite_priv { 62 view_t *view; /* the view for this ite. */ 63 u_char **row_ptr; /* array of pointers into the bitmap */ 64 u_long row_bytes; 65 u_long cursor_opt; 66 u_int *column_offset; /* array of offsets for columns */ 67 u_int row_offset; /* the row offset */ 68 u_short width; /* the bitmap width */ 69 u_short underline; /* where the underline goes */ 70 u_short ft_x; /* the font width */ 71 u_short ft_y; /* the font height */ 72 u_char *font_cell[256]; /* the font pointer */ 73 }; 74 typedef struct ite_priv ipriv_t; 75 76 void view_deinit __P((struct ite_softc *)); 77 void view_init __P((struct ite_softc *)); 78 79 static void putc8 __P((struct ite_softc *, int, int, int, int)); 80 static void clear8 __P((struct ite_softc *, int, int, int, int)); 81 static void scroll8 __P((struct ite_softc *, int, int, int, int)); 82 static void cursor32 __P((struct ite_softc *, int)); 83 static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short, 84 short, short, u_char)); 85 86 /* patchable */ 87 int ite_default_x = 0; /* def leftedge offset */ 88 int ite_default_y = 0; /* def topedge offset */ 89 int ite_default_width = 640; /* def width */ 90 int ite_default_depth = 2; /* def depth */ 91 #if defined (GRF_NTSC) 92 int ite_default_height = 400; /* def NTSC height */ 93 #elif defined (GRF_PAL) 94 int ite_default_height = 512; /* def PAL height */ 95 #else 96 int ite_default_height = 400; /* def NON-PAL/NTSC height (?) */ 97 #endif 98 99 /* audio bell stuff */ 100 u_int bvolume = 10; 101 u_int bpitch = 660; 102 u_int bmsec = 75; 103 104 static char *bsamplep; 105 static char sample[20] = { 106 0,39,75,103,121,127,121,103,75,39,0, 107 -39,-75,-103,-121,-127,-121,-103,-75,-39 108 }; 109 110 /* 111 * called from grf_cc to return console priority 112 */ 113 int 114 grfcc_cnprobe() 115 { 116 return(CN_INTERNAL); 117 } 118 119 /* 120 * called from grf_cc to init ite portion of 121 * grf_softc struct 122 */ 123 void 124 grfcc_iteinit(gp) 125 struct grf_softc *gp; 126 { 127 gp->g_itecursor = cursor32; 128 gp->g_iteputc = putc8; 129 gp->g_iteclear = clear8; 130 gp->g_itescroll = scroll8; 131 gp->g_iteinit = view_init; 132 gp->g_itedeinit = view_deinit; 133 } 134 135 void 136 init_bell() 137 { 138 short i; 139 140 if (bsamplep != NULL) 141 return; 142 bsamplep = alloc_chipmem(20); 143 if (bsamplep == NULL) 144 panic("no chipmem for ccbell"); 145 146 bcopy(sample, bsamplep, 20); 147 } 148 149 void 150 cc_bell() 151 { 152 u_int clock; 153 u_int period; 154 u_int count; 155 156 clock = 3579545; /* PAL 3546895 */ 157 158 /* 159 * the number of clock ticks per sample byte must be > 124 160 * ergo bpitch must be < clock / 124*20 161 * i.e. ~1443, 1300 to be safe (PAL etc.). also not zero obviously 162 */ 163 period = clock / (bpitch * 20); 164 count = bmsec * bpitch / 1000; 165 166 play_sample(10, PREP_DMA_MEM(bsamplep), period, bvolume, 0x3, count); 167 } 168 169 170 int 171 ite_newsize(ip, winsz) 172 struct ite_softc *ip; 173 struct itewinsize *winsz; 174 { 175 extern struct view_softc views[]; 176 struct view_size vs; 177 ipriv_t *cci = ip->priv; 178 u_long fbp, i; 179 int error; 180 181 vs.x = winsz->x; 182 vs.y = winsz->y; 183 vs.width = winsz->width; 184 vs.height = winsz->height; 185 vs.depth = winsz->depth; 186 error = viewioctl(0, VIOCSSIZE, &vs, 0, -1); 187 188 /* 189 * Reinitialize our structs 190 */ 191 cci->view = views[0].view; 192 193 /* -1 for bold. */ 194 ip->cols = (cci->view->display.width - 1) / ip->ftwidth; 195 ip->rows = cci->view->display.height / ip->ftheight; 196 197 /* 198 * save new values so that future opens use them 199 * this may not be correct when we implement Virtual Consoles 200 */ 201 ite_default_height = cci->view->display.height; 202 ite_default_width = cci->view->display.width; 203 ite_default_x = cci->view->display.x; 204 ite_default_y = cci->view->display.y; 205 ite_default_depth = cci->view->bitmap->depth; 206 207 if (cci->row_ptr) 208 free_chipmem(cci->row_ptr); 209 if (cci->column_offset) 210 free_chipmem(cci->column_offset); 211 212 cci->row_ptr = alloc_chipmem(sizeof(u_char *) * ip->rows); 213 cci->column_offset = alloc_chipmem(sizeof(u_int) * ip->cols); 214 215 if (cci->row_ptr == NULL || cci->column_offset == NULL) 216 panic("no chipmem for itecc data"); 217 218 219 cci->width = cci->view->bitmap->bytes_per_row << 3; 220 cci->underline = ip->ftbaseline + 1; 221 cci->row_offset = cci->view->bitmap->bytes_per_row 222 + cci->view->bitmap->row_mod; 223 cci->ft_x = ip->ftwidth; 224 cci->ft_y = ip->ftheight; 225 226 cci->row_bytes = cci->row_offset * ip->ftheight; 227 228 cci->row_ptr[0] = VDISPLAY_LINE (cci->view, 0, 0); 229 for (i = 1; i < ip->rows; i++) 230 cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes; 231 232 /* initialize the column offsets */ 233 cci->column_offset[0] = 0; 234 for (i = 1; i < ip->cols; i++) 235 cci->column_offset[i] = cci->column_offset[i - 1] + cci->ft_x; 236 237 /* initialize the font cell pointers */ 238 cci->font_cell[ip->font_lo] = ip->font; 239 for (i=ip->font_lo+1; i<=ip->font_hi; i++) 240 cci->font_cell[i] = cci->font_cell[i-1] + ip->ftheight; 241 242 return (error); 243 } 244 245 void 246 view_init(ip) 247 register struct ite_softc *ip; 248 { 249 struct itewinsize wsz; 250 ipriv_t *cci; 251 252 cci = ip->priv; 253 254 if (cci) 255 return; 256 257 init_bell(); 258 259 ip->font = kernel_font; 260 ip->font_lo = kernel_font_lo; 261 ip->font_hi = kernel_font_hi; 262 ip->ftwidth = kernel_font_width; 263 ip->ftheight = kernel_font_height; 264 ip->ftbaseline = kernel_font_baseline; 265 ip->ftboldsmear = kernel_font_boldsmear; 266 267 /* Find the correct set of rendering routines for this font. */ 268 if (ip->ftwidth > 8) 269 panic("kernel font size not supported"); 270 cci = alloc_chipmem(sizeof (*cci)); 271 if (cci == NULL) 272 panic("no memory for console device."); 273 274 ip->priv = cci; 275 cci->cursor_opt = 0; 276 cci->view = NULL; 277 cci->row_ptr = NULL; 278 cci->column_offset = NULL; 279 280 wsz.x = ite_default_x; 281 wsz.y = ite_default_y; 282 wsz.width = ite_default_width; 283 wsz.height = ite_default_height; 284 wsz.depth = ite_default_depth; 285 286 ite_newsize (ip, &wsz); 287 cc_mode(ip->grf, GM_GRFON, NULL, 0, 0); 288 } 289 290 int 291 ite_grf_ioctl (ip, cmd, addr, flag, p) 292 struct ite_softc *ip; 293 caddr_t addr; 294 struct proc *p; 295 { 296 struct winsize ws; 297 struct itewinsize *is; 298 struct itebell *ib; 299 ipriv_t *cci; 300 int error; 301 302 cci = ip->priv; 303 error = 0; 304 305 switch (cmd) { 306 case ITEIOCGWINSZ: 307 is = (struct itewinsize *)addr; 308 is->x = cci->view->display.x; 309 is->y = cci->view->display.y; 310 is->width = cci->view->display.width; 311 is->height = cci->view->display.height; 312 is->depth = cci->view->bitmap->depth; 313 break; 314 case ITEIOCSWINSZ: 315 is = (struct itewinsize *)addr; 316 317 if (ite_newsize(ip, is)) 318 error = ENOMEM; 319 else { 320 ws.ws_row = ip->rows; 321 ws.ws_col = ip->cols; 322 ws.ws_xpixel = cci->view->display.width; 323 ws.ws_ypixel = cci->view->display.height; 324 ite_reset (ip); 325 /* 326 * XXX tell tty about the change 327 * XXX this is messy, but works 328 */ 329 iteioctl(0, TIOCSWINSZ, (caddr_t)&ws, 0, p); 330 } 331 break; 332 case ITEIOCDSPWIN: 333 cc_mode(ip->grf, GM_GRFON, NULL, 0, 0); 334 break; 335 case ITEIOCREMWIN: 336 cc_mode(ip->grf, GM_GRFOFF, NULL, 0, 0); 337 break; 338 case ITEIOCGBELL: 339 ib = (struct itebell *)addr; 340 ib->volume = bvolume; 341 ib->pitch = bpitch; 342 ib->msec = bmsec; 343 break; 344 case ITEIOCSBELL: 345 ib = (struct itebell *)addr; 346 /* bounds check */ 347 if (ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH || 348 ib->volume > MAXBVOLUME || ib->msec > MAXBTIME) 349 error = EINVAL; 350 else { 351 bvolume = ib->volume; 352 bpitch = ib->pitch; 353 bmsec = ib->msec; 354 } 355 break; 356 case VIOCSCMAP: 357 case VIOCGCMAP: 358 /* 359 * XXX needs to be fixed when multiple console implemented 360 * XXX watchout for that -1 its not really the kernel talking 361 * XXX these two commands don't use the proc pointer though 362 */ 363 error = viewioctl(0, cmd, addr, flag, -1); 364 break; 365 default: 366 error = -1; 367 break; 368 } 369 return (error); 370 } 371 372 void 373 view_deinit(ip) 374 struct ite_softc *ip; 375 { 376 ip->flags &= ~ITE_INITED; 377 } 378 379 /*** (M<8)-by-N routines ***/ 380 381 static void 382 cursor32(struct ite_softc *ip, int flag) 383 { 384 int cend, ofs, h, cstart, dr_plane; 385 u_char *pl, opclr, opset; 386 ipriv_t *cci; 387 bmap_t *bm; 388 view_t *v; 389 390 cci = ip->priv; 391 v = cci->view; 392 bm = v->bitmap; 393 dr_plane = (bm->depth > 1 ? bm->depth-1 : 0); 394 395 if (flag == END_CURSOROPT) 396 cci->cursor_opt--; 397 else if (flag == START_CURSOROPT) { 398 if (!cci->cursor_opt) 399 cursor32 (ip, ERASE_CURSOR); 400 cci->cursor_opt++; 401 return; /* if we are already opted. */ 402 } 403 404 if (cci->cursor_opt) 405 return; /* if we are still nested. */ 406 /* else we draw the cursor. */ 407 cstart = 0; 408 cend = ip->ftheight-1; 409 pl = VDISPLAY_LINE(v, dr_plane, (ip->cursory * ip->ftheight + cstart)); 410 ofs = (ip->cursorx * ip->ftwidth); 411 412 if (flag != DRAW_CURSOR && flag != END_CURSOROPT) { 413 /* 414 * erase the cursor 415 */ 416 int h; 417 418 if (dr_plane) { 419 for (h = cend; h >= 0; h--) { 420 asm("bfclr %0@{%1:%2}" : : "a" (pl), 421 "d" (ofs), "d" (ip->ftwidth)); 422 pl += cci->row_offset; 423 } 424 } else { 425 for (h = cend; h >= 0; h--) { 426 asm("bfchg %0@{%1:%2}" : : "a" (pl), 427 "d" (ofs), "d" (ip->ftwidth)); 428 pl += cci->row_offset; 429 } 430 } 431 } 432 433 if (flag != DRAW_CURSOR && flag != MOVE_CURSOR && 434 flag != END_CURSOROPT) 435 return; 436 437 /* 438 * draw the cursor 439 */ 440 441 ip->cursorx = min(ip->curx, ip->cols-1); 442 ip->cursory = ip->cury; 443 cstart = 0; 444 cend = ip->ftheight-1; 445 pl = VDISPLAY_LINE(v, dr_plane, ip->cursory * ip->ftheight + cstart); 446 ofs = ip->cursorx * ip->ftwidth; 447 448 if (dr_plane) { 449 for (h = cend; h >= 0; h--) { 450 asm("bfset %0@{%1:%2}" : : "a" (pl), 451 "d" (ofs), "d" (ip->ftwidth)); 452 pl += cci->row_offset; 453 } 454 } else { 455 for (h = cend; h >= 0; h--) { 456 asm("bfchg %0@{%1:%2}" : : "a" (pl), 457 "d" (ofs), "d" (ip->ftwidth)); 458 pl += cci->row_offset; 459 } 460 } 461 } 462 463 464 static inline 465 int expbits (int data) 466 { 467 int i, nd = 0; 468 469 if (data & 1) 470 nd |= 0x02; 471 for (i=1; i < 32; i++) { 472 if (data & (1 << i)) 473 nd |= 0x5 << (i-1); 474 } 475 nd &= ~data; 476 return(~nd); 477 } 478 479 480 /* Notes: optimizations given the kernel_font_(width|height) #define'd. 481 * the dbra loops could be elminated and unrolled using height, 482 * the :width in the bfxxx instruction could be made immediate instead 483 * of a data register as it now is. 484 * the underline could be added when the loop is unrolled 485 * 486 * It would look like hell but be very fast.*/ 487 488 static void 489 putc_nm (cci,p,f,co,ro,fw,fh) 490 register ipriv_t *cci; 491 register u_char *p; 492 register u_char *f; 493 register u_int co; 494 register u_int ro; 495 register u_int fw; 496 register u_int fh; 497 { 498 while (fh--) { 499 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 500 "d" (*f++), "a" (p), "d" (co), "d" (fw)); 501 p += ro; 502 } 503 } 504 505 static void 506 putc_in (cci,p,f,co,ro,fw,fh) 507 register ipriv_t *cci; 508 register u_char *p; 509 register u_char *f; 510 register u_int co; 511 register u_int ro; 512 register u_int fw; 513 register u_int fh; 514 { 515 while (fh--) { 516 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 517 "d" (~(*f++)), "a" (p), "d" (co), "d" (fw)); 518 p += ro; 519 } 520 } 521 522 523 static void 524 putc_ul (cci,p,f,co,ro,fw,fh) 525 register ipriv_t *cci; 526 register u_char *p; 527 register u_char *f; 528 register u_int co; 529 register u_int ro; 530 register u_int fw; 531 register u_int fh; 532 { 533 int underline = cci->underline; 534 while (underline--) { 535 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 536 "d" (*f++), "a" (p), "d" (co), "d" (fw)); 537 p += ro; 538 } 539 540 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 541 "d" (expbits(*f++)), "a" (p), "d" (co), "d" (fw)); 542 p += ro; 543 544 underline = fh - cci->underline - 1; 545 while (underline--) { 546 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 547 "d" (*f++), "a" (p), "d" (co), "d" (fw)); 548 p += ro; 549 } 550 } 551 552 553 static void 554 putc_ul_in (cci,p,f,co,ro,fw,fh) 555 register ipriv_t *cci; 556 register u_char *p; 557 register u_char *f; 558 register u_int co; 559 register u_int ro; 560 register u_int fw; 561 register u_int fh; 562 { 563 int underline = cci->underline; 564 while (underline--) { 565 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 566 "d" (~(*f++)), "a" (p), "d" (co), "d" (fw)); 567 p += ro; 568 } 569 570 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 571 "d" (~expbits(*f++)), "a" (p), "d" (co), "d" (fw)); 572 p += ro; 573 574 underline = fh - cci->underline - 1; 575 while (underline--) { 576 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 577 "d" (~(*f++)), "a" (p), "d" (co), "d" (fw)); 578 p += ro; 579 } 580 } 581 582 /* bold */ 583 static void 584 putc_bd (cci,p,f,co,ro,fw,fh) 585 register ipriv_t *cci; 586 register u_char *p; 587 register u_char *f; 588 register u_int co; 589 register u_int ro; 590 register u_int fw; 591 register u_int fh; 592 { 593 u_short ch; 594 595 while (fh--) { 596 ch = *f++; 597 ch |= ch << 1; 598 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 599 "d" (ch), "a" (p), "d" (co), "d" (fw+1)); 600 p += ro; 601 } 602 } 603 604 static void 605 putc_bd_in (cci,p,f,co,ro,fw,fh) 606 register ipriv_t *cci; 607 register u_char *p; 608 register u_char *f; 609 register u_int co; 610 register u_int ro; 611 register u_int fw; 612 register u_int fh; 613 { 614 u_short ch; 615 616 while (fh--) { 617 ch = *f++; 618 ch |= ch << 1; 619 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 620 "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1)); 621 p += ro; 622 } 623 } 624 625 626 static void 627 putc_bd_ul (cci,p,f,co,ro,fw,fh) 628 register ipriv_t *cci; 629 register u_char *p; 630 register u_char *f; 631 register u_int co; 632 register u_int ro; 633 register u_int fw; 634 register u_int fh; 635 { 636 int underline = cci->underline; 637 u_short ch; 638 639 while (underline--) { 640 ch = *f++; 641 ch |= ch << 1; 642 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 643 "d" (ch), "a" (p), "d" (co), "d" (fw+1)); 644 p += ro; 645 } 646 647 ch = *f++; 648 ch |= ch << 1; 649 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 650 "d" (expbits(ch)), "a" (p), "d" (co), "d" (fw+1)); 651 p += ro; 652 653 underline = fh - cci->underline - 1; 654 while (underline--) { 655 ch = *f++; 656 ch |= ch << 1; 657 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 658 "d" (ch), "a" (p), "d" (co), "d" (fw+1)); 659 p += ro; 660 } 661 } 662 663 664 static void 665 putc_bd_ul_in (cci,p,f,co,ro,fw,fh) 666 register ipriv_t *cci; 667 register u_char *p; 668 register u_char *f; 669 register u_int co; 670 register u_int ro; 671 register u_int fw; 672 register u_int fh; 673 { 674 int underline = cci->underline; 675 u_short ch; 676 677 while (underline--) { 678 ch = *f++; 679 ch |= ch << 1; 680 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 681 "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1)); 682 p += ro; 683 } 684 685 ch = *f++; 686 ch |= ch << 1; 687 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 688 "d" (~expbits(ch)), "a" (p), "d" (co), "d" (fw+1)); 689 p += ro; 690 691 underline = fh - cci->underline - 1; 692 while (underline--) { 693 ch = *f++; 694 ch |= ch << 1; 695 asm ("bfins %0,%1@{%2:%3}" : /* no output */ : 696 "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1)); 697 p += ro; 698 } 699 } 700 701 702 typedef void cc_putc_func (); 703 704 cc_putc_func *put_func[ATTR_ALL+1] = { 705 putc_nm, 706 putc_in, 707 putc_ul, 708 putc_ul_in, 709 putc_bd, 710 putc_bd_in, 711 putc_bd_ul, 712 putc_bd_ul_in, 713 /* no support for blink */ 714 putc_nm, 715 putc_in, 716 putc_ul, 717 putc_ul_in, 718 putc_bd, 719 putc_bd_in, 720 putc_bd_ul, 721 putc_bd_ul_in 722 }; 723 724 725 /* FIX: shouldn't this advance the cursor even if the character to 726 be output is not available in the font? -ch */ 727 728 static void 729 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode) 730 { 731 register ipriv_t *cci = (ipriv_t *) ip->priv; 732 if (c < ip->font_lo || c > ip->font_hi) 733 return; 734 735 put_func[mode](cci, 736 cci->row_ptr[dy], 737 cci->font_cell[c], 738 cci->column_offset[dx], 739 cci->row_offset, 740 cci->ft_x, 741 cci->ft_y); 742 } 743 744 static void 745 clear8(struct ite_softc *ip, int sy, int sx, int h, int w) 746 { 747 ipriv_t *cci = (ipriv_t *) ip->priv; 748 view_t *v = cci->view; 749 bmap_t *bm = cci->view->bitmap; 750 751 if ((sx == 0) && (w == ip->cols)) 752 { 753 /* common case: clearing whole lines */ 754 while (h--) 755 { 756 int i; 757 u_char *ptr = cci->row_ptr[sy]; 758 for (i=0; i < ip->ftheight; i++) { 759 bzero(ptr, bm->bytes_per_row); 760 ptr += bm->bytes_per_row + bm->row_mod; /* don't get any smart 761 ideas, becuase this is for 762 interleaved bitmaps */ 763 } 764 sy++; 765 } 766 } 767 else 768 { 769 /* clearing only part of a line */ 770 /* XXX could be optimized MUCH better, but is it worth the trouble? */ 771 while (h--) 772 { 773 u_char *pl = cci->row_ptr[sy]; 774 int ofs = sx * ip->ftwidth; 775 int i, j; 776 for (i = w-1; i >= 0; i--) 777 { 778 u_char *ppl = pl; 779 for (j = ip->ftheight-1; j >= 0; j--) 780 { 781 asm("bfclr %0@{%1:%2}" 782 : : "a" (ppl), "d" (ofs), "d" (ip->ftwidth)); 783 ppl += bm->row_mod + bm->bytes_per_row; 784 } 785 ofs += ip->ftwidth; 786 } 787 sy++; 788 } 789 } 790 } 791 792 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */ 793 static void 794 scroll8(ip, sy, sx, count, dir) 795 register struct ite_softc *ip; 796 register int sy; 797 int dir, sx, count; 798 { 799 bmap_t *bm = ((ipriv_t *)ip->priv)->view->bitmap; 800 u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy]; 801 802 if (dir == SCROLL_UP) 803 { 804 int dy = sy - count; 805 int height = ip->bottom_margin - sy + 1; 806 int i; 807 808 /*FIX: add scroll bitmap call */ 809 cursor32(ip, ERASE_CURSOR); 810 scrollbmap (bm, 0, dy*ip->ftheight, 811 bm->bytes_per_row >> 3, (ip->bottom_margin-dy+1)*ip->ftheight, 812 0, -(count*ip->ftheight), 0x1); 813 /* if (ip->cursory <= bot || ip->cursory >= dy) { 814 ip->cursory -= count; 815 } */ 816 } 817 else if (dir == SCROLL_DOWN) 818 { 819 int dy = sy + count; 820 int height = ip->bottom_margin - dy + 1; 821 int i; 822 823 /* FIX: add scroll bitmap call */ 824 cursor32(ip, ERASE_CURSOR); 825 scrollbmap (bm, 0, sy*ip->ftheight, 826 bm->bytes_per_row >> 3, (ip->bottom_margin-sy+1)*ip->ftheight, 827 0, count*ip->ftheight, 0x1); 828 /* if (ip->cursory <= bot || ip->cursory >= sy) { 829 ip->cursory += count; 830 } */ 831 } 832 else if (dir == SCROLL_RIGHT) 833 { 834 int sofs = (ip->cols - count) * ip->ftwidth; 835 int dofs = (ip->cols) * ip->ftwidth; 836 int i, j; 837 838 cursor32(ip, ERASE_CURSOR); 839 for (j = ip->ftheight-1; j >= 0; j--) 840 { 841 int sofs2 = sofs, dofs2 = dofs; 842 for (i = (ip->cols - (sx + count))-1; i >= 0; i--) 843 { 844 int t; 845 sofs2 -= ip->ftwidth; 846 dofs2 -= ip->ftwidth; 847 asm("bfextu %1@{%2:%3},%0" 848 : "=d" (t) 849 : "a" (pl), "d" (sofs2), "d" (ip->ftwidth)); 850 asm("bfins %3,%0@{%1:%2}" 851 : : "a" (pl), "d" (dofs2), "d" (ip->ftwidth), "d" (t)); 852 } 853 pl += bm->row_mod + bm->bytes_per_row; 854 } 855 } 856 else /* SCROLL_LEFT */ 857 { 858 int sofs = (sx) * ip->ftwidth; 859 int dofs = (sx - count) * ip->ftwidth; 860 int i, j; 861 862 cursor32(ip, ERASE_CURSOR); 863 for (j = ip->ftheight-1; j >= 0; j--) 864 { 865 int sofs2 = sofs, dofs2 = dofs; 866 for (i = (ip->cols - sx)-1; i >= 0; i--) 867 { 868 int t; 869 asm("bfextu %1@{%2:%3},%0" 870 : "=d" (t) 871 : "a" (pl), "d" (sofs2), "d" (ip->ftwidth)); 872 asm("bfins %3,%0@{%1:%2}" 873 : : "a" (pl), "d" (dofs2), "d" (ip->ftwidth), "d" (t)); 874 sofs2 += ip->ftwidth; 875 dofs2 += ip->ftwidth; 876 } 877 pl += bm->row_mod + bm->bytes_per_row; 878 } 879 } 880 } 881 882 void 883 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy, u_char mask) 884 { 885 u_short depth = bm->depth; 886 u_short lwpr = bm->bytes_per_row >> 2; 887 if (dx) { 888 /* FIX: */ panic ("delta x not supported in scroll bitmap yet."); 889 } 890 if (bm->flags & BMF_INTERLEAVED) { 891 height *= depth; 892 depth = 1; 893 } 894 if (dy == 0) { 895 return; 896 } 897 if (dy > 0) { 898 int i; 899 for (i=0; i < depth && mask; i++, mask >>= 1) { 900 if (0x1 & mask) { 901 u_long *pl = (u_long *)bm->plane[i]; 902 u_long *src_y = pl + (lwpr*y); 903 u_long *dest_y = pl + (lwpr*(y+dy)); 904 u_long count = lwpr*(height-dy); 905 u_long *clr_y = src_y; 906 u_long clr_count = dest_y - src_y; 907 u_long bc, cbc; 908 909 src_y += count - 1; 910 dest_y += count - 1; 911 912 bc = count >> 4; 913 count &= 0xf; 914 915 while (bc--) { 916 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 917 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 918 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 919 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 920 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 921 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 922 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 923 *dest_y-- = *src_y--; *dest_y-- = *src_y--; 924 } 925 while (count--) { 926 *dest_y-- = *src_y--; 927 } 928 929 cbc = clr_count >> 4; 930 clr_count &= 0xf; 931 932 while (cbc--) { 933 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 934 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 935 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 936 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 937 } 938 while (clr_count--) { 939 *clr_y++ = 0; 940 } 941 } 942 } 943 } else if (dy < 0) { 944 int i; 945 for (i=0; i < depth && mask; i++, mask >>= 1) { 946 if (0x1 & mask) { 947 u_long *pl = (u_long *)bm->plane[i]; 948 u_long *src_y = pl + (lwpr*(y-dy)); 949 u_long *dest_y = pl + (lwpr*y); 950 long count = lwpr*(height + dy); 951 u_long *clr_y = dest_y + count; 952 u_long clr_count = src_y - dest_y; 953 u_long bc, cbc; 954 955 bc = count >> 4; 956 count &= 0xf; 957 958 while (bc--) { 959 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 960 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 961 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 962 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 963 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 964 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 965 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 966 *dest_y++ = *src_y++; *dest_y++ = *src_y++; 967 } 968 while (count--) { 969 *dest_y++ = *src_y++; 970 } 971 972 cbc = clr_count >> 4; 973 clr_count &= 0xf; 974 975 while (cbc--) { 976 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 977 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 978 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 979 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; 980 } 981 while (clr_count--) { 982 *clr_y++ = 0; 983 } 984 } 985 } 986 } 987 } 988 989 #endif /* NGRFCC */ 990