ite_cc.c revision 1.40.12.1 1 /* $NetBSD: ite_cc.c,v 1.40.12.1 2021/03/21 21:08:57 thorpej 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.12.1 2021/03/21 21:08:57 thorpej 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, CFARG_EOL);
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 CFARG_EOL);
281 }
282 }
283 }
284
285 static int
286 grfccprint(void *aux, const char *pnp)
287 {
288
289 if (pnp)
290 aprint_normal("ite at %s", pnp);
291 return UNCONF;
292 }
293
294 /*
295 * called from grf_cc to return console priority
296 */
297 int
298 grfcc_cnprobe(void)
299 {
300 return CN_INTERNAL;
301 }
302 /*
303 * called from grf_cc to init ite portion of
304 * grf_softc struct
305 */
306 void
307 grfcc_iteinit(struct grf_softc *sc)
308 {
309
310 sc->g_itecursor = cursor32;
311 sc->g_iteputc = putc8;
312 sc->g_iteclear = clear8;
313 sc->g_itescroll = scroll8;
314 sc->g_iteinit = view_init;
315 sc->g_itedeinit = view_deinit;
316 }
317
318 static void
319 view_deinit(struct ite_softc *ip)
320 {
321 ip->flags &= ~ITE_INITED;
322 }
323
324 static void
325 view_init(register struct ite_softc *ip)
326 {
327 struct itewinsize wsz;
328 ipriv_t *cci;
329
330 if ((cci = ip->priv) != NULL)
331 return;
332
333 ip->itexx_ioctl = itecc_ioctl;
334
335 #if defined(KFONT_8X8)
336 ip->font = font_info_8x8;
337 #else
338 ip->font = font_info_8x16;
339 #endif
340
341 /* Find the correct set of rendering routines for this font. */
342 if (ip->font.width != 8)
343 panic("kernel font size not supported");
344
345 if (!atari_realconfig)
346 ip->priv = cci = &con_ipriv;
347 else
348 ip->priv = cci = malloc(sizeof(*cci), M_DEVBUF, M_WAITOK);
349 if (cci == NULL)
350 panic("No memory for ite-view");
351 memset(cci, 0, sizeof(*cci));
352
353 cci->cursor_opt = 0;
354 cci->row_ptr = NULL;
355 cci->column_offset = NULL;
356
357 wsz.x = ite_default_x;
358 wsz.y = ite_default_y;
359 wsz.width = ite_default_width;
360 wsz.height = ite_default_height;
361 wsz.depth = ite_default_depth;
362
363 ite_newsize (ip, &wsz);
364
365 /*
366 * Only console will be turned on by default..
367 */
368 if (ip->flags & ITE_ISCONS)
369 ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
370 }
371
372 static int
373 ite_newsize(struct ite_softc *ip, struct itewinsize *winsz)
374 {
375 struct view_size vs;
376 ipriv_t *cci = ip->priv;
377 u_long i, j;
378 int error = 0;
379 view_t *view;
380 extern const struct cdevsw view_cdevsw;
381
382 vs.x = winsz->x;
383 vs.y = winsz->y;
384 vs.width = winsz->width;
385 vs.height = winsz->height;
386 vs.depth = winsz->depth;
387
388 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, VIOCSSIZE,
389 (void *)&vs, 0, NOLWP);
390 view = viewview(ip->grf->g_viewdev);
391
392 /*
393 * Reinitialize our structs
394 */
395 ip->cols = view->display.width / ip->font.width;
396 ip->rows = view->display.height / ip->font.height;
397
398 /*
399 * save new values so that future opens use them
400 * this may not be correct when we implement Virtual Consoles
401 */
402 ite_default_height = view->display.height;
403 ite_default_width = view->display.width;
404 ite_default_x = view->display.x;
405 ite_default_y = view->display.y;
406 ite_default_depth = view->bitmap->depth;
407
408 if (cci->row_ptr && (cci->row_ptr != con_rows)) {
409 free(cci->row_ptr, M_DEVBUF);
410 cci->row_ptr = NULL;
411 }
412 if (cci->column_offset && (cci->column_offset != con_columns)) {
413 free(cci->column_offset, M_DEVBUF);
414 cci->column_offset = NULL;
415 }
416
417 if (!atari_realconfig) {
418 cci->row_ptr = con_rows;
419 cci->column_offset = con_columns;
420 } else {
421 cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,
422 M_DEVBUF, M_NOWAIT);
423 cci->column_offset = malloc(sizeof(u_int) * ip->cols,
424 M_DEVBUF, M_NOWAIT);
425 }
426
427 if (!cci->row_ptr || !cci->column_offset)
428 panic("No memory for ite-view");
429
430 cci->width = view->bitmap->bytes_per_row << 3;
431 cci->underline = ip->font.baseline + 1;
432 cci->row_offset = view->bitmap->bytes_per_row;
433 cci->ft_x = ip->font.width;
434 cci->ft_y = ip->font.height;
435 cci->row_bytes = cci->row_offset * cci->ft_y;
436 cci->row_ptr[0] = view->bitmap->plane;
437 for (i = 1; i < ip->rows; i++)
438 cci->row_ptr[i] = cci->row_ptr[i - 1] + cci->row_bytes;
439
440 /*
441 * Initialize the column offsets to point at the correct location
442 * in the first plane. This definitely assumes a font width of 8!
443 */
444 j = view->bitmap->depth * 2;
445 cci->column_offset[0] = 0;
446 for (i = 1; i < ip->cols; i++)
447 cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
448
449 /* initialize the font cell pointers */
450 cci->font_cell[ip->font.font_lo] = ip->font.font_p;
451 for (i = ip->font.font_lo + 1; i <= ip->font.font_hi; i++)
452 cci->font_cell[i] = cci->font_cell[i - 1] + ip->font.height;
453
454 return error;
455 }
456
457 int
458 itecc_ioctl(struct ite_softc *ip, u_long cmd, void * addr, int flag,
459 struct lwp *l)
460 {
461 struct winsize ws;
462 struct itewinsize *is;
463 int error = 0;
464 view_t *view = viewview(ip->grf->g_viewdev);
465 extern const struct cdevsw ite_cdevsw;
466 extern const struct cdevsw view_cdevsw;
467
468 switch (cmd) {
469 case ITEIOCSWINSZ:
470 is = (struct itewinsize *)addr;
471
472 if (ite_newsize(ip, is))
473 error = ENOMEM;
474 else {
475 view = viewview(ip->grf->g_viewdev);
476 ws.ws_row = ip->rows;
477 ws.ws_col = ip->cols;
478 ws.ws_xpixel = view->display.width;
479 ws.ws_ypixel = view->display.height;
480 ite_reset(ip);
481 /*
482 * XXX tell tty about the change
483 * XXX this is messy, but works
484 */
485 (*ite_cdevsw.d_ioctl)(ip->grf->g_itedev, TIOCSWINSZ,
486 (void *)&ws, 0, l);
487 }
488 break;
489 case VIOCSCMAP:
490 case VIOCGCMAP:
491 /*
492 * XXX watchout for that NOLWP. its not really the kernel
493 * XXX talking these two commands don't use the proc pointer
494 * XXX though.
495 */
496 error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, cmd, addr,
497 flag, NOLWP);
498 break;
499 default:
500 error = EPASSTHROUGH;
501 break;
502 }
503 return error;
504 }
505
506 static void
507 cursor32(struct ite_softc *ip, int flag)
508 {
509 int cend;
510 u_char *pl;
511 ipriv_t *cci;
512
513 cci = ip->priv;
514
515 if (flag == END_CURSOROPT)
516 cci->cursor_opt--;
517 else if (flag == START_CURSOROPT) {
518 if (!cci->cursor_opt)
519 cursor32(ip, ERASE_CURSOR);
520 cci->cursor_opt++;
521 return; /* if we are already opted. */
522 }
523
524 if (cci->cursor_opt)
525 return; /* if we are still nested. */
526 /* else we draw the cursor. */
527
528 if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
529 /*
530 * erase the cursor
531 */
532 cend = ip->font.height - 1;
533 pl = cci->column_offset[ip->cursorx]
534 + cci->row_ptr[ip->cursory];
535 __asm volatile
536 ("1: notb %0@ ; addaw %4,%0\n\t"
537 "dbra %1,1b"
538 : "=a" (pl), "=d" (cend)
539 : "0" (pl), "1" (cend),
540 "d" (cci->row_offset)
541 );
542 }
543
544 if (flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
545 return;
546
547 /*
548 * draw the cursor
549 */
550 cend = uimin(ip->curx, ip->cols - 1);
551 if (flag == DRAW_CURSOR
552 && ip->cursorx == cend && ip->cursory == ip->cury)
553 return;
554 ip->cursorx = cend;
555 ip->cursory = ip->cury;
556 cend = ip->font.height - 1;
557 pl = cci->column_offset[ip->cursorx]
558 + cci->row_ptr[ip->cursory];
559
560 __asm volatile
561 ("1: notb %0@ ; addaw %4,%0\n\t"
562 "dbra %1,1b"
563 : "=a" (pl), "=d" (cend)
564 : "0" (pl), "1" (cend),
565 "d" (cci->row_offset)
566 );
567 }
568
569 static void
570 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
571 {
572 ipriv_t *cci = (ipriv_t *)ip->priv;
573 u_char *pl = cci->column_offset[dx] + cci->row_ptr[dy];
574 u_int fh = cci->ft_y;
575 u_int ro = cci->row_offset;
576 u_char eor_mask;
577 u_char bl, tmp, ul;
578 u_char *ft;
579
580 if (c < ip->font.font_lo || c > ip->font.font_hi)
581 return;
582
583 ft = cci->font_cell[c];
584
585 if (!mode) {
586 while (fh--) {
587 *pl = *ft++; pl += ro;
588 }
589 return;
590 }
591
592 eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
593 bl = (mode & ATTR_BOLD) ? 1 : 0;
594 ul = (mode & ATTR_UL) ? fh - cci->underline : fh;
595 for (; fh--; pl += ro) {
596 if (fh != ul) {
597 tmp = *ft++;
598 if (bl)
599 tmp |= (tmp >> 1);
600 *pl = tmp ^ eor_mask;
601 } else {
602 *pl = 0xff ^ eor_mask;
603 ft++;
604 }
605 }
606 }
607
608 static void
609 clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
610 {
611 ipriv_t *cci = (ipriv_t *) ip->priv;
612 view_t *v = viewview(ip->grf->g_viewdev);
613 bmap_t *bm = v->bitmap;
614
615 if ((sx == 0) && (w == ip->cols)) {
616 /* common case: clearing whole lines */
617 while (h--) {
618 int i;
619 u_char *ptr = cci->row_ptr[sy];
620 for (i = 0; i < ip->font.height; i++) {
621 memset(ptr, 0, bm->bytes_per_row);
622 ptr += bm->bytes_per_row;
623 }
624 sy++;
625 }
626 } else {
627 /*
628 * clearing only part of a line
629 * XXX could be optimized MUCH better, but is it worth the
630 * trouble?
631 */
632
633 int i;
634 u_char *pls, *ple;
635
636 pls = cci->row_ptr[sy];
637 ple = pls + cci->column_offset[sx + w - 1];
638 pls = pls + cci->column_offset[sx];
639
640 for (i = ((ip->font.height) * h) - 1; i >= 0; i--) {
641 u_char *p = pls;
642 while (p <= ple)
643 *p++ = 0;
644 pls += bm->bytes_per_row;
645 ple += bm->bytes_per_row;
646 }
647 }
648 }
649
650 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
651 static void
652 scroll8(register struct ite_softc *ip, register int sy, int sx, int count,
653 int dir)
654 {
655 bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
656 u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
657
658 if (dir == SCROLL_UP) {
659 int dy = sy - count;
660
661 cursor32(ip, ERASE_CURSOR);
662 scrollbmap(bm, 0, dy * ip->font.height, bm->bytes_per_row >> 3,
663 (ip->bottom_margin - dy + 1) * ip->font.height,
664 0, -(count * ip->font.height));
665 } else if (dir == SCROLL_DOWN) {
666 cursor32(ip, ERASE_CURSOR);
667 scrollbmap(bm, 0, sy * ip->font.height, bm->bytes_per_row >> 3,
668 (ip->bottom_margin - sy + 1) * ip->font.height,
669 0, count * ip->font.height);
670 } else if (dir == SCROLL_RIGHT) {
671 int sofs = (ip->cols - count) * ip->font.width;
672 int dofs = (ip->cols) * ip->font.width;
673 int i, j;
674
675 cursor32(ip, ERASE_CURSOR);
676 for (j = ip->font.height - 1; j >= 0; j--) {
677 int sofs2 = sofs, dofs2 = dofs;
678 for (i = (ip->cols - (sx + count)) - 1; i >= 0; i--) {
679 int t;
680 sofs2 -= ip->font.width;
681 dofs2 -= ip->font.width;
682 __asm("bfextu %1@{%2:%3}, %0" : "=d" (t)
683 : "a" (pl), "d" (sofs2),
684 "d" (ip->font.width));
685 __asm("bfins %3, %0@{%1:%2}" :
686 : "a" (pl), "d" (dofs2),
687 "d" (ip->font.width), "d" (t));
688 }
689 pl += bm->bytes_per_row;
690 }
691 } else { /* SCROLL_LEFT */
692 int sofs = (sx) * ip->font.width;
693 int dofs = (sx - count) * ip->font.width;
694 int i, j;
695
696 cursor32(ip, ERASE_CURSOR);
697 for (j = ip->font.height - 1; j >= 0; j--) {
698 int sofs2 = sofs, dofs2 = dofs;
699 for (i = (ip->cols - sx) - 1; i >= 0; i--) {
700 int t;
701
702 __asm("bfextu %1@{%2:%3}, %0" : "=d" (t)
703 : "a" (pl), "d" (sofs2),
704 "d" (ip->font.width));
705 __asm("bfins %3, %0@{%1:%2}" :
706 : "a" (pl), "d" (dofs2),
707 "d" (ip->font.width), "d" (t));
708 sofs2 += ip->font.width;
709 dofs2 += ip->font.width;
710 }
711 pl += bm->bytes_per_row;
712 }
713 }
714 }
715
716 static void
717 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height,
718 short dx, short dy)
719 {
720 u_short lwpr = bm->bytes_per_row >> 2;
721
722 if (dx) {
723 /* FIX: */
724 panic ("delta x not supported in scroll bitmap yet.");
725 }
726
727 if (dy == 0) {
728 return;
729 }
730 if (dy > 0) {
731 u_long *pl = (u_long *)bm->plane;
732 u_long *src_y = pl + (lwpr * y);
733 u_long *dest_y = pl + (lwpr * (y + dy));
734 u_long count = lwpr * (height - dy);
735 u_long *clr_y = src_y;
736 u_long clr_count = dest_y - src_y;
737 u_long bc, cbc;
738
739 src_y += count - 1;
740 dest_y += count - 1;
741
742 bc = count >> 4;
743 count &= 0xf;
744
745 while (bc--) {
746 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
747 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
748 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
749 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
750 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
751 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
752 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
753 *dest_y-- = *src_y--; *dest_y-- = *src_y--;
754 }
755 while (count--)
756 *dest_y-- = *src_y--;
757
758 cbc = clr_count >> 4;
759 clr_count &= 0xf;
760
761 while (cbc--) {
762 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
763 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
764 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
765 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
766 }
767 while (clr_count--)
768 *clr_y++ = 0;
769 } else {
770 u_long *pl = (u_long *)bm->plane;
771 u_long *src_y = pl + (lwpr * (y - dy));
772 u_long *dest_y = pl + (lwpr * y);
773 long count = lwpr * (height + dy);
774 u_long *clr_y = dest_y + count;
775 u_long clr_count = src_y - dest_y;
776 u_long bc, cbc;
777
778 bc = count >> 4;
779 count &= 0xf;
780
781 while (bc--) {
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 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
786 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
787 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
788 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
789 *dest_y++ = *src_y++; *dest_y++ = *src_y++;
790 }
791 while (count--)
792 *dest_y++ = *src_y++;
793
794 cbc = clr_count >> 4;
795 clr_count &= 0xf;
796
797 while (cbc--) {
798 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
799 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
800 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
801 *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
802 }
803 while (clr_count--)
804 *clr_y++ = 0;
805 }
806 }
807