ite_cc.c revision 1.7 1 /* $NetBSD: ite_cc.c,v 1.7 1996/09/16 06:43:41 leo Exp $ */
2
3 /*
4 * Copyright (c) 1996 Leo Weppelman
5 * Copyright (c) 1994 Christian E. Hopps
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Christian E. Hopps.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "grfcc.h"
35 #if NGRFCC > 0
36
37 #include <sys/param.h>
38 #include <sys/conf.h>
39 #include <sys/proc.h>
40 #include <sys/ioctl.h>
41 #include <sys/tty.h>
42 #include <sys/systm.h>
43 #include <sys/queue.h>
44 #include <sys/termios.h>
45 #include <sys/malloc.h>
46 #include <sys/device.h>
47 #include <dev/cons.h>
48 #include <machine/cpu.h>
49 #include <atari/atari/device.h>
50 #include <atari/dev/itevar.h>
51 #include <atari/dev/iteioctl.h>
52 #include <atari/dev/grfioctl.h>
53 #include <atari/dev/grfabs_reg.h>
54 #include <atari/dev/grfvar.h>
55 #include <atari/dev/font.h>
56 #include <atari/dev/viewioctl.h>
57 #include <atari/dev/viewvar.h>
58
59 /*
60 * This is what ip->priv points to;
61 * it contains local variables for custom-chip ites.
62 */
63 struct ite_priv {
64 u_char **row_ptr; /* array of pointers into the bitmap */
65 u_long row_bytes;
66 u_long cursor_opt;
67 u_short *column_offset; /* array of offsets for columns */
68 u_int row_offset; /* the row offset */
69 u_short width; /* the bitmap width */
70 u_short underline; /* where the underline goes */
71 u_short ft_x; /* the font width */
72 u_short ft_y; /* the font height */
73 u_char *font_cell[256];/* the font pointer */
74 };
75 typedef struct ite_priv ipriv_t;
76
77 /*
78 * We need the following space to get an ite-console setup before
79 * the VM-system is brought up. We setup for a 1280x960 monitor with
80 * an 8x8 font.
81 */
82 #define CONS_MAXROW 120 /* Max. number of rows on console */
83 #define CONS_MAXCOL 160 /* Max. number of columns on console */
84 static u_short con_columns[CONS_MAXCOL];
85 static u_char *con_rows[CONS_MAXROW];
86 static ipriv_t con_ipriv;
87
88 extern font_info font_info_8x8;
89 extern font_info font_info_8x16;
90
91 static void view_init __P((struct ite_softc *));
92 static void view_deinit __P((struct ite_softc *));
93 static int ite_newsize __P((struct ite_softc *, struct itewinsize *));
94 static void cursor32 __P((struct ite_softc *, int));
95 static void putc8 __P((struct ite_softc *, int, int, int, int));
96 static void clear8 __P((struct ite_softc *, int, int, int, int));
97 static void scroll8 __P((struct ite_softc *, int, int, int, int));
98 static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short,
99 short, short));
100
101 /*
102 * Patchable
103 */
104 int ite_default_x = 0; /* def leftedge offset */
105 int ite_default_y = 0; /* def topedge offset */
106 int ite_default_width = 640; /* def width */
107 int ite_default_depth = 1; /* def depth */
108 int ite_default_height = 400; /* def height */
109
110 /*
111 * grfcc config stuff
112 */
113 void grfccattach __P((struct device *, struct device *, void *));
114 int grfccmatch __P((struct device *, void *, void *));
115 int grfccprint __P((void *, const char *));
116
117 struct cfattach grfcc_ca = {
118 sizeof(struct grf_softc), grfccmatch, grfccattach
119 };
120
121 struct cfdriver grfcc_cd = {
122 NULL, "grfcc", DV_DULL
123 };
124
125 /*
126 * only used in console init.
127 */
128 static struct cfdata *cfdata_grf = NULL;
129
130 /*
131 * Probe functions we can use:
132 */
133 #ifdef TT_VIDEO
134 void tt_probe_video __P((MODES *));
135 #endif /* TT_VIDEO */
136 #ifdef FALCON_VIDEO
137 void falcon_probe_video __P((MODES *));
138 #endif /* FALCON_VIDEO */
139
140 int
141 grfccmatch(pdp, match, auxp)
142 struct device *pdp;
143 void *match, *auxp;
144 {
145 static int must_probe = 1;
146 grf_auxp_t *grf_auxp = auxp;
147 struct cfdata *cfp = match;
148
149 if (must_probe) {
150 /*
151 * Check if the layers we depend on exist
152 */
153 if (!(machineid & (ATARI_TT|ATARI_FALCON)))
154 return (0);
155 #ifdef TT_VIDEO
156 if ((machineid & ATARI_TT) && !grfabs_probe(&tt_probe_video))
157 return (0);
158 #endif /* TT_VIDEO */
159 #ifdef FALCON_VIDEO
160 if ((machineid & ATARI_FALCON)
161 && !grfabs_probe(&falcon_probe_video))
162 return (0);
163 #endif /* FALCON_VIDEO */
164
165 viewprobe();
166 must_probe = 0;
167 }
168
169 if (atari_realconfig == 0) {
170 /*
171 * Early console init. Only match unit 0.
172 */
173 if (cfp->cf_unit != 0)
174 return(0);
175 if (viewopen(0, 0, 0, NULL))
176 return(0);
177 cfdata_grf = cfp;
178 return (1);
179 }
180
181 /*
182 * Normal config. When we are called directly from the grfbus,
183 * we only match unit 0. The attach function will call us for
184 * the other configured units.
185 */
186 if (grf_auxp->from_bus_match && (cfp->cf_unit != 0))
187 return (0);
188
189 if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
190 return (0);
191
192 /*
193 * Final constraint: each grf needs a view....
194 */
195 if((cfdata_grf == NULL) || (cfp->cf_unit != 0)) {
196 if(viewopen(cfp->cf_unit, 0, 0, NULL))
197 return(0);
198 }
199 return(1);
200 }
201
202 /*
203 * attach: initialize the grf-structure and try to attach an ite to us.
204 * note : dp is NULL during early console init.
205 */
206 void
207 grfccattach(pdp, dp, auxp)
208 struct device *pdp, *dp;
209 void *auxp;
210 {
211 static struct grf_softc congrf;
212 grf_auxp_t *grf_bus_auxp = auxp;
213 grf_auxp_t grf_auxp;
214 struct grf_softc *gp;
215 int maj;
216
217 /*
218 * find our major device number
219 */
220 for(maj = 0; maj < nchrdev; maj++)
221 if (cdevsw[maj].d_open == grfopen)
222 break;
223
224 /*
225 * Handle exeption case: early console init
226 */
227 if(dp == NULL) {
228 congrf.g_unit = 0;
229 congrf.g_itedev = (dev_t)-1;
230 congrf.g_grfdev = makedev(maj, 0);
231 congrf.g_flags = GF_ALIVE;
232 congrf.g_mode = grf_mode;
233 congrf.g_conpri = grfcc_cnprobe();
234 congrf.g_viewdev = congrf.g_unit;
235 grfcc_iteinit(&congrf);
236 grf_viewsync(&congrf);
237
238 /* Attach console ite */
239 atari_config_found(cfdata_grf, NULL, &congrf, grfccprint);
240 return;
241 }
242
243 gp = (struct grf_softc *)dp;
244 gp->g_unit = gp->g_device.dv_unit;
245 grfsp[gp->g_unit] = gp;
246
247 if((cfdata_grf != NULL) && (gp->g_unit == 0)) {
248 /*
249 * We inited earlier just copy the info, take care
250 * not to copy the device struct though.
251 */
252 bcopy(&congrf.g_display, &gp->g_display,
253 (char *)&gp[1] - (char *)&gp->g_display);
254 }
255 else {
256 gp->g_grfdev = makedev(maj, gp->g_unit);
257 gp->g_itedev = (dev_t)-1;
258 gp->g_flags = GF_ALIVE;
259 gp->g_mode = grf_mode;
260 gp->g_conpri = 0;
261 gp->g_viewdev = gp->g_unit;
262 grfcc_iteinit(gp);
263 grf_viewsync(gp);
264 }
265
266 printf(": width %d height %d", gp->g_display.gd_dwidth,
267 gp->g_display.gd_dheight);
268 if(gp->g_display.gd_colors == 2)
269 printf(" monochrome\n");
270 else printf(" colors %d\n", gp->g_display.gd_colors);
271
272 /*
273 * try and attach an ite
274 */
275 config_found(dp, gp, grfccprint);
276
277 /*
278 * If attaching unit 0, go ahead and 'find' the rest of us
279 */
280 if (gp->g_unit == 0) {
281 grf_auxp.from_bus_match = 0;
282 for (grf_auxp.unit=1; grf_auxp.unit < NGRFCC; grf_auxp.unit++) {
283 config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
284 }
285 }
286 }
287
288 int
289 grfccprint(auxp, pnp)
290 void *auxp;
291 const char *pnp;
292 {
293 if(pnp)
294 printf("ite at %s", pnp);
295 return(UNCONF);
296 }
297
298 /*
299 * called from grf_cc to return console priority
300 */
301 int
302 grfcc_cnprobe()
303 {
304 return(CN_INTERNAL);
305 }
306 /*
307 * called from grf_cc to init ite portion of
308 * grf_softc struct
309 */
310 void
311 grfcc_iteinit(gp)
312 struct grf_softc *gp;
313 {
314
315 gp->g_itecursor = cursor32;
316 gp->g_iteputc = putc8;
317 gp->g_iteclear = clear8;
318 gp->g_itescroll = scroll8;
319 gp->g_iteinit = view_init;
320 gp->g_itedeinit = view_deinit;
321 }
322
323 static void
324 view_deinit(ip)
325 struct ite_softc *ip;
326 {
327 ip->flags &= ~ITE_INITED;
328 }
329
330 static void
331 view_init(ip)
332 register struct ite_softc *ip;
333 {
334 struct itewinsize wsz;
335 ipriv_t *cci;
336
337 if((cci = ip->priv) != NULL)
338 return;
339
340 #if defined(KFONT_8X8)
341 ip->font = font_info_8x8;
342 #else
343 ip->font = font_info_8x16;
344 #endif
345
346 /* Find the correct set of rendering routines for this font. */
347 if(ip->font.width != 8)
348 panic("kernel font size not supported");
349
350 if(!atari_realconfig)
351 ip->priv = cci = &con_ipriv;
352 else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
353 if(cci == NULL)
354 panic("No memory for ite-view");
355 bzero(cci, sizeof(*cci));
356
357 cci->cursor_opt = 0;
358 cci->row_ptr = NULL;
359 cci->column_offset = NULL;
360
361 wsz.x = ite_default_x;
362 wsz.y = ite_default_y;
363 wsz.width = ite_default_width;
364 wsz.height = ite_default_height;
365 wsz.depth = ite_default_depth;
366
367 ite_newsize (ip, &wsz);
368
369 /*
370 * Only console will be turned on by default..
371 */
372 if(ip->flags & ITE_ISCONS)
373 ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
374 }
375
376 static int
377 ite_newsize(ip, winsz)
378 struct ite_softc *ip;
379 struct itewinsize *winsz;
380 {
381 struct view_size vs;
382 ipriv_t *cci = ip->priv;
383 u_long i, j;
384 int error = 0;
385 view_t *view;
386
387 vs.x = winsz->x;
388 vs.y = winsz->y;
389 vs.width = winsz->width;
390 vs.height = winsz->height;
391 vs.depth = winsz->depth;
392
393 error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, (caddr_t)&vs, 0,
394 NOPROC);
395 view = viewview(ip->grf->g_viewdev);
396
397 /*
398 * Reinitialize our structs
399 */
400 ip->cols = view->display.width / ip->font.width;
401 ip->rows = view->display.height / ip->font.height;
402
403 /*
404 * save new values so that future opens use them
405 * this may not be correct when we implement Virtual Consoles
406 */
407 ite_default_height = view->display.height;
408 ite_default_width = view->display.width;
409 ite_default_x = view->display.x;
410 ite_default_y = view->display.y;
411 ite_default_depth = view->bitmap->depth;
412
413 if(cci->row_ptr && (cci->row_ptr != con_rows)) {
414 free(cci->row_ptr, M_DEVBUF);
415 cci->row_ptr = NULL;
416 }
417 if(cci->column_offset && (cci->column_offset != con_columns)) {
418 free(cci->column_offset, M_DEVBUF);
419 cci->column_offset = NULL;
420 }
421
422 if(!atari_realconfig) {
423 cci->row_ptr = con_rows;
424 cci->column_offset = con_columns;
425 }
426 else {
427 cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,M_DEVBUF,M_NOWAIT);
428 cci->column_offset = malloc(sizeof(u_int)*ip->cols,M_DEVBUF,M_NOWAIT);
429 }
430
431 if(!cci->row_ptr || !cci->column_offset)
432 panic("No memory for ite-view");
433
434 cci->width = view->bitmap->bytes_per_row << 3;
435 cci->underline = ip->font.baseline + 1;
436 cci->row_offset = view->bitmap->bytes_per_row;
437 cci->ft_x = ip->font.width;
438 cci->ft_y = ip->font.height;
439 cci->row_bytes = cci->row_offset * cci->ft_y;
440 cci->row_ptr[0] = view->bitmap->plane;
441 for(i = 1; i < ip->rows; i++)
442 cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
443
444 /*
445 * Initialize the column offsets to point at the correct location
446 * in the first plane. This definitely assumes a font width of 8!
447 */
448 j = view->bitmap->depth * 2;
449 cci->column_offset[0] = 0;
450 for(i = 1; i < ip->cols; i++)
451 cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
452
453 /* initialize the font cell pointers */
454 cci->font_cell[ip->font.font_lo] = ip->font.font_p;
455 for(i = ip->font.font_lo+1; i <= ip->font.font_hi; i++)
456 cci->font_cell[i] = cci->font_cell[i-1] + ip->font.height;
457
458 return(error);
459 }
460
461 int
462 ite_grf_ioctl(ip, cmd, addr, flag, p)
463 struct ite_softc *ip;
464 u_long cmd;
465 caddr_t addr;
466 int flag;
467 struct proc *p;
468 {
469 struct winsize ws;
470 struct itewinsize *is;
471 int error = 0;
472 view_t *view = viewview(ip->grf->g_viewdev);
473 #if 0 /* LWP: notyet */
474 struct itebell *ib;
475 #endif
476
477 switch (cmd) {
478 case ITEIOCGWINSZ:
479 is = (struct itewinsize *)addr;
480 is->x = view->display.x;
481 is->y = view->display.y;
482 is->width = view->display.width;
483 is->height = view->display.height;
484 is->depth = view->bitmap->depth;
485 break;
486 case ITEIOCSWINSZ:
487 is = (struct itewinsize *)addr;
488
489 if(ite_newsize(ip, is))
490 error = ENOMEM;
491 else {
492 view = viewview(ip->grf->g_viewdev);
493 ws.ws_row = ip->rows;
494 ws.ws_col = ip->cols;
495 ws.ws_xpixel = view->display.width;
496 ws.ws_ypixel = view->display.height;
497 ite_reset(ip);
498 /*
499 * XXX tell tty about the change
500 * XXX this is messy, but works
501 */
502 iteioctl(ip->grf->g_itedev,TIOCSWINSZ,(caddr_t)&ws,0,p);
503 }
504 break;
505 case ITEIOCDSPWIN:
506 ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
507 break;
508 case ITEIOCREMWIN:
509 ip->grf->g_mode(ip->grf, GM_GRFOFF, NULL, 0, 0);
510 break;
511 case ITEIOCGBELL:
512 #if 0 /* LWP */
513 /* XXX This won't work now */
514 /* XXX Should the bell be device dependent? */
515 ib = (struct itebell *)addr;
516 ib->volume = bvolume;
517 ib->pitch = bpitch;
518 ib->msec = bmsec;
519 #endif
520 break;
521 case ITEIOCSBELL:
522 #if 0 /* LWP */
523 /* XXX See above */
524 ib = (struct itebell *)addr;
525 /* bounds check */
526 if(ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH ||
527 ib->volume > MAXBVOLUME || ib->msec > MAXBTIME)
528 error = EINVAL;
529 else {
530 bvolume = ib->volume;
531 bpitch = ib->pitch;
532 bmsec = ib->msec;
533 }
534 #endif
535 break;
536 case VIOCSCMAP:
537 case VIOCGCMAP:
538 /*
539 * XXX watchout for that NOPROC. its not really the kernel
540 * XXX talking these two commands don't use the proc pointer
541 * XXX though.
542 */
543 error = viewioctl(ip->grf->g_viewdev, cmd, addr, flag, NOPROC);
544 break;
545 default:
546 error = -1;
547 break;
548 }
549 return (error);
550 }
551
552 static void
553 cursor32(struct ite_softc *ip, int flag)
554 {
555 int cend;
556 u_char *pl;
557 ipriv_t *cci;
558
559 cci = ip->priv;
560
561 if(flag == END_CURSOROPT)
562 cci->cursor_opt--;
563 else if(flag == START_CURSOROPT) {
564 if(!cci->cursor_opt)
565 cursor32(ip, ERASE_CURSOR);
566 cci->cursor_opt++;
567 return; /* if we are already opted. */
568 }
569
570 if(cci->cursor_opt)
571 return; /* if we are still nested. */
572 /* else we draw the cursor. */
573
574 if(flag != DRAW_CURSOR && flag != END_CURSOROPT) {
575 /*
576 * erase the cursor
577 */
578 cend = ip->font.height-1;
579 pl = cci->column_offset[ip->cursorx]
580 + cci->row_ptr[ip->cursory];
581 __asm__ __volatile__
582 ("1: notb %0@ ; addaw %4,%0\n\t"
583 "dbra %1,1b"
584 : "=a" (pl), "=d" (cend)
585 : "0" (pl), "1" (cend),
586 "d" (cci->row_offset)
587 );
588 }
589
590 if(flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
591 return;
592
593 /*
594 * draw the cursor
595 */
596 ip->cursorx = min(ip->curx, ip->cols-1);
597 ip->cursory = ip->cury;
598 cend = ip->font.height-1;
599 pl = cci->column_offset[ip->cursorx]
600 + cci->row_ptr[ip->cursory];
601
602 __asm__ __volatile__
603 ("1: notb %0@ ; addaw %4,%0\n\t"
604 "dbra %1,1b"
605 : "=a" (pl), "=d" (cend)
606 : "0" (pl), "1" (cend),
607 "d" (cci->row_offset)
608 );
609 }
610
611 static void
612 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
613 {
614 register ipriv_t *cci = (ipriv_t *)ip->priv;
615 register u_char *pl = cci->column_offset[dx] + cci->row_ptr[dy];
616 register u_int fh = cci->ft_y;
617 register u_int ro = cci->row_offset;
618 register u_char eor_mask;
619 register u_char bl, tmp, ul;
620 register u_char *ft;
621
622 if(c < ip->font.font_lo || c > ip->font.font_hi)
623 return;
624
625 ft = cci->font_cell[c];
626
627 if(!mode) {
628 while(fh--) {
629 *pl = *ft++; pl += ro;
630 }
631 return;
632 }
633
634 eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
635 bl = (mode & ATTR_BOLD) ? 1 : 0;
636 ul = (mode & ATTR_UL) ? fh - cci->underline : fh;
637 for(; fh--; pl += ro) {
638 if(fh != ul) {
639 tmp = *ft++;
640 if(bl)
641 tmp |= (tmp >> 1);
642 *pl = tmp ^ eor_mask;
643 }
644 else {
645 *pl = 0xff ^ eor_mask;
646 ft++;
647 }
648 }
649 }
650
651 static void
652 clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
653 {
654 ipriv_t *cci = (ipriv_t *) ip->priv;
655 view_t *v = viewview(ip->grf->g_viewdev);
656 bmap_t *bm = v->bitmap;
657
658 if((sx == 0) && (w == ip->cols)) {
659 /* common case: clearing whole lines */
660 while (h--) {
661 int i;
662 u_char *ptr = cci->row_ptr[sy];
663 for(i = 0; i < ip->font.height; i++) {
664 bzero(ptr, bm->bytes_per_row);
665 ptr += bm->bytes_per_row;
666 }
667 sy++;
668 }
669 }
670 else {
671 /*
672 * clearing only part of a line
673 * XXX could be optimized MUCH better, but is it worth the
674 * trouble?
675 */
676
677 int i;
678 u_char *pls, *ple;
679
680 pls = cci->row_ptr[sy];
681 ple = pls + cci->column_offset[sx + w-1];
682 pls = pls + cci->column_offset[sx];
683
684 for(i = ((ip->font.height) * h)-1; i >= 0; i--) {
685 u_char *p = pls;
686 while(p <= ple)
687 *p++ = 0;
688 pls += bm->bytes_per_row;
689 ple += bm->bytes_per_row;
690 }
691 }
692 }
693
694 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
695 static void
696 scroll8(ip, sy, sx, count, dir)
697 register struct ite_softc *ip;
698 register int sy;
699 int dir, sx, count;
700 {
701 bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
702 u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
703
704 if(dir == SCROLL_UP) {
705 int dy = sy - count;
706
707 cursor32(ip, ERASE_CURSOR);
708 scrollbmap(bm, 0, dy*ip->font.height, bm->bytes_per_row >> 3,
709 (ip->bottom_margin-dy+1)*ip->font.height,
710 0, -(count*ip->font.height));
711 }
712 else if(dir == SCROLL_DOWN) {
713 cursor32(ip, ERASE_CURSOR);
714 scrollbmap(bm, 0, sy*ip->font.height, bm->bytes_per_row >> 3,
715 (ip->bottom_margin-sy+1)*ip->font.height,
716 0, count*ip->font.height);
717 }
718 else if(dir == SCROLL_RIGHT) {
719 int sofs = (ip->cols - count) * ip->font.width;
720 int dofs = (ip->cols) * ip->font.width;
721 int i, j;
722
723 cursor32(ip, ERASE_CURSOR);
724 for(j = ip->font.height-1; j >= 0; j--) {
725 int sofs2 = sofs, dofs2 = dofs;
726 for (i = (ip->cols - (sx + count))-1; i >= 0; i--) {
727 int t;
728 sofs2 -= ip->font.width;
729 dofs2 -= ip->font.width;
730 asm("bfextu %1@{%2:%3},%0" : "=d" (t)
731 : "a" (pl), "d" (sofs2), "d" (ip->font.width));
732 asm("bfins %3,%0@{%1:%2}" :
733 : "a" (pl), "d" (dofs2), "d" (ip->font.width),
734 "d" (t));
735 }
736 pl += bm->bytes_per_row;
737 }
738 }
739 else { /* SCROLL_LEFT */
740 int sofs = (sx) * ip->font.width;
741 int dofs = (sx - count) * ip->font.width;
742 int i, j;
743
744 cursor32(ip, ERASE_CURSOR);
745 for(j = ip->font.height-1; j >= 0; j--) {
746 int sofs2 = sofs, dofs2 = dofs;
747 for(i = (ip->cols - sx)-1; i >= 0; i--) {
748 int t;
749
750 asm("bfextu %1@{%2:%3},%0" : "=d" (t)
751 : "a" (pl), "d" (sofs2), "d" (ip->font.width));
752 asm("bfins %3,%0@{%1:%2}"
753 : : "a" (pl), "d" (dofs2),"d" (ip->font.width),
754 "d" (t));
755 sofs2 += ip->font.width;
756 dofs2 += ip->font.width;
757 }
758 pl += bm->bytes_per_row;
759 }
760 }
761 }
762
763 static void
764 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy)
765 {
766 u_short lwpr = bm->bytes_per_row >> 2;
767
768 if(dx) {
769 /* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
770 }
771
772 if(dy == 0) {
773 return;
774 }
775 if(dy > 0) {
776 u_long *pl = (u_long *)bm->plane;
777 u_long *src_y = pl + (lwpr*y);
778 u_long *dest_y = pl + (lwpr*(y+dy));
779 u_long count = lwpr*(height-dy);
780 u_long *clr_y = src_y;
781 u_long clr_count = dest_y - src_y;
782 u_long bc, cbc;
783
784 src_y += count - 1;
785 dest_y += count - 1;
786
787 bc = count >> 4;
788 count &= 0xf;
789
790 while (bc--) {
791 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
792 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
793 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
794 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
795 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
796 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
797 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
798 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
799 }
800 while (count--)
801 *dest_y-- = *src_y--;
802
803 cbc = clr_count >> 4;
804 clr_count &= 0xf;
805
806 while (cbc--) {
807 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
808 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
809 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
810 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
811 }
812 while(clr_count--)
813 *clr_y++ = 0;
814 }
815 else {
816 u_long *pl = (u_long *)bm->plane;
817 u_long *src_y = pl + (lwpr*(y-dy));
818 u_long *dest_y = pl + (lwpr*y);
819 long count = lwpr*(height + dy);
820 u_long *clr_y = dest_y + count;
821 u_long clr_count = src_y - dest_y;
822 u_long bc, cbc;
823
824 bc = count >> 4;
825 count &= 0xf;
826
827 while(bc--) {
828 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
829 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
830 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
831 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
832 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
833 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
834 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
835 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
836 }
837 while(count--)
838 *dest_y++ = *src_y++;
839
840 cbc = clr_count >> 4;
841 clr_count &= 0xf;
842
843 while (cbc--) {
844 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
845 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
846 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
847 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
848 }
849 while (clr_count--)
850 *clr_y++ = 0;
851 }
852 }
853 #else
854 #error Must be defined
855 #endif /* NGRFCC */
856