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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include "opt_syscons.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
42 #include <sys/consio.h>
44 #include <machine/bus.h>
46 #include <dev/fb/fbreg.h>
47 #include <dev/fb/vgareg.h>
48 #include <dev/syscons/syscons.h>
50 #include <isa/isareg.h>
52 #ifndef SC_RENDER_DEBUG
53 #define SC_RENDER_DEBUG 0
56 static vr_clear_t vga_txtclear;
57 static vr_draw_border_t vga_txtborder;
58 static vr_draw_t vga_txtdraw;
59 static vr_set_cursor_t vga_txtcursor_shape;
60 static vr_draw_cursor_t vga_txtcursor;
61 static vr_blink_cursor_t vga_txtblink;
62 #ifndef SC_NO_CUTPASTE
63 static vr_draw_mouse_t vga_txtmouse;
65 #define vga_txtmouse (vr_draw_mouse_t *)vga_nop
69 static vr_init_t vga_rndrinit;
70 static vr_clear_t vga_pxlclear_direct;
71 static vr_clear_t vga_pxlclear_planar;
72 static vr_draw_border_t vga_pxlborder_direct;
73 static vr_draw_border_t vga_pxlborder_planar;
74 static vr_draw_t vga_egadraw;
75 static vr_draw_t vga_vgadraw_direct;
76 static vr_draw_t vga_vgadraw_planar;
77 static vr_set_cursor_t vga_pxlcursor_shape;
78 static vr_draw_cursor_t vga_pxlcursor_direct;
79 static vr_draw_cursor_t vga_pxlcursor_planar;
80 static vr_blink_cursor_t vga_pxlblink_direct;
81 static vr_blink_cursor_t vga_pxlblink_planar;
82 #ifndef SC_NO_CUTPASTE
83 static vr_draw_mouse_t vga_pxlmouse_direct;
84 static vr_draw_mouse_t vga_pxlmouse_planar;
86 #define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop
87 #define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop
89 #endif /* SC_PIXEL_MODE */
91 #ifndef SC_NO_MODE_CHANGE
92 static vr_draw_border_t vga_grborder;
95 static void vga_nop(scr_stat *scp);
97 static sc_rndr_sw_t txtrndrsw = {
105 (vr_set_mouse_t *)vga_nop,
108 RENDERER(mda, 0, txtrndrsw, vga_set);
109 RENDERER(cga, 0, txtrndrsw, vga_set);
110 RENDERER(ega, 0, txtrndrsw, vga_set);
111 RENDERER(vga, 0, txtrndrsw, vga_set);
114 static sc_rndr_sw_t egarndrsw = {
115 (vr_init_t *)vga_nop,
117 vga_pxlborder_planar,
120 vga_pxlcursor_planar,
122 (vr_set_mouse_t *)vga_nop,
125 RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set);
127 static sc_rndr_sw_t vgarndrsw = {
129 (vr_clear_t *)vga_nop,
130 (vr_draw_border_t *)vga_nop,
131 (vr_draw_t *)vga_nop,
133 (vr_draw_cursor_t *)vga_nop,
134 (vr_blink_cursor_t *)vga_nop,
135 (vr_set_mouse_t *)vga_nop,
136 (vr_draw_mouse_t *)vga_nop,
138 RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
139 #endif /* SC_PIXEL_MODE */
141 #ifndef SC_NO_MODE_CHANGE
142 static sc_rndr_sw_t grrndrsw = {
143 (vr_init_t *)vga_nop,
144 (vr_clear_t *)vga_nop,
146 (vr_draw_t *)vga_nop,
147 (vr_set_cursor_t *)vga_nop,
148 (vr_draw_cursor_t *)vga_nop,
149 (vr_blink_cursor_t *)vga_nop,
150 (vr_set_mouse_t *)vga_nop,
151 (vr_draw_mouse_t *)vga_nop,
153 RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set);
154 RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set);
155 RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
156 #endif /* SC_NO_MODE_CHANGE */
158 RENDERER_MODULE(vga, vga_set);
160 #ifndef SC_NO_CUTPASTE
161 #if !defined(SC_ALT_MOUSE_IMAGE) || defined(SC_PIXEL_MODE)
162 static u_short mouse_and_mask[16] = {
163 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
164 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
166 static u_short mouse_or_mask[16] = {
167 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
168 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
174 #define VIDEO_MEMORY_POS(scp, pos, x) \
175 scp->sc->adp->va_window + \
177 scp->yoff * scp->font_size * scp->sc->adp->va_line_width + \
178 x * (pos % scp->xsize) + \
179 scp->font_size * scp->sc->adp->va_line_width * (pos / scp->xsize)
181 #define vga_drawpxl(pos, color) \
182 switch (scp->sc->adp->va_info.vi_depth) { \
185 writel(pos, vga_palette32[color]); \
188 if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\
189 writew(pos, vga_palette15[color]); \
191 writew(pos, vga_palette16[color]); \
194 writew(pos, vga_palette15[color]); \
198 static uint32_t vga_palette32[16] = {
199 0x000000, 0x0000ad, 0x00ad00, 0x00adad,
200 0xad0000, 0xad00ad, 0xad5200, 0xadadad,
201 0x525252, 0x5252ff, 0x52ff52, 0x52ffff,
202 0xff5252, 0xff52ff, 0xffff52, 0xffffff
205 static uint16_t vga_palette16[16] = {
206 0x0000, 0x0016, 0x0560, 0x0576, 0xb000, 0xb016, 0xb2a0, 0xb576,
207 0x52aa, 0x52bf, 0x57ea, 0x57ff, 0xfaaa, 0xfabf, 0xffea, 0xffff
210 static uint16_t vga_palette15[16] = {
211 0x0000, 0x0016, 0x02c0, 0x02d6, 0x5800, 0x5816, 0x5940, 0x5ad6,
212 0x294a, 0x295f, 0x2bea, 0x2bff, 0x7d4a, 0x7d5f, 0x7fea, 0x7fff
215 #ifndef SC_NO_CUTPASTE
216 static uint32_t mouse_buf32[256];
217 static uint16_t mouse_buf16[256];
222 vga_nop(scr_stat *scp)
226 /* text mode renderer */
229 vga_txtclear(scr_stat *scp, int c, int attr)
231 sc_vtb_clear(&scp->scr, c, attr);
235 vga_txtborder(scr_stat *scp, int color)
237 vidd_set_border(scp->sc->adp, color);
241 vga_txtdraw(scr_stat *scp, int from, int count, int flip)
247 if (from + count > scp->xsize*scp->ysize)
248 count = scp->xsize*scp->ysize - from;
251 for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
252 c = sc_vtb_getc(&scp->vtb, from);
253 a = sc_vtb_geta(&scp->vtb, from);
254 a = (a & 0x8800) | ((a & 0x7000) >> 4)
255 | ((a & 0x0700) << 4);
256 p = sc_vtb_putchar(&scp->scr, p, c, a);
259 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
264 vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
266 if (base < 0 || base >= scp->font_size)
268 /* the caller may set height <= 0 in order to disable the cursor */
270 scp->curs_attr.base = base;
271 scp->curs_attr.height = height;
273 vidd_set_hw_cursor_shape(scp->sc->adp, base, height,
274 scp->font_size, blink);
278 draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
283 scp->cursor_saveunder_char = c;
284 scp->cursor_saveunder_attr = a;
286 #ifndef SC_NO_FONT_LOADING
287 if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
292 if (scp->font_size < 14) {
295 } else if (scp->font_size >= 16) {
302 if (scp->curs_attr.base >= h)
306 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
307 bcopy(font + c*h, font + sc->cursor_char*h, h);
308 font = font + sc->cursor_char*h;
309 for (i = imax(h - scp->curs_attr.base - scp->curs_attr.height, 0);
310 i < h - scp->curs_attr.base; ++i) {
314 vidd_load_font(sc->adp, 0, h, 8, font, sc->cursor_char, 1);
315 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
317 #endif /* SC_NO_FONT_LOADING */
319 if ((a & 0x7000) == 0x7000) {
321 if ((a & 0x0700) == 0)
325 if ((a & 0x0700) == 0x0700)
330 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
331 sc_vtb_putc(&scp->scr, at, c, a);
336 vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
338 video_adapter_t *adp;
341 if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
346 scp->status |= VR_CURSOR_BLINK;
348 scp->status |= VR_CURSOR_ON;
349 vidd_set_hw_cursor(adp, at%scp->xsize,
352 if (scp->status & VR_CURSOR_ON)
353 vidd_set_hw_cursor(adp, -1, -1);
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 vidd_load_font(scp->sc->adp, 0, 32, 8, font_buf, c, 4);
439 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
440 /* FIXME: may be out of range! */
441 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
442 sc_vtb_geta(&scp->scr, pos + scp->xsize));
443 if (x < (scp->xsize - 1)*8) {
444 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
445 sc_vtb_geta(&scp->scr, pos + 1));
446 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
447 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
450 #endif /* SC_ALT_MOUSE_IMAGE */
452 /* Red, magenta and brown are mapped to green to to keep it readable */
453 static const int col_conv[16] = {
454 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
460 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
461 a = sc_vtb_geta(&scp->scr, pos);
462 if (scp->sc->adp->va_flags & V_ADP_COLOR)
463 color = (col_conv[(a & 0xf000) >> 12] << 12)
464 | ((a & 0x0f00) | 0x0800);
466 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
467 sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
472 remove_txtmouse(scr_stat *scp, int x, int y)
477 vga_txtmouse(scr_stat *scp, int x, int y, int on)
480 draw_txtmouse(scp, x, y);
482 remove_txtmouse(scp, x, y);
485 #endif /* SC_NO_CUTPASTE */
489 /* pixel (raster text) mode renderer */
492 vga_rndrinit(scr_stat *scp)
494 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
495 scp->rndr->clear = vga_pxlclear_planar;
496 scp->rndr->draw_border = vga_pxlborder_planar;
497 scp->rndr->draw = vga_vgadraw_planar;
498 scp->rndr->draw_cursor = vga_pxlcursor_planar;
499 scp->rndr->blink_cursor = vga_pxlblink_planar;
500 scp->rndr->draw_mouse = vga_pxlmouse_planar;
501 } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) {
502 scp->rndr->clear = vga_pxlclear_direct;
503 scp->rndr->draw_border = vga_pxlborder_direct;
504 scp->rndr->draw = vga_vgadraw_direct;
505 scp->rndr->draw_cursor = vga_pxlcursor_direct;
506 scp->rndr->blink_cursor = vga_pxlblink_direct;
507 scp->rndr->draw_mouse = vga_pxlmouse_direct;
512 vga_pxlclear_direct(scr_stat *scp, int c, int attr)
520 line_width = scp->sc->adp->va_line_width;
521 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
522 lines = scp->ysize * scp->font_size;
523 p = scp->sc->adp->va_window +
524 line_width * scp->yoff * scp->font_size +
525 scp->xoff * 8 * pixel_size;
527 for (i = 0; i < lines; ++i) {
528 bzero_io((void *)p, scp->xsize * 8 * pixel_size);
534 vga_pxlclear_planar(scr_stat *scp, int c, int attr)
541 /* XXX: we are just filling the screen with the background color... */
542 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
543 outw(GDCIDX, 0x0003); /* data rotate/function select */
544 outw(GDCIDX, 0x0f01); /* set/reset enable */
545 outw(GDCIDX, 0xff08); /* bit mask */
546 outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
547 line_width = scp->sc->adp->va_line_width;
548 lines = scp->ysize*scp->font_size;
549 p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
551 for (i = 0; i < lines; ++i) {
552 bzero_io((void *)p, scp->xsize);
555 outw(GDCIDX, 0x0000); /* set/reset */
556 outw(GDCIDX, 0x0001); /* set/reset enable */
560 vga_pxlborder_direct(scr_stat *scp, int color)
571 line_width = scp->sc->adp->va_line_width;
572 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
575 s = scp->sc->adp->va_window;
576 e = s + line_width * scp->yoff * scp->font_size;
578 for (f = s; f < e; f += pixel_size)
579 vga_drawpxl(f, color);
582 y = (scp->yoff + scp->ysize) * scp->font_size;
584 if (scp->ypixel > y) {
585 s = scp->sc->adp->va_window + line_width * y;
586 e = s + line_width * (scp->ypixel - y);
588 for (f = s; f < e; f += pixel_size)
589 vga_drawpxl(f, color);
592 y = scp->yoff * scp->font_size;
593 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
595 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
597 s = scp->sc->adp->va_window + line_width * (y + i);
598 e = s + scp->xoff * 8 * pixel_size;
600 for (f = s; f < e; f += pixel_size)
601 vga_drawpxl(f, color);
605 s = scp->sc->adp->va_window + line_width * (y + i) +
606 scp->xoff * 8 * pixel_size +
607 scp->xsize * 8 * pixel_size;
608 e = s + x * 8 * pixel_size;
610 for (f = s; f < e; f += pixel_size)
611 vga_drawpxl(f, color);
617 vga_pxlborder_planar(scr_stat *scp, int color)
625 vidd_set_border(scp->sc->adp, color);
627 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
628 outw(GDCIDX, 0x0003); /* data rotate/function select */
629 outw(GDCIDX, 0x0f01); /* set/reset enable */
630 outw(GDCIDX, 0xff08); /* bit mask */
631 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
632 line_width = scp->sc->adp->va_line_width;
633 p = scp->sc->adp->va_window;
635 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
636 y = (scp->yoff + scp->ysize)*scp->font_size;
638 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
639 y = scp->yoff*scp->font_size;
640 x = scp->xpixel/8 - scp->xoff - scp->xsize;
641 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
643 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
645 bzero_io((void *)(p + line_width*(y + i)
646 + scp->xoff + scp->xsize), x);
648 outw(GDCIDX, 0x0000); /* set/reset */
649 outw(GDCIDX, 0x0001); /* set/reset enable */
653 vga_egadraw(scr_stat *scp, int from, int count, int flip)
665 line_width = scp->sc->adp->va_line_width;
667 d = VIDEO_MEMORY_POS(scp, from, 1);
669 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
670 outw(GDCIDX, 0x0003); /* data rotate/function select */
671 outw(GDCIDX, 0x0f01); /* set/reset enable */
673 if (from + count > scp->xsize*scp->ysize)
674 count = scp->xsize*scp->ysize - from;
675 for (i = from; count-- > 0; ++i) {
676 a = sc_vtb_geta(&scp->vtb, i);
678 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
679 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
682 col2 = (a & 0xf000) >> 4;
684 /* set background color in EGA/VGA latch */
687 outw(GDCIDX, bg | 0x00); /* set/reset */
688 outw(GDCIDX, 0xff08); /* bit mask */
690 c = readb(d); /* set bg color in the latch */
692 /* foreground color */
693 outw(GDCIDX, col1 | 0x00); /* set/reset */
695 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
696 for (j = 0; j < scp->font_size; ++j, ++f) {
697 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
702 if ((i % scp->xsize) == scp->xsize - 1)
704 + (scp->font_size - 1)*line_width;
706 outw(GDCIDX, 0x0000); /* set/reset */
707 outw(GDCIDX, 0x0001); /* set/reset enable */
708 outw(GDCIDX, 0xff08); /* bit mask */
712 vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
717 u_short col1, col2, color;
718 int line_width, pixel_size;
722 line_width = scp->sc->adp->va_line_width;
723 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
725 d = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
727 if (from + count > scp->xsize * scp->ysize)
728 count = scp->xsize * scp->ysize - from;
730 for (i = from; count-- > 0; ++i) {
731 a = sc_vtb_geta(&scp->vtb, i);
734 col1 = (((a & 0x7000) >> 4) | (a & 0x0800)) >> 8;
735 col2 = (((a & 0x8000) >> 4) | (a & 0x0700)) >> 8;
737 col1 = (a & 0x0f00) >> 8;
738 col2 = (a & 0xf000) >> 12;
742 f = &(scp->font[sc_vtb_getc(&scp->vtb, i) * scp->font_size]);
744 for (j = 0; j < scp->font_size; ++j, ++f) {
745 for (k = 0; k < 8; ++k) {
746 color = *f & (1 << (7 - k)) ? col1 : col2;
747 vga_drawpxl(e + pixel_size * k, color);
755 if ((i % scp->xsize) == scp->xsize - 1)
756 d += scp->xoff * 16 * pixel_size +
757 (scp->font_size - 1) * line_width;
762 vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
774 d = VIDEO_MEMORY_POS(scp, from, 1);
776 line_width = scp->sc->adp->va_line_width;
778 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
779 outw(GDCIDX, 0x0003); /* data rotate/function select */
780 outw(GDCIDX, 0x0f01); /* set/reset enable */
781 outw(GDCIDX, 0xff08); /* bit mask */
783 if (from + count > scp->xsize*scp->ysize)
784 count = scp->xsize*scp->ysize - from;
785 for (i = from; count-- > 0; ++i) {
786 a = sc_vtb_geta(&scp->vtb, i);
788 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
789 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
792 col2 = (a & 0xf000) >> 4;
794 /* set background color in EGA/VGA latch */
797 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
798 outw(GDCIDX, bg | 0x00); /* set/reset */
800 c = readb(d); /* set bg color in the latch */
801 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
803 /* foreground color */
804 outw(GDCIDX, col1 | 0x00); /* set/reset */
806 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
807 for (j = 0; j < scp->font_size; ++j, ++f) {
812 if ((i % scp->xsize) == scp->xsize - 1)
814 + (scp->font_size - 1)*line_width;
816 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
817 outw(GDCIDX, 0x0000); /* set/reset */
818 outw(GDCIDX, 0x0001); /* set/reset enable */
822 vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
824 if (base < 0 || base >= scp->font_size)
826 /* the caller may set height <= 0 in order to disable the cursor */
828 scp->curs_attr.base = base;
829 scp->curs_attr.height = height;
834 draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
838 int line_width, pixel_size;
840 int col1, col2, color;
844 line_width = scp->sc->adp->va_line_width;
845 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
847 d = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
848 (scp->font_size - scp->curs_attr.base - 1) * line_width;
850 a = sc_vtb_geta(&scp->vtb, at);
853 col1 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
854 col2 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
856 col1 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
857 col2 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
860 f = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
861 scp->font_size - scp->curs_attr.base - 1]);
863 height = imin(scp->curs_attr.height, scp->font_size);
865 for (i = 0; i < height; ++i, --f) {
866 for (j = 0; j < 8; ++j) {
867 color = *f & (1 << (7 - j)) ? col1 : col2;
868 vga_drawpxl(d + pixel_size * j, color);
876 draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
887 line_width = scp->sc->adp->va_line_width;
889 d = VIDEO_MEMORY_POS(scp, at, 1) +
890 (scp->font_size - scp->curs_attr.base - 1) * line_width;
892 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
893 outw(GDCIDX, 0x0003); /* data rotate/function select */
894 outw(GDCIDX, 0x0f01); /* set/reset enable */
895 /* set background color in EGA/VGA latch */
896 a = sc_vtb_geta(&scp->vtb, at);
898 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
900 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
901 outw(GDCIDX, col | 0x00); /* set/reset */
902 outw(GDCIDX, 0xff08); /* bit mask */
904 c = readb(d); /* set bg color in the latch */
905 /* foreground color */
907 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
909 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
910 outw(GDCIDX, col | 0x00); /* set/reset */
911 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
912 + scp->font_size - scp->curs_attr.base - 1]);
913 height = imin(scp->curs_attr.height, scp->font_size);
914 for (i = 0; i < height; ++i, --f) {
915 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
919 outw(GDCIDX, 0x0000); /* set/reset */
920 outw(GDCIDX, 0x0001); /* set/reset enable */
921 outw(GDCIDX, 0xff08); /* bit mask */
924 static int pxlblinkrate = 0;
927 vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
929 if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
934 scp->status |= VR_CURSOR_ON;
935 draw_pxlcursor_direct(scp, at, on, flip);
936 } else if (++pxlblinkrate & 4) {
938 scp->status ^= VR_CURSOR_ON;
939 draw_pxlcursor_direct(scp, at,
940 scp->status & VR_CURSOR_ON,
944 if (scp->status & VR_CURSOR_ON)
945 draw_pxlcursor_direct(scp, at, on, flip);
946 scp->status &= ~VR_CURSOR_ON;
949 scp->status |= VR_CURSOR_BLINK;
951 scp->status &= ~VR_CURSOR_BLINK;
955 vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
957 if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
962 scp->status |= VR_CURSOR_ON;
963 draw_pxlcursor_planar(scp, at, on, flip);
964 } else if (++pxlblinkrate & 4) {
966 scp->status ^= VR_CURSOR_ON;
967 draw_pxlcursor_planar(scp, at,
968 scp->status & VR_CURSOR_ON,
972 if (scp->status & VR_CURSOR_ON)
973 draw_pxlcursor_planar(scp, at, on, flip);
974 scp->status &= ~VR_CURSOR_ON;
977 scp->status |= VR_CURSOR_BLINK;
979 scp->status &= ~VR_CURSOR_BLINK;
983 vga_pxlblink_direct(scr_stat *scp, int at, int flip)
985 if (!(scp->status & VR_CURSOR_BLINK))
987 if (!(++pxlblinkrate & 4))
990 scp->status ^= VR_CURSOR_ON;
991 draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
995 vga_pxlblink_planar(scr_stat *scp, int at, int flip)
997 if (!(scp->status & VR_CURSOR_BLINK))
999 if (!(++pxlblinkrate & 4))
1002 scp->status ^= VR_CURSOR_ON;
1003 draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
1006 #ifndef SC_NO_CUTPASTE
1009 draw_pxlmouse_planar(scr_stat *scp, int x, int y)
1018 line_width = scp->sc->adp->va_line_width;
1019 xoff = (x - scp->xoff*8)%8;
1020 yoff = y - (y/line_width)*line_width;
1021 ymax = imin(y + 16, scp->ypixel);
1023 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
1024 outw(GDCIDX, 0x0001); /* set/reset enable */
1025 outw(GDCIDX, 0x0002); /* color compare */
1026 outw(GDCIDX, 0x0007); /* color don't care */
1027 outw(GDCIDX, 0xff08); /* bit mask */
1028 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
1029 p = scp->sc->adp->va_window + line_width*y + x/8;
1030 if (x < scp->xpixel - 8) {
1031 for (i = y, j = 0; i < ymax; ++i, ++j) {
1032 m = ~(mouse_and_mask[j] >> xoff);
1033 #if defined(__i386__) || defined(__amd64__)
1034 *(u_char *)p &= m >> 8;
1035 *(u_char *)(p + 1) &= m;
1037 writeb(p, readb(p) & (m >> 8));
1038 writeb(p + 1, readb(p + 1) & (m >> 8));
1044 for (i = y, j = 0; i < ymax; ++i, ++j) {
1045 m = ~(mouse_and_mask[j] >> xoff);
1046 #if defined(__i386__) || defined(__amd64__)
1049 writeb(p, readb(p) & (m >> 8));
1054 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
1055 p = scp->sc->adp->va_window + line_width*y + x/8;
1056 if (x < scp->xpixel - 8) {
1057 for (i = y, j = 0; i < ymax; ++i, ++j) {
1058 m = mouse_or_mask[j] >> xoff;
1059 #if defined(__i386__) || defined(__amd64__)
1060 *(u_char *)p &= m >> 8;
1061 *(u_char *)(p + 1) &= m;
1063 writeb(p, readb(p) & (m >> 8));
1064 writeb(p + 1, readb(p + 1) & (m >> 8));
1069 for (i = y, j = 0; i < ymax; ++i, ++j) {
1070 m = mouse_or_mask[j] >> xoff;
1071 #if defined(__i386__) || defined(__amd64__)
1074 writeb(p, readb(p) & (m >> 8));
1079 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1080 outw(GDCIDX, 0x0003); /* data rotate/function select */
1084 remove_pxlmouse_planar(scr_stat *scp, int x, int y)
1093 /* erase the mouse cursor image */
1094 col = x/8 - scp->xoff;
1095 row = y/scp->font_size - scp->yoff;
1096 pos = row*scp->xsize + col;
1097 i = (col < scp->xsize - 1) ? 2 : 1;
1098 (*scp->rndr->draw)(scp, pos, i, FALSE);
1099 if (row < scp->ysize - 1)
1100 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
1102 /* paint border if necessary */
1103 line_width = scp->sc->adp->va_line_width;
1104 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1105 outw(GDCIDX, 0x0003); /* data rotate/function select */
1106 outw(GDCIDX, 0x0f01); /* set/reset enable */
1107 outw(GDCIDX, 0xff08); /* bit mask */
1108 outw(GDCIDX, (scp->border << 8) | 0x00); /* set/reset */
1109 if (row == scp->ysize - 1) {
1110 i = (scp->ysize + scp->yoff)*scp->font_size;
1111 ymax = imin(i + scp->font_size, scp->ypixel);
1112 p = scp->sc->adp->va_window + i*line_width + scp->xoff + col;
1113 if (col < scp->xsize - 1) {
1114 for (; i < ymax; ++i) {
1120 for (; i < ymax; ++i) {
1126 if ((col == scp->xsize - 1) && (scp->xoff > 0)) {
1127 i = (row + scp->yoff)*scp->font_size;
1128 ymax = imin(i + scp->font_size*2, scp->ypixel);
1129 p = scp->sc->adp->va_window + i*line_width
1130 + scp->xoff + scp->xsize;
1131 for (; i < ymax; ++i) {
1136 outw(GDCIDX, 0x0000); /* set/reset */
1137 outw(GDCIDX, 0x0001); /* set/reset enable */
1141 vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
1144 int line_width, pixel_size;
1146 static int x_old = 0, xend_old = 0;
1147 static int y_old = 0, yend_old = 0;
1156 bpp = scp->sc->adp->va_info.vi_depth;
1158 if ((bpp == 16) && (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5))
1161 line_width = scp->sc->adp->va_line_width;
1162 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
1164 xend = imin(x + 16, scp->xpixel);
1165 yend = imin(y + 16, scp->ypixel);
1167 p = scp->sc->adp->va_window + y_old * line_width + x_old * pixel_size;
1169 for (i = 0; i < (yend_old - y_old); i++) {
1170 for (j = (xend_old - x_old - 1); j >= 0; j--) {
1173 u32 = (uint32_t*)(p + j * pixel_size);
1174 writel(u32, mouse_buf32[i * 16 + j]);
1179 u16 = (uint16_t*)(p + j * pixel_size);
1180 writew(u16, mouse_buf16[i * 16 + j]);
1188 p = scp->sc->adp->va_window + y * line_width + x * pixel_size;
1190 for (i = 0; i < (yend - y); i++) {
1191 for (j = (xend - x - 1); j >= 0; j--) {
1194 u32 = (uint32_t*)(p + j * pixel_size);
1195 mouse_buf32[i * 16 + j] = *u32;
1196 if (mouse_or_mask[i] & (1 << (15 - j)))
1197 writel(u32, vga_palette32[15]);
1198 else if (mouse_and_mask[i] & (1 << (15 - j)))
1202 u16 = (uint16_t*)(p + j * pixel_size);
1203 mouse_buf16[i * 16 + j] = *u16;
1204 if (mouse_or_mask[i] & (1 << (15 - j)))
1205 writew(u16, vga_palette16[15]);
1206 else if (mouse_and_mask[i] & (1 << (15 - j)))
1210 u16 = (uint16_t*)(p + j * pixel_size);
1211 mouse_buf16[i * 16 + j] = *u16;
1212 if (mouse_or_mask[i] & (1 << (15 - j)))
1213 writew(u16, vga_palette15[15]);
1214 else if (mouse_and_mask[i] & (1 << (15 - j)))
1230 vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
1233 draw_pxlmouse_planar(scp, x, y);
1235 remove_pxlmouse_planar(scp, x, y);
1238 #endif /* SC_NO_CUTPASTE */
1239 #endif /* SC_PIXEL_MODE */
1241 #ifndef SC_NO_MODE_CHANGE
1243 /* graphics mode renderer */
1246 vga_grborder(scr_stat *scp, int color)
1248 vidd_set_border(scp->sc->adp, color);