Deleted Added
full compact
scgfbrndr.c (81030) scgfbrndr.c (85810)
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/syscons/scgfbrndr.c 81030 2001-08-02 08:30:40Z yokota $
26 * Copyright (c) 2000 Andrew Miklic
27 */
28
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/dev/syscons/scgfbrndr.c 85810 2001-11-01 08:26:30Z obrien $");
31
29#include "opt_syscons.h"
32#include "opt_syscons.h"
30#include "opt_vga.h"
33#include "opt_gfb.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/fbio.h>
36#include <sys/consio.h>
37
38#include <machine/bus.h>
39
40#include <dev/fb/fbreg.h>
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/fbio.h>
39#include <sys/consio.h>
40
41#include <machine/bus.h>
42
43#include <dev/fb/fbreg.h>
41#include <dev/fb/vgareg.h>
42#include <dev/syscons/syscons.h>
43
44#include <dev/syscons/syscons.h>
45
44#include <isa/isareg.h>
45
46#ifndef SC_RENDER_DEBUG
47#define SC_RENDER_DEBUG 0
48#endif
49
46#ifndef SC_RENDER_DEBUG
47#define SC_RENDER_DEBUG 0
48#endif
49
50static vr_clear_t vga_txtclear;
51static vr_draw_border_t vga_txtborder;
52static vr_draw_t vga_txtdraw;
53static vr_set_cursor_t vga_txtcursor_shape;
54static vr_draw_cursor_t vga_txtcursor;
55static vr_blink_cursor_t vga_txtblink;
50static vr_clear_t gfb_clear;
51static vr_draw_border_t gfb_border;
52static vr_draw_t gfb_draw;
53static vr_set_cursor_t gfb_cursor_shape;
54static vr_draw_cursor_t gfb_cursor;
55static vr_blink_cursor_t gfb_blink;
56#ifndef SC_NO_CUTPASTE
56#ifndef SC_NO_CUTPASTE
57static vr_draw_mouse_t vga_txtmouse;
57static vr_draw_mouse_t gfb_mouse;
58#else
58#else
59#define vga_txtmouse (vr_draw_mouse_t *)vga_nop
59#define gfb_mouse (vr_draw_mouse_t *)gfb_nop
60#endif
61
60#endif
61
62#ifdef SC_PIXEL_MODE
63static vr_clear_t vga_pxlclear;
64static vr_draw_border_t vga_pxlborder;
65static vr_draw_t vga_egadraw;
66static vr_draw_t vga_vgadraw;
67static vr_set_cursor_t vga_pxlcursor_shape;
68static vr_draw_cursor_t vga_pxlcursor;
69static vr_blink_cursor_t vga_pxlblink;
70#ifndef SC_NO_CUTPASTE
71static vr_draw_mouse_t vga_pxlmouse;
72#else
73#define vga_pxlmouse (vr_draw_mouse_t *)vga_nop
74#endif
75#endif /* SC_PIXEL_MODE */
62static void gfb_nop(scr_stat *scp, ...);
76
63
77#ifndef SC_NO_MODE_CHANGE
78static vr_draw_border_t vga_grborder;
79#endif
80
81static void vga_nop(scr_stat *scp, ...);
82
83static sc_rndr_sw_t txtrndrsw = {
84 vga_txtclear,
85 vga_txtborder,
86 vga_txtdraw,
87 vga_txtcursor_shape,
88 vga_txtcursor,
89 vga_txtblink,
90 (vr_set_mouse_t *)vga_nop,
91 vga_txtmouse,
64sc_rndr_sw_t txtrndrsw = {
65 gfb_clear,
66 gfb_border,
67 gfb_draw,
68 gfb_cursor_shape,
69 gfb_cursor,
70 gfb_blink,
71 (vr_set_mouse_t *)gfb_nop,
72 gfb_mouse,
92};
73};
93RENDERER(mda, 0, txtrndrsw, vga_set);
94RENDERER(cga, 0, txtrndrsw, vga_set);
95RENDERER(ega, 0, txtrndrsw, vga_set);
96RENDERER(vga, 0, txtrndrsw, vga_set);
97
98#ifdef SC_PIXEL_MODE
74
75#ifdef SC_PIXEL_MODE
99static sc_rndr_sw_t egarndrsw = {
100 vga_pxlclear,
101 vga_pxlborder,
102 vga_egadraw,
103 vga_pxlcursor_shape,
104 vga_pxlcursor,
105 vga_pxlblink,
106 (vr_set_mouse_t *)vga_nop,
107 vga_pxlmouse,
76sc_rndr_sw_t gfbrndrsw = {
77 gfb_clear,
78 gfb_border,
79 gfb_draw,
80 gfb_cursor_shape,
81 gfb_cursor,
82 gfb_blink,
83 (vr_set_mouse_t *)gfb_nop,
84 gfb_mouse,
108};
85};
109RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set);
110
111static sc_rndr_sw_t vgarndrsw = {
112 vga_pxlclear,
113 vga_pxlborder,
114 vga_vgadraw,
115 vga_pxlcursor_shape,
116 vga_pxlcursor,
117 vga_pxlblink,
118 (vr_set_mouse_t *)vga_nop,
119 vga_pxlmouse,
120};
121RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
122#endif /* SC_PIXEL_MODE */
123
124#ifndef SC_NO_MODE_CHANGE
86#endif /* SC_PIXEL_MODE */
87
88#ifndef SC_NO_MODE_CHANGE
125static sc_rndr_sw_t grrndrsw = {
126 (vr_clear_t *)vga_nop,
127 vga_grborder,
128 (vr_draw_t *)vga_nop,
129 (vr_set_cursor_t *)vga_nop,
130 (vr_draw_cursor_t *)vga_nop,
131 (vr_blink_cursor_t *)vga_nop,
132 (vr_set_mouse_t *)vga_nop,
133 (vr_draw_mouse_t *)vga_nop,
89sc_rndr_sw_t grrndrsw = {
90 (vr_clear_t *)gfb_nop,
91 gfb_border,
92 (vr_draw_t *)gfb_nop,
93 (vr_set_cursor_t *)gfb_nop,
94 (vr_draw_cursor_t *)gfb_nop,
95 (vr_blink_cursor_t *)gfb_nop,
96 (vr_set_mouse_t *)gfb_nop,
97 (vr_draw_mouse_t *)gfb_nop,
134};
98};
135RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set);
136RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set);
137RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
138#endif /* SC_NO_MODE_CHANGE */
139
99#endif /* SC_NO_MODE_CHANGE */
100
140RENDERER_MODULE(vga, vga_set);
141
142#ifndef SC_NO_CUTPASTE
101#ifndef SC_NO_CUTPASTE
143static u_short mouse_and_mask[16] = {
144 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
145 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
102
103static u_char mouse_pointer[16] = {
104 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
105 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
146};
106};
147static u_short mouse_or_mask[16] = {
148 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
149 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
150};
151#endif
152
153static void
107#endif
108
109static void
154vga_nop(scr_stat *scp, ...)
110gfb_nop(scr_stat *scp, ...)
155{
156}
157
158/* text mode renderer */
159
160static void
111{
112}
113
114/* text mode renderer */
115
116static void
161vga_txtclear(scr_stat *scp, int c, int attr)
117gfb_clear(scr_stat *scp, int c, int attr)
162{
118{
163 sc_vtb_clear(&scp->scr, c, attr);
119 (*vidsw[scp->sc->adapter]->clear)(scp->sc->adp);
164}
165
166static void
120}
121
122static void
167vga_txtborder(scr_stat *scp, int color)
123gfb_border(scr_stat *scp, int color)
168{
169 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
170}
171
172static void
124{
125 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
126}
127
128static void
173vga_txtdraw(scr_stat *scp, int from, int count, int flip)
129gfb_draw(scr_stat *scp, int from, int count, int flip)
174{
130{
175 vm_offset_t p;
176 int c;
177 int a;
131 char c;
132 char a;
133 int i, n;
134 video_adapter_t *adp;
178
135
179 if (from + count > scp->xsize*scp->ysize)
180 count = scp->xsize*scp->ysize - from;
136 adp = scp->sc->adp;
181
137
182 if (flip) {
183 for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
184 c = sc_vtb_getc(&scp->vtb, from);
185 a = sc_vtb_geta(&scp->vtb, from);
186 a = (a & 0x8800) | ((a & 0x7000) >> 4)
187 | ((a & 0x0700) << 4);
188 p = sc_vtb_putchar(&scp->scr, p, c, a);
138 /*
139 Determine if we need to scroll based on the offset
140 and the number of characters to be displayed...
141 */
142 if (from + count > scp->xsize*scp->ysize) {
143
144 /*
145 Calculate the number of characters past the end of the
146 visible screen...
147 */
148 count = (from + count) -
149 (adp->va_info.vi_width * adp->va_info.vi_height);
150
151 /*
152 Calculate the number of rows past the end of the visible
153 screen...
154 */
155 n = (count / adp->va_info.vi_width) + 1;
156
157 /* Scroll to make room for new text rows... */
158 (*vidsw[scp->sc->adapter]->copy)(adp, n, 0, n);
159#ifdef 0
160 (*vidsw[scp->sc->adapter]->clear)(adp, n);
161#endif
162
163 /* Display new text rows... */
164 (*vidsw[scp->sc->adapter]->puts)(adp, from,
165 (u_int16_t *)sc_vtb_pointer(&scp->vtb, from), count);
166 }
167
168 /*
169 We don't need to scroll, so we can just put the characters
170 all-at-once...
171 */
172 else {
173
174 /*
175 Determine the method by which we are to display characters
176 (are we going to print forwards or backwards?
177 do we need to do a character-by-character copy, then?)...
178 */
179 if (flip)
180 for (i = count; i-- > 0; ++from) {
181 c = sc_vtb_getc(&scp->vtb, from);
182 a = sc_vtb_geta(&scp->vtb, from) >> 8;
183 (*vidsw[scp->sc->adapter]->putc)(adp, from, c,
184 a);
185 }
186 else {
187 (*vidsw[scp->sc->adapter]->puts)(adp, from,
188 (u_int16_t *)sc_vtb_pointer(&scp->vtb, from),
189 count);
189 }
190 }
190 } else {
191 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
192 }
193}
194
195static void
191 }
192}
193
194static void
196vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
195gfb_cursor_shape(scr_stat *scp, int base, int height, int blink)
197{
198 if (base < 0 || base >= scp->font_size)
199 return;
200 /* the caller may set height <= 0 in order to disable the cursor */
201#if 0
196{
197 if (base < 0 || base >= scp->font_size)
198 return;
199 /* the caller may set height <= 0 in order to disable the cursor */
200#if 0
202 scp->curs_attr.base = base;
203 scp->curs_attr.height = height;
201 scp->cursor_base = base;
202 scp->cursor_height = height;
204#endif
205 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
203#endif
204 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
206 base, height,
207 scp->font_size, blink);
205 base, height, scp->font_size, blink);
208}
209
206}
207
210static void
211draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
212{
213 sc_softc_t *sc;
208static int pxlblinkrate = 0;
214
209
215 sc = scp->sc;
216 scp->cursor_saveunder_char = c;
217 scp->cursor_saveunder_attr = a;
218
219#ifndef SC_NO_FONT_LOADING
220 if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
221 unsigned char *font;
222 int h;
223 int i;
224
225 if (scp->font_size < 14) {
226 font = sc->font_8;
227 h = 8;
228 } else if (scp->font_size >= 16) {
229 font = sc->font_16;
230 h = 16;
231 } else {
232 font = sc->font_14;
233 h = 14;
234 }
235 if (scp->curs_attr.base >= h)
236 return;
237 if (flip)
238 a = (a & 0x8800)
239 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
240 bcopy(font + c*h, font + sc->cursor_char*h, h);
241 font = font + sc->cursor_char*h;
242 for (i = imax(h - scp->curs_attr.base - scp->curs_attr.height, 0);
243 i < h - scp->curs_attr.base; ++i) {
244 font[i] ^= 0xff;
245 }
246 /* XXX */
247 (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, font,
248 sc->cursor_char, 1);
249 sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
250 } else
251#endif /* SC_NO_FONT_LOADING */
252 {
253 if ((a & 0x7000) == 0x7000) {
254 a &= 0x8f00;
255 if ((a & 0x0700) == 0)
256 a |= 0x0700;
257 } else {
258 a |= 0x7000;
259 if ((a & 0x0700) == 0x0700)
260 a &= 0xf000;
261 }
262 if (flip)
263 a = (a & 0x8800)
264 | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
265 sc_vtb_putc(&scp->scr, at, c, a);
266 }
267}
268
210#ifdef 0
269static void
211static void
270vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
212gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
271{
272 video_adapter_t *adp;
213{
214 video_adapter_t *adp;
273 int cursor_attr;
274
215
275 if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
216 if (scp->cursor_height <= 0) /* the text cursor is disabled */
276 return;
277
278 adp = scp->sc->adp;
217 return;
218
219 adp = scp->sc->adp;
279 if (blink) {
220 if(blink) {
280 scp->status |= VR_CURSOR_BLINK;
281 if (on) {
282 scp->status |= VR_CURSOR_ON;
283 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
221 scp->status |= VR_CURSOR_BLINK;
222 if (on) {
223 scp->status |= VR_CURSOR_ON;
224 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
284 at%scp->xsize,
285 at/scp->xsize);
225 at%scp->xsize,
226 at/scp->xsize);
286 } else {
287 if (scp->status & VR_CURSOR_ON)
227 } else {
228 if (scp->status & VR_CURSOR_ON)
288 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
289 -1, -1);
229 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1,
230 -1);
290 scp->status &= ~VR_CURSOR_ON;
291 }
292 } else {
293 scp->status &= ~VR_CURSOR_BLINK;
231 scp->status &= ~VR_CURSOR_ON;
232 }
233 } else {
234 scp->status &= ~VR_CURSOR_BLINK;
294 if (on) {
235 if(on) {
295 scp->status |= VR_CURSOR_ON;
236 scp->status |= VR_CURSOR_ON;
296 draw_txtcharcursor(scp, at,
297 sc_vtb_getc(&scp->scr, at),
298 sc_vtb_geta(&scp->scr, at),
299 flip);
237 scp->cursor_saveunder_char = sc_vtb_getc(&scp->scr, at);
238 scp->cursor_saveunder_attr = sc_vtb_geta(&scp->scr, at);
239 (*vidsw[scp->sc->adapter]->putc)(scp->sc->adp, at,
240 scp->cursor_saveunder_char,
241 scp->cursor_saveunder_attr);
300 } else {
242 } else {
301 cursor_attr = scp->cursor_saveunder_attr;
302 if (flip)
303 cursor_attr = (cursor_attr & 0x8800)
304 | ((cursor_attr & 0x7000) >> 4)
305 | ((cursor_attr & 0x0700) << 4);
306 if (scp->status & VR_CURSOR_ON)
243 if (scp->status & VR_CURSOR_ON)
307 sc_vtb_putc(&scp->scr, at,
308 scp->cursor_saveunder_char,
309 cursor_attr);
244 (*vidsw[scp->sc->adapter]->putc)(scp->sc->adp,
245 at, scp->cursor_saveunder_char,
246 scp->cursor_saveunder_attr);
310 scp->status &= ~VR_CURSOR_ON;
311 }
312 }
313}
247 scp->status &= ~VR_CURSOR_ON;
248 }
249 }
250}
314
315static void
316vga_txtblink(scr_stat *scp, int at, int flip)
317{
318}
319
320#ifndef SC_NO_CUTPASTE
321
322static void
323draw_txtmouse(scr_stat *scp, int x, int y)
324{
325#ifndef SC_ALT_MOUSE_IMAGE
326 if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
327 u_char font_buf[128];
328 u_short cursor[32];
329 u_char c;
330 int pos;
331 int xoffset, yoffset;
332 int crtc_addr;
333 int i;
334
335 /* prepare mousepointer char's bitmaps */
336 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
337 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
338 &font_buf[0], scp->font_size);
339 bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
340 &font_buf[32], scp->font_size);
341 bcopy(scp->font
342 + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
343 &font_buf[64], scp->font_size);
344 bcopy(scp->font
345 + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
346 &font_buf[96], scp->font_size);
347 for (i = 0; i < scp->font_size; ++i) {
348 cursor[i] = font_buf[i]<<8 | font_buf[i+32];
349 cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
350 }
351
352 /* now and-or in the mousepointer image */
353 xoffset = x%8;
354 yoffset = y%scp->font_size;
355 for (i = 0; i < 16; ++i) {
356 cursor[i + yoffset] =
357 (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
358 | (mouse_or_mask[i] >> xoffset);
359 }
360 for (i = 0; i < scp->font_size; ++i) {
361 font_buf[i] = (cursor[i] & 0xff00) >> 8;
362 font_buf[i + 32] = cursor[i] & 0xff;
363 font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
364 font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
365 }
366
367#if 1
368 /* wait for vertical retrace to avoid jitter on some videocards */
369 crtc_addr = scp->sc->adp->va_crtc_addr;
370 while (!(inb(crtc_addr + 6) & 0x08)) /* idle */ ;
371#endif
251#endif
372 c = scp->sc->mouse_char;
373 (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
374 c, 4);
375
252
376 sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
377 /* FIXME: may be out of range! */
378 sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
379 sc_vtb_geta(&scp->scr, pos + scp->xsize));
380 if (x < (scp->xsize - 1)*8) {
381 sc_vtb_putc(&scp->scr, pos + 1, c + 1,
382 sc_vtb_geta(&scp->scr, pos + 1));
383 sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
384 sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
385 }
386 } else
387#endif /* SC_ALT_MOUSE_IMAGE */
388 {
389 /* Red, magenta and brown are mapped to green to to keep it readable */
390 static const int col_conv[16] = {
391 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
392 };
393 int pos;
394 int color;
395 int a;
396
397 pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
398 a = sc_vtb_geta(&scp->scr, pos);
399 if (scp->sc->adp->va_flags & V_ADP_COLOR)
400 color = (col_conv[(a & 0xf000) >> 12] << 12)
401 | ((a & 0x0f00) | 0x0800);
402 else
403 color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
404 sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
405 }
406}
407
408static void
409remove_txtmouse(scr_stat *scp, int x, int y)
410{
411}
412
413static void
253static void
414vga_txtmouse(scr_stat *scp, int x, int y, int on)
254gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
415{
255{
416 if (on)
417 draw_txtmouse(scp, x, y);
418 else
419 remove_txtmouse(scp, x, y);
420}
256 video_adapter_t *adp;
421
257
422#endif /* SC_NO_CUTPASTE */
423
424#ifdef SC_PIXEL_MODE
425
426/* pixel (raster text) mode renderer */
427
428static void
429vga_pxlclear(scr_stat *scp, int c, int attr)
430{
431 vm_offset_t p;
432 int line_width;
433 int lines;
434 int i;
435
436 /* XXX: we are just filling the screen with the background color... */
437 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
438 outw(GDCIDX, 0x0003); /* data rotate/function select */
439 outw(GDCIDX, 0x0f01); /* set/reset enable */
440 outw(GDCIDX, 0xff08); /* bit mask */
441 outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
442 line_width = scp->sc->adp->va_line_width;
443 lines = scp->ysize*scp->font_size;
444 p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
445 + scp->xoff;
446 for (i = 0; i < lines; ++i) {
447 bzero_io((void *)p, scp->xsize);
448 p += line_width;
449 }
450 outw(GDCIDX, 0x0000); /* set/reset */
451 outw(GDCIDX, 0x0001); /* set/reset enable */
452}
453
454static void
455vga_pxlborder(scr_stat *scp, int color)
456{
457 vm_offset_t p;
458 int line_width;
459 int x;
460 int y;
461 int i;
462
463 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
464
465 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
466 outw(GDCIDX, 0x0003); /* data rotate/function select */
467 outw(GDCIDX, 0x0f01); /* set/reset enable */
468 outw(GDCIDX, 0xff08); /* bit mask */
469 outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
470 line_width = scp->sc->adp->va_line_width;
471 p = scp->sc->adp->va_window;
472 if (scp->yoff > 0)
473 bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
474 y = (scp->yoff + scp->ysize)*scp->font_size;
475 if (scp->ypixel > y)
476 bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
477 y = scp->yoff*scp->font_size;
478 x = scp->xpixel/8 - scp->xoff - scp->xsize;
479 for (i = 0; i < scp->ysize*scp->font_size; ++i) {
480 if (scp->xoff > 0)
481 bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
482 if (x > 0)
483 bzero_io((void *)(p + line_width*(y + i)
484 + scp->xoff + scp->xsize), x);
485 }
486 outw(GDCIDX, 0x0000); /* set/reset */
487 outw(GDCIDX, 0x0001); /* set/reset enable */
488}
489
490static void
491vga_egadraw(scr_stat *scp, int from, int count, int flip)
492{
493 vm_offset_t d;
494 vm_offset_t e;
495 u_char *f;
496 u_short bg;
497 u_short col1, col2;
498 int line_width;
499 int i, j;
500 int a;
501 u_char c;
502
503 line_width = scp->sc->adp->va_line_width;
504 d = scp->sc->adp->va_window
505 + scp->xoff
506 + scp->yoff*scp->font_size*line_width
507 + (from%scp->xsize)
508 + scp->font_size*line_width*(from/scp->xsize);
509
510 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
511 outw(GDCIDX, 0x0003); /* data rotate/function select */
512 outw(GDCIDX, 0x0f01); /* set/reset enable */
513 bg = -1;
514 if (from + count > scp->xsize*scp->ysize)
515 count = scp->xsize*scp->ysize - from;
516 for (i = from; count-- > 0; ++i) {
517 a = sc_vtb_geta(&scp->vtb, i);
518 if (flip) {
519 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
520 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
521 } else {
522 col1 = (a & 0x0f00);
523 col2 = (a & 0xf000) >> 4;
524 }
525 /* set background color in EGA/VGA latch */
526 if (bg != col2) {
527 bg = col2;
528 outw(GDCIDX, bg | 0x00); /* set/reset */
529 outw(GDCIDX, 0xff08); /* bit mask */
530 writeb(d, 0);
531 c = readb(d); /* set bg color in the latch */
532 }
533 /* foreground color */
534 outw(GDCIDX, col1 | 0x00); /* set/reset */
535 e = d;
536 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
537 for (j = 0; j < scp->font_size; ++j, ++f) {
538 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
539 writeb(e, 0);
540 e += line_width;
541 }
542 ++d;
543 if ((i % scp->xsize) == scp->xsize - 1)
544 d += scp->xoff*2
545 + (scp->font_size - 1)*line_width;
546 }
547 outw(GDCIDX, 0x0000); /* set/reset */
548 outw(GDCIDX, 0x0001); /* set/reset enable */
549 outw(GDCIDX, 0xff08); /* bit mask */
550}
551
552static void
553vga_vgadraw(scr_stat *scp, int from, int count, int flip)
554{
555 vm_offset_t d;
556 vm_offset_t e;
557 u_char *f;
558 u_short bg;
559 u_short col1, col2;
560 int line_width;
561 int i, j;
562 int a;
563 u_char c;
564
565 line_width = scp->sc->adp->va_line_width;
566 d = scp->sc->adp->va_window
567 + scp->xoff
568 + scp->yoff*scp->font_size*line_width
569 + (from%scp->xsize)
570 + scp->font_size*line_width*(from/scp->xsize);
571
572 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
573 outw(GDCIDX, 0x0003); /* data rotate/function select */
574 outw(GDCIDX, 0x0f01); /* set/reset enable */
575 outw(GDCIDX, 0xff08); /* bit mask */
576 bg = -1;
577 if (from + count > scp->xsize*scp->ysize)
578 count = scp->xsize*scp->ysize - from;
579 for (i = from; count-- > 0; ++i) {
580 a = sc_vtb_geta(&scp->vtb, i);
581 if (flip) {
582 col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
583 col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
584 } else {
585 col1 = (a & 0x0f00);
586 col2 = (a & 0xf000) >> 4;
587 }
588 /* set background color in EGA/VGA latch */
589 if (bg != col2) {
590 bg = col2;
591 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
592 outw(GDCIDX, bg | 0x00); /* set/reset */
593 writeb(d, 0);
594 c = readb(d); /* set bg color in the latch */
595 outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
596 }
597 /* foreground color */
598 outw(GDCIDX, col1 | 0x00); /* set/reset */
599 e = d;
600 f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
601 for (j = 0; j < scp->font_size; ++j, ++f) {
602 writeb(e, *f);
603 e += line_width;
604 }
605 ++d;
606 if ((i % scp->xsize) == scp->xsize - 1)
607 d += scp->xoff*2
608 + (scp->font_size - 1)*line_width;
609 }
610 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
611 outw(GDCIDX, 0x0000); /* set/reset */
612 outw(GDCIDX, 0x0001); /* set/reset enable */
613}
614
615static void
616vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
617{
618 if (base < 0 || base >= scp->font_size)
258 adp = scp->sc->adp;
259 if (scp->cursor_height <= 0) /* the text cursor is disabled */
619 return;
260 return;
620 /* the caller may set height <= 0 in order to disable the cursor */
621#if 0
622 scp->curs_attr.base = base;
623 scp->curs_attr.height = height;
624#endif
625}
626
261
627static void
628draw_pxlcursor(scr_stat *scp, int at, int on, int flip)
629{
630 vm_offset_t d;
631 u_char *f;
632 int line_width;
633 int height;
634 int col;
635 int a;
636 int i;
637 u_char c;
638
639 line_width = scp->sc->adp->va_line_width;
640 d = scp->sc->adp->va_window
641 + scp->xoff
642 + scp->yoff*scp->font_size*line_width
643 + (at%scp->xsize)
644 + scp->font_size*line_width*(at/scp->xsize)
645 + (scp->font_size - scp->curs_attr.base - 1)*line_width;
646
647 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
648 outw(GDCIDX, 0x0003); /* data rotate/function select */
649 outw(GDCIDX, 0x0f01); /* set/reset enable */
650 /* set background color in EGA/VGA latch */
651 a = sc_vtb_geta(&scp->vtb, at);
652 if (flip)
653 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
654 else
655 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
656 outw(GDCIDX, col | 0x00); /* set/reset */
657 outw(GDCIDX, 0xff08); /* bit mask */
658 writeb(d, 0);
659 c = readb(d); /* set bg color in the latch */
660 /* foreground color */
661 if (flip)
662 col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
663 else
664 col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
665 outw(GDCIDX, col | 0x00); /* set/reset */
666 f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
667 + scp->font_size - scp->curs_attr.base - 1]);
668 height = imin(scp->curs_attr.height, scp->font_size);
669 for (i = 0; i < height; ++i, --f) {
670 outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
671 writeb(d, 0);
672 d -= line_width;
673 }
674 outw(GDCIDX, 0x0000); /* set/reset */
675 outw(GDCIDX, 0x0001); /* set/reset enable */
676 outw(GDCIDX, 0xff08); /* bit mask */
677}
678
679static int pxlblinkrate = 0;
680
681static void
682vga_pxlcursor(scr_stat *scp, int at, int blink, int on, int flip)
683{
684 if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
685 return;
686
687 if (on) {
688 if (!blink) {
689 scp->status |= VR_CURSOR_ON;
262 if (on) {
263 if (!blink) {
264 scp->status |= VR_CURSOR_ON;
690 draw_pxlcursor(scp, at, on, flip);
265 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
266 at%scp->xsize, at/scp->xsize);
691 } else if (++pxlblinkrate & 4) {
692 pxlblinkrate = 0;
693 scp->status ^= VR_CURSOR_ON;
267 } else if (++pxlblinkrate & 4) {
268 pxlblinkrate = 0;
269 scp->status ^= VR_CURSOR_ON;
694 draw_pxlcursor(scp, at,
695 scp->status & VR_CURSOR_ON,
696 flip);
270 if(scp->status & VR_CURSOR_ON)
271 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
272 at%scp->xsize, at/scp->xsize);
273 else
274 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1,
275 -1);
697 }
698 } else {
699 if (scp->status & VR_CURSOR_ON)
276 }
277 } else {
278 if (scp->status & VR_CURSOR_ON)
700 draw_pxlcursor(scp, at, on, flip);
279 (*vidsw[adp->va_index]->set_hw_cursor)(adp,
280 at%scp->xsize, at/scp->xsize);
701 scp->status &= ~VR_CURSOR_ON;
702 }
703 if (blink)
704 scp->status |= VR_CURSOR_BLINK;
705 else
706 scp->status &= ~VR_CURSOR_BLINK;
707}
708
709static void
281 scp->status &= ~VR_CURSOR_ON;
282 }
283 if (blink)
284 scp->status |= VR_CURSOR_BLINK;
285 else
286 scp->status &= ~VR_CURSOR_BLINK;
287}
288
289static void
710vga_pxlblink(scr_stat *scp, int at, int flip)
290gfb_blink(scr_stat *scp, int at, int flip)
711{
712 if (!(scp->status & VR_CURSOR_BLINK))
713 return;
714 if (!(++pxlblinkrate & 4))
715 return;
716 pxlblinkrate = 0;
717 scp->status ^= VR_CURSOR_ON;
291{
292 if (!(scp->status & VR_CURSOR_BLINK))
293 return;
294 if (!(++pxlblinkrate & 4))
295 return;
296 pxlblinkrate = 0;
297 scp->status ^= VR_CURSOR_ON;
718 draw_pxlcursor(scp, at, scp->status & VR_CURSOR_ON, flip);
298 gfb_cursor(scp, at, scp->status & VR_CURSOR_BLINK,
299 scp->status & VR_CURSOR_ON, flip);
719}
720
721#ifndef SC_NO_CUTPASTE
722
300}
301
302#ifndef SC_NO_CUTPASTE
303
723static void
724draw_pxlmouse(scr_stat *scp, int x, int y)
304static void
305gfb_mouse(scr_stat *scp, int x, int y, int on)
725{
306{
726 vm_offset_t p;
727 int line_width;
728 int xoff, yoff;
729 int ymax;
730 u_short m;
731 int i, j;
307 int i, pos;
732
308
733 line_width = scp->sc->adp->va_line_width;
734 xoff = (x - scp->xoff*8)%8;
735 yoff = y - (y/line_width)*line_width;
736 ymax = imin(y + 16, scp->ypixel);
309 if (on) {
737
310
738 outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
739 outw(GDCIDX, 0x0001); /* set/reset enable */
740 outw(GDCIDX, 0x0002); /* color compare */
741 outw(GDCIDX, 0x0007); /* color don't care */
742 outw(GDCIDX, 0xff08); /* bit mask */
743 outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
744 p = scp->sc->adp->va_window + line_width*y + x/8;
745 if (x < scp->xpixel - 8) {
746 for (i = y, j = 0; i < ymax; ++i, ++j) {
747 m = ~(mouse_and_mask[j] >> xoff);
748#ifdef __i386__
749 *(u_char *)p &= m >> 8;
750 *(u_char *)(p + 1) &= m;
751#elif defined(__alpha__)
752 writeb(p, readb(p) & (m >> 8));
753 writeb(p + 1, readb(p + 1) & (m >> 8));
754#endif
755 p += line_width;
756 }
311 /* Display the mouse pointer image... */
312 (*vidsw[scp->sc->adapter]->putm)(scp->sc->adp, x, y,
313 mouse_pointer, 0xffffffff, 16);
757 } else {
314 } else {
758 xoff += 8;
759 for (i = y, j = 0; i < ymax; ++i, ++j) {
760 m = ~(mouse_and_mask[j] >> xoff);
761#ifdef __i386__
762 *(u_char *)p &= m;
763#elif defined(__alpha__)
764 writeb(p, readb(p) & (m >> 8));
765#endif
766 p += line_width;
767 }
768 }
769 outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
770 p = scp->sc->adp->va_window + line_width*y + x/8;
771 if (x < scp->xpixel - 8) {
772 for (i = y, j = 0; i < ymax; ++i, ++j) {
773 m = mouse_or_mask[j] >> xoff;
774#ifdef __i386__
775 *(u_char *)p &= m >> 8;
776 *(u_char *)(p + 1) &= m;
777#elif defined(__alpha__)
778 writeb(p, readb(p) & (m >> 8));
779 writeb(p + 1, readb(p + 1) & (m >> 8));
780#endif
781 p += line_width;
782 }
783 } else {
784 for (i = y, j = 0; i < ymax; ++i, ++j) {
785 m = mouse_or_mask[j] >> xoff;
786#ifdef __i386__
787 *(u_char *)p &= m;
788#elif defined(__alpha__)
789 writeb(p, readb(p) & (m >> 8));
790#endif
791 p += line_width;
792 }
793 }
794 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
795 outw(GDCIDX, 0x0003); /* data rotate/function select */
796}
797
315
798static void
799remove_pxlmouse(scr_stat *scp, int x, int y)
800{
801 vm_offset_t p;
802 int col, row;
803 int pos;
804 int line_width;
805 int ymax;
806 int i;
807
808 /* erase the mouse cursor image */
809 col = x/8 - scp->xoff;
810 row = y/scp->font_size - scp->yoff;
811 pos = row*scp->xsize + col;
812 i = (col < scp->xsize - 1) ? 2 : 1;
813 (*scp->rndr->draw)(scp, pos, i, FALSE);
814 if (row < scp->ysize - 1)
815 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
816
817 /* paint border if necessary */
818 line_width = scp->sc->adp->va_line_width;
819 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
820 outw(GDCIDX, 0x0003); /* data rotate/function select */
821 outw(GDCIDX, 0x0f01); /* set/reset enable */
822 outw(GDCIDX, 0xff08); /* bit mask */
823 outw(GDCIDX, (scp->border << 8) | 0x00); /* set/reset */
824 if (row == scp->ysize - 1) {
825 i = (scp->ysize + scp->yoff)*scp->font_size;
826 ymax = imin(i + scp->font_size, scp->ypixel);
827 p = scp->sc->adp->va_window + i*line_width + scp->xoff + col;
828 if (col < scp->xsize - 1) {
829 for (; i < ymax; ++i) {
830 writeb(p, 0);
831 writeb(p + 1, 0);
832 p += line_width;
833 }
834 } else {
835 for (; i < ymax; ++i) {
836 writeb(p, 0);
837 p += line_width;
838 }
839 }
316 /*
317 Erase the mouse cursor image by redrawing the text
318 underneath it...
319 */
320 return;
321 pos = x*scp->xsize + y;
322 i = (y < scp->xsize - 1) ? 2 : 1;
323 (*scp->rndr->draw)(scp, pos, i, FALSE);
324 if (x < scp->ysize - 1)
325 (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
840 }
326 }
841 if ((col == scp->xsize - 1) && (scp->xoff > 0)) {
842 i = (row + scp->yoff)*scp->font_size;
843 ymax = imin(i + scp->font_size*2, scp->ypixel);
844 p = scp->sc->adp->va_window + i*line_width
845 + scp->xoff + scp->xsize;
846 for (; i < ymax; ++i) {
847 writeb(p, 0);
848 p += line_width;
849 }
850 }
851 outw(GDCIDX, 0x0000); /* set/reset */
852 outw(GDCIDX, 0x0001); /* set/reset enable */
853}
854
327}
328
855static void
856vga_pxlmouse(scr_stat *scp, int x, int y, int on)
857{
858 if (on)
859 draw_pxlmouse(scp, x, y);
860 else
861 remove_pxlmouse(scp, x, y);
862}
863
864#endif /* SC_NO_CUTPASTE */
329#endif /* SC_NO_CUTPASTE */
865#endif /* SC_PIXEL_MODE */
866
867#ifndef SC_NO_MODE_CHANGE
868
869/* graphics mode renderer */
870
871static void
872vga_grborder(scr_stat *scp, int color)
873{
874 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
875}
876
877#endif