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