ite_cc.c revision 1.40.2.1 1 /* $NetBSD: ite_cc.c,v 1.40.2.1 2022/09/11 18:10:23 martin 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.40.2.1 2022/09/11 18:10:23 martin 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 static void grfccattach(device_t, device_t, void *);
109 static int grfccmatch(device_t, cfdata_t, void *);
110 static int grfccprint(void *, const char *);
111
112 CFATTACH_DECL_NEW(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 static int
131 grfccmatch(device_t parent, cfdata_t cf, void *aux)
132 {
133 static int did_consinit = 0;
134 static int must_probe = 1;
135 grf_auxp_t *grf_auxp = aux;
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)(cf->cf_unit, 0, 0, NULL))
165 return 0;
166 cfdata_grf = cf;
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 != cf->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)(cf->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 : self is NULL during early console init.
196 */
197 static void
198 grfccattach(device_t parent, device_t self, void *aux)
199 {
200 static struct grf_softc congrf;
201 static int first_attach = 1;
202 grf_auxp_t *grf_bus_auxp = aux;
203 grf_auxp_t grf_auxp;
204 struct grf_softc *sc;
205 int maj;
206 extern const struct cdevsw grf_cdevsw;
207
208 /*
209 * find our major device number
210 */
211 maj = cdevsw_lookup_major(&grf_cdevsw);
212
213 /*
214 * Handle exception case: early console init
215 */
216 if (self == NULL) {
217 struct device itedev;
218
219 memset(&itedev, 0, sizeof(itedev));
220 itedev.dv_private = &congrf;
221
222 congrf.g_unit = cfdata_grf->cf_unit;
223 congrf.g_grfdev = makedev(maj, congrf.g_unit);
224 congrf.g_itedev = (dev_t)-1;
225 congrf.g_flags = GF_ALIVE;
226 congrf.g_mode = grf_mode;
227 congrf.g_conpri = grfcc_cnprobe();
228 congrf.g_viewdev = congrf.g_unit;
229 grfcc_iteinit(&congrf);
230 grf_viewsync(&congrf);
231
232 /* Attach console ite */
233 atari_config_found(cfdata_grf, &itedev, &congrf, grfccprint);
234 return;
235 }
236
237 sc = device_private(self);
238 sc->g_device = self;
239 sc->g_unit = device_unit(self);
240 grfsp[sc->g_unit] = sc;
241
242 if ((cfdata_grf != NULL) && (sc->g_unit == congrf.g_unit)) {
243 /*
244 * We inited earlier just copy the info, take care
245 * not to copy the device struct though.
246 */
247 memcpy(&sc->g_display, &congrf.g_display,
248 (char *)&sc[1] - (char *)&sc->g_display);
249 } else {
250 sc->g_grfdev = makedev(maj, sc->g_unit);
251 sc->g_itedev = (dev_t)-1;
252 sc->g_flags = GF_ALIVE;
253 sc->g_mode = grf_mode;
254 sc->g_conpri = 0;
255 sc->g_viewdev = sc->g_unit;
256 grfcc_iteinit(sc);
257 grf_viewsync(sc);
258 }
259
260 printf(": width %d height %d", sc->g_display.gd_dwidth,
261 sc->g_display.gd_dheight);
262 if (sc->g_display.gd_colors == 2)
263 printf(" monochrome\n");
264 else
265 printf(" colors %d\n", sc->g_display.gd_colors);
266
267 /*
268 * try and attach an ite
269 */
270 config_found(self, sc /* XXX */, grfccprint);
271
272 /*
273 * If attaching the first unit, go ahead and 'find' the rest of us
274 */
275 if (first_attach) {
276 first_attach = 0;
277 grf_auxp.from_bus_match = 0;
278 for (grf_auxp.unit=1; grf_auxp.unit < NGRFCC; grf_auxp.unit++) {
279 config_found(parent, &grf_auxp, grf_bus_auxp->busprint);
280 }
281 }
282 }
283
284 static int
285 grfccprint(void *aux, const char *pnp)
286 {
287
288 if (pnp)
289 aprint_normal("ite at %s", pnp);
290 return UNCONF;
291 }
292
293 /*
294 * called from grf_cc to return console priority
295 */
296 int
297 grfcc_cnprobe(void)
298 {
299 return CN_INTERNAL;
300 }
301 /*
302 * called from grf_cc to init ite portion of
303 * grf_softc struct
304 */
305 void
306 grfcc_iteinit(struct grf_softc *sc)
307 {
308
309 sc->g_itecursor = cursor32;
310 sc->g_iteputc = putc8;
311 sc->g_iteclear = clear8;
312 sc->g_itescroll = scroll8;
313 sc->g_iteinit = view_init;
314 sc->g_itedeinit = view_deinit;
315 }
316
317 static void
318 view_deinit(struct ite_softc *ip)
319 {
320 ip->flags &= ~ITE_INITED;
321 }
322
323 static void
324 view_init(register struct ite_softc *ip)
325 {
326 struct itewinsize wsz;
327 ipriv_t *cci;
328
329 if ((cci = ip->priv) != NULL)
330 return;
331
332 ip->itexx_ioctl = itecc_ioctl;
333
334 #if defined(KFONT_8X8)
335 ip->font = font_info_8x8;
336 #else
337 ip->font = font_info_8x16;
338 #endif
339
340 /* Find the correct set of rendering routines for this font. */
341 if (ip->font.width != 8)
342 panic("kernel font size not supported");
343
344 if (!atari_realconfig)
345 ip->priv = cci = &con_ipriv;
346 else
347 ip->priv = cci = malloc(sizeof(*cci), M_DEVBUF, M_WAITOK);
348 if (cci == NULL)
349 panic("No memory for ite-view");
350 memset(cci, 0, sizeof(*cci));
351
352 cci->cursor_opt = 0;
353 cci->row_ptr = NULL;
354 cci->column_offset = NULL;
355
356 wsz.x = ite_default_x;
357 wsz.y = ite_default_y;
358 wsz.width = ite_default_width;
359 wsz.height = ite_default_height;
360 wsz.depth = ite_default_depth;
361
362 ite_newsize (ip, &wsz);
363
364 /*
365 * Only console will be turned on by default..
366 */
367 if (ip->flags & ITE_ISCONS)
368 ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
369 }
370
371 static int
372 ite_newsize(struct ite_softc *ip, struct itewinsize *winsz)
373 {
374 struct view_size vs;
375 ipriv_t *cci = ip->priv;
376 u_long i, j;
377 int error = 0;
378 view_t *view;
379 extern const struct cdevsw view_cdevsw;
380
381 vs.x = winsz->x;
382 vs.y = winsz->y;
383 vs.width = winsz->width;
384 vs.height = winsz->height;
385 vs.depth = winsz->depth;
386
387 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, VIOCSSIZE,
388 (void *)&vs, 0, NOLWP);
389 view = viewview(ip->grf->g_viewdev);
390
391 /*
392 * Reinitialize our structs
393 */
394 ip->cols = view->display.width / ip->font.width;
395 ip->rows = view->display.height / ip->font.height;
396
397 /*
398 * save new values so that future opens use them
399 * this may not be correct when we implement Virtual Consoles
400 */
401 ite_default_height = view->display.height;
402 ite_default_width = view->display.width;
403 ite_default_x = view->display.x;
404 ite_default_y = view->display.y;
405 ite_default_depth = view->bitmap->depth;
406
407 if (cci->row_ptr && (cci->row_ptr != con_rows)) {
408 free(cci->row_ptr, M_DEVBUF);
409 cci->row_ptr = NULL;
410 }
411 if (cci->column_offset && (cci->column_offset != con_columns)) {
412 free(cci->column_offset, M_DEVBUF);
413 cci->column_offset = NULL;
414 }
415
416 if (!atari_realconfig) {
417 cci->row_ptr = con_rows;
418 cci->column_offset = con_columns;
419 } else {
420 cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,
421 M_DEVBUF, M_NOWAIT);
422 cci->column_offset = malloc(sizeof(u_int) * ip->cols,
423 M_DEVBUF, M_NOWAIT);
424 }
425
426 if (!cci->row_ptr || !cci->column_offset)
427 panic("No memory for ite-view");
428
429 cci->width = view->bitmap->bytes_per_row << 3;
430 cci->underline = ip->font.baseline + 1;
431 cci->row_offset = view->bitmap->bytes_per_row;
432 cci->ft_x = ip->font.width;
433 cci->ft_y = ip->font.height;
434 cci->row_bytes = cci->row_offset * cci->ft_y;
435 cci->row_ptr[0] = view->bitmap->plane;
436 for (i = 1; i < ip->rows; i++)
437 cci->row_ptr[i] = cci->row_ptr[i - 1] + cci->row_bytes;
438
439 /*
440 * Initialize the column offsets to point at the correct location
441 * in the first plane. This definitely assumes a font width of 8!
442 */
443 j = view->bitmap->depth * 2;
444 cci->column_offset[0] = 0;
445 for (i = 1; i < ip->cols; i++)
446 cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
447
448 /* initialize the font cell pointers */
449 cci->font_cell[ip->font.font_lo] = ip->font.font_p;
450 for (i = ip->font.font_lo + 1; i <= ip->font.font_hi; i++)
451 cci->font_cell[i] = cci->font_cell[i - 1] + ip->font.height;
452
453 return error;
454 }
455
456 int
457 itecc_ioctl(struct ite_softc *ip, u_long cmd, void * addr, int flag,
458 struct lwp *l)
459 {
460 struct winsize ws;
461 struct itewinsize *is;
462 int error = 0;
463 view_t *view = viewview(ip->grf->g_viewdev);
464 extern const struct cdevsw ite_cdevsw;
465 extern const struct cdevsw view_cdevsw;
466
467 switch (cmd) {
468 case ITEIOCSWINSZ:
469 is = (struct itewinsize *)addr;
470
471 if (ite_newsize(ip, is))
472 error = ENOMEM;
473 else {
474 view = viewview(ip->grf->g_viewdev);
475 ws.ws_row = ip->rows;
476 ws.ws_col = ip->cols;
477 ws.ws_xpixel = view->display.width;
478 ws.ws_ypixel = view->display.height;
479 ite_reset(ip);
480 /*
481 * XXX tell tty about the change
482 * XXX this is messy, but works
483 */
484 (*ite_cdevsw.d_ioctl)(ip->grf->g_itedev, TIOCSWINSZ,
485 (void *)&ws, 0, l);
486 }
487 break;
488 case VIOCSCMAP:
489 case VIOCGCMAP:
490 /*
491 * XXX watchout for that NOLWP. its not really the kernel
492 * XXX talking these two commands don't use the proc pointer
493 * XXX though.
494 */
495 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, cmd, addr,
496 flag, NOLWP);
497 break;
498 default:
499 error = EPASSTHROUGH;
500 break;
501 }
502 return error;
503 }
504
505 static void
506 cursor32(struct ite_softc *ip, int flag)
507 {
508 int cend;
509 u_char *pl;
510 ipriv_t *cci;
511
512 cci = ip->priv;
513
514 if (flag == END_CURSOROPT)
515 cci->cursor_opt--;
516 else if (flag == START_CURSOROPT) {
517 if (!cci->cursor_opt)
518 cursor32(ip, ERASE_CURSOR);
519 cci->cursor_opt++;
520 return; /* if we are already opted. */
521 }
522
523 if (cci->cursor_opt)
524 return; /* if we are still nested. */
525 /* else we draw the cursor. */
526
527 if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
528 /*
529 * erase the cursor
530 */
531 cend = ip->font.height - 1;
532 pl = cci->column_offset[ip->cursorx]
533 + cci->row_ptr[ip->cursory];
534 __asm volatile
535 ("1: notb %0@ ; addaw %4,%0\n\t"
536 "dbra %1,1b"
537 : "=a" (pl), "=d" (cend)
538 : "0" (pl), "1" (cend),
539 "d" (cci->row_offset)
540 );
541 }
542
543 if (flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
544 return;
545
546 /*
547 * draw the cursor
548 */
549 cend = uimin(ip->curx, ip->cols - 1);
550 if (flag == DRAW_CURSOR
551 && ip->cursorx == cend && ip->cursory == ip->cury)
552 return;
553 ip->cursorx = cend;
554 ip->cursory = ip->cury;
555 cend = ip->font.height - 1;
556 pl = cci->column_offset[ip->cursorx]
557 + cci->row_ptr[ip->cursory];
558
559 __asm volatile
560 ("1: notb %0@ ; addaw %4,%0\n\t"
561 "dbra %1,1b"
562 : "=a" (pl), "=d" (cend)
563 : "0" (pl), "1" (cend),
564 "d" (cci->row_offset)
565 );
566 }
567
568 static void
569 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
570 {
571 ipriv_t *cci = (ipriv_t *)ip->priv;
572 u_char *pl = cci->column_offset[dx] + cci->row_ptr[dy];
573 u_int fh = cci->ft_y;
574 u_int ro = cci->row_offset;
575 u_char eor_mask;
576 u_char bl, tmp, ul;
577 u_char *ft;
578
579 if (c < ip->font.font_lo || c > ip->font.font_hi)
580 return;
581
582 /*
583 * Handle DEC special graphics character by 'ESC ( B' sequence.
584 * Note we assume all font data (fontdata_8x8 and fontdata_8x16)
585 * contain DEC graphics glyph (for 0x5f to 0x7e) at 0x00 to 0x1F.
586 */
587 if (*ip->GL == CSET_DECGRAPH) {
588 if (ip->font.font_lo == 0 && c >= 0x5f && c <= 0x7e)
589 c -= 0x5f;
590 }
591 ft = cci->font_cell[c];
592
593 if (!mode) {
594 while (fh--) {
595 *pl = *ft++; pl += ro;
596 }
597 return;
598 }
599
600 eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
601 bl = (mode & ATTR_BOLD) ? 1 : 0;
602 ul = (mode & ATTR_UL) ? fh - cci->underline : fh;
603 for (; fh--; pl += ro) {
604 if (fh != ul) {
605 tmp = *ft++;
606 if (bl)
607 tmp |= (tmp >> 1);
608 *pl = tmp ^ eor_mask;
609 } else {
610 *pl = 0xff ^ eor_mask;
611 ft++;
612 }
613 }
614 }
615
616 static void
617 clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
618 {
619 ipriv_t *cci = (ipriv_t *) ip->priv;
620 view_t *v = viewview(ip->grf->g_viewdev);
621 bmap_t *bm = v->bitmap;
622
623 if ((sx == 0) && (w == ip->cols)) {
624 /* common case: clearing whole lines */
625 while (h--) {
626 int i;
627 u_char *ptr = cci->row_ptr[sy];
628 for (i = 0; i < ip->font.height; i++) {
629 memset(ptr, 0, bm->bytes_per_row);
630 ptr += bm->bytes_per_row;
631 }
632 sy++;
633 }
634 } else {
635 /*
636 * clearing only part of a line
637 * XXX could be optimized MUCH better, but is it worth the
638 * trouble?
639 */
640
641 int i;
642 u_char *pls, *ple;
643
644 pls = cci->row_ptr[sy];
645 ple = pls + cci->column_offset[sx + w - 1];
646 pls = pls + cci->column_offset[sx];
647
648 for (i = ((ip->font.height) * h) - 1; i >= 0; i--) {
649 u_char *p = pls;
650 while (p <= ple)
651 *p++ = 0;
652 pls += bm->bytes_per_row;
653 ple += bm->bytes_per_row;
654 }
655 }
656 }
657
658 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
659 static void
660 scroll8(register struct ite_softc *ip, register int sy, int sx, int count,
661 int dir)
662 {
663 bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
664 u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
665
666 if (dir == SCROLL_UP) {
667 int dy = sy - count;
668
669 cursor32(ip, ERASE_CURSOR);
670 scrollbmap(bm, 0, dy * ip->font.height, bm->bytes_per_row >> 3,
671 (ip->bottom_margin - dy + 1) * ip->font.height,
672 0, -(count * ip->font.height));
673 } else if (dir == SCROLL_DOWN) {
674 cursor32(ip, ERASE_CURSOR);
675 scrollbmap(bm, 0, sy * ip->font.height, bm->bytes_per_row >> 3,
676 (ip->bottom_margin - sy + 1) * ip->font.height,
677 0, count * ip->font.height);
678 } else if (dir == SCROLL_RIGHT) {
679 int sofs = (ip->cols - count) * ip->font.width;
680 int dofs = (ip->cols) * ip->font.width;
681 int i, j;
682
683 cursor32(ip, ERASE_CURSOR);
684 for (j = ip->font.height - 1; j >= 0; j--) {
685 int sofs2 = sofs, dofs2 = dofs;
686 for (i = (ip->cols - (sx + count)) - 1; i >= 0; i--) {
687 int t;
688 sofs2 -= ip->font.width;
689 dofs2 -= ip->font.width;
690 __asm("bfextu %1@{%2:%3}, %0" : "=d" (t)
691 : "a" (pl), "d" (sofs2),
692 "d" (ip->font.width));
693 __asm("bfins %3, %0@{%1:%2}" :
694 : "a" (pl), "d" (dofs2),
695 "d" (ip->font.width), "d" (t));
696 }
697 pl += bm->bytes_per_row;
698 }
699 } else { /* SCROLL_LEFT */
700 int sofs = (sx) * ip->font.width;
701 int dofs = (sx - count) * ip->font.width;
702 int i, j;
703
704 cursor32(ip, ERASE_CURSOR);
705 for (j = ip->font.height - 1; j >= 0; j--) {
706 int sofs2 = sofs, dofs2 = dofs;
707 for (i = (ip->cols - sx) - 1; i >= 0; i--) {
708 int t;
709
710 __asm("bfextu %1@{%2:%3}, %0" : "=d" (t)
711 : "a" (pl), "d" (sofs2),
712 "d" (ip->font.width));
713 __asm("bfins %3, %0@{%1:%2}" :
714 : "a" (pl), "d" (dofs2),
715 "d" (ip->font.width), "d" (t));
716 sofs2 += ip->font.width;
717 dofs2 += ip->font.width;
718 }
719 pl += bm->bytes_per_row;
720 }
721 }
722 }
723
724 static void
725 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height,
726 short dx, short dy)
727 {
728 u_short lwpr = bm->bytes_per_row >> 2;
729
730 if (dx) {
731 /* FIX: */
732 panic ("delta x not supported in scroll bitmap yet.");
733 }
734
735 if (dy == 0) {
736 return;
737 }
738 if (dy > 0) {
739 u_long *pl = (u_long *)bm->plane;
740 u_long *src_y = pl + (lwpr * y);
741 u_long *dest_y = pl + (lwpr * (y + dy));
742 u_long count = lwpr * (height - dy);
743 u_long *clr_y = src_y;
744 u_long clr_count = dest_y - src_y;
745 u_long bc, cbc;
746
747 src_y += count - 1;
748 dest_y += count - 1;
749
750 bc = count >> 4;
751 count &= 0xf;
752
753 while (bc--) {
754 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
755 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
756 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
757 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
758 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
759 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
760 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
761 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
762 }
763 while (count--)
764 *dest_y-- = *src_y--;
765
766 cbc = clr_count >> 4;
767 clr_count &= 0xf;
768
769 while (cbc--) {
770 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
771 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
772 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
773 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
774 }
775 while (clr_count--)
776 *clr_y++ = 0;
777 } else {
778 u_long *pl = (u_long *)bm->plane;
779 u_long *src_y = pl + (lwpr * (y - dy));
780 u_long *dest_y = pl + (lwpr * y);
781 long count = lwpr * (height + dy);
782 u_long *clr_y = dest_y + count;
783 u_long clr_count = src_y - dest_y;
784 u_long bc, cbc;
785
786 bc = count >> 4;
787 count &= 0xf;
788
789 while (bc--) {
790 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
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 }
799 while (count--)
800 *dest_y++ = *src_y++;
801
802 cbc = clr_count >> 4;
803 clr_count &= 0xf;
804
805 while (cbc--) {
806 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
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 }
811 while (clr_count--)
812 *clr_y++ = 0;
813 }
814 }
815