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