2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $FreeBSD: src/sys/dev/syscons/scvgarndr.c,v 1.5.2.3 2001/07/28 12:51:47 yokota Exp $
30 * $DragonFly: src/sys/dev/misc/syscons/scvgarndr.c,v 1.6 2004/09/04 12:03:14 eirikn Exp $
33 #include "opt_syscons.h"
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <machine/console.h>
42 #include <dev/video/fb/fbreg.h>
43 #include <dev/video/fb/vgareg.h>
46 #include <bus/isa/isareg.h>
48 #ifndef SC_RENDER_DEBUG
49 #define SC_RENDER_DEBUG 0
52 static vr_clear_t vga_txtclear;
53 static vr_draw_border_t vga_txtborder;
54 static vr_draw_t vga_txtdraw;
55 static vr_set_cursor_t vga_txtcursor_shape;
56 static vr_draw_cursor_t vga_txtcursor;
57 static vr_blink_cursor_t vga_txtblink;
58 #ifndef SC_NO_CUTPASTE
59 static vr_draw_mouse_t vga_txtmouse;
61 #define vga_txtmouse (vr_draw_mouse_t *)vga_nop
65 static vr_init_t vga_rndrinit;
66 static vr_clear_t vga_pxlclear_direct;
67 static vr_clear_t vga_pxlclear_planar;
68 static vr_draw_border_t vga_pxlborder_direct;
69 static vr_draw_border_t vga_pxlborder_planar;
70 static vr_draw_t vga_egadraw;
71 static vr_draw_t vga_vgadraw_direct;
72 static vr_draw_t vga_vgadraw_planar;
73 static vr_set_cursor_t vga_pxlcursor_shape;
74 static vr_draw_cursor_t vga_pxlcursor_direct;
75 static vr_draw_cursor_t vga_pxlcursor_planar;
76 static vr_blink_cursor_t vga_pxlblink_direct;
77 static vr_blink_cursor_t vga_pxlblink_planar;
78 #ifndef SC_NO_CUTPASTE
79 static vr_draw_mouse_t vga_pxlmouse_direct;
80 static vr_draw_mouse_t vga_pxlmouse_planar;
82 #define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop
83 #define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop
85 #endif /* SC_PIXEL_MODE */
87 #ifndef SC_NO_MODE_CHANGE
88 static vr_draw_border_t vga_grborder;
91 static void vga_nop(scr_stat *scp, ...);
93 static sc_rndr_sw_t txtrndrsw = {
101 (vr_set_mouse_t *)vga_nop,
104 RENDERER(mda, 0, txtrndrsw, vga_set);
105 RENDERER(cga, 0, txtrndrsw, vga_set);
106 RENDERER(ega, 0, txtrndrsw, vga_set);
107 RENDERER(vga, 0, txtrndrsw, vga_set);
110 static sc_rndr_sw_t egarndrsw = {
111 (vr_init_t *)vga_nop,
113 vga_pxlborder_planar,
116 vga_pxlcursor_planar,
118 (vr_set_mouse_t *)vga_nop,
121 RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set);
123 static sc_rndr_sw_t vgarndrsw = {
125 (vr_clear_t *)vga_nop,
126 (vr_draw_border_t *)vga_nop,
127 (vr_draw_t *)vga_nop,
129 (vr_draw_cursor_t *)vga_nop,
130 (vr_blink_cursor_t *)vga_nop,
131 (vr_set_mouse_t *)vga_nop,
132 (vr_draw_mouse_t *)vga_nop,
134 RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
135 #endif /* SC_PIXEL_MODE */
137 #ifndef SC_NO_MODE_CHANGE
138 static sc_rndr_sw_t grrndrsw = {
139 (vr_init_t *)vga_nop,
140 (vr_clear_t *)vga_nop,
142 (vr_draw_t *)vga_nop,
143 (vr_set_cursor_t *)vga_nop,
144 (vr_draw_cursor_t *)vga_nop,
145 (vr_blink_cursor_t *)vga_nop,
146 (vr_set_mouse_t *)vga_nop,
147 (vr_draw_mouse_t *)vga_nop,
149 RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set);
150 RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set);
151 RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
152 #endif /* SC_NO_MODE_CHANGE */
154 RENDERER_MODULE(vga, vga_set);
156 #ifndef SC_NO_CUTPASTE
157 static u_short mouse_and_mask[16] = {
158 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
159 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
161 static u_short mouse_or_mask[16] = {
162 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
163 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
168 #define VIDEO_MEMORY_POS(scp, pos, x) \
169 scp->sc->adp->va_window + \
171 scp->yoff * scp->font_size * scp->sc->adp->va_line_width + \
172 x * (pos % scp->xsize) + \
173 scp->font_size * scp->sc->adp->va_line_width * (pos / scp->xsize)
175 #define vga_drawpxl(pos, color) \
176 switch (scp->sc->adp->va_info.vi_depth) { \
179 writel(pos, vga_palette32[color]); \
182 if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\
183 writew(pos, vga_palette15[color]); \
185 writew(pos, vga_palette16[color]); \
188 writew(pos, vga_palette15[color]); \
192 static uint32_t vga_palette32[16] = {
193 0x000000, 0x0000ad, 0x00ad00, 0x00adad,
194 0xad0000, 0xad00ad, 0xad5200, 0xadadad,
195 0x525252, 0x5252ff, 0x52ff52, 0x52ffff,
196 0xff5252, 0xff52ff, 0xffff52, 0xffffff
199 static uint16_t vga_palette16[16] = {
200 0x0000, 0x0016, 0x0560, 0x0576, 0xb000, 0xb016, 0xb2a0, 0xb576,
201 0x52aa, 0x52bf, 0x57ea, 0x57ff, 0xfaaa, 0xfabf, 0xffea, 0xffff
204 static uint16_t vga_palette15[16] = {
205 0x0000, 0x0016, 0x02c0, 0x02d6, 0x5800, 0x5816, 0x5940, 0x5ad6,
206 0x294a, 0x295f, 0x2bea, 0x2bff, 0x7d4a, 0x7d5f, 0x7fea, 0x7fff
209 #ifndef SC_NO_CUTPASTE
210 static uint32_t mouse_buf32[256];
211 static uint16_t mouse_buf16[256];
216 vga_nop(scr_stat *scp, ...)
220 /* text mode renderer */
223 vga_txtclear(scr_stat *scp, int c, int attr)
225 sc_vtb_clear(&scp->scr, c, attr);
229 vga_txtborder(scr_stat *scp, int color)
231 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
235 vga_txtdraw(scr_stat *scp, int from, int count, int flip)
241 if (from + count > scp->xsize*scp->ysize)
242 count = scp->xsize*scp->ysize - from;
245 for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
246 c = sc_vtb_getc(&scp->vtb, from);
247 a = sc_vtb_geta(&scp->vtb, from);
248 a = (a & 0x8800) | ((a & 0x7000) >> 4)
249 | ((a & 0x0700) << 4);
250 p = sc_vtb_putchar(&scp->scr, p, c, a);
253 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
258 vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
260 if (base < 0 || base >= scp->font_size)
262 /* the caller may set height <= 0 in order to disable the cursor */
264 scp->cursor_base = base;
265 scp->cursor_height = height;
267 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
269 scp->font_size, blink);
273 draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
278 scp->cursor_saveunder_char = c;
279 scp->cursor_saveunder_attr = a;
281 #ifndef SC_NO_FONT_LOADING
282 if (sc->flags & SC_CHAR_CURSOR) {
287 if (scp->font_size < 14) {
290 } else if (scp->font_size >= 16) {
297 if (scp->cursor_base >= h)
301 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
302 bcopy(font + c*h, font + sc->cursor_char*h, h);
303 font = font + sc->cursor_char*h;
304 for (i = imax(h - scp->cursor_base - scp->cursor_height, 0);
305 i < h - scp->cursor_base; ++i) {
308 sc->font_loading_in_progress = TRUE;
310 (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, font,
312 sc->font_loading_in_progress = FALSE;
313 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
315 #endif /* SC_NO_FONT_LOADING */
317 if ((a & 0x7000) == 0x7000) {
319 if ((a & 0x0700) == 0)
323 if ((a & 0x0700) == 0x0700)
328 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
329 sc_vtb_putc(&scp->scr, at, c, a);
334 vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
336 video_adapter_t *adp;
339 if (scp->cursor_height <= 0) /* the text cursor is disabled */
344 scp->status |= VR_CURSOR_BLINK;
346 scp->status |= VR_CURSOR_ON;
347 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
351 if (scp->status & VR_CURSOR_ON)
352 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
354 scp->status &= ~VR_CURSOR_ON;
357 scp->status &= ~VR_CURSOR_BLINK;
359 scp->status |= VR_CURSOR_ON;
360 draw_txtcharcursor(scp, at,
361 sc_vtb_getc(&scp->scr, at),
362 sc_vtb_geta(&scp->scr, at),
365 cursor_attr = scp->cursor_saveunder_attr;
367 cursor_attr = (cursor_attr & 0x8800)
368 | ((cursor_attr & 0x7000) >> 4)
369 | ((cursor_attr & 0x0700) << 4);
370 if (scp->status & VR_CURSOR_ON)
371 sc_vtb_putc(&scp->scr, at,
372 scp->cursor_saveunder_char,
374 scp->status &= ~VR_CURSOR_ON;
380 vga_txtblink(scr_stat *scp, int at, int flip)
384 #ifndef SC_NO_CUTPASTE
387 draw_txtmouse(scr_stat *scp, int x, int y)
389 #ifndef SC_ALT_MOUSE_IMAGE
390 if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
391 u_char font_buf[128];
395 int xoffset, yoffset;
399 /* prepare mousepointer char's bitmaps */
400 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
401 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
402 &font_buf[0], scp->font_size);
403 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
404 &font_buf[32], scp->font_size);
406 + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
407 &font_buf[64], scp->font_size);
409 + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
410 &font_buf[96], scp->font_size);
411 for (i = 0; i < scp->font_size; ++i) {
412 cursor[i] = font_buf[i]<<8 | font_buf[i+32];
413 cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
416 /* now and-or in the mousepointer image */
418 yoffset = y%scp->font_size;
419 for (i = 0; i < 16; ++i) {
420 cursor[i + yoffset] =
421 (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
422 | (mouse_or_mask[i] >> xoffset);
424 for (i = 0; i < scp->font_size; ++i) {
425 font_buf[i] = (cursor[i] & 0xff00) >> 8;
426 font_buf[i + 32] = cursor[i] & 0xff;
427 font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
428 font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
432 /* wait for vertical retrace to avoid jitter on some videocards */
433 crtc_addr = scp->sc->adp->va_crtc_addr;
434 while (!(inb(crtc_addr + 6) & 0x08)) /* idle */ ;
436 c = scp->sc->mouse_char;
437 (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
440 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
441 /* FIXME: may be out of range! */
442 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
443 sc_vtb_geta(&scp->scr, pos + scp->xsize));
444 if (x < (scp->xsize - 1)*8) {
445 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
446 sc_vtb_geta(&scp->scr, pos + 1));
447 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
448 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
451 #endif /* SC_ALT_MOUSE_IMAGE */
453 /* Red, magenta and brown are mapped to green to to keep it readable */
454 static const int col_conv[16] = {
455 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
461 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
462 a = sc_vtb_geta(&scp->scr, pos);
463 if (scp->sc->adp->va_flags & V_ADP_COLOR)
464 color = (col_conv[(a & 0xf000) >> 12] << 12)
465 | ((a & 0x0f00) | 0x0800);
467 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
468 sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
473 remove_txtmouse(scr_stat *scp, int x, int y)
478 vga_txtmouse(scr_stat *scp, int x, int y, int on)
481 draw_txtmouse(scp, x, y);
483 remove_txtmouse(scp, x, y);
486 #endif /* SC_NO_CUTPASTE */
490 /* pixel (raster text) mode renderer */
493 vga_rndrinit(scr_stat *scp)
495 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
496 scp->rndr->clear = vga_pxlclear_planar;
497 scp->rndr->draw_border = vga_pxlborder_planar;
498 scp->rndr->draw = vga_vgadraw_planar;
499 scp->rndr->draw_cursor = vga_pxlcursor_planar;
500 scp->rndr->blink_cursor = vga_pxlblink_planar;
501 scp->rndr->draw_mouse = vga_pxlmouse_planar;
502 } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) {
503 scp->rndr->clear = vga_pxlclear_direct;
504 scp->rndr->draw_border = vga_pxlborder_direct;
505 scp->rndr->draw = vga_vgadraw_direct;
506 scp->rndr->draw_cursor = vga_pxlcursor_direct;
507 scp->rndr->blink_cursor = vga_pxlblink_direct;
508 scp->rndr->draw_mouse = vga_pxlmouse_direct;
513 vga_pxlclear_direct(scr_stat *scp, int c, int attr)
521 line_width = scp->sc->adp->va_line_width;
522 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
523 lines = scp->ysize * scp->font_size;
524 p = scp->sc->adp->va_window +
525 line_width * scp->yoff * scp->font_size +
526 scp->xoff * 8 * pixel_size;
528 for (i = 0; i < lines; ++i) {
529 bzero_io((void *)p, scp->xsize * 8 * pixel_size);
535 vga_pxlclear_planar(scr_stat *scp, int c, int attr)
542 /* XXX: we are just filling the screen with the background color... */
543 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
544 outw(GDCIDX, 0x0003); /* data rotate/function select */
545 outw(GDCIDX, 0x0f01); /* set/reset enable */
546 outw(GDCIDX, 0xff08); /* bit mask */
547 outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
548 line_width = scp->sc->adp->va_line_width;
549 lines = scp->ysize*scp->font_size;
550 p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
552 for (i = 0; i < lines; ++i) {
553 bzero_io((void *)p, scp->xsize);
556 outw(GDCIDX, 0x0000); /* set/reset */
557 outw(GDCIDX, 0x0001); /* set/reset enable */
561 vga_pxlborder_direct(scr_stat *scp, int color)
572 line_width = scp->sc->adp->va_line_width;
573 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
576 s = scp->sc->adp->va_window;
577 e = s + line_width * scp->yoff * scp->font_size;
579 for (f = s; f < e; f += pixel_size)
580 vga_drawpxl(f, color);
583 y = (scp->yoff + scp->ysize) * scp->font_size;
585 if (scp->ypixel > y) {
586 s = scp->sc->adp->va_window + line_width * y;
587 e = s + line_width * (scp->ypixel - y);
589 for (f = s; f < e; f += pixel_size)
590 vga_drawpxl(f, color);
593 y = scp->yoff * scp->font_size;
594 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
596 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
598 s = scp->sc->adp->va_window + line_width * (y + i);
599 e = s + scp->xoff * 8 * pixel_size;
601 for (f = s; f < e; f += pixel_size)
602 vga_drawpxl(f, color);
606 s = scp->sc->adp->va_window + line_width * (y + i) +
607 scp->xoff * 8 * pixel_size +
608 scp->xsize * 8 * pixel_size;
609 e = s + x * 8 * pixel_size;
611 for (f = s; f < e; f += pixel_size)
612 vga_drawpxl(f, color);
618 vga_pxlborder_planar(scr_stat *scp, int color)
626 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
628 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
629 outw(GDCIDX, 0x0003); /* data rotate/function select */
630 outw(GDCIDX, 0x0f01); /* set/reset enable */
631 outw(GDCIDX, 0xff08); /* bit mask */
632 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
633 line_width = scp->sc->adp->va_line_width;
634 p = scp->sc->adp->va_window;
636 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
637 y = (scp->yoff + scp->ysize)*scp->font_size;
639 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
640 y = scp->yoff*scp->font_size;
641 x = scp->xpixel/8 - scp->xoff - scp->xsize;
642 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
644 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
646 bzero_io((void *)(p + line_width*(y + i)
647 + scp->xoff + scp->xsize), x);
649 outw(GDCIDX, 0x0000); /* set/reset */
650 outw(GDCIDX, 0x0001); /* set/reset enable */
654 vga_egadraw(scr_stat *scp, int from, int count, int flip)
666 line_width = scp->sc->adp->va_line_width;
668 d = VIDEO_MEMORY_POS(scp, from, 1);
670 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
671 outw(GDCIDX, 0x0003); /* data rotate/function select */
672 outw(GDCIDX, 0x0f01); /* set/reset enable */
674 if (from + count > scp->xsize*scp->ysize)
675 count = scp->xsize*scp->ysize - from;
676 for (i = from; count-- > 0; ++i) {
677 a = sc_vtb_geta(&scp->vtb, i);
679 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
680 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
683 col2 = (a & 0xf000) >> 4;
685 /* set background color in EGA/VGA latch */
688 outw(GDCIDX, bg | 0x00); /* set/reset */
689 outw(GDCIDX, 0xff08); /* bit mask */
691 c = readb(d); /* set bg color in the latch */
693 /* foreground color */
694 outw(GDCIDX, col1 | 0x00); /* set/reset */
696 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
697 for (j = 0; j < scp->font_size; ++j, ++f) {
698 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
703 if ((i % scp->xsize) == scp->xsize - 1)
705 + (scp->font_size - 1)*line_width;
707 outw(GDCIDX, 0x0000); /* set/reset */
708 outw(GDCIDX, 0x0001); /* set/reset enable */
709 outw(GDCIDX, 0xff08); /* bit mask */
713 vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
718 u_short col1, col2, color;
719 int line_width, pixel_size;
723 line_width = scp->sc->adp->va_line_width;
724 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
726 d = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
728 if (from + count > scp->xsize * scp->ysize)
729 count = scp->xsize * scp->ysize - from;
731 for (i = from; count-- > 0; ++i) {
732 a = sc_vtb_geta(&scp->vtb, i);
735 col1 = (((a & 0x7000) >> 4) | (a & 0x0800)) >> 8;
736 col2 = (((a & 0x8000) >> 4) | (a & 0x0700)) >> 8;
738 col1 = (a & 0x0f00) >> 8;
739 col2 = (a & 0xf000) >> 12;
743 f = &(scp->font[sc_vtb_getc(&scp->vtb, i) * scp->font_size]);
745 for (j = 0; j < scp->font_size; ++j, ++f) {
746 for (k = 0; k < 8; ++k) {
747 color = *f & (1 << (7 - k)) ? col1 : col2;
748 vga_drawpxl(e + pixel_size * k, color);
756 if ((i % scp->xsize) == scp->xsize - 1)
757 d += scp->xoff * 16 * pixel_size +
758 (scp->font_size - 1) * line_width;
763 vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
775 d = VIDEO_MEMORY_POS(scp, from, 1);
777 line_width = scp->sc->adp->va_line_width;
779 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
780 outw(GDCIDX, 0x0003); /* data rotate/function select */
781 outw(GDCIDX, 0x0f01); /* set/reset enable */
782 outw(GDCIDX, 0xff08); /* bit mask */
784 if (from + count > scp->xsize*scp->ysize)
785 count = scp->xsize*scp->ysize - from;
786 for (i = from; count-- > 0; ++i) {
787 a = sc_vtb_geta(&scp->vtb, i);
789 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
790 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
793 col2 = (a & 0xf000) >> 4;
795 /* set background color in EGA/VGA latch */
798 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
799 outw(GDCIDX, bg | 0x00); /* set/reset */
801 c = readb(d); /* set bg color in the latch */
802 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
804 /* foreground color */
805 outw(GDCIDX, col1 | 0x00); /* set/reset */
807 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
808 for (j = 0; j < scp->font_size; ++j, ++f) {
813 if ((i % scp->xsize) == scp->xsize - 1)
815 + (scp->font_size - 1)*line_width;
817 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
818 outw(GDCIDX, 0x0000); /* set/reset */
819 outw(GDCIDX, 0x0001); /* set/reset enable */
823 vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
825 if (base < 0 || base >= scp->font_size)
827 /* the caller may set height <= 0 in order to disable the cursor */
829 scp->cursor_base = base;
830 scp->cursor_height = height;
835 draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
839 int line_width, pixel_size;
841 int col1, col2, color;
845 line_width = scp->sc->adp->va_line_width;
846 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
848 d = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
849 (scp->font_size - scp->cursor_base - 1) * line_width;
851 a = sc_vtb_geta(&scp->vtb, at);
854 col1 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
855 col2 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
857 col1 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
858 col2 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
861 f = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
862 scp->font_size - scp->cursor_base - 1]);
864 height = imin(scp->cursor_height, scp->font_size);
866 for (i = 0; i < height; ++i, --f) {
867 for (j = 0; j < 8; ++j) {
868 color = *f & (1 << (7 - j)) ? col1 : col2;
869 vga_drawpxl(d + pixel_size * j, color);
877 draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
888 line_width = scp->sc->adp->va_line_width;
890 d = VIDEO_MEMORY_POS(scp, at, 1) +
891 (scp->font_size - scp->cursor_base - 1) * line_width;
893 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
894 outw(GDCIDX, 0x0003); /* data rotate/function select */
895 outw(GDCIDX, 0x0f01); /* set/reset enable */
896 /* set background color in EGA/VGA latch */
897 a = sc_vtb_geta(&scp->vtb, at);
899 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
901 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
902 outw(GDCIDX, col | 0x00); /* set/reset */
903 outw(GDCIDX, 0xff08); /* bit mask */
905 c = readb(d); /* set bg color in the latch */
906 /* foreground color */
908 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
910 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
911 outw(GDCIDX, col | 0x00); /* set/reset */
912 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
913 + scp->font_size - scp->cursor_base - 1]);
914 height = imin(scp->cursor_height, scp->font_size);
915 for (i = 0; i < height; ++i, --f) {
916 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
920 outw(GDCIDX, 0x0000); /* set/reset */
921 outw(GDCIDX, 0x0001); /* set/reset enable */
922 outw(GDCIDX, 0xff08); /* bit mask */
925 static int pxlblinkrate = 0;
928 vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
930 if (scp->cursor_height <= 0) /* the text cursor is disabled */
935 scp->status |= VR_CURSOR_ON;
936 draw_pxlcursor_direct(scp, at, on, flip);
937 } else if (++pxlblinkrate & 4) {
939 scp->status ^= VR_CURSOR_ON;
940 draw_pxlcursor_direct(scp, at,
941 scp->status & VR_CURSOR_ON,
945 if (scp->status & VR_CURSOR_ON)
946 draw_pxlcursor_direct(scp, at, on, flip);
947 scp->status &= ~VR_CURSOR_ON;
950 scp->status |= VR_CURSOR_BLINK;
952 scp->status &= ~VR_CURSOR_BLINK;
956 vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
958 if (scp->cursor_height <= 0) /* the text cursor is disabled */
963 scp->status |= VR_CURSOR_ON;
964 draw_pxlcursor_planar(scp, at, on, flip);
965 } else if (++pxlblinkrate & 4) {
967 scp->status ^= VR_CURSOR_ON;
968 draw_pxlcursor_planar(scp, at,
969 scp->status & VR_CURSOR_ON,
973 if (scp->status & VR_CURSOR_ON)
974 draw_pxlcursor_planar(scp, at, on, flip);
975 scp->status &= ~VR_CURSOR_ON;
978 scp->status |= VR_CURSOR_BLINK;
980 scp->status &= ~VR_CURSOR_BLINK;
984 vga_pxlblink_direct(scr_stat *scp, int at, int flip)
986 if (!(scp->status & VR_CURSOR_BLINK))
988 if (!(++pxlblinkrate & 4))
991 scp->status ^= VR_CURSOR_ON;
992 draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
996 vga_pxlblink_planar(scr_stat *scp, int at, int flip)
998 if (!(scp->status & VR_CURSOR_BLINK))
1000 if (!(++pxlblinkrate & 4))
1003 scp->status ^= VR_CURSOR_ON;
1004 draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
1007 #ifndef SC_NO_CUTPASTE
1010 draw_pxlmouse_planar(scr_stat *scp, int x, int y)
1019 line_width = scp->sc->adp->va_line_width;
1020 xoff = (x - scp->xoff*8)%8;
1021 yoff = y - (y/line_width)*line_width;
1022 ymax = imin(y + 16, scp->ypixel);
1024 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
1025 outw(GDCIDX, 0x0001); /* set/reset enable */
1026 outw(GDCIDX, 0x0002); /* color compare */
1027 outw(GDCIDX, 0x0007); /* color don't care */
1028 outw(GDCIDX, 0xff08); /* bit mask */
1029 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
1030 p = scp->sc->adp->va_window + line_width*y + x/8;
1031 if (x < scp->xpixel - 8) {
1032 for (i = y, j = 0; i < ymax; ++i, ++j) {
1033 m = ~(mouse_and_mask[j] >> xoff);
1035 *(u_char *)p &= m >> 8;
1036 *(u_char *)(p + 1) &= m;
1037 #elif defined(__alpha__)
1038 writeb(p, readb(p) & (m >> 8));
1039 writeb(p + 1, readb(p + 1) & (m >> 8));
1045 for (i = y, j = 0; i < ymax; ++i, ++j) {
1046 m = ~(mouse_and_mask[j] >> xoff);
1049 #elif defined(__alpha__)
1050 writeb(p, readb(p) & (m >> 8));
1055 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
1056 p = scp->sc->adp->va_window + line_width*y + x/8;
1057 if (x < scp->xpixel - 8) {
1058 for (i = y, j = 0; i < ymax; ++i, ++j) {
1059 m = mouse_or_mask[j] >> xoff;
1061 *(u_char *)p &= m >> 8;
1062 *(u_char *)(p + 1) &= m;
1063 #elif defined(__alpha__)
1064 writeb(p, readb(p) & (m >> 8));
1065 writeb(p + 1, readb(p + 1) & (m >> 8));
1070 for (i = y, j = 0; i < ymax; ++i, ++j) {
1071 m = mouse_or_mask[j] >> xoff;
1074 #elif defined(__alpha__)
1075 writeb(p, readb(p) & (m >> 8));
1080 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1081 outw(GDCIDX, 0x0003); /* data rotate/function select */
1085 remove_pxlmouse_planar(scr_stat *scp, int x, int y)
1094 /* erase the mouse cursor image */
1095 col = x/8 - scp->xoff;
1096 row = y/scp->font_size - scp->yoff;
1097 pos = row*scp->xsize + col;
1098 i = (col < scp->xsize - 1) ? 2 : 1;
1099 (*scp->rndr->draw)(scp, pos, i, FALSE);
1100 if (row < scp->ysize - 1)
1101 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
1103 /* paint border if necessary */
1104 line_width = scp->sc->adp->va_line_width;
1105 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1106 outw(GDCIDX, 0x0003); /* data rotate/function select */
1107 outw(GDCIDX, 0x0f01); /* set/reset enable */
1108 outw(GDCIDX, 0xff08); /* bit mask */
1109 outw(GDCIDX, (scp->border << 8) | 0x00); /* set/reset */
1110 if (row == scp->ysize - 1) {
1111 i = (scp->ysize + scp->yoff)*scp->font_size;
1112 ymax = imin(i + scp->font_size, scp->ypixel);
1113 p = scp->sc->adp->va_window + i*line_width + scp->xoff + col;
1114 if (col < scp->xsize - 1) {
1115 for (; i < ymax; ++i) {
1121 for (; i < ymax; ++i) {
1127 if ((col == scp->xsize - 1) && (scp->xoff > 0)) {
1128 i = (row + scp->yoff)*scp->font_size;
1129 ymax = imin(i + scp->font_size*2, scp->ypixel);
1130 p = scp->sc->adp->va_window + i*line_width
1131 + scp->xoff + scp->xsize;
1132 for (; i < ymax; ++i) {
1137 outw(GDCIDX, 0x0000); /* set/reset */
1138 outw(GDCIDX, 0x0001); /* set/reset enable */
1142 vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
1145 int line_width, pixel_size;
1147 static int x_old = 0, xend_old = 0;
1148 static int y_old = 0, yend_old = 0;
1157 bpp = scp->sc->adp->va_info.vi_depth;
1159 if ((bpp == 16) && (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5))
1162 line_width = scp->sc->adp->va_line_width;
1163 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
1165 xend = imin(x + 16, scp->xpixel);
1166 yend = imin(y + 16, scp->ypixel);
1168 p = scp->sc->adp->va_window + y_old * line_width + x_old * pixel_size;
1170 for (i = 0; i < (yend_old - y_old); i++) {
1171 for (j = (xend_old - x_old - 1); j >= 0; j--) {
1174 u32 = (uint32_t*)(p + j * pixel_size);
1175 writel(u32, mouse_buf32[i * 16 + j]);
1180 u16 = (uint16_t*)(p + j * pixel_size);
1181 writew(u16, mouse_buf16[i * 16 + j]);
1189 p = scp->sc->adp->va_window + y * line_width + x * pixel_size;
1191 for (i = 0; i < (yend - y); i++) {
1192 for (j = (xend - x - 1); j >= 0; j--) {
1195 u32 = (uint32_t*)(p + j * pixel_size);
1196 mouse_buf32[i * 16 + j] = *u32;
1197 if (mouse_or_mask[i] & (1 << (15 - j)))
1198 writel(u32, vga_palette32[15]);
1199 else if (mouse_and_mask[i] & (1 << (15 - j)))
1203 u16 = (uint16_t*)(p + j * pixel_size);
1204 mouse_buf16[i * 16 + j] = *u16;
1205 if (mouse_or_mask[i] & (1 << (15 - j)))
1206 writew(u16, vga_palette16[15]);
1207 else if (mouse_and_mask[i] & (1 << (15 - j)))
1211 u16 = (uint16_t*)(p + j * pixel_size);
1212 mouse_buf16[i * 16 + j] = *u16;
1213 if (mouse_or_mask[i] & (1 << (15 - j)))
1214 writew(u16, vga_palette15[15]);
1215 else if (mouse_and_mask[i] & (1 << (15 - j)))
1231 vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
1234 draw_pxlmouse_planar(scp, x, y);
1236 remove_pxlmouse_planar(scp, x, y);
1239 #endif /* SC_NO_CUTPASTE */
1240 #endif /* SC_PIXEL_MODE */
1242 #ifndef SC_NO_MODE_CHANGE
1244 /* graphics mode renderer */
1247 vga_grborder(scr_stat *scp, int color)
1249 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);