ite_cc.c revision 1.29 1 /* $NetBSD: ite_cc.c,v 1.29 2009/03/14 15:36:03 dsl 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 <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ite_cc.c,v 1.29 2009/03/14 15:36:03 dsl Exp $");
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 #include "grfcc.h"
60
61 /*
62 * This is what ip->priv points to;
63 * it contains local variables for custom-chip ites.
64 */
65 struct ite_priv {
66 u_char **row_ptr; /* array of pointers into the bitmap */
67 u_long row_bytes;
68 u_long cursor_opt;
69 u_short *column_offset; /* array of offsets for columns */
70 u_int row_offset; /* the row offset */
71 u_short width; /* the bitmap width */
72 u_short underline; /* where the underline goes */
73 u_short ft_x; /* the font width */
74 u_short ft_y; /* the font height */
75 u_char *font_cell[256];/* the font pointer */
76 };
77 typedef struct ite_priv ipriv_t;
78
79 /*
80 * We need the following space to get an ite-console setup before
81 * the VM-system is brought up. We setup for a 1280x960 monitor with
82 * an 8x8 font.
83 */
84 #define CONS_MAXROW 120 /* Max. number of rows on console */
85 #define CONS_MAXCOL 160 /* Max. number of columns on console */
86 static u_short con_columns[CONS_MAXCOL];
87 static u_char *con_rows[CONS_MAXROW];
88 static ipriv_t con_ipriv;
89
90 extern font_info font_info_8x8;
91 extern font_info font_info_8x16;
92
93 static void view_init(struct ite_softc *);
94 static void view_deinit(struct ite_softc *);
95 static int itecc_ioctl(struct ite_softc *, u_long, void *, int,
96 struct lwp *);
97 static int ite_newsize(struct ite_softc *, struct itewinsize *);
98 static void cursor32(struct ite_softc *, int);
99 static void putc8(struct ite_softc *, int, int, int, int);
100 static void clear8(struct ite_softc *, int, int, int, int);
101 static void scroll8(struct ite_softc *, int, int, int, int);
102 static void scrollbmap(bmap_t *, u_short, u_short, u_short, u_short,
103 short, short);
104
105 /*
106 * grfcc config stuff
107 */
108 void grfccattach(struct device *, struct device *, void *);
109 int grfccmatch(struct device *, struct cfdata *, void *);
110 int grfccprint(void *, const char *);
111
112 CFATTACH_DECL(grfcc, sizeof(struct grf_softc),
113 grfccmatch, grfccattach, NULL, NULL);
114
115 /*
116 * only used in console init.
117 */
118 static struct cfdata *cfdata_grf = NULL;
119
120 /*
121 * Probe functions we can use:
122 */
123 #ifdef TT_VIDEO
124 void tt_probe_video(MODES *);
125 #endif /* TT_VIDEO */
126 #ifdef FALCON_VIDEO
127 void falcon_probe_video(MODES *);
128 #endif /* FALCON_VIDEO */
129
130 int
131 grfccmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
132 {
133 static int did_consinit = 0;
134 static int must_probe = 1;
135 grf_auxp_t *grf_auxp = auxp;
136 extern const struct cdevsw view_cdevsw;
137
138 if (must_probe) {
139 /*
140 * Check if the layers we depend on exist
141 */
142 if (!(machineid & (ATARI_TT|ATARI_FALCON)))
143 return (0);
144 #ifdef TT_VIDEO
145 if ((machineid & ATARI_TT) && !grfabs_probe(&tt_probe_video))
146 return (0);
147 #endif /* TT_VIDEO */
148 #ifdef FALCON_VIDEO
149 if ((machineid & ATARI_FALCON)
150 && !grfabs_probe(&falcon_probe_video))
151 return (0);
152 #endif /* FALCON_VIDEO */
153
154 viewprobe();
155 must_probe = 0;
156 }
157
158 if (atari_realconfig == 0) {
159 /*
160 * Early console init. Only match first unit.
161 */
162 if (did_consinit)
163 return(0);
164 if ((*view_cdevsw.d_open)(cfp->cf_unit, 0, 0, NULL))
165 return(0);
166 cfdata_grf = cfp;
167 did_consinit = 1;
168 return (1);
169 }
170
171 /*
172 * Normal config. When we are called directly from the grfbus,
173 * we only match the first unit. The attach function will call us for
174 * the other configured units.
175 */
176 if (grf_auxp->from_bus_match && (did_consinit > 1))
177 return (0);
178
179 if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
180 return (0);
181
182 /*
183 * Final constraint: each grf needs a view....
184 */
185 if((cfdata_grf == NULL) || (did_consinit > 1)) {
186 if((*view_cdevsw.d_open)(cfp->cf_unit, 0, 0, NULL))
187 return(0);
188 }
189 did_consinit = 2;
190 return(1);
191 }
192
193 /*
194 * attach: initialize the grf-structure and try to attach an ite to us.
195 * note : dp is NULL during early console init.
196 */
197 void
198 grfccattach(pdp, dp, auxp)
199 struct device *pdp, *dp;
200 void *auxp;
201 {
202 static struct grf_softc congrf;
203 static int first_attach = 1;
204 grf_auxp_t *grf_bus_auxp = auxp;
205 grf_auxp_t grf_auxp;
206 struct grf_softc *gp;
207 int maj;
208 extern const struct cdevsw grf_cdevsw;
209
210 /*
211 * find our major device number
212 */
213 maj = cdevsw_lookup_major(&grf_cdevsw);
214
215 /*
216 * Handle exeption case: early console init
217 */
218 if(dp == NULL) {
219 congrf.g_unit = cfdata_grf->cf_unit;
220 congrf.g_grfdev = makedev(maj, congrf.g_unit);
221 congrf.g_itedev = (dev_t)-1;
222 congrf.g_flags = GF_ALIVE;
223 congrf.g_mode = grf_mode;
224 congrf.g_conpri = grfcc_cnprobe();
225 congrf.g_viewdev = congrf.g_unit;
226 grfcc_iteinit(&congrf);
227 grf_viewsync(&congrf);
228
229 /* Attach console ite */
230 atari_config_found(cfdata_grf, NULL, &congrf, grfccprint);
231 return;
232 }
233
234 gp = (struct grf_softc *)dp;
235 gp->g_unit = device_unit(&gp->g_device);
236 grfsp[gp->g_unit] = gp;
237
238 if((cfdata_grf != NULL) && (gp->g_unit == congrf.g_unit)) {
239 /*
240 * We inited earlier just copy the info, take care
241 * not to copy the device struct though.
242 */
243 bcopy(&congrf.g_display, &gp->g_display,
244 (char *)&gp[1] - (char *)&gp->g_display);
245 }
246 else {
247 gp->g_grfdev = makedev(maj, gp->g_unit);
248 gp->g_itedev = (dev_t)-1;
249 gp->g_flags = GF_ALIVE;
250 gp->g_mode = grf_mode;
251 gp->g_conpri = 0;
252 gp->g_viewdev = gp->g_unit;
253 grfcc_iteinit(gp);
254 grf_viewsync(gp);
255 }
256
257 printf(": width %d height %d", gp->g_display.gd_dwidth,
258 gp->g_display.gd_dheight);
259 if(gp->g_display.gd_colors == 2)
260 printf(" monochrome\n");
261 else printf(" colors %d\n", gp->g_display.gd_colors);
262
263 /*
264 * try and attach an ite
265 */
266 config_found(dp, gp, grfccprint);
267
268 /*
269 * If attaching the first unit, go ahead and 'find' the rest of us
270 */
271 if (first_attach) {
272 first_attach = 0;
273 grf_auxp.from_bus_match = 0;
274 for (grf_auxp.unit=1; grf_auxp.unit < NGRFCC; grf_auxp.unit++) {
275 config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
276 }
277 }
278 }
279
280 int
281 grfccprint(void *auxp, const char *pnp)
282 {
283 if(pnp)
284 aprint_normal("ite at %s", pnp);
285 return(UNCONF);
286 }
287
288 /*
289 * called from grf_cc to return console priority
290 */
291 int
292 grfcc_cnprobe()
293 {
294 return(CN_INTERNAL);
295 }
296 /*
297 * called from grf_cc to init ite portion of
298 * grf_softc struct
299 */
300 void
301 grfcc_iteinit(struct grf_softc *gp)
302 {
303
304 gp->g_itecursor = cursor32;
305 gp->g_iteputc = putc8;
306 gp->g_iteclear = clear8;
307 gp->g_itescroll = scroll8;
308 gp->g_iteinit = view_init;
309 gp->g_itedeinit = view_deinit;
310 }
311
312 static void
313 view_deinit(struct ite_softc *ip)
314 {
315 ip->flags &= ~ITE_INITED;
316 }
317
318 static void
319 view_init(register struct ite_softc *ip)
320 {
321 struct itewinsize wsz;
322 ipriv_t *cci;
323
324 if((cci = ip->priv) != NULL)
325 return;
326
327 ip->itexx_ioctl = itecc_ioctl;
328
329 #if defined(KFONT_8X8)
330 ip->font = font_info_8x8;
331 #else
332 ip->font = font_info_8x16;
333 #endif
334
335 /* Find the correct set of rendering routines for this font. */
336 if(ip->font.width != 8)
337 panic("kernel font size not supported");
338
339 if(!atari_realconfig)
340 ip->priv = cci = &con_ipriv;
341 else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
342 if(cci == NULL)
343 panic("No memory for ite-view");
344 bzero(cci, sizeof(*cci));
345
346 cci->cursor_opt = 0;
347 cci->row_ptr = NULL;
348 cci->column_offset = NULL;
349
350 wsz.x = ite_default_x;
351 wsz.y = ite_default_y;
352 wsz.width = ite_default_width;
353 wsz.height = ite_default_height;
354 wsz.depth = ite_default_depth;
355
356 ite_newsize (ip, &wsz);
357
358 /*
359 * Only console will be turned on by default..
360 */
361 if(ip->flags & ITE_ISCONS)
362 ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
363 }
364
365 static int
366 ite_newsize(struct ite_softc *ip, struct itewinsize *winsz)
367 {
368 struct view_size vs;
369 ipriv_t *cci = ip->priv;
370 u_long i, j;
371 int error = 0;
372 view_t *view;
373 extern const struct cdevsw view_cdevsw;
374
375 vs.x = winsz->x;
376 vs.y = winsz->y;
377 vs.width = winsz->width;
378 vs.height = winsz->height;
379 vs.depth = winsz->depth;
380
381 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, VIOCSSIZE,
382 (void *)&vs, 0, NOLWP);
383 view = viewview(ip->grf->g_viewdev);
384
385 /*
386 * Reinitialize our structs
387 */
388 ip->cols = view->display.width / ip->font.width;
389 ip->rows = view->display.height / ip->font.height;
390
391 /*
392 * save new values so that future opens use them
393 * this may not be correct when we implement Virtual Consoles
394 */
395 ite_default_height = view->display.height;
396 ite_default_width = view->display.width;
397 ite_default_x = view->display.x;
398 ite_default_y = view->display.y;
399 ite_default_depth = view->bitmap->depth;
400
401 if(cci->row_ptr && (cci->row_ptr != con_rows)) {
402 free(cci->row_ptr, M_DEVBUF);
403 cci->row_ptr = NULL;
404 }
405 if(cci->column_offset && (cci->column_offset != con_columns)) {
406 free(cci->column_offset, M_DEVBUF);
407 cci->column_offset = NULL;
408 }
409
410 if(!atari_realconfig) {
411 cci->row_ptr = con_rows;
412 cci->column_offset = con_columns;
413 }
414 else {
415 cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,M_DEVBUF,M_NOWAIT);
416 cci->column_offset = malloc(sizeof(u_int)*ip->cols,M_DEVBUF,M_NOWAIT);
417 }
418
419 if(!cci->row_ptr || !cci->column_offset)
420 panic("No memory for ite-view");
421
422 cci->width = view->bitmap->bytes_per_row << 3;
423 cci->underline = ip->font.baseline + 1;
424 cci->row_offset = view->bitmap->bytes_per_row;
425 cci->ft_x = ip->font.width;
426 cci->ft_y = ip->font.height;
427 cci->row_bytes = cci->row_offset * cci->ft_y;
428 cci->row_ptr[0] = view->bitmap->plane;
429 for(i = 1; i < ip->rows; i++)
430 cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
431
432 /*
433 * Initialize the column offsets to point at the correct location
434 * in the first plane. This definitely assumes a font width of 8!
435 */
436 j = view->bitmap->depth * 2;
437 cci->column_offset[0] = 0;
438 for(i = 1; i < ip->cols; i++)
439 cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
440
441 /* initialize the font cell pointers */
442 cci->font_cell[ip->font.font_lo] = ip->font.font_p;
443 for(i = ip->font.font_lo+1; i <= ip->font.font_hi; i++)
444 cci->font_cell[i] = cci->font_cell[i-1] + ip->font.height;
445
446 return(error);
447 }
448
449 int
450 itecc_ioctl(struct ite_softc *ip, u_long cmd, void * addr, int flag, struct lwp *l)
451 {
452 struct winsize ws;
453 struct itewinsize *is;
454 int error = 0;
455 view_t *view = viewview(ip->grf->g_viewdev);
456 extern const struct cdevsw ite_cdevsw;
457 extern const struct cdevsw view_cdevsw;
458
459 switch (cmd) {
460 case ITEIOCSWINSZ:
461 is = (struct itewinsize *)addr;
462
463 if(ite_newsize(ip, is))
464 error = ENOMEM;
465 else {
466 view = viewview(ip->grf->g_viewdev);
467 ws.ws_row = ip->rows;
468 ws.ws_col = ip->cols;
469 ws.ws_xpixel = view->display.width;
470 ws.ws_ypixel = view->display.height;
471 ite_reset(ip);
472 /*
473 * XXX tell tty about the change
474 * XXX this is messy, but works
475 */
476 (*ite_cdevsw.d_ioctl)(ip->grf->g_itedev, TIOCSWINSZ,
477 (void *)&ws, 0, l);
478 }
479 break;
480 case VIOCSCMAP:
481 case VIOCGCMAP:
482 /*
483 * XXX watchout for that NOLWP. its not really the kernel
484 * XXX talking these two commands don't use the proc pointer
485 * XXX though.
486 */
487 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, cmd, addr,
488 flag, NOLWP);
489 break;
490 default:
491 error = EPASSTHROUGH;
492 break;
493 }
494 return (error);
495 }
496
497 static void
498 cursor32(struct ite_softc *ip, int flag)
499 {
500 int cend;
501 u_char *pl;
502 ipriv_t *cci;
503
504 cci = ip->priv;
505
506 if(flag == END_CURSOROPT)
507 cci->cursor_opt--;
508 else if(flag == START_CURSOROPT) {
509 if(!cci->cursor_opt)
510 cursor32(ip, ERASE_CURSOR);
511 cci->cursor_opt++;
512 return; /* if we are already opted. */
513 }
514
515 if(cci->cursor_opt)
516 return; /* if we are still nested. */
517 /* else we draw the cursor. */
518
519 if(flag != DRAW_CURSOR && flag != END_CURSOROPT) {
520 /*
521 * erase the cursor
522 */
523 cend = ip->font.height-1;
524 pl = cci->column_offset[ip->cursorx]
525 + cci->row_ptr[ip->cursory];
526 __asm volatile
527 ("1: notb %0@ ; addaw %4,%0\n\t"
528 "dbra %1,1b"
529 : "=a" (pl), "=d" (cend)
530 : "0" (pl), "1" (cend),
531 "d" (cci->row_offset)
532 );
533 }
534
535 if(flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
536 return;
537
538 /*
539 * draw the cursor
540 */
541 cend = min(ip->curx, ip->cols-1);
542 if (flag == DRAW_CURSOR
543 && ip->cursorx == cend && ip->cursory == ip->cury)
544 return;
545 ip->cursorx = cend;
546 ip->cursory = ip->cury;
547 cend = ip->font.height-1;
548 pl = cci->column_offset[ip->cursorx]
549 + cci->row_ptr[ip->cursory];
550
551 __asm volatile
552 ("1: notb %0@ ; addaw %4,%0\n\t"
553 "dbra %1,1b"
554 : "=a" (pl), "=d" (cend)
555 : "0" (pl), "1" (cend),
556 "d" (cci->row_offset)
557 );
558 }
559
560 static void
561 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
562 {
563 register ipriv_t *cci = (ipriv_t *)ip->priv;
564 register u_char *pl = cci->column_offset[dx] + cci->row_ptr[dy];
565 register u_int fh = cci->ft_y;
566 register u_int ro = cci->row_offset;
567 register u_char eor_mask;
568 register u_char bl, tmp, ul;
569 register u_char *ft;
570
571 if(c < ip->font.font_lo || c > ip->font.font_hi)
572 return;
573
574 ft = cci->font_cell[c];
575
576 if(!mode) {
577 while(fh--) {
578 *pl = *ft++; pl += ro;
579 }
580 return;
581 }
582
583 eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
584 bl = (mode & ATTR_BOLD) ? 1 : 0;
585 ul = (mode & ATTR_UL) ? fh - cci->underline : fh;
586 for(; fh--; pl += ro) {
587 if(fh != ul) {
588 tmp = *ft++;
589 if(bl)
590 tmp |= (tmp >> 1);
591 *pl = tmp ^ eor_mask;
592 }
593 else {
594 *pl = 0xff ^ eor_mask;
595 ft++;
596 }
597 }
598 }
599
600 static void
601 clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
602 {
603 ipriv_t *cci = (ipriv_t *) ip->priv;
604 view_t *v = viewview(ip->grf->g_viewdev);
605 bmap_t *bm = v->bitmap;
606
607 if((sx == 0) && (w == ip->cols)) {
608 /* common case: clearing whole lines */
609 while (h--) {
610 int i;
611 u_char *ptr = cci->row_ptr[sy];
612 for(i = 0; i < ip->font.height; i++) {
613 bzero(ptr, bm->bytes_per_row);
614 ptr += bm->bytes_per_row;
615 }
616 sy++;
617 }
618 }
619 else {
620 /*
621 * clearing only part of a line
622 * XXX could be optimized MUCH better, but is it worth the
623 * trouble?
624 */
625
626 int i;
627 u_char *pls, *ple;
628
629 pls = cci->row_ptr[sy];
630 ple = pls + cci->column_offset[sx + w-1];
631 pls = pls + cci->column_offset[sx];
632
633 for(i = ((ip->font.height) * h)-1; i >= 0; i--) {
634 u_char *p = pls;
635 while(p <= ple)
636 *p++ = 0;
637 pls += bm->bytes_per_row;
638 ple += bm->bytes_per_row;
639 }
640 }
641 }
642
643 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
644 static void
645 scroll8(ip, sy, sx, count, dir)
646 register struct ite_softc *ip;
647 register int sy;
648 int dir, sx, count;
649 {
650 bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
651 u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
652
653 if(dir == SCROLL_UP) {
654 int dy = sy - count;
655
656 cursor32(ip, ERASE_CURSOR);
657 scrollbmap(bm, 0, dy*ip->font.height, bm->bytes_per_row >> 3,
658 (ip->bottom_margin-dy+1)*ip->font.height,
659 0, -(count*ip->font.height));
660 }
661 else if(dir == SCROLL_DOWN) {
662 cursor32(ip, ERASE_CURSOR);
663 scrollbmap(bm, 0, sy*ip->font.height, bm->bytes_per_row >> 3,
664 (ip->bottom_margin-sy+1)*ip->font.height,
665 0, count*ip->font.height);
666 }
667 else if(dir == SCROLL_RIGHT) {
668 int sofs = (ip->cols - count) * ip->font.width;
669 int dofs = (ip->cols) * ip->font.width;
670 int i, j;
671
672 cursor32(ip, ERASE_CURSOR);
673 for(j = ip->font.height-1; j >= 0; j--) {
674 int sofs2 = sofs, dofs2 = dofs;
675 for (i = (ip->cols - (sx + count))-1; i >= 0; i--) {
676 int t;
677 sofs2 -= ip->font.width;
678 dofs2 -= ip->font.width;
679 __asm("bfextu %1@{%2:%3},%0" : "=d" (t)
680 : "a" (pl), "d" (sofs2), "d" (ip->font.width));
681 __asm("bfins %3,%0@{%1:%2}" :
682 : "a" (pl), "d" (dofs2), "d" (ip->font.width),
683 "d" (t));
684 }
685 pl += bm->bytes_per_row;
686 }
687 }
688 else { /* SCROLL_LEFT */
689 int sofs = (sx) * ip->font.width;
690 int dofs = (sx - count) * ip->font.width;
691 int i, j;
692
693 cursor32(ip, ERASE_CURSOR);
694 for(j = ip->font.height-1; j >= 0; j--) {
695 int sofs2 = sofs, dofs2 = dofs;
696 for(i = (ip->cols - sx)-1; i >= 0; i--) {
697 int t;
698
699 __asm("bfextu %1@{%2:%3},%0" : "=d" (t)
700 : "a" (pl), "d" (sofs2), "d" (ip->font.width));
701 __asm("bfins %3,%0@{%1:%2}"
702 : : "a" (pl), "d" (dofs2),"d" (ip->font.width),
703 "d" (t));
704 sofs2 += ip->font.width;
705 dofs2 += ip->font.width;
706 }
707 pl += bm->bytes_per_row;
708 }
709 }
710 }
711
712 static void
713 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy)
714 {
715 u_short lwpr = bm->bytes_per_row >> 2;
716
717 if(dx) {
718 /* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
719 }
720
721 if(dy == 0) {
722 return;
723 }
724 if(dy > 0) {
725 u_long *pl = (u_long *)bm->plane;
726 u_long *src_y = pl + (lwpr*y);
727 u_long *dest_y = pl + (lwpr*(y+dy));
728 u_long count = lwpr*(height-dy);
729 u_long *clr_y = src_y;
730 u_long clr_count = dest_y - src_y;
731 u_long bc, cbc;
732
733 src_y += count - 1;
734 dest_y += count - 1;
735
736 bc = count >> 4;
737 count &= 0xf;
738
739 while (bc--) {
740 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
741 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
742 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
743 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
744 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
745 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
746 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
747 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
748 }
749 while (count--)
750 *dest_y-- = *src_y--;
751
752 cbc = clr_count >> 4;
753 clr_count &= 0xf;
754
755 while (cbc--) {
756 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
757 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
758 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
759 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
760 }
761 while(clr_count--)
762 *clr_y++ = 0;
763 }
764 else {
765 u_long *pl = (u_long *)bm->plane;
766 u_long *src_y = pl + (lwpr*(y-dy));
767 u_long *dest_y = pl + (lwpr*y);
768 long count = lwpr*(height + dy);
769 u_long *clr_y = dest_y + count;
770 u_long clr_count = src_y - dest_y;
771 u_long bc, cbc;
772
773 bc = count >> 4;
774 count &= 0xf;
775
776 while(bc--) {
777 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
778 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
779 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
780 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
781 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
782 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
783 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
784 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
785 }
786 while(count--)
787 *dest_y++ = *src_y++;
788
789 cbc = clr_count >> 4;
790 clr_count &= 0xf;
791
792 while (cbc--) {
793 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
794 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
795 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
796 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
797 }
798 while (clr_count--)
799 *clr_y++ = 0;
800 }
801 }
802