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.11 2005/02/18 16:38:23 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 #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 vga_nop(scr_stat *scp, ...)
172 /* text mode renderer */
175 vga_txtclear(scr_stat *scp, int c, int attr)
177 sc_vtb_clear(&scp->scr, c, attr);
181 vga_txtborder(scr_stat *scp, int color)
183 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
187 vga_txtdraw(scr_stat *scp, int from, int count, int flip)
193 if (from + count > scp->xsize*scp->ysize)
194 count = scp->xsize*scp->ysize - from;
197 for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
198 c = sc_vtb_getc(&scp->vtb, from);
199 a = sc_vtb_geta(&scp->vtb, from);
200 a = (a & 0x8800) | ((a & 0x7000) >> 4)
201 | ((a & 0x0700) << 4);
202 p = sc_vtb_putchar(&scp->scr, p, c, a);
205 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
210 vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
212 if (base < 0 || base >= scp->font_size)
214 /* the caller may set height <= 0 in order to disable the cursor */
216 scp->cursor_base = base;
217 scp->cursor_height = height;
219 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
221 scp->font_size, blink);
225 draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
230 scp->cursor_saveunder_char = c;
231 scp->cursor_saveunder_attr = a;
233 #ifndef SC_NO_FONT_LOADING
234 if (sc->flags & SC_CHAR_CURSOR) {
239 if (scp->font_size < 14) {
242 } else if (scp->font_size >= 16) {
249 if (scp->cursor_base >= h)
253 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
254 bcopy(font + c*h, font + sc->cursor_char*h, h);
255 font = font + sc->cursor_char*h;
256 for (i = imax(h - scp->cursor_base - scp->cursor_height, 0);
257 i < h - scp->cursor_base; ++i) {
260 sc->font_loading_in_progress = TRUE;
262 (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, font,
264 sc->font_loading_in_progress = FALSE;
265 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
267 #endif /* SC_NO_FONT_LOADING */
269 if ((a & 0x7000) == 0x7000) {
271 if ((a & 0x0700) == 0)
275 if ((a & 0x0700) == 0x0700)
280 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
281 sc_vtb_putc(&scp->scr, at, c, a);
286 vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
288 video_adapter_t *adp;
291 if (scp->cursor_height <= 0) /* the text cursor is disabled */
296 scp->status |= VR_CURSOR_BLINK;
298 scp->status |= VR_CURSOR_ON;
299 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
303 if (scp->status & VR_CURSOR_ON)
304 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
306 scp->status &= ~VR_CURSOR_ON;
309 scp->status &= ~VR_CURSOR_BLINK;
311 scp->status |= VR_CURSOR_ON;
312 draw_txtcharcursor(scp, at,
313 sc_vtb_getc(&scp->scr, at),
314 sc_vtb_geta(&scp->scr, at),
317 cursor_attr = scp->cursor_saveunder_attr;
319 cursor_attr = (cursor_attr & 0x8800)
320 | ((cursor_attr & 0x7000) >> 4)
321 | ((cursor_attr & 0x0700) << 4);
322 if (scp->status & VR_CURSOR_ON)
323 sc_vtb_putc(&scp->scr, at,
324 scp->cursor_saveunder_char,
326 scp->status &= ~VR_CURSOR_ON;
332 vga_txtblink(scr_stat *scp, int at, int flip)
336 #ifndef SC_NO_CUTPASTE
339 draw_txtmouse(scr_stat *scp, int x, int y)
341 #ifndef SC_ALT_MOUSE_IMAGE
342 if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
343 u_char font_buf[128];
347 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 crtc_addr = scp->sc->adp->va_crtc_addr;
386 while (!(inb(crtc_addr + 6) & 0x08)) /* idle */ ;
388 c = scp->sc->mouse_char;
389 (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
392 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
393 /* FIXME: may be out of range! */
394 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
395 sc_vtb_geta(&scp->scr, pos + scp->xsize));
396 if (x < (scp->xsize - 1)*8) {
397 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
398 sc_vtb_geta(&scp->scr, pos + 1));
399 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
400 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
403 #endif /* SC_ALT_MOUSE_IMAGE */
405 /* Red, magenta and brown are mapped to green to to keep it readable */
406 static const int col_conv[16] = {
407 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
413 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
414 a = sc_vtb_geta(&scp->scr, pos);
415 if (scp->sc->adp->va_flags & V_ADP_COLOR)
416 color = (col_conv[(a & 0xf000) >> 12] << 12)
417 | ((a & 0x0f00) | 0x0800);
419 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
420 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_rndrinit(scr_stat *scp)
447 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
448 scp->rndr->clear = vga_pxlclear_planar;
449 scp->rndr->draw_border = vga_pxlborder_planar;
450 scp->rndr->draw = vga_vgadraw_planar;
451 scp->rndr->draw_cursor = vga_pxlcursor_planar;
452 scp->rndr->blink_cursor = vga_pxlblink_planar;
453 scp->rndr->draw_mouse = vga_pxlmouse_planar;
454 } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) {
455 scp->rndr->clear = vga_pxlclear_direct;
456 scp->rndr->draw_border = vga_pxlborder_direct;
457 scp->rndr->draw = vga_vgadraw_direct;
458 scp->rndr->draw_cursor = vga_pxlcursor_direct;
459 scp->rndr->blink_cursor = vga_pxlblink_direct;
460 scp->rndr->draw_mouse = vga_pxlmouse_direct;
465 vga_pxlclear_direct(scr_stat *scp, int c, int attr)
473 line_width = scp->sc->adp->va_line_width;
474 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
475 lines = scp->ysize * scp->font_size;
476 p = scp->sc->adp->va_window +
477 line_width * scp->yoff * scp->font_size +
478 scp->xoff * 8 * pixel_size;
480 for (i = 0; i < lines; ++i) {
481 bzero_io((void *)p, scp->xsize * 8 * pixel_size);
487 vga_pxlclear_planar(scr_stat *scp, int c, int attr)
494 /* XXX: we are just filling the screen with the background color... */
495 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
496 outw(GDCIDX, 0x0003); /* data rotate/function select */
497 outw(GDCIDX, 0x0f01); /* set/reset enable */
498 outw(GDCIDX, 0xff08); /* bit mask */
499 outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
500 line_width = scp->sc->adp->va_line_width;
501 lines = scp->ysize*scp->font_size;
502 p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
504 for (i = 0; i < lines; ++i) {
505 bzero_io((void *)p, scp->xsize);
508 outw(GDCIDX, 0x0000); /* set/reset */
509 outw(GDCIDX, 0x0001); /* set/reset enable */
513 vga_pxlborder_direct(scr_stat *scp, int color)
516 int line_width, pixel_size;
518 vm_offset_t draw_pos, draw_end, p;
520 line_width = scp->sc->adp->va_line_width;
521 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
523 for (i = 0; i < 4 / pixel_size; ++i)
524 u32 += scp->ega_palette[color] << (i * 8 * pixel_size);
527 draw_pos = scp->sc->adp->va_window;
528 draw_end = draw_pos +
529 line_width * scp->yoff * scp->font_size;
531 for (p = draw_pos; p < draw_end; p += 4)
535 y = (scp->yoff + scp->ysize) * scp->font_size;
537 if (scp->ypixel > y) {
538 draw_pos = scp->sc->adp->va_window + line_width * y;
539 draw_end = draw_pos + line_width * (scp->ypixel - y);
541 for (p = draw_pos; p < draw_end; p += 4)
545 y = scp->yoff * scp->font_size;
546 x = scp->xpixel / 8 - scp->xoff - scp->xsize;
548 for (i = 0; i < scp->ysize * scp->font_size; ++i) {
550 draw_pos = scp->sc->adp->va_window +
551 line_width * (y + i);
552 draw_end = draw_pos + scp->xoff * 8 * pixel_size;
554 for (p = draw_pos; p < draw_end; p += 4)
559 draw_pos = scp->sc->adp->va_window +
560 line_width * (y + i) +
561 scp->xoff * 8 * pixel_size +
562 scp->xsize * 8 * pixel_size;
563 draw_end = draw_pos + x * 8 * pixel_size;
565 for (p = draw_pos; p < draw_end; p += 4)
572 vga_pxlborder_planar(scr_stat *scp, int color)
580 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
582 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
583 outw(GDCIDX, 0x0003); /* data rotate/function select */
584 outw(GDCIDX, 0x0f01); /* set/reset enable */
585 outw(GDCIDX, 0xff08); /* bit mask */
586 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
587 line_width = scp->sc->adp->va_line_width;
588 p = scp->sc->adp->va_window;
590 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
591 y = (scp->yoff + scp->ysize)*scp->font_size;
593 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
594 y = scp->yoff*scp->font_size;
595 x = scp->xpixel/8 - scp->xoff - scp->xsize;
596 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
598 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
600 bzero_io((void *)(p + line_width*(y + i)
601 + scp->xoff + scp->xsize), x);
603 outw(GDCIDX, 0x0000); /* set/reset */
604 outw(GDCIDX, 0x0001); /* set/reset enable */
608 vga_egadraw(scr_stat *scp, int from, int count, int flip)
620 line_width = scp->sc->adp->va_line_width;
622 d = VIDEO_MEMORY_POS(scp, from, 1);
624 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
625 outw(GDCIDX, 0x0003); /* data rotate/function select */
626 outw(GDCIDX, 0x0f01); /* set/reset enable */
628 if (from + count > scp->xsize*scp->ysize)
629 count = scp->xsize*scp->ysize - from;
630 for (i = from; count-- > 0; ++i) {
631 a = sc_vtb_geta(&scp->vtb, i);
633 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
634 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
637 col2 = (a & 0xf000) >> 4;
639 /* set background color in EGA/VGA latch */
642 outw(GDCIDX, bg | 0x00); /* set/reset */
643 outw(GDCIDX, 0xff08); /* bit mask */
645 c = readb(d); /* set bg color in the latch */
647 /* foreground color */
648 outw(GDCIDX, col1 | 0x00); /* set/reset */
650 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
651 for (j = 0; j < scp->font_size; ++j, ++f) {
652 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
657 if ((i % scp->xsize) == scp->xsize - 1)
659 + (scp->font_size - 1)*line_width;
661 outw(GDCIDX, 0x0000); /* set/reset */
662 outw(GDCIDX, 0x0001); /* set/reset enable */
663 outw(GDCIDX, 0xff08); /* bit mask */
667 vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
669 int line_width, pixel_size;
670 int a, i, j, k, l, pos;
671 uint32_t fg, bg, u32;
672 unsigned char *char_data;
673 vm_offset_t draw_pos, p;
675 line_width = scp->sc->adp->va_line_width;
676 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
678 draw_pos = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
680 if (from + count > scp->xsize * scp->ysize)
681 count = scp->xsize * scp->ysize - from;
683 for (i = from; count-- > 0; ++i) {
684 a = sc_vtb_geta(&scp->vtb, i);
687 fg = scp->ega_palette[(((a & 0x7000) >> 4) |
689 bg = scp->ega_palette[(((a & 0x8000) >> 4) |
692 fg = scp->ega_palette[(a & 0x0f00) >> 8];
693 bg = scp->ega_palette[(a & 0xf000) >> 12];
697 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, i) *
700 for (j = 0; j < scp->font_size; ++j, ++char_data) {
703 for (k = 0; k < 2 * pixel_size; ++k) {
706 for (l = 0; l < 4 / pixel_size; ++l) {
707 u32 += (*char_data & (1 << pos--) ?
708 fg : bg) << (l * 8 * pixel_size);
715 p += line_width - 8 * pixel_size;
718 draw_pos += 8 * pixel_size;
720 if ((i % scp->xsize) == scp->xsize - 1)
721 draw_pos += scp->xoff * 16 * pixel_size +
722 (scp->font_size - 1) * line_width;
727 vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
739 d = VIDEO_MEMORY_POS(scp, from, 1);
741 line_width = scp->sc->adp->va_line_width;
743 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
744 outw(GDCIDX, 0x0003); /* data rotate/function select */
745 outw(GDCIDX, 0x0f01); /* set/reset enable */
746 outw(GDCIDX, 0xff08); /* bit mask */
748 if (from + count > scp->xsize*scp->ysize)
749 count = scp->xsize*scp->ysize - from;
750 for (i = from; count-- > 0; ++i) {
751 a = sc_vtb_geta(&scp->vtb, i);
753 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
754 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
757 col2 = (a & 0xf000) >> 4;
759 /* set background color in EGA/VGA latch */
762 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
763 outw(GDCIDX, bg | 0x00); /* set/reset */
765 c = readb(d); /* set bg color in the latch */
766 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
768 /* foreground color */
769 outw(GDCIDX, col1 | 0x00); /* set/reset */
771 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
772 for (j = 0; j < scp->font_size; ++j, ++f) {
777 if ((i % scp->xsize) == scp->xsize - 1)
779 + (scp->font_size - 1)*line_width;
781 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
782 outw(GDCIDX, 0x0000); /* set/reset */
783 outw(GDCIDX, 0x0001); /* set/reset enable */
787 vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
789 if (base < 0 || base >= scp->font_size)
791 /* the caller may set height <= 0 in order to disable the cursor */
793 scp->cursor_base = base;
794 scp->cursor_height = height;
799 draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
801 int line_width, pixel_size, height;
803 uint32_t fg, bg, u32;
804 unsigned char *char_data;
805 vm_offset_t draw_pos;
807 line_width = scp->sc->adp->va_line_width;
808 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
810 draw_pos = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
811 (scp->font_size - scp->cursor_base - 1) * line_width;
813 a = sc_vtb_geta(&scp->vtb, at);
816 fg = scp->ega_palette[((on) ? (a & 0x0f00) :
817 ((a & 0xf000) >> 4)) >> 8];
818 bg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
821 fg = scp->ega_palette[((on) ? ((a & 0xf000) >> 4) :
823 bg = scp->ega_palette[((on) ? (a & 0x0f00) :
824 ((a & 0xf000) >> 4)) >> 8];
827 char_data = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
828 scp->font_size - scp->cursor_base - 1]);
830 height = imin(scp->cursor_height, scp->font_size);
832 for (i = 0; i < height; ++i, --char_data) {
835 for (j = 0; j < 2 * pixel_size; ++j) {
838 for (k = 0; k < 4 / pixel_size; ++k) {
839 u32 += (*char_data & (1 << pos--) ?
840 fg : bg) << (k * 8 * pixel_size);
843 writel(draw_pos, u32);
847 draw_pos -= line_width + 8 * pixel_size;
852 draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
863 line_width = scp->sc->adp->va_line_width;
865 d = VIDEO_MEMORY_POS(scp, at, 1) +
866 (scp->font_size - scp->cursor_base - 1) * line_width;
868 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
869 outw(GDCIDX, 0x0003); /* data rotate/function select */
870 outw(GDCIDX, 0x0f01); /* set/reset enable */
871 /* set background color in EGA/VGA latch */
872 a = sc_vtb_geta(&scp->vtb, at);
874 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
876 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
877 outw(GDCIDX, col | 0x00); /* set/reset */
878 outw(GDCIDX, 0xff08); /* bit mask */
880 c = readb(d); /* set bg color in the latch */
881 /* foreground color */
883 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
885 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
886 outw(GDCIDX, col | 0x00); /* set/reset */
887 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
888 + scp->font_size - scp->cursor_base - 1]);
889 height = imin(scp->cursor_height, scp->font_size);
890 for (i = 0; i < height; ++i, --f) {
891 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
895 outw(GDCIDX, 0x0000); /* set/reset */
896 outw(GDCIDX, 0x0001); /* set/reset enable */
897 outw(GDCIDX, 0xff08); /* bit mask */
900 static int pxlblinkrate = 0;
903 vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
905 if (scp->cursor_height <= 0) /* the text cursor is disabled */
910 scp->status |= VR_CURSOR_ON;
911 draw_pxlcursor_direct(scp, at, on, flip);
912 } else if (++pxlblinkrate & 4) {
914 scp->status ^= VR_CURSOR_ON;
915 draw_pxlcursor_direct(scp, at,
916 scp->status & VR_CURSOR_ON,
920 if (scp->status & VR_CURSOR_ON)
921 draw_pxlcursor_direct(scp, at, on, flip);
922 scp->status &= ~VR_CURSOR_ON;
925 scp->status |= VR_CURSOR_BLINK;
927 scp->status &= ~VR_CURSOR_BLINK;
931 vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
933 if (scp->cursor_height <= 0) /* the text cursor is disabled */
938 scp->status |= VR_CURSOR_ON;
939 draw_pxlcursor_planar(scp, at, on, flip);
940 } else if (++pxlblinkrate & 4) {
942 scp->status ^= VR_CURSOR_ON;
943 draw_pxlcursor_planar(scp, at,
944 scp->status & VR_CURSOR_ON,
948 if (scp->status & VR_CURSOR_ON)
949 draw_pxlcursor_planar(scp, at, on, flip);
950 scp->status &= ~VR_CURSOR_ON;
953 scp->status |= VR_CURSOR_BLINK;
955 scp->status &= ~VR_CURSOR_BLINK;
959 vga_pxlblink_direct(scr_stat *scp, int at, int flip)
961 if (!(scp->status & VR_CURSOR_BLINK))
963 if (!(++pxlblinkrate & 4))
966 scp->status ^= VR_CURSOR_ON;
967 draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
971 vga_pxlblink_planar(scr_stat *scp, int at, int flip)
973 if (!(scp->status & VR_CURSOR_BLINK))
975 if (!(++pxlblinkrate & 4))
978 scp->status ^= VR_CURSOR_ON;
979 draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
982 #ifndef SC_NO_CUTPASTE
985 draw_pxlmouse_direct(scr_stat *scp, int x, int y)
987 int line_width, pixel_size;
990 vm_offset_t draw_pos;
992 line_width = scp->sc->adp->va_line_width;
993 pixel_size = scp->sc->adp->va_info.vi_pixel_size;
995 xend = imin(x + 8, 8 * (scp->xoff + scp->xsize));
996 yend = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
998 draw_pos = scp->sc->adp->va_window + y * line_width + x * pixel_size;
1000 for (i = 0; i < (yend - y); i++) {
1001 for (j = (xend - x - 1); j >= 0; j--) {
1002 switch (scp->sc->adp->va_info.vi_depth) {
1004 if (mouse_or_mask[i] & 1 << (15 - j))
1005 writel(draw_pos + 4 * j,
1006 scp->ega_palette[15]);
1007 else if (mouse_and_mask[i] & 1 << (15 - j))
1008 writel(draw_pos + 4 * j,
1009 scp->ega_palette[0]);
1014 if (mouse_or_mask[i] & 1 << (15 - j))
1015 writew(draw_pos + 2 * j,
1016 scp->ega_palette[15]);
1017 else if (mouse_and_mask[i] & 1 << (15 - j))
1018 writew(draw_pos + 2 * j,
1019 scp->ega_palette[0]);
1024 draw_pos += line_width;
1029 draw_pxlmouse_planar(scr_stat *scp, int x, int y)
1038 line_width = scp->sc->adp->va_line_width;
1039 xoff = (x - scp->xoff*8)%8;
1040 yoff = y - (y/line_width)*line_width;
1041 ymax = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
1043 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
1044 outw(GDCIDX, 0x0001); /* set/reset enable */
1045 outw(GDCIDX, 0x0002); /* color compare */
1046 outw(GDCIDX, 0x0007); /* color don't care */
1047 outw(GDCIDX, 0xff08); /* bit mask */
1048 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
1049 p = scp->sc->adp->va_window + line_width*y + x/8;
1050 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
1051 for (i = y, j = 0; i < ymax; ++i, ++j) {
1052 m = ~(mouse_and_mask[j] >> xoff);
1053 *(u_char *)p &= m >> 8;
1054 *(u_char *)(p + 1) &= m;
1059 for (i = y, j = 0; i < ymax; ++i, ++j) {
1060 m = ~(mouse_and_mask[j] >> xoff);
1065 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
1066 p = scp->sc->adp->va_window + line_width*y + x/8;
1067 if (x < 8 * (scp->xoff + scp->xsize) - 8) {
1068 for (i = y, j = 0; i < ymax; ++i, ++j) {
1069 m = mouse_or_mask[j] >> xoff;
1070 *(u_char *)p &= m >> 8;
1071 *(u_char *)(p + 1) &= m;
1075 for (i = y, j = 0; i < ymax; ++i, ++j) {
1076 m = mouse_or_mask[j] >> xoff;
1081 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1082 outw(GDCIDX, 0x0003); /* data rotate/function select */
1086 remove_pxlmouse(scr_stat *scp, int x, int y)
1092 /* erase the mouse cursor image */
1093 col = x/8 - scp->xoff;
1094 row = y/scp->font_size - scp->yoff;
1095 pos = row*scp->xsize + col;
1096 i = (col < scp->xsize - 1) ? 2 : 1;
1097 (*scp->rndr->draw)(scp, pos, i, FALSE);
1098 if (row < scp->ysize - 1)
1099 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
1103 vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
1106 draw_pxlmouse_direct(scp, x, y);
1108 remove_pxlmouse(scp, x, y);
1112 vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
1115 draw_pxlmouse_planar(scp, x, y);
1117 remove_pxlmouse(scp, x, y);
1120 #endif /* SC_NO_CUTPASTE */
1121 #endif /* SC_PIXEL_MODE */
1123 #ifndef SC_NO_MODE_CHANGE
1125 /* graphics mode renderer */
1128 vga_grborder(scr_stat *scp, int color)
1130 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);