4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
7 * This code is derived from software contributed to The DragonFly Project
8 * by Sascha Wildner <saw@online.de>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer as
15 * the first lines of this file unmodified.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: src/sys/dev/syscons/scvgarndr.c,v 1.5.2.3 2001/07/28 12:51:47 yokota Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/scvgarndr.c,v 1.17 2008/08/10 19:45:01 swildner Exp $
35 #include "opt_syscons.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/thread.h>
42 #include <sys/thread2.h>
44 #include <machine/console.h>
46 #include <dev/video/fb/fbreg.h>
47 #include <dev/video/fb/vgareg.h>
50 #include <bus/isa/isareg.h>
53 * XXX: this still doesn't quite work with tokens (mainly vga_txtcursor*),
54 * so temporarily disable tokens here.
57 #define lwkt_gettoken(x)
58 #define lwkt_reltoken(x)
61 static vr_draw_border_t vga_txtborder;
62 static vr_draw_t vga_txtdraw;
63 static vr_set_cursor_t vga_txtcursor_shape;
64 static vr_draw_cursor_t vga_txtcursor;
65 static vr_blink_cursor_t vga_txtblink;
66 #ifndef SC_NO_CUTPASTE
67 static vr_draw_mouse_t vga_txtmouse;
69 #define vga_txtmouse (vr_draw_mouse_t *)vga_nop
73 static vr_draw_border_t vga_pxlborder_direct;
74 static vr_draw_border_t vga_pxlborder_packed;
75 static vr_draw_border_t vga_pxlborder_planar;
76 static vr_draw_t vga_vgadraw_direct;
77 static vr_draw_t vga_vgadraw_packed;
78 static vr_draw_t vga_vgadraw_planar;
79 static vr_set_cursor_t vga_pxlcursor_shape;
80 static vr_draw_cursor_t vga_pxlcursor_direct;
81 static vr_draw_cursor_t vga_pxlcursor_packed;
82 static vr_draw_cursor_t vga_pxlcursor_planar;
83 static vr_blink_cursor_t vga_pxlblink_direct;
84 static vr_blink_cursor_t vga_pxlblink_packed;
85 static vr_blink_cursor_t vga_pxlblink_planar;
86 #ifndef SC_NO_CUTPASTE
87 static vr_draw_mouse_t vga_pxlmouse_direct;
88 static vr_draw_mouse_t vga_pxlmouse_packed;
89 static vr_draw_mouse_t vga_pxlmouse_planar;
91 #define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop
92 #define vga_pxlmouse_packed (vr_draw_mouse_t *)vga_nop
93 #define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop
95 #endif /* SC_PIXEL_MODE */
97 #ifndef SC_NO_MODE_CHANGE
98 static vr_draw_border_t vga_grborder;
101 static void vga_nop(scr_stat *scp, ...);
103 static sc_rndr_sw_t txtrndrsw = {
111 RENDERER(vga, V_INFO_MM_TEXT, txtrndrsw, vga_set);
114 static sc_rndr_sw_t directrndrsw = {
115 vga_pxlborder_direct,
118 vga_pxlcursor_direct,
122 RENDERER(vga, V_INFO_MM_DIRECT, directrndrsw, vga_set);
124 static sc_rndr_sw_t packedrndrsw = {
125 vga_pxlborder_packed,
128 vga_pxlcursor_packed,
132 RENDERER(vga, V_INFO_MM_PACKED, packedrndrsw, vga_set);
134 static sc_rndr_sw_t planarrndrsw = {
135 vga_pxlborder_planar,
138 vga_pxlcursor_planar,
142 RENDERER(vga, V_INFO_MM_PLANAR, planarrndrsw, vga_set);
143 #endif /* SC_PIXEL_MODE */
145 #ifndef SC_NO_MODE_CHANGE
146 static sc_rndr_sw_t grrndrsw = {
148 (vr_draw_t *)vga_nop,
149 (vr_set_cursor_t *)vga_nop,
150 (vr_draw_cursor_t *)vga_nop,
151 (vr_blink_cursor_t *)vga_nop,
152 (vr_draw_mouse_t *)vga_nop,
154 RENDERER(vga, V_INFO_MM_OTHER, grrndrsw, vga_set);
155 #endif /* SC_NO_MODE_CHANGE */
157 RENDERER_MODULE(vga, vga_set);
159 #ifndef SC_NO_CUTPASTE
160 static u_short mouse_and_mask[16] = {
161 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
162 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
164 static u_short mouse_or_mask[16] = {
165 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
166 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
171 vga_nop(scr_stat *scp, ...)
175 /* text mode renderer */
178 vga_txtborder(scr_stat *scp, int color)
180 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
184 vga_txtdraw(scr_stat *scp, int from, int count, int flip)
190 if (from + count > scp->xsize*scp->ysize)
191 count = scp->xsize*scp->ysize - from;
194 for (p = scp->scr.vtb_buffer + from; count-- > 0; ++from) {
195 c = sc_vtb_getc(&scp->vtb, from);
196 a = sc_vtb_geta(&scp->vtb, from);
197 a = (a & 0x8800) | ((a & 0x7000) >> 4)
198 | ((a & 0x0700) << 4);
199 p = sc_vtb_putchar(&scp->scr, p, c, a);
202 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
207 vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
209 if (base < 0 || base >= scp->font_size)
212 /* the caller may set height <= 0 in order to disable the cursor */
214 scp->cursor_base = base;
215 scp->cursor_height = height;
217 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
219 scp->font_size, blink);
224 draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
229 scp->cursor_saveunder_char = c;
230 scp->cursor_saveunder_attr = a;
232 #ifndef SC_NO_FONT_LOADING
233 if (sc->flags & SC_CHAR_CURSOR) {
238 if (scp->font_size < 14) {
241 } else if (scp->font_size >= 16) {
248 if (scp->cursor_base >= h) {
249 lwkt_reltoken(&tty_token);
254 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
255 bcopy(font + c*h, font + sc->cursor_char*h, h);
256 font = font + sc->cursor_char*h;
257 for (i = imax(h - scp->cursor_base - scp->cursor_height, 0);
258 i < h - scp->cursor_base; ++i) {
261 sc->font_loading_in_progress = TRUE;
263 (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, font,
265 sc->font_loading_in_progress = FALSE;
266 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
268 #endif /* SC_NO_FONT_LOADING */
270 if ((a & 0x7000) == 0x7000) {
272 if ((a & 0x0700) == 0)
276 if ((a & 0x0700) == 0x0700)
281 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
282 sc_vtb_putc(&scp->scr, at, c, a);
287 vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
289 video_adapter_t *adp;
292 if (scp->cursor_height <= 0) /* the text cursor is disabled */
297 scp->status |= VR_CURSOR_BLINK;
299 scp->status |= VR_CURSOR_ON;
300 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
304 if (scp->status & VR_CURSOR_ON)
305 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
307 scp->status &= ~VR_CURSOR_ON;
310 scp->status &= ~VR_CURSOR_BLINK;
312 scp->status |= VR_CURSOR_ON;
313 draw_txtcharcursor(scp, at,
314 sc_vtb_getc(&scp->scr, at),
315 sc_vtb_geta(&scp->scr, at),
318 cursor_attr = scp->cursor_saveunder_attr;
320 cursor_attr = (cursor_attr & 0x8800)
321 | ((cursor_attr & 0x7000) >> 4)
322 | ((cursor_attr & 0x0700) << 4);
323 if (scp->status & VR_CURSOR_ON)
324 sc_vtb_putc(&scp->scr, at,
325 scp->cursor_saveunder_char,
327 scp->status &= ~VR_CURSOR_ON;
333 vga_txtblink(scr_stat *scp, int at, int flip)
337 #ifndef SC_NO_CUTPASTE
340 draw_txtmouse(scr_stat *scp, int x, int y)
342 #ifndef SC_ALT_MOUSE_IMAGE
343 if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
344 u_char font_buf[128];
348 int xoffset, yoffset;
351 /* prepare mousepointer char's bitmaps */
352 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
353 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
354 &font_buf[0], scp->font_size);
355 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
356 &font_buf[32], scp->font_size);
358 + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
359 &font_buf[64], scp->font_size);
361 + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
362 &font_buf[96], scp->font_size);
363 for (i = 0; i < scp->font_size; ++i) {
364 cursor[i] = font_buf[i]<<8 | font_buf[i+32];
365 cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
368 /* now and-or in the mousepointer image */
370 yoffset = y%scp->font_size;
371 for (i = 0; i < 16; ++i) {
372 cursor[i + yoffset] =
373 (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
374 | (mouse_or_mask[i] >> xoffset);
376 for (i = 0; i < scp->font_size; ++i) {
377 font_buf[i] = (cursor[i] & 0xff00) >> 8;
378 font_buf[i + 32] = cursor[i] & 0xff;
379 font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
380 font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
384 /* wait for vertical retrace to avoid jitter on some videocards */
385 while (!(inb(CRTC + 6) & 0x08)) /* idle */ ;
387 c = scp->sc->mouse_char;
388 (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
391 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
392 /* FIXME: may be out of range! */
393 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
394 sc_vtb_geta(&scp->scr, pos + scp->xsize));
395 if (x < (scp->xsize - 1)*8) {
396 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
397 sc_vtb_geta(&scp->scr, pos + 1));
398 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
399 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
402 #endif /* SC_ALT_MOUSE_IMAGE */
404 /* Red, magenta and brown are mapped to green to to keep it readable */
405 static const int col_conv[16] = {
406 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
412 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
413 a = sc_vtb_geta(&scp->scr, pos);
414 if (scp->sc->adp->va_flags & V_ADP_COLOR)
415 color = (col_conv[(a & 0xf000) >> 12] << 12)
416 | ((a & 0x0f00) | 0x0800);
418 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
419 sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
425 remove_txtmouse(scr_stat *scp, int x, int y)
430 vga_txtmouse(scr_stat *scp, int x, int y, int on)
433 draw_txtmouse(scp, x, y);
435 remove_txtmouse(scp, x, y);
438 #endif /* SC_NO_CUTPASTE */
442 /* pixel (raster text) mode renderer */
445 vga_pxlborder_direct(scr_stat *scp, int color)
448 int line_width, pixel_size;
450 vm_offset_t draw_pos, draw_end, p;
452 line_width = scp->sc->adp->va_line_width;
453 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
455 for (i = 0; i < 4 / pixel_size; ++i)
456 u32 += scp->ega_palette[color] << (i * 8 * pixel_size);
459 draw_pos = scp->sc->adp->va_window;
460 draw_end = draw_pos + line_width * scp->yoff * scp->font_size;
462 for (p = draw_pos; p < draw_end; p += 4)
466 y = (scp->yoff + scp->ysize) * scp->font_size;
468 if (scp->ypixel > y) {
469 draw_pos = scp->sc->adp->va_window + line_width * y;
470 draw_end = draw_pos + line_width * (scp->ypixel - y);
472 for (p = draw_pos; p < draw_end; p += 4)
476 y = scp->yoff * scp->font_size;
477 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
479 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
481 draw_pos = scp->sc->adp->va_window +
482 line_width * (y + i);
483 draw_end = draw_pos + scp->xoff * 8 * pixel_size;
485 for (p = draw_pos; p < draw_end; p += 4)
490 draw_pos = scp->sc->adp->va_window +
491 line_width * (y + i) +
492 scp->xoff * 8 * pixel_size +
493 scp->xsize * 8 * pixel_size;
494 draw_end = draw_pos + x * 8 * pixel_size;
496 for (p = draw_pos; p < draw_end; p += 4)
503 vga_pxlborder_packed(scr_stat *scp, int color)
508 vm_offset_t draw_pos, draw_end, p;
510 line_width = scp->sc->adp->va_line_width;
511 u32 = (color << 24) + (color << 16) + (color << 8) + color;
514 draw_pos = scp->sc->adp->va_window;
515 draw_end = draw_pos + line_width * scp->yoff * scp->font_size;
517 for (p = draw_pos; p < draw_end; p += 4)
521 y = (scp->yoff + scp->ysize) * scp->font_size;
523 if (scp->ypixel > y) {
524 draw_pos = scp->sc->adp->va_window + line_width * y;
525 draw_end = draw_pos + line_width * (scp->ypixel - y);
527 for (p = draw_pos; p < draw_end; p += 4)
531 y = scp->yoff * scp->font_size;
532 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
534 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
536 draw_pos = scp->sc->adp->va_window +
537 line_width * (y + i);
538 draw_end = draw_pos + scp->xoff * 8;
540 for (p = draw_pos; p < draw_end; p += 4)
545 draw_pos = scp->sc->adp->va_window +
546 line_width * (y + i) + scp->xoff * 8 +
548 draw_end = draw_pos + x * 8;
550 for (p = draw_pos; p < draw_end; p += 4)
557 vga_pxlborder_planar(scr_stat *scp, int color)
565 lwkt_gettoken(&tty_token);
567 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
569 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
570 outw(GDCIDX, 0x0003); /* data rotate/function select */
571 outw(GDCIDX, 0x0f01); /* set/reset enable */
572 outw(GDCIDX, 0xff08); /* bit mask */
573 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
574 line_width = scp->sc->adp->va_line_width;
575 p = scp->sc->adp->va_window;
577 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
578 y = (scp->yoff + scp->ysize)*scp->font_size;
580 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
581 y = scp->yoff*scp->font_size;
582 x = scp->xpixel/8 - scp->xoff - scp->xsize;
583 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
585 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
587 bzero_io((void *)(p + line_width*(y + i)
588 + scp->xoff + scp->xsize), x);
590 outw(GDCIDX, 0x0000); /* set/reset */
591 outw(GDCIDX, 0x0001); /* set/reset enable */
592 lwkt_reltoken(&tty_token);
596 vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
598 int line_width, pixel_size;
599 int a, i, j, k, l, pos;
600 uint32_t fg, bg, u32;
601 unsigned char *char_data;
602 vm_offset_t draw_pos, p;
604 line_width = scp->sc->adp->va_line_width;
605 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
607 draw_pos = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
609 if (from + count > scp->xsize * scp->ysize)
610 count = scp->xsize * scp->ysize - from;
612 for (i = from; count-- > 0; ++i) {
613 a = sc_vtb_geta(&scp->vtb, i);
616 fg = scp->ega_palette[(((a & 0x7000) >> 4) |
618 bg = scp->ega_palette[(((a & 0x8000) >> 4) |
621 fg = scp->ega_palette[(a & 0x0f00) >> 8];
622 bg = scp->ega_palette[(a & 0xf000) >> 12];
626 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, i) *
629 for (j = 0; j < scp->font_size; ++j, ++char_data) {
632 for (k = 0; k < 2 * pixel_size; ++k) {
635 for (l = 0; l < 4 / pixel_size; ++l) {
636 u32 += (*char_data & (1 << pos--) ?
637 fg : bg) << (l * 8 * pixel_size);
644 p += line_width - 8 * pixel_size;
647 draw_pos += 8 * pixel_size;
649 if ((i % scp->xsize) == scp->xsize - 1)
650 draw_pos += scp->xoff * 16 * pixel_size +
651 (scp->font_size - 1) * line_width;
656 vga_vgadraw_packed(scr_stat *scp, int from, int count, int flip)
660 uint32_t fg, bg, u32;
661 unsigned char *char_data;
662 vm_offset_t draw_pos, p;
664 line_width = scp->sc->adp->va_line_width;
666 draw_pos = VIDEO_MEMORY_POS(scp, from, 8);
668 if (from + count > scp->xsize * scp->ysize)
669 count = scp->xsize * scp->ysize - from;
671 for (i = from; count-- > 0; ++i) {
672 a = sc_vtb_geta(&scp->vtb, i);
675 fg = ((a & 0xf000) >> 4) >> 8;
676 bg = (a & 0x0f00) >> 8;
678 fg = (a & 0x0f00) >> 8;
679 bg = ((a & 0xf000) >> 4) >> 8;
683 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, i) *
686 for (j = 0; j < scp->font_size; ++j, ++char_data) {
687 u32 = ((*char_data & 1 ? fg : bg) << 24) +
688 ((*char_data & 2 ? fg : bg) << 16) +
689 ((*char_data & 4 ? fg : bg) << 8) +
690 (*char_data & 8 ? fg : bg);
693 u32 = ((*char_data & 16 ? fg : bg) << 24) +
694 ((*char_data & 32 ? fg : bg) << 16) +
695 ((*char_data & 64 ? fg : bg) << 8) +
696 (*char_data & 128 ? fg : bg);
704 if ((i % scp->xsize) == scp->xsize - 1)
705 draw_pos += scp->xoff * 16 +
706 (scp->font_size - 1) * line_width;
711 vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
723 d = VIDEO_MEMORY_POS(scp, from, 1);
725 line_width = scp->sc->adp->va_line_width;
727 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
728 outw(GDCIDX, 0x0003); /* data rotate/function select */
729 outw(GDCIDX, 0x0f01); /* set/reset enable */
730 outw(GDCIDX, 0xff08); /* bit mask */
732 if (from + count > scp->xsize*scp->ysize)
733 count = scp->xsize*scp->ysize - from;
734 for (i = from; count-- > 0; ++i) {
735 a = sc_vtb_geta(&scp->vtb, i);
737 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
738 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
741 col2 = (a & 0xf000) >> 4;
743 /* set background color in EGA/VGA latch */
746 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
747 outw(GDCIDX, bg | 0x00); /* set/reset */
749 c = readb(d); /* set bg color in the latch */
750 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
752 /* foreground color */
753 outw(GDCIDX, col1 | 0x00); /* set/reset */
755 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
756 for (j = 0; j < scp->font_size; ++j, ++f) {
761 if ((i % scp->xsize) == scp->xsize - 1)
763 + (scp->font_size - 1)*line_width;
765 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
766 outw(GDCIDX, 0x0000); /* set/reset */
767 outw(GDCIDX, 0x0001); /* set/reset enable */
771 vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
773 if (base < 0 || base >= scp->font_size)
775 /* the caller may set height <= 0 in order to disable the cursor */
777 scp->cursor_base = base;
778 scp->cursor_height = height;
783 draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
785 int line_width, pixel_size, height;
787 uint32_t fg, bg, u32;
788 unsigned char *char_data;
789 vm_offset_t draw_pos;
791 line_width = scp->sc->adp->va_line_width;
792 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
794 draw_pos = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
795 (scp->font_size - scp->cursor_base - 1) * line_width;
797 a = sc_vtb_geta(&scp->vtb, at);
800 fg = scp->ega_palette[((on) ? (a & 0x0f00) :
801 ((a & 0xf000) >> 4)) >> 8];
802 bg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
805 fg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
807 bg = scp->ega_palette[((on) ? (a & 0x0f00) :
808 ((a & 0xf000) >> 4)) >> 8];
811 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
812 scp->font_size - scp->cursor_base - 1]);
814 height = imin(scp->cursor_height, scp->font_size);
816 for (i = 0; i < height; ++i, --char_data) {
819 for (j = 0; j < 2 * pixel_size; ++j) {
822 for (k = 0; k < 4 / pixel_size; ++k) {
823 u32 += (*char_data & (1 << pos--) ?
824 fg : bg) << (k * 8 * pixel_size);
827 writel(draw_pos, u32);
831 draw_pos -= line_width + 8 * pixel_size;
836 draw_pxlcursor_packed(scr_stat *scp, int at, int on, int flip)
838 int line_width, height;
840 uint32_t fg, bg, u32;
841 unsigned char *char_data;
842 vm_offset_t draw_pos;
844 line_width = scp->sc->adp->va_line_width;
846 draw_pos = VIDEO_MEMORY_POS(scp, at, 8) +
847 (scp->font_size - scp->cursor_base - 1) * line_width;
849 a = sc_vtb_geta(&scp->vtb, at);
852 fg = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
853 bg = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
855 fg = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
856 bg = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
859 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
860 scp->font_size - scp->cursor_base - 1]);
862 height = imin(scp->cursor_height, scp->font_size);
864 for (i = 0; i < height; ++i, --char_data) {
865 u32 = ((*char_data & 1 ? fg : bg) << 24) +
866 ((*char_data & 2 ? fg : bg) << 16) +
867 ((*char_data & 4 ? fg : bg) << 8) +
868 (*char_data & 8 ? fg : bg);
869 writel(draw_pos + 4, u32);
871 u32 = ((*char_data & 16 ? fg : bg) << 24) +
872 ((*char_data & 32 ? fg : bg) << 16) +
873 ((*char_data & 64 ? fg : bg) << 8) +
874 (*char_data & 128 ? fg : bg);
875 writel(draw_pos, u32);
877 draw_pos -= line_width;
882 draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
893 line_width = scp->sc->adp->va_line_width;
895 d = VIDEO_MEMORY_POS(scp, at, 1) +
896 (scp->font_size - scp->cursor_base - 1) * line_width;
898 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
899 outw(GDCIDX, 0x0003); /* data rotate/function select */
900 outw(GDCIDX, 0x0f01); /* set/reset enable */
901 /* set background color in EGA/VGA latch */
902 a = sc_vtb_geta(&scp->vtb, at);
904 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
906 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
907 outw(GDCIDX, col | 0x00); /* set/reset */
908 outw(GDCIDX, 0xff08); /* bit mask */
910 c = readb(d); /* set bg color in the latch */
911 /* foreground color */
913 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
915 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
916 outw(GDCIDX, col | 0x00); /* set/reset */
917 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
918 + scp->font_size - scp->cursor_base - 1]);
919 height = imin(scp->cursor_height, scp->font_size);
920 for (i = 0; i < height; ++i, --f) {
921 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
925 outw(GDCIDX, 0x0000); /* set/reset */
926 outw(GDCIDX, 0x0001); /* set/reset enable */
927 outw(GDCIDX, 0xff08); /* bit mask */
930 static int pxlblinkrate = 0;
933 vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
935 if (scp->cursor_height <= 0) /* the text cursor is disabled */
940 scp->status |= VR_CURSOR_ON;
941 draw_pxlcursor_direct(scp, at, on, flip);
942 } else if (++pxlblinkrate & 4) {
944 scp->status ^= VR_CURSOR_ON;
945 draw_pxlcursor_direct(scp, at,
946 scp->status & VR_CURSOR_ON,
950 if (scp->status & VR_CURSOR_ON)
951 draw_pxlcursor_direct(scp, at, on, flip);
952 scp->status &= ~VR_CURSOR_ON;
955 scp->status |= VR_CURSOR_BLINK;
957 scp->status &= ~VR_CURSOR_BLINK;
961 vga_pxlcursor_packed(scr_stat *scp, int at, int blink, int on, int flip)
963 if (scp->cursor_height <= 0) /* the text cursor is disabled */
968 scp->status |= VR_CURSOR_ON;
969 draw_pxlcursor_packed(scp, at, on, flip);
970 } else if (++pxlblinkrate & 4) {
972 scp->status ^= VR_CURSOR_ON;
973 draw_pxlcursor_packed(scp, at,
974 scp->status & VR_CURSOR_ON,
978 if (scp->status & VR_CURSOR_ON)
979 draw_pxlcursor_packed(scp, at, on, flip);
980 scp->status &= ~VR_CURSOR_ON;
983 scp->status |= VR_CURSOR_BLINK;
985 scp->status &= ~VR_CURSOR_BLINK;
989 vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
991 if (scp->cursor_height <= 0) /* the text cursor is disabled */
996 scp->status |= VR_CURSOR_ON;
997 draw_pxlcursor_planar(scp, at, on, flip);
998 } else if (++pxlblinkrate & 4) {
1000 scp->status ^= VR_CURSOR_ON;
1001 draw_pxlcursor_planar(scp, at,
1002 scp->status & VR_CURSOR_ON,
1006 if (scp->status & VR_CURSOR_ON)
1007 draw_pxlcursor_planar(scp, at, on, flip);
1008 scp->status &= ~VR_CURSOR_ON;
1011 scp->status |= VR_CURSOR_BLINK;
1013 scp->status &= ~VR_CURSOR_BLINK;
1017 vga_pxlblink_direct(scr_stat *scp, int at, int flip)
1019 if (!(scp->status & VR_CURSOR_BLINK))
1021 if (!(++pxlblinkrate & 4))
1024 scp->status ^= VR_CURSOR_ON;
1025 draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
1029 vga_pxlblink_packed(scr_stat *scp, int at, int flip)
1031 if (!(scp->status & VR_CURSOR_BLINK))
1033 if (!(++pxlblinkrate & 4))
1036 scp->status ^= VR_CURSOR_ON;
1037 draw_pxlcursor_packed(scp, at, scp->status & VR_CURSOR_ON, flip);
1041 vga_pxlblink_planar(scr_stat *scp, int at, int flip)
1043 if (!(scp->status & VR_CURSOR_BLINK))
1045 if (!(++pxlblinkrate & 4))
1048 scp->status ^= VR_CURSOR_ON;
1049 draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
1052 #ifndef SC_NO_CUTPASTE
1055 draw_pxlmouse_direct(scr_stat *scp, int x, int y)
1057 int line_width, pixel_size;
1060 vm_offset_t draw_pos;
1062 line_width = scp->sc->adp->va_line_width;
1063 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
1065 xend = imin(x + 8, 8 * (scp->xoff + scp->xsize));
1066 yend = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
1068 draw_pos = scp->sc->adp->va_window + y * line_width + x * pixel_size;
1070 for (i = 0; i < (yend - y); i++) {
1071 for (j = (xend - x - 1); j >= 0; j--) {
1072 switch (scp->sc->adp->va_info.vi_depth) {
1074 if (mouse_or_mask[i] & 1 << (15 - j))
1075 writel(draw_pos + 4 * j,
1076 scp->ega_palette[15]);
1077 else if (mouse_and_mask[i] & 1 << (15 - j))
1078 writel(draw_pos + 4 * j,
1079 scp->ega_palette[0]);
1084 if (mouse_or_mask[i] & 1 << (15 - j))
1085 writew(draw_pos + 2 * j,
1086 scp->ega_palette[15]);
1087 else if (mouse_and_mask[i] & 1 << (15 - j))
1088 writew(draw_pos + 2 * j,
1089 scp->ega_palette[0]);
1094 draw_pos += line_width;
1099 draw_pxlmouse_packed(scr_stat *scp, int x, int y)
1104 vm_offset_t draw_pos;
1106 line_width = scp->sc->adp->va_line_width;
1108 xend = imin(8 * (scp->xoff + scp->xsize), imin(x + 16, scp->xpixel));
1109 yend = imin(scp->font_size * (scp->yoff + scp->ysize),
1110 imin(y + 16, scp->ypixel));
1112 draw_pos = scp->sc->adp->va_window + y * line_width + x;
1114 for (i = 0; i < (yend - y); i++) {
1115 for (j = (xend - x - 1); j >= 0; j--) {
1116 if (mouse_or_mask[i] & 1 << (15 - j))
1117 writeb(draw_pos + j, 15);
1118 else if (mouse_and_mask[i] & 1 << (15 - j))
1119 writeb(draw_pos + j, 0);
1122 draw_pos += line_width;
1127 draw_pxlmouse_planar(scr_stat *scp, int x, int y)
1136 line_width = scp->sc->adp->va_line_width;
1137 xoff = (x - scp->xoff*8)%8;
1138 ymax = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
1140 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
1141 outw(GDCIDX, 0x0001); /* set/reset enable */
1142 outw(GDCIDX, 0x0002); /* color compare */
1143 outw(GDCIDX, 0x0007); /* color don't care */
1144 outw(GDCIDX, 0xff08); /* bit mask */
1145 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
1146 p = scp->sc->adp->va_window + line_width*y + x/8;
1147 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
1148 for (i = y, j = 0; i < ymax; ++i, ++j) {
1149 m = ~(mouse_and_mask[j] >> xoff);
1150 *(u_char *)p &= m >> 8;
1151 *(u_char *)(p + 1) &= m;
1156 for (i = y, j = 0; i < ymax; ++i, ++j) {
1157 m = ~(mouse_and_mask[j] >> xoff);
1162 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
1163 p = scp->sc->adp->va_window + line_width*y + x/8;
1164 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
1165 for (i = y, j = 0; i < ymax; ++i, ++j) {
1166 m = mouse_or_mask[j] >> xoff;
1167 *(u_char *)p &= m >> 8;
1168 *(u_char *)(p + 1) &= m;
1172 for (i = y, j = 0; i < ymax; ++i, ++j) {
1173 m = mouse_or_mask[j] >> xoff;
1178 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1179 outw(GDCIDX, 0x0003); /* data rotate/function select */
1183 remove_pxlmouse(scr_stat *scp, int x, int y)
1189 /* erase the mouse cursor image */
1190 col = x/8 - scp->xoff;
1191 row = y/scp->font_size - scp->yoff;
1192 pos = row*scp->xsize + col;
1193 i = (col < scp->xsize - 1) ? 2 : 1;
1194 (*scp->rndr->draw)(scp, pos, i, FALSE);
1195 if (row < scp->ysize - 1)
1196 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
1200 vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
1203 draw_pxlmouse_direct(scp, x, y);
1205 remove_pxlmouse(scp, x, y);
1209 vga_pxlmouse_packed(scr_stat *scp, int x, int y, int on)
1212 draw_pxlmouse_packed(scp, x, y);
1214 remove_pxlmouse(scp, x, y);
1218 vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
1221 draw_pxlmouse_planar(scp, x, y);
1223 remove_pxlmouse(scp, x, y);
1226 #endif /* SC_NO_CUTPASTE */
1227 #endif /* SC_PIXEL_MODE */
1229 #ifndef SC_NO_MODE_CHANGE
1231 /* graphics mode renderer */
1234 vga_grborder(scr_stat *scp, int color)
1236 lwkt_gettoken(&tty_token);
1237 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
1238 lwkt_reltoken(&tty_token);