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.17 2008/08/10 19:45:01 swildner 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 static vr_draw_border_t vga_txtborder;
49 static vr_draw_t vga_txtdraw;
50 static vr_set_cursor_t vga_txtcursor_shape;
51 static vr_draw_cursor_t vga_txtcursor;
52 static vr_blink_cursor_t vga_txtblink;
53 #ifndef SC_NO_CUTPASTE
54 static vr_draw_mouse_t vga_txtmouse;
56 #define vga_txtmouse (vr_draw_mouse_t *)vga_nop
60 static vr_draw_border_t vga_pxlborder_direct;
61 static vr_draw_border_t vga_pxlborder_planar;
62 static vr_draw_t vga_vgadraw_direct;
63 static vr_draw_t vga_vgadraw_planar;
64 static vr_set_cursor_t vga_pxlcursor_shape;
65 static vr_draw_cursor_t vga_pxlcursor_direct;
66 static vr_draw_cursor_t vga_pxlcursor_planar;
67 static vr_blink_cursor_t vga_pxlblink_direct;
68 static vr_blink_cursor_t vga_pxlblink_planar;
69 #ifndef SC_NO_CUTPASTE
70 static vr_draw_mouse_t vga_pxlmouse_direct;
71 static vr_draw_mouse_t vga_pxlmouse_planar;
73 #define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop
74 #define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop
76 #endif /* SC_PIXEL_MODE */
78 #ifndef SC_NO_MODE_CHANGE
79 static vr_draw_border_t vga_grborder;
82 static void vga_nop(scr_stat *scp, ...);
84 static sc_rndr_sw_t txtrndrsw = {
92 RENDERER(vga, V_INFO_MM_TEXT, txtrndrsw, vga_set);
95 static sc_rndr_sw_t planarrndrsw = {
103 RENDERER(vga, V_INFO_MM_PLANAR, planarrndrsw, vga_set);
105 static sc_rndr_sw_t directrndrsw = {
106 vga_pxlborder_direct,
109 vga_pxlcursor_direct,
113 RENDERER(vga, V_INFO_MM_DIRECT, directrndrsw, vga_set);
114 #endif /* SC_PIXEL_MODE */
116 #ifndef SC_NO_MODE_CHANGE
117 static sc_rndr_sw_t grrndrsw = {
119 (vr_draw_t *)vga_nop,
120 (vr_set_cursor_t *)vga_nop,
121 (vr_draw_cursor_t *)vga_nop,
122 (vr_blink_cursor_t *)vga_nop,
123 (vr_draw_mouse_t *)vga_nop,
125 RENDERER(vga, V_INFO_MM_OTHER, grrndrsw, vga_set);
126 #endif /* SC_NO_MODE_CHANGE */
128 RENDERER_MODULE(vga, vga_set);
130 #ifndef SC_NO_CUTPASTE
131 static u_short mouse_and_mask[16] = {
132 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
133 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
135 static u_short mouse_or_mask[16] = {
136 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
137 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
142 vga_nop(scr_stat *scp, ...)
146 /* text mode renderer */
149 vga_txtborder(scr_stat *scp, int color)
151 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
155 vga_txtdraw(scr_stat *scp, int from, int count, int flip)
161 if (from + count > scp->xsize*scp->ysize)
162 count = scp->xsize*scp->ysize - from;
165 for (p = scp->scr.vtb_buffer + from; count-- > 0; ++from) {
166 c = sc_vtb_getc(&scp->vtb, from);
167 a = sc_vtb_geta(&scp->vtb, from);
168 a = (a & 0x8800) | ((a & 0x7000) >> 4)
169 | ((a & 0x0700) << 4);
170 p = sc_vtb_putchar(&scp->scr, p, c, a);
173 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
178 vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
180 if (base < 0 || base >= scp->font_size)
182 /* the caller may set height <= 0 in order to disable the cursor */
184 scp->cursor_base = base;
185 scp->cursor_height = height;
187 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
189 scp->font_size, blink);
193 draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
198 scp->cursor_saveunder_char = c;
199 scp->cursor_saveunder_attr = a;
201 #ifndef SC_NO_FONT_LOADING
202 if (sc->flags & SC_CHAR_CURSOR) {
207 if (scp->font_size < 14) {
210 } else if (scp->font_size >= 16) {
217 if (scp->cursor_base >= h)
221 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
222 bcopy(font + c*h, font + sc->cursor_char*h, h);
223 font = font + sc->cursor_char*h;
224 for (i = imax(h - scp->cursor_base - scp->cursor_height, 0);
225 i < h - scp->cursor_base; ++i) {
228 sc->font_loading_in_progress = TRUE;
230 (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, font,
232 sc->font_loading_in_progress = FALSE;
233 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
235 #endif /* SC_NO_FONT_LOADING */
237 if ((a & 0x7000) == 0x7000) {
239 if ((a & 0x0700) == 0)
243 if ((a & 0x0700) == 0x0700)
248 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
249 sc_vtb_putc(&scp->scr, at, c, a);
254 vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
256 video_adapter_t *adp;
259 if (scp->cursor_height <= 0) /* the text cursor is disabled */
264 scp->status |= VR_CURSOR_BLINK;
266 scp->status |= VR_CURSOR_ON;
267 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
271 if (scp->status & VR_CURSOR_ON)
272 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
274 scp->status &= ~VR_CURSOR_ON;
277 scp->status &= ~VR_CURSOR_BLINK;
279 scp->status |= VR_CURSOR_ON;
280 draw_txtcharcursor(scp, at,
281 sc_vtb_getc(&scp->scr, at),
282 sc_vtb_geta(&scp->scr, at),
285 cursor_attr = scp->cursor_saveunder_attr;
287 cursor_attr = (cursor_attr & 0x8800)
288 | ((cursor_attr & 0x7000) >> 4)
289 | ((cursor_attr & 0x0700) << 4);
290 if (scp->status & VR_CURSOR_ON)
291 sc_vtb_putc(&scp->scr, at,
292 scp->cursor_saveunder_char,
294 scp->status &= ~VR_CURSOR_ON;
300 vga_txtblink(scr_stat *scp, int at, int flip)
304 #ifndef SC_NO_CUTPASTE
307 draw_txtmouse(scr_stat *scp, int x, int y)
309 #ifndef SC_ALT_MOUSE_IMAGE
310 if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
311 u_char font_buf[128];
315 int xoffset, yoffset;
318 /* prepare mousepointer char's bitmaps */
319 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
320 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
321 &font_buf[0], scp->font_size);
322 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
323 &font_buf[32], scp->font_size);
325 + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
326 &font_buf[64], scp->font_size);
328 + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
329 &font_buf[96], scp->font_size);
330 for (i = 0; i < scp->font_size; ++i) {
331 cursor[i] = font_buf[i]<<8 | font_buf[i+32];
332 cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
335 /* now and-or in the mousepointer image */
337 yoffset = y%scp->font_size;
338 for (i = 0; i < 16; ++i) {
339 cursor[i + yoffset] =
340 (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
341 | (mouse_or_mask[i] >> xoffset);
343 for (i = 0; i < scp->font_size; ++i) {
344 font_buf[i] = (cursor[i] & 0xff00) >> 8;
345 font_buf[i + 32] = cursor[i] & 0xff;
346 font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
347 font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
351 /* wait for vertical retrace to avoid jitter on some videocards */
352 while (!(inb(CRTC + 6) & 0x08)) /* idle */ ;
354 c = scp->sc->mouse_char;
355 (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
358 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
359 /* FIXME: may be out of range! */
360 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
361 sc_vtb_geta(&scp->scr, pos + scp->xsize));
362 if (x < (scp->xsize - 1)*8) {
363 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
364 sc_vtb_geta(&scp->scr, pos + 1));
365 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
366 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
369 #endif /* SC_ALT_MOUSE_IMAGE */
371 /* Red, magenta and brown are mapped to green to to keep it readable */
372 static const int col_conv[16] = {
373 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
379 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
380 a = sc_vtb_geta(&scp->scr, pos);
381 if (scp->sc->adp->va_flags & V_ADP_COLOR)
382 color = (col_conv[(a & 0xf000) >> 12] << 12)
383 | ((a & 0x0f00) | 0x0800);
385 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
386 sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
391 remove_txtmouse(scr_stat *scp, int x, int y)
396 vga_txtmouse(scr_stat *scp, int x, int y, int on)
399 draw_txtmouse(scp, x, y);
401 remove_txtmouse(scp, x, y);
404 #endif /* SC_NO_CUTPASTE */
408 /* pixel (raster text) mode renderer */
411 vga_pxlborder_direct(scr_stat *scp, int color)
414 int line_width, pixel_size;
416 vm_offset_t draw_pos, draw_end, p;
418 line_width = scp->sc->adp->va_line_width;
419 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
421 for (i = 0; i < 4 / pixel_size; ++i)
422 u32 += scp->ega_palette[color] << (i * 8 * pixel_size);
425 draw_pos = scp->sc->adp->va_window;
426 draw_end = draw_pos +
427 line_width * scp->yoff * scp->font_size;
429 for (p = draw_pos; p < draw_end; p += 4)
433 y = (scp->yoff + scp->ysize) * scp->font_size;
435 if (scp->ypixel > y) {
436 draw_pos = scp->sc->adp->va_window + line_width * y;
437 draw_end = draw_pos + line_width * (scp->ypixel - y);
439 for (p = draw_pos; p < draw_end; p += 4)
443 y = scp->yoff * scp->font_size;
444 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
446 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
448 draw_pos = scp->sc->adp->va_window +
449 line_width * (y + i);
450 draw_end = draw_pos + scp->xoff * 8 * pixel_size;
452 for (p = draw_pos; p < draw_end; p += 4)
457 draw_pos = scp->sc->adp->va_window +
458 line_width * (y + i) +
459 scp->xoff * 8 * pixel_size +
460 scp->xsize * 8 * pixel_size;
461 draw_end = draw_pos + x * 8 * pixel_size;
463 for (p = draw_pos; p < draw_end; p += 4)
470 vga_pxlborder_planar(scr_stat *scp, int color)
478 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
480 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
481 outw(GDCIDX, 0x0003); /* data rotate/function select */
482 outw(GDCIDX, 0x0f01); /* set/reset enable */
483 outw(GDCIDX, 0xff08); /* bit mask */
484 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
485 line_width = scp->sc->adp->va_line_width;
486 p = scp->sc->adp->va_window;
488 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
489 y = (scp->yoff + scp->ysize)*scp->font_size;
491 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
492 y = scp->yoff*scp->font_size;
493 x = scp->xpixel/8 - scp->xoff - scp->xsize;
494 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
496 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
498 bzero_io((void *)(p + line_width*(y + i)
499 + scp->xoff + scp->xsize), x);
501 outw(GDCIDX, 0x0000); /* set/reset */
502 outw(GDCIDX, 0x0001); /* set/reset enable */
506 vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
508 int line_width, pixel_size;
509 int a, i, j, k, l, pos;
510 uint32_t fg, bg, u32;
511 unsigned char *char_data;
512 vm_offset_t draw_pos, p;
514 line_width = scp->sc->adp->va_line_width;
515 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
517 draw_pos = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
519 if (from + count > scp->xsize * scp->ysize)
520 count = scp->xsize * scp->ysize - from;
522 for (i = from; count-- > 0; ++i) {
523 a = sc_vtb_geta(&scp->vtb, i);
526 fg = scp->ega_palette[(((a & 0x7000) >> 4) |
528 bg = scp->ega_palette[(((a & 0x8000) >> 4) |
531 fg = scp->ega_palette[(a & 0x0f00) >> 8];
532 bg = scp->ega_palette[(a & 0xf000) >> 12];
536 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, i) *
539 for (j = 0; j < scp->font_size; ++j, ++char_data) {
542 for (k = 0; k < 2 * pixel_size; ++k) {
545 for (l = 0; l < 4 / pixel_size; ++l) {
546 u32 += (*char_data & (1 << pos--) ?
547 fg : bg) << (l * 8 * pixel_size);
554 p += line_width - 8 * pixel_size;
557 draw_pos += 8 * pixel_size;
559 if ((i % scp->xsize) == scp->xsize - 1)
560 draw_pos += scp->xoff * 16 * pixel_size +
561 (scp->font_size - 1) * line_width;
566 vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
578 d = VIDEO_MEMORY_POS(scp, from, 1);
580 line_width = scp->sc->adp->va_line_width;
582 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
583 outw(GDCIDX, 0x0003); /* data rotate/function select */
584 outw(GDCIDX, 0x0f01); /* set/reset enable */
585 outw(GDCIDX, 0xff08); /* bit mask */
587 if (from + count > scp->xsize*scp->ysize)
588 count = scp->xsize*scp->ysize - from;
589 for (i = from; count-- > 0; ++i) {
590 a = sc_vtb_geta(&scp->vtb, i);
592 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
593 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
596 col2 = (a & 0xf000) >> 4;
598 /* set background color in EGA/VGA latch */
601 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
602 outw(GDCIDX, bg | 0x00); /* set/reset */
604 c = readb(d); /* set bg color in the latch */
605 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
607 /* foreground color */
608 outw(GDCIDX, col1 | 0x00); /* set/reset */
610 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
611 for (j = 0; j < scp->font_size; ++j, ++f) {
616 if ((i % scp->xsize) == scp->xsize - 1)
618 + (scp->font_size - 1)*line_width;
620 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
621 outw(GDCIDX, 0x0000); /* set/reset */
622 outw(GDCIDX, 0x0001); /* set/reset enable */
626 vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
628 if (base < 0 || base >= scp->font_size)
630 /* the caller may set height <= 0 in order to disable the cursor */
632 scp->cursor_base = base;
633 scp->cursor_height = height;
638 draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
640 int line_width, pixel_size, height;
642 uint32_t fg, bg, u32;
643 unsigned char *char_data;
644 vm_offset_t draw_pos;
646 line_width = scp->sc->adp->va_line_width;
647 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
649 draw_pos = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
650 (scp->font_size - scp->cursor_base - 1) * line_width;
652 a = sc_vtb_geta(&scp->vtb, at);
655 fg = scp->ega_palette[((on) ? (a & 0x0f00) :
656 ((a & 0xf000) >> 4)) >> 8];
657 bg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
660 fg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
662 bg = scp->ega_palette[((on) ? (a & 0x0f00) :
663 ((a & 0xf000) >> 4)) >> 8];
666 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
667 scp->font_size - scp->cursor_base - 1]);
669 height = imin(scp->cursor_height, scp->font_size);
671 for (i = 0; i < height; ++i, --char_data) {
674 for (j = 0; j < 2 * pixel_size; ++j) {
677 for (k = 0; k < 4 / pixel_size; ++k) {
678 u32 += (*char_data & (1 << pos--) ?
679 fg : bg) << (k * 8 * pixel_size);
682 writel(draw_pos, u32);
686 draw_pos -= line_width + 8 * pixel_size;
691 draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
702 line_width = scp->sc->adp->va_line_width;
704 d = VIDEO_MEMORY_POS(scp, at, 1) +
705 (scp->font_size - scp->cursor_base - 1) * line_width;
707 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
708 outw(GDCIDX, 0x0003); /* data rotate/function select */
709 outw(GDCIDX, 0x0f01); /* set/reset enable */
710 /* set background color in EGA/VGA latch */
711 a = sc_vtb_geta(&scp->vtb, at);
713 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
715 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
716 outw(GDCIDX, col | 0x00); /* set/reset */
717 outw(GDCIDX, 0xff08); /* bit mask */
719 c = readb(d); /* set bg color in the latch */
720 /* foreground color */
722 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
724 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
725 outw(GDCIDX, col | 0x00); /* set/reset */
726 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
727 + scp->font_size - scp->cursor_base - 1]);
728 height = imin(scp->cursor_height, scp->font_size);
729 for (i = 0; i < height; ++i, --f) {
730 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
734 outw(GDCIDX, 0x0000); /* set/reset */
735 outw(GDCIDX, 0x0001); /* set/reset enable */
736 outw(GDCIDX, 0xff08); /* bit mask */
739 static int pxlblinkrate = 0;
742 vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
744 if (scp->cursor_height <= 0) /* the text cursor is disabled */
749 scp->status |= VR_CURSOR_ON;
750 draw_pxlcursor_direct(scp, at, on, flip);
751 } else if (++pxlblinkrate & 4) {
753 scp->status ^= VR_CURSOR_ON;
754 draw_pxlcursor_direct(scp, at,
755 scp->status & VR_CURSOR_ON,
759 if (scp->status & VR_CURSOR_ON)
760 draw_pxlcursor_direct(scp, at, on, flip);
761 scp->status &= ~VR_CURSOR_ON;
764 scp->status |= VR_CURSOR_BLINK;
766 scp->status &= ~VR_CURSOR_BLINK;
770 vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
772 if (scp->cursor_height <= 0) /* the text cursor is disabled */
777 scp->status |= VR_CURSOR_ON;
778 draw_pxlcursor_planar(scp, at, on, flip);
779 } else if (++pxlblinkrate & 4) {
781 scp->status ^= VR_CURSOR_ON;
782 draw_pxlcursor_planar(scp, at,
783 scp->status & VR_CURSOR_ON,
787 if (scp->status & VR_CURSOR_ON)
788 draw_pxlcursor_planar(scp, at, on, flip);
789 scp->status &= ~VR_CURSOR_ON;
792 scp->status |= VR_CURSOR_BLINK;
794 scp->status &= ~VR_CURSOR_BLINK;
798 vga_pxlblink_direct(scr_stat *scp, int at, int flip)
800 if (!(scp->status & VR_CURSOR_BLINK))
802 if (!(++pxlblinkrate & 4))
805 scp->status ^= VR_CURSOR_ON;
806 draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
810 vga_pxlblink_planar(scr_stat *scp, int at, int flip)
812 if (!(scp->status & VR_CURSOR_BLINK))
814 if (!(++pxlblinkrate & 4))
817 scp->status ^= VR_CURSOR_ON;
818 draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
821 #ifndef SC_NO_CUTPASTE
824 draw_pxlmouse_direct(scr_stat *scp, int x, int y)
826 int line_width, pixel_size;
829 vm_offset_t draw_pos;
831 line_width = scp->sc->adp->va_line_width;
832 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
834 xend = imin(x + 8, 8 * (scp->xoff + scp->xsize));
835 yend = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
837 draw_pos = scp->sc->adp->va_window + y * line_width + x * pixel_size;
839 for (i = 0; i < (yend - y); i++) {
840 for (j = (xend - x - 1); j >= 0; j--) {
841 switch (scp->sc->adp->va_info.vi_depth) {
843 if (mouse_or_mask[i] & 1 << (15 - j))
844 writel(draw_pos + 4 * j,
845 scp->ega_palette[15]);
846 else if (mouse_and_mask[i] & 1 << (15 - j))
847 writel(draw_pos + 4 * j,
848 scp->ega_palette[0]);
853 if (mouse_or_mask[i] & 1 << (15 - j))
854 writew(draw_pos + 2 * j,
855 scp->ega_palette[15]);
856 else if (mouse_and_mask[i] & 1 << (15 - j))
857 writew(draw_pos + 2 * j,
858 scp->ega_palette[0]);
863 draw_pos += line_width;
868 draw_pxlmouse_planar(scr_stat *scp, int x, int y)
877 line_width = scp->sc->adp->va_line_width;
878 xoff = (x - scp->xoff*8)%8;
879 ymax = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
881 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
882 outw(GDCIDX, 0x0001); /* set/reset enable */
883 outw(GDCIDX, 0x0002); /* color compare */
884 outw(GDCIDX, 0x0007); /* color don't care */
885 outw(GDCIDX, 0xff08); /* bit mask */
886 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
887 p = scp->sc->adp->va_window + line_width*y + x/8;
888 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
889 for (i = y, j = 0; i < ymax; ++i, ++j) {
890 m = ~(mouse_and_mask[j] >> xoff);
891 *(u_char *)p &= m >> 8;
892 *(u_char *)(p + 1) &= m;
897 for (i = y, j = 0; i < ymax; ++i, ++j) {
898 m = ~(mouse_and_mask[j] >> xoff);
903 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
904 p = scp->sc->adp->va_window + line_width*y + x/8;
905 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
906 for (i = y, j = 0; i < ymax; ++i, ++j) {
907 m = mouse_or_mask[j] >> xoff;
908 *(u_char *)p &= m >> 8;
909 *(u_char *)(p + 1) &= m;
913 for (i = y, j = 0; i < ymax; ++i, ++j) {
914 m = mouse_or_mask[j] >> xoff;
919 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
920 outw(GDCIDX, 0x0003); /* data rotate/function select */
924 remove_pxlmouse(scr_stat *scp, int x, int y)
930 /* erase the mouse cursor image */
931 col = x/8 - scp->xoff;
932 row = y/scp->font_size - scp->yoff;
933 pos = row*scp->xsize + col;
934 i = (col < scp->xsize - 1) ? 2 : 1;
935 (*scp->rndr->draw)(scp, pos, i, FALSE);
936 if (row < scp->ysize - 1)
937 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
941 vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
944 draw_pxlmouse_direct(scp, x, y);
946 remove_pxlmouse(scp, x, y);
950 vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
953 draw_pxlmouse_planar(scp, x, y);
955 remove_pxlmouse(scp, x, y);
958 #endif /* SC_NO_CUTPASTE */
959 #endif /* SC_PIXEL_MODE */
961 #ifndef SC_NO_MODE_CHANGE
963 /* graphics mode renderer */
966 vga_grborder(scr_stat *scp, int color)
968 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);