scvgarndr.c revision 330446
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
17 *
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.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/11/sys/dev/syscons/scvgarndr.c 330446 2018-03-05 06:59:30Z eadler $");
33
34#include "opt_syscons.h"
35#include "opt_vga.h"
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/module.h>
41#include <sys/fbio.h>
42#include <sys/consio.h>
43
44#include <machine/bus.h>
45
46#include <dev/fb/fbreg.h>
47#include <dev/fb/vgareg.h>
48#include <dev/syscons/syscons.h>
49
50#include <isa/isareg.h>
51
52#ifndef SC_RENDER_DEBUG
53#define SC_RENDER_DEBUG		0
54#endif
55
56static vr_clear_t		vga_txtclear;
57static vr_draw_border_t		vga_txtborder;
58static vr_draw_t		vga_txtdraw;
59static vr_set_cursor_t		vga_txtcursor_shape;
60static vr_draw_cursor_t		vga_txtcursor;
61static vr_blink_cursor_t	vga_txtblink;
62#ifndef SC_NO_CUTPASTE
63static vr_draw_mouse_t		vga_txtmouse;
64#else
65#define vga_txtmouse		(vr_draw_mouse_t *)vga_nop
66#endif
67
68#ifdef SC_PIXEL_MODE
69static vr_init_t		vga_rndrinit;
70static vr_clear_t		vga_pxlclear_direct;
71static vr_clear_t		vga_pxlclear_planar;
72static vr_draw_border_t		vga_pxlborder_direct;
73static vr_draw_border_t		vga_pxlborder_planar;
74static vr_draw_t		vga_egadraw;
75static vr_draw_t		vga_vgadraw_direct;
76static vr_draw_t		vga_vgadraw_planar;
77static vr_set_cursor_t		vga_pxlcursor_shape;
78static vr_draw_cursor_t		vga_pxlcursor_direct;
79static vr_draw_cursor_t		vga_pxlcursor_planar;
80static vr_blink_cursor_t	vga_pxlblink_direct;
81static vr_blink_cursor_t	vga_pxlblink_planar;
82#ifndef SC_NO_CUTPASTE
83static vr_draw_mouse_t		vga_pxlmouse_direct;
84static vr_draw_mouse_t		vga_pxlmouse_planar;
85#else
86#define vga_pxlmouse_direct	(vr_draw_mouse_t *)vga_nop
87#define vga_pxlmouse_planar	(vr_draw_mouse_t *)vga_nop
88#endif
89#endif /* SC_PIXEL_MODE */
90
91#ifndef SC_NO_MODE_CHANGE
92static vr_draw_border_t		vga_grborder;
93#endif
94
95static void			vga_nop(scr_stat *scp);
96
97static sc_rndr_sw_t txtrndrsw = {
98	(vr_init_t *)vga_nop,
99	vga_txtclear,
100	vga_txtborder,
101	vga_txtdraw,
102	vga_txtcursor_shape,
103	vga_txtcursor,
104	vga_txtblink,
105	(vr_set_mouse_t *)vga_nop,
106	vga_txtmouse,
107};
108RENDERER(mda, 0, txtrndrsw, vga_set);
109RENDERER(cga, 0, txtrndrsw, vga_set);
110RENDERER(ega, 0, txtrndrsw, vga_set);
111RENDERER(vga, 0, txtrndrsw, vga_set);
112
113#ifdef SC_PIXEL_MODE
114static sc_rndr_sw_t egarndrsw = {
115	(vr_init_t *)vga_nop,
116	vga_pxlclear_planar,
117	vga_pxlborder_planar,
118	vga_egadraw,
119	vga_pxlcursor_shape,
120	vga_pxlcursor_planar,
121	vga_pxlblink_planar,
122	(vr_set_mouse_t *)vga_nop,
123	vga_pxlmouse_planar,
124};
125RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set);
126
127static sc_rndr_sw_t vgarndrsw = {
128	vga_rndrinit,
129	(vr_clear_t *)vga_nop,
130	(vr_draw_border_t *)vga_nop,
131	(vr_draw_t *)vga_nop,
132	vga_pxlcursor_shape,
133	(vr_draw_cursor_t *)vga_nop,
134	(vr_blink_cursor_t *)vga_nop,
135	(vr_set_mouse_t *)vga_nop,
136	(vr_draw_mouse_t *)vga_nop,
137};
138RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
139#endif /* SC_PIXEL_MODE */
140
141#ifndef SC_NO_MODE_CHANGE
142static sc_rndr_sw_t grrndrsw = {
143	(vr_init_t *)vga_nop,
144	(vr_clear_t *)vga_nop,
145	vga_grborder,
146	(vr_draw_t *)vga_nop,
147	(vr_set_cursor_t *)vga_nop,
148	(vr_draw_cursor_t *)vga_nop,
149	(vr_blink_cursor_t *)vga_nop,
150	(vr_set_mouse_t *)vga_nop,
151	(vr_draw_mouse_t *)vga_nop,
152};
153RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set);
154RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set);
155RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
156#endif /* SC_NO_MODE_CHANGE */
157
158RENDERER_MODULE(vga, vga_set);
159
160#ifndef SC_NO_CUTPASTE
161#if !defined(SC_ALT_MOUSE_IMAGE) || defined(SC_PIXEL_MODE)
162static u_short mouse_and_mask[16] = {
163	0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
164	0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
165};
166static u_short mouse_or_mask[16] = {
167	0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
168	0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
169};
170#endif
171#endif
172
173#ifdef SC_PIXEL_MODE
174#define	GET_PIXEL(scp, pos, x, w)					\
175({									\
176	(scp)->sc->adp->va_window +					\
177	    (x) * (scp)->xoff +						\
178	    (scp)->yoff * (scp)->font_size * (w) +			\
179	    (x) * ((pos) % (scp)->xsize) +				\
180	    (scp)->font_size * (w) * ((pos) / (scp)->xsize);		\
181})
182
183#define	DRAW_PIXEL(scp, pos, color) do {				\
184	switch ((scp)->sc->adp->va_info.vi_depth) {			\
185	case 32:							\
186		writel((pos), vga_palette32[color]);			\
187		break;							\
188	case 24:							\
189		if (((pos) & 1) == 0) {					\
190			writew((pos), vga_palette32[color]);		\
191			writeb((pos) + 2, vga_palette32[color] >> 16);	\
192		} else {						\
193			writeb((pos), vga_palette32[color]);		\
194			writew((pos) + 1, vga_palette32[color] >> 8);	\
195		}							\
196		break;							\
197	case 16:							\
198		if ((scp)->sc->adp->va_info.vi_pixel_fsizes[1] == 5)	\
199			writew((pos), vga_palette15[color]);		\
200		else							\
201			writew((pos), vga_palette16[color]);		\
202		break;							\
203	case 15:							\
204		writew((pos), vga_palette15[color]);			\
205		break;							\
206	case 8:								\
207		writeb((pos), (uint8_t)(color));			\
208	}								\
209} while (0)
210
211static uint32_t vga_palette32[16] = {
212	0x000000, 0x0000ad, 0x00ad00, 0x00adad,
213	0xad0000, 0xad00ad, 0xad5200, 0xadadad,
214	0x525252, 0x5252ff, 0x52ff52, 0x52ffff,
215	0xff5252, 0xff52ff, 0xffff52, 0xffffff
216};
217
218static uint16_t vga_palette16[16] = {
219	0x0000, 0x0016, 0x0560, 0x0576, 0xb000, 0xb016, 0xb2a0, 0xb576,
220	0x52aa, 0x52bf, 0x57ea, 0x57ff, 0xfaaa, 0xfabf, 0xffea, 0xffff
221};
222
223static uint16_t vga_palette15[16] = {
224	0x0000, 0x0016, 0x02c0, 0x02d6, 0x5800, 0x5816, 0x5940, 0x5ad6,
225	0x294a, 0x295f, 0x2bea, 0x2bff, 0x7d4a, 0x7d5f, 0x7fea, 0x7fff
226};
227
228#ifndef SC_NO_CUTPASTE
229static uint32_t mouse_buf32[256];
230static uint16_t mouse_buf16[256];
231static uint8_t  mouse_buf8[256];
232#endif
233#endif
234
235static void
236vga_nop(scr_stat *scp)
237{
238}
239
240/* text mode renderer */
241
242static void
243vga_txtclear(scr_stat *scp, int c, int attr)
244{
245	sc_vtb_clear(&scp->scr, c, attr);
246}
247
248static void
249vga_txtborder(scr_stat *scp, int color)
250{
251	vidd_set_border(scp->sc->adp, color);
252}
253
254static void
255vga_txtdraw(scr_stat *scp, int from, int count, int flip)
256{
257	vm_offset_t p;
258	int c;
259	int a;
260
261	if (from + count > scp->xsize*scp->ysize)
262		count = scp->xsize*scp->ysize - from;
263
264	if (flip) {
265		for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
266			c = sc_vtb_getc(&scp->vtb, from);
267			a = sc_vtb_geta(&scp->vtb, from);
268			a = (a & 0x8800) | ((a & 0x7000) >> 4)
269				| ((a & 0x0700) << 4);
270			p = sc_vtb_putchar(&scp->scr, p, c, a);
271		}
272	} else {
273		sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
274	}
275}
276
277static void
278vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
279{
280	if (base < 0 || base >= scp->font_size)
281		return;
282	/* the caller may set height <= 0 in order to disable the cursor */
283#if 0
284	scp->curs_attr.base = base;
285	scp->curs_attr.height = height;
286#endif
287	vidd_set_hw_cursor_shape(scp->sc->adp, base, height,
288	    scp->font_size, blink);
289}
290
291static void
292draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
293{
294	sc_softc_t *sc;
295
296	sc = scp->sc;
297	scp->cursor_saveunder_char = c;
298	scp->cursor_saveunder_attr = a;
299
300#ifndef SC_NO_FONT_LOADING
301	if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
302		unsigned char *font;
303		int h;
304		int i;
305
306		if (scp->font_size < 14) {
307			font = sc->font_8;
308			h = 8;
309		} else if (scp->font_size >= 16) {
310			font = sc->font_16;
311			h = 16;
312		} else {
313			font = sc->font_14;
314			h = 14;
315		}
316		if (scp->curs_attr.base >= h)
317			return;
318		if (flip)
319			a = (a & 0x8800)
320				| ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
321		bcopy(font + c*h, font + sc->cursor_char*h, h);
322		font = font + sc->cursor_char*h;
323		for (i = imax(h - scp->curs_attr.base - scp->curs_attr.height, 0);
324			i < h - scp->curs_attr.base; ++i) {
325			font[i] ^= 0xff;
326		}
327		/* XXX */
328		vidd_load_font(sc->adp, 0, h, 8, font, sc->cursor_char, 1);
329		sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
330	} else
331#endif /* SC_NO_FONT_LOADING */
332	{
333		if ((a & 0x7000) == 0x7000) {
334			a &= 0x8f00;
335			if ((a & 0x0700) == 0)
336				a |= 0x0700;
337		} else {
338			a |= 0x7000;
339			if ((a & 0x0700) == 0x0700)
340				a &= 0xf000;
341		}
342		if (flip)
343			a = (a & 0x8800)
344				| ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
345		sc_vtb_putc(&scp->scr, at, c, a);
346	}
347}
348
349static void
350vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
351{
352	video_adapter_t *adp;
353	int cursor_attr;
354
355	if (scp->curs_attr.height <= 0)	/* the text cursor is disabled */
356		return;
357
358	adp = scp->sc->adp;
359	if (blink) {
360		scp->status |= VR_CURSOR_BLINK;
361		if (on) {
362			scp->status |= VR_CURSOR_ON;
363			vidd_set_hw_cursor(adp, at%scp->xsize,
364			    at/scp->xsize);
365		} else {
366			if (scp->status & VR_CURSOR_ON)
367				vidd_set_hw_cursor(adp, -1, -1);
368			scp->status &= ~VR_CURSOR_ON;
369		}
370	} else {
371		scp->status &= ~VR_CURSOR_BLINK;
372		if (on) {
373			scp->status |= VR_CURSOR_ON;
374			draw_txtcharcursor(scp, at,
375					   sc_vtb_getc(&scp->scr, at),
376					   sc_vtb_geta(&scp->scr, at),
377					   flip);
378		} else {
379			cursor_attr = scp->cursor_saveunder_attr;
380			if (flip)
381				cursor_attr = (cursor_attr & 0x8800)
382					| ((cursor_attr & 0x7000) >> 4)
383					| ((cursor_attr & 0x0700) << 4);
384			if (scp->status & VR_CURSOR_ON)
385				sc_vtb_putc(&scp->scr, at,
386					    scp->cursor_saveunder_char,
387					    cursor_attr);
388			scp->status &= ~VR_CURSOR_ON;
389		}
390	}
391}
392
393static void
394vga_txtblink(scr_stat *scp, int at, int flip)
395{
396}
397
398int sc_txtmouse_no_retrace_wait;
399
400#ifndef SC_NO_CUTPASTE
401
402static void
403draw_txtmouse(scr_stat *scp, int x, int y)
404{
405#ifndef SC_ALT_MOUSE_IMAGE
406    if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
407	u_char font_buf[128];
408	u_short cursor[32];
409	u_char c;
410	int pos;
411	int xoffset, yoffset;
412	int crtc_addr;
413	int i;
414
415	/* prepare mousepointer char's bitmaps */
416	pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
417	bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
418	      &font_buf[0], scp->font_size);
419	bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
420	      &font_buf[32], scp->font_size);
421	bcopy(scp->font
422		 + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
423	      &font_buf[64], scp->font_size);
424	bcopy(scp->font
425		 + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
426	      &font_buf[96], scp->font_size);
427	for (i = 0; i < scp->font_size; ++i) {
428		cursor[i] = font_buf[i]<<8 | font_buf[i+32];
429		cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
430	}
431
432	/* now and-or in the mousepointer image */
433	xoffset = x%8;
434	yoffset = y%scp->font_size;
435	for (i = 0; i < 16; ++i) {
436		cursor[i + yoffset] =
437	    		(cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
438	    		| (mouse_or_mask[i] >> xoffset);
439	}
440	for (i = 0; i < scp->font_size; ++i) {
441		font_buf[i] = (cursor[i] & 0xff00) >> 8;
442		font_buf[i + 32] = cursor[i] & 0xff;
443		font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
444		font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
445	}
446
447#if 1
448	/* wait for vertical retrace to avoid jitter on some videocards */
449	crtc_addr = scp->sc->adp->va_crtc_addr;
450	while (!sc_txtmouse_no_retrace_wait &&
451	    !(inb(crtc_addr + 6) & 0x08))
452		/* idle */ ;
453#endif
454	c = scp->sc->mouse_char;
455	vidd_load_font(scp->sc->adp, 0, 32, 8, font_buf, c, 4);
456
457	sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
458	/* FIXME: may be out of range! */
459	sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
460		    sc_vtb_geta(&scp->scr, pos + scp->xsize));
461	if (x < (scp->xsize - 1)*8) {
462		sc_vtb_putc(&scp->scr, pos + 1, c + 1,
463			    sc_vtb_geta(&scp->scr, pos + 1));
464		sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
465			    sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
466	}
467    } else
468#endif /* SC_ALT_MOUSE_IMAGE */
469    {
470	/* Red, magenta and brown are mapped to green to keep it readable */
471	static const int col_conv[16] = {
472		6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
473	};
474	int pos;
475	int color;
476	int a;
477
478	pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
479	a = sc_vtb_geta(&scp->scr, pos);
480	if (scp->sc->adp->va_flags & V_ADP_COLOR)
481		color = (col_conv[(a & 0xf000) >> 12] << 12)
482			| ((a & 0x0f00) | 0x0800);
483	else
484		color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
485	sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
486    }
487}
488
489static void
490remove_txtmouse(scr_stat *scp, int x, int y)
491{
492}
493
494static void
495vga_txtmouse(scr_stat *scp, int x, int y, int on)
496{
497	if (on)
498		draw_txtmouse(scp, x, y);
499	else
500		remove_txtmouse(scp, x, y);
501}
502
503#endif /* SC_NO_CUTPASTE */
504
505#ifdef SC_PIXEL_MODE
506
507/* pixel (raster text) mode renderer */
508
509static void
510vga_rndrinit(scr_stat *scp)
511{
512	if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
513		scp->rndr->clear = vga_pxlclear_planar;
514		scp->rndr->draw_border = vga_pxlborder_planar;
515		scp->rndr->draw = vga_vgadraw_planar;
516		scp->rndr->draw_cursor = vga_pxlcursor_planar;
517		scp->rndr->blink_cursor = vga_pxlblink_planar;
518		scp->rndr->draw_mouse = vga_pxlmouse_planar;
519	} else
520	if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT ||
521	    scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PACKED) {
522		scp->rndr->clear = vga_pxlclear_direct;
523		scp->rndr->draw_border = vga_pxlborder_direct;
524		scp->rndr->draw = vga_vgadraw_direct;
525		scp->rndr->draw_cursor = vga_pxlcursor_direct;
526		scp->rndr->blink_cursor = vga_pxlblink_direct;
527		scp->rndr->draw_mouse = vga_pxlmouse_direct;
528	}
529}
530
531static void
532vga_pxlclear_direct(scr_stat *scp, int c, int attr)
533{
534	vm_offset_t p;
535	int line_width;
536	int pixel_size;
537	int lines;
538	int i;
539
540	line_width = scp->sc->adp->va_line_width;
541	pixel_size = scp->sc->adp->va_info.vi_pixel_size;
542	lines = scp->ysize * scp->font_size;
543	p = scp->sc->adp->va_window +
544	    line_width * scp->yoff * scp->font_size +
545	    scp->xoff * 8 * pixel_size;
546
547	for (i = 0; i < lines; ++i) {
548		bzero_io((void *)p, scp->xsize * 8 * pixel_size);
549		p += line_width;
550	}
551}
552
553static void
554vga_pxlclear_planar(scr_stat *scp, int c, int attr)
555{
556	vm_offset_t p;
557	int line_width;
558	int lines;
559	int i;
560
561	/* XXX: we are just filling the screen with the background color... */
562	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
563	outw(GDCIDX, 0x0003);		/* data rotate/function select */
564	outw(GDCIDX, 0x0f01);		/* set/reset enable */
565	outw(GDCIDX, 0xff08);		/* bit mask */
566	outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
567	line_width = scp->sc->adp->va_line_width;
568	lines = scp->ysize*scp->font_size;
569	p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
570		+ scp->xoff;
571	for (i = 0; i < lines; ++i) {
572		bzero_io((void *)p, scp->xsize);
573		p += line_width;
574	}
575	outw(GDCIDX, 0x0000);		/* set/reset */
576	outw(GDCIDX, 0x0001);		/* set/reset enable */
577}
578
579static void
580vga_pxlborder_direct(scr_stat *scp, int color)
581{
582	vm_offset_t s;
583	vm_offset_t e;
584	vm_offset_t f;
585	int line_width;
586	int pixel_size;
587	int x;
588	int y;
589	int i;
590
591	line_width = scp->sc->adp->va_line_width;
592	pixel_size = scp->sc->adp->va_info.vi_pixel_size;
593
594	if (scp->yoff > 0) {
595		s = scp->sc->adp->va_window;
596		e = s + line_width * scp->yoff * scp->font_size;
597
598		for (f = s; f < e; f += pixel_size)
599			DRAW_PIXEL(scp, f, color);
600	}
601
602	y = (scp->yoff + scp->ysize) * scp->font_size;
603
604	if (scp->ypixel > y) {
605		s = scp->sc->adp->va_window + line_width * y;
606		e = s + line_width * (scp->ypixel - y);
607
608		for (f = s; f < e; f += pixel_size)
609			DRAW_PIXEL(scp, f, color);
610	}
611
612	y = scp->yoff * scp->font_size;
613	x = scp->xpixel / 8 - scp->xoff - scp->xsize;
614
615	for (i = 0; i < scp->ysize * scp->font_size; ++i) {
616		if (scp->xoff > 0) {
617			s = scp->sc->adp->va_window + line_width * (y + i);
618			e = s + scp->xoff * 8 * pixel_size;
619
620			for (f = s; f < e; f += pixel_size)
621				DRAW_PIXEL(scp, f, color);
622		}
623
624		if (x > 0) {
625			s = scp->sc->adp->va_window + line_width * (y + i) +
626			    scp->xoff * 8 * pixel_size +
627			    scp->xsize * 8 * pixel_size;
628			e = s + x * 8 * pixel_size;
629
630			for (f = s; f < e; f += pixel_size)
631				DRAW_PIXEL(scp, f, color);
632		}
633	}
634}
635
636static void
637vga_pxlborder_planar(scr_stat *scp, int color)
638{
639	vm_offset_t p;
640	int line_width;
641	int x;
642	int y;
643	int i;
644
645	vidd_set_border(scp->sc->adp, color);
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	outw(GDCIDX, 0xff08);		/* bit mask */
651	outw(GDCIDX, (color << 8) | 0x00);	/* set/reset */
652	line_width = scp->sc->adp->va_line_width;
653	p = scp->sc->adp->va_window;
654	if (scp->yoff > 0)
655		bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
656	y = (scp->yoff + scp->ysize)*scp->font_size;
657	if (scp->ypixel > y)
658		bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
659	y = scp->yoff*scp->font_size;
660	x = scp->xpixel/8 - scp->xoff - scp->xsize;
661	for (i = 0; i < scp->ysize*scp->font_size; ++i) {
662		if (scp->xoff > 0)
663			bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
664		if (x > 0)
665			bzero_io((void *)(p + line_width*(y + i)
666				     + scp->xoff + scp->xsize), x);
667	}
668	outw(GDCIDX, 0x0000);		/* set/reset */
669	outw(GDCIDX, 0x0001);		/* set/reset enable */
670}
671
672static void
673vga_egadraw(scr_stat *scp, int from, int count, int flip)
674{
675	vm_offset_t d;
676	vm_offset_t e;
677	u_char *f;
678	u_short bg;
679	u_short col1, col2;
680	int line_width;
681	int i, j;
682	int a;
683	u_char c;
684
685	line_width = scp->sc->adp->va_line_width;
686
687	d = GET_PIXEL(scp, from, 1, line_width);
688
689	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
690	outw(GDCIDX, 0x0003);		/* data rotate/function select */
691	outw(GDCIDX, 0x0f01);		/* set/reset enable */
692	bg = -1;
693	if (from + count > scp->xsize*scp->ysize)
694		count = scp->xsize*scp->ysize - from;
695	for (i = from; count-- > 0; ++i) {
696		a = sc_vtb_geta(&scp->vtb, i);
697		if (flip) {
698			col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
699			col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
700		} else {
701			col1 = (a & 0x0f00);
702			col2 = (a & 0xf000) >> 4;
703		}
704		/* set background color in EGA/VGA latch */
705		if (bg != col2) {
706			bg = col2;
707			outw(GDCIDX, bg | 0x00);	/* set/reset */
708			outw(GDCIDX, 0xff08);		/* bit mask */
709			writeb(d, 0);
710			c = readb(d);	/* set bg color in the latch */
711		}
712		/* foreground color */
713		outw(GDCIDX, col1 | 0x00);		/* set/reset */
714		e = d;
715		f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
716		for (j = 0; j < scp->font_size; ++j, ++f) {
717			outw(GDCIDX, (*f << 8) | 0x08);	/* bit mask */
718	        	writeb(e, 0);
719			e += line_width;
720		}
721		++d;
722		if ((i % scp->xsize) == scp->xsize - 1)
723			d += scp->font_size * line_width - scp->xsize;
724	}
725	outw(GDCIDX, 0x0000);		/* set/reset */
726	outw(GDCIDX, 0x0001);		/* set/reset enable */
727	outw(GDCIDX, 0xff08);		/* bit mask */
728}
729
730static void
731vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
732{
733	vm_offset_t d;
734	vm_offset_t e;
735	u_char *f;
736	u_short col1, col2, color;
737	int line_width, pixel_size;
738	int i, j, k;
739	int a;
740
741	line_width = scp->sc->adp->va_line_width;
742	pixel_size = scp->sc->adp->va_info.vi_pixel_size;
743
744	d = GET_PIXEL(scp, from, 8 * pixel_size, line_width);
745
746	if (from + count > scp->xsize * scp->ysize)
747		count = scp->xsize * scp->ysize - from;
748
749	for (i = from; count-- > 0; ++i) {
750		a = sc_vtb_geta(&scp->vtb, i);
751
752		if (flip) {
753			col1 = (((a & 0x7000) >> 4) | (a & 0x0800)) >> 8;
754			col2 = (((a & 0x8000) >> 4) | (a & 0x0700)) >> 8;
755		} else {
756			col1 = (a & 0x0f00) >> 8;
757			col2 = (a & 0xf000) >> 12;
758		}
759
760		e = d;
761		f = &(scp->font[sc_vtb_getc(&scp->vtb, i) * scp->font_size]);
762
763		for (j = 0; j < scp->font_size; ++j, ++f) {
764			for (k = 0; k < 8; ++k) {
765				color = *f & (1 << (7 - k)) ? col1 : col2;
766				DRAW_PIXEL(scp, e + pixel_size * k, color);
767			}
768
769			e += line_width;
770		}
771
772		d += 8 * pixel_size;
773
774		if ((i % scp->xsize) == scp->xsize - 1)
775			d += scp->font_size * line_width -
776			    scp->xsize * 8 * pixel_size;
777	}
778}
779
780static void
781vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
782{
783	vm_offset_t d;
784	vm_offset_t e;
785	u_char *f;
786	u_short bg;
787	u_short col1, col2;
788	int line_width;
789	int i, j;
790	int a;
791	u_char c;
792
793	line_width = scp->sc->adp->va_line_width;
794
795	d = GET_PIXEL(scp, from, 1, line_width);
796
797	outw(GDCIDX, 0x0305);		/* read mode 0, write mode 3 */
798	outw(GDCIDX, 0x0003);		/* data rotate/function select */
799	outw(GDCIDX, 0x0f01);		/* set/reset enable */
800	outw(GDCIDX, 0xff08);		/* bit mask */
801	bg = -1;
802	if (from + count > scp->xsize*scp->ysize)
803		count = scp->xsize*scp->ysize - from;
804	for (i = from; count-- > 0; ++i) {
805		a = sc_vtb_geta(&scp->vtb, i);
806		if (flip) {
807			col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
808			col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
809		} else {
810			col1 = (a & 0x0f00);
811			col2 = (a & 0xf000) >> 4;
812		}
813		/* set background color in EGA/VGA latch */
814		if (bg != col2) {
815			bg = col2;
816			outw(GDCIDX, 0x0005);	/* read mode 0, write mode 0 */
817			outw(GDCIDX, bg | 0x00); /* set/reset */
818			writeb(d, 0);
819			c = readb(d);		/* set bg color in the latch */
820			outw(GDCIDX, 0x0305);	/* read mode 0, write mode 3 */
821		}
822		/* foreground color */
823		outw(GDCIDX, col1 | 0x00);	/* set/reset */
824		e = d;
825		f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
826		for (j = 0; j < scp->font_size; ++j, ++f) {
827	        	writeb(e, *f);
828			e += line_width;
829		}
830		++d;
831		if ((i % scp->xsize) == scp->xsize - 1)
832			d += scp->font_size * line_width - scp->xsize;
833	}
834	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
835	outw(GDCIDX, 0x0000);		/* set/reset */
836	outw(GDCIDX, 0x0001);		/* set/reset enable */
837}
838
839static void
840vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
841{
842	if (base < 0 || base >= scp->font_size)
843		return;
844	/* the caller may set height <= 0 in order to disable the cursor */
845#if 0
846	scp->curs_attr.base = base;
847	scp->curs_attr.height = height;
848#endif
849}
850
851static void
852draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
853{
854	vm_offset_t d;
855	u_char *f;
856	int line_width, pixel_size;
857	int height;
858	int col1, col2, color;
859	int a;
860	int i, j;
861
862	line_width = scp->sc->adp->va_line_width;
863	pixel_size = scp->sc->adp->va_info.vi_pixel_size;
864
865	d = GET_PIXEL(scp, at, 8 * pixel_size, line_width) +
866	    (scp->font_size - scp->curs_attr.base - 1) * line_width;
867
868	a = sc_vtb_geta(&scp->vtb, at);
869
870	if (flip) {
871		col1 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
872		col2 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
873	} else {
874		col1 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
875		col2 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
876	}
877
878	f = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
879	      scp->font_size - scp->curs_attr.base - 1]);
880
881	height = imin(scp->curs_attr.height, scp->font_size);
882
883	for (i = 0; i < height; ++i, --f) {
884		for (j = 0; j < 8; ++j) {
885			color = *f & (1 << (7 - j)) ? col1 : col2;
886			DRAW_PIXEL(scp, d + pixel_size * j, color);
887		}
888
889		d -= line_width;
890	}
891}
892
893static void
894draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
895{
896	vm_offset_t d;
897	u_char *f;
898	int line_width;
899	int height;
900	int col;
901	int a;
902	int i;
903	u_char c;
904
905	line_width = scp->sc->adp->va_line_width;
906
907	d = GET_PIXEL(scp, at, 1, line_width) +
908	    (scp->font_size - scp->curs_attr.base - 1) * line_width;
909
910	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
911	outw(GDCIDX, 0x0003);		/* data rotate/function select */
912	outw(GDCIDX, 0x0f01);		/* set/reset enable */
913	/* set background color in EGA/VGA latch */
914	a = sc_vtb_geta(&scp->vtb, at);
915	if (flip)
916		col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
917	else
918		col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
919	outw(GDCIDX, col | 0x00);	/* set/reset */
920	outw(GDCIDX, 0xff08);		/* bit mask */
921	writeb(d, 0);
922	c = readb(d);			/* set bg color in the latch */
923	/* foreground color */
924	if (flip)
925		col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
926	else
927		col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
928	outw(GDCIDX, col | 0x00);	/* set/reset */
929	f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
930		+ scp->font_size - scp->curs_attr.base - 1]);
931	height = imin(scp->curs_attr.height, scp->font_size);
932	for (i = 0; i < height; ++i, --f) {
933		outw(GDCIDX, (*f << 8) | 0x08);	/* bit mask */
934	       	writeb(d, 0);
935		d -= line_width;
936	}
937	outw(GDCIDX, 0x0000);		/* set/reset */
938	outw(GDCIDX, 0x0001);		/* set/reset enable */
939	outw(GDCIDX, 0xff08);		/* bit mask */
940}
941
942static int pxlblinkrate = 0;
943
944static void
945vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
946{
947	if (scp->curs_attr.height <= 0)	/* the text cursor is disabled */
948		return;
949
950	if (on) {
951		if (!blink) {
952			scp->status |= VR_CURSOR_ON;
953			draw_pxlcursor_direct(scp, at, on, flip);
954		} else if (++pxlblinkrate & 4) {
955			pxlblinkrate = 0;
956			scp->status ^= VR_CURSOR_ON;
957			draw_pxlcursor_direct(scp, at,
958					      scp->status & VR_CURSOR_ON,
959					      flip);
960		}
961	} else {
962		if (scp->status & VR_CURSOR_ON)
963			draw_pxlcursor_direct(scp, at, on, flip);
964		scp->status &= ~VR_CURSOR_ON;
965	}
966	if (blink)
967		scp->status |= VR_CURSOR_BLINK;
968	else
969		scp->status &= ~VR_CURSOR_BLINK;
970}
971
972static void
973vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
974{
975	if (scp->curs_attr.height <= 0)	/* the text cursor is disabled */
976		return;
977
978	if (on) {
979		if (!blink) {
980			scp->status |= VR_CURSOR_ON;
981			draw_pxlcursor_planar(scp, at, on, flip);
982		} else if (++pxlblinkrate & 4) {
983			pxlblinkrate = 0;
984			scp->status ^= VR_CURSOR_ON;
985			draw_pxlcursor_planar(scp, at,
986					      scp->status & VR_CURSOR_ON,
987					      flip);
988		}
989	} else {
990		if (scp->status & VR_CURSOR_ON)
991			draw_pxlcursor_planar(scp, at, on, flip);
992		scp->status &= ~VR_CURSOR_ON;
993	}
994	if (blink)
995		scp->status |= VR_CURSOR_BLINK;
996	else
997		scp->status &= ~VR_CURSOR_BLINK;
998}
999
1000static void
1001vga_pxlblink_direct(scr_stat *scp, int at, int flip)
1002{
1003	if (!(scp->status & VR_CURSOR_BLINK))
1004		return;
1005	if (!(++pxlblinkrate & 4))
1006		return;
1007	pxlblinkrate = 0;
1008	scp->status ^= VR_CURSOR_ON;
1009	draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
1010}
1011
1012static void
1013vga_pxlblink_planar(scr_stat *scp, int at, int flip)
1014{
1015	if (!(scp->status & VR_CURSOR_BLINK))
1016		return;
1017	if (!(++pxlblinkrate & 4))
1018		return;
1019	pxlblinkrate = 0;
1020	scp->status ^= VR_CURSOR_ON;
1021	draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
1022}
1023
1024#ifndef SC_NO_CUTPASTE
1025
1026static void
1027draw_pxlmouse_planar(scr_stat *scp, int x, int y)
1028{
1029	vm_offset_t p;
1030	int line_width;
1031	int xoff, yoff;
1032	int ymax;
1033	u_short m;
1034	int i, j;
1035
1036	line_width = scp->sc->adp->va_line_width;
1037	xoff = (x - scp->xoff*8)%8;
1038	yoff = y - rounddown(y, line_width);
1039	ymax = imin(y + 16, scp->ypixel);
1040
1041	outw(GDCIDX, 0x0805);		/* read mode 1, write mode 0 */
1042	outw(GDCIDX, 0x0001);		/* set/reset enable */
1043	outw(GDCIDX, 0x0002);		/* color compare */
1044	outw(GDCIDX, 0x0007);		/* color don't care */
1045	outw(GDCIDX, 0xff08);		/* bit mask */
1046	outw(GDCIDX, 0x0803);		/* data rotate/function select (and) */
1047	p = scp->sc->adp->va_window + line_width*y + x/8;
1048	if (x < scp->xpixel - 8) {
1049		for (i = y, j = 0; i < ymax; ++i, ++j) {
1050			m = ~(mouse_and_mask[j] >> xoff);
1051#if defined(__i386__) || defined(__amd64__)
1052			*(u_char *)p &= m >> 8;
1053			*(u_char *)(p + 1) &= m;
1054#else
1055			writeb(p, readb(p) & (m >> 8));
1056			writeb(p + 1, readb(p + 1) & (m >> 8));
1057#endif
1058			p += line_width;
1059		}
1060	} else {
1061		xoff += 8;
1062		for (i = y, j = 0; i < ymax; ++i, ++j) {
1063			m = ~(mouse_and_mask[j] >> xoff);
1064#if defined(__i386__) || defined(__amd64__)
1065			*(u_char *)p &= m;
1066#else
1067			writeb(p, readb(p) & (m >> 8));
1068#endif
1069			p += line_width;
1070		}
1071	}
1072	outw(GDCIDX, 0x1003);		/* data rotate/function select (or) */
1073	p = scp->sc->adp->va_window + line_width*y + x/8;
1074	if (x < scp->xpixel - 8) {
1075		for (i = y, j = 0; i < ymax; ++i, ++j) {
1076			m = mouse_or_mask[j] >> xoff;
1077#if defined(__i386__) || defined(__amd64__)
1078			*(u_char *)p &= m >> 8;
1079			*(u_char *)(p + 1) &= m;
1080#else
1081			writeb(p, readb(p) & (m >> 8));
1082			writeb(p + 1, readb(p + 1) & (m >> 8));
1083#endif
1084			p += line_width;
1085		}
1086	} else {
1087		for (i = y, j = 0; i < ymax; ++i, ++j) {
1088			m = mouse_or_mask[j] >> xoff;
1089#if defined(__i386__) || defined(__amd64__)
1090			*(u_char *)p &= m;
1091#else
1092			writeb(p, readb(p) & (m >> 8));
1093#endif
1094			p += line_width;
1095		}
1096	}
1097	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
1098	outw(GDCIDX, 0x0003);		/* data rotate/function select */
1099}
1100
1101static void
1102remove_pxlmouse_planar(scr_stat *scp, int x, int y)
1103{
1104	vm_offset_t p;
1105	int col, row;
1106	int pos;
1107	int line_width;
1108	int ymax;
1109	int i;
1110
1111	/* erase the mouse cursor image */
1112	col = x/8 - scp->xoff;
1113	row = y/scp->font_size - scp->yoff;
1114	pos = row*scp->xsize + col;
1115	i = (col < scp->xsize - 1) ? 2 : 1;
1116	(*scp->rndr->draw)(scp, pos, i, FALSE);
1117	if (row < scp->ysize - 1)
1118		(*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
1119
1120	/* paint border if necessary */
1121	line_width = scp->sc->adp->va_line_width;
1122	outw(GDCIDX, 0x0005);		/* read mode 0, write mode 0 */
1123	outw(GDCIDX, 0x0003);		/* data rotate/function select */
1124	outw(GDCIDX, 0x0f01);		/* set/reset enable */
1125	outw(GDCIDX, 0xff08);		/* bit mask */
1126	outw(GDCIDX, (scp->border << 8) | 0x00);	/* set/reset */
1127	if (row == scp->ysize - 1) {
1128		i = (scp->ysize + scp->yoff)*scp->font_size;
1129		ymax = imin(i + scp->font_size, scp->ypixel);
1130		p = scp->sc->adp->va_window + i*line_width + scp->xoff + col;
1131		if (col < scp->xsize - 1) {
1132			for (; i < ymax; ++i) {
1133				writeb(p, 0);
1134				writeb(p + 1, 0);
1135				p += line_width;
1136			}
1137		} else {
1138			for (; i < ymax; ++i) {
1139				writeb(p, 0);
1140				p += line_width;
1141			}
1142		}
1143	}
1144	if ((col == scp->xsize - 1) && (scp->xoff > 0)) {
1145		i = (row + scp->yoff)*scp->font_size;
1146		ymax = imin(i + scp->font_size*2, scp->ypixel);
1147		p = scp->sc->adp->va_window + i*line_width
1148			+ scp->xoff + scp->xsize;
1149		for (; i < ymax; ++i) {
1150			writeb(p, 0);
1151			p += line_width;
1152		}
1153	}
1154	outw(GDCIDX, 0x0000);		/* set/reset */
1155	outw(GDCIDX, 0x0001);		/* set/reset enable */
1156}
1157
1158static void
1159vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
1160{
1161	vm_offset_t p;
1162	int line_width, pixel_size;
1163	int xend, yend;
1164	static int x_old = 0, xend_old = 0;
1165	static int y_old = 0, yend_old = 0;
1166	int i, j;
1167	uint32_t *u32;
1168	uint16_t *u16;
1169	uint8_t  *u8;
1170	int bpp;
1171
1172	if (!on)
1173		return;
1174
1175	bpp = scp->sc->adp->va_info.vi_depth;
1176
1177	if ((bpp == 16) && (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5))
1178		bpp = 15;
1179
1180	line_width = scp->sc->adp->va_line_width;
1181	pixel_size = scp->sc->adp->va_info.vi_pixel_size;
1182
1183	xend = imin(x + 16, scp->xpixel);
1184	yend = imin(y + 16, scp->ypixel);
1185
1186	p = scp->sc->adp->va_window + y_old * line_width + x_old * pixel_size;
1187
1188	for (i = 0; i < (yend_old - y_old); i++) {
1189		for (j = (xend_old - x_old - 1); j >= 0; j--) {
1190			switch (bpp) {
1191			case 32:
1192				u32 = (uint32_t*)(p + j * pixel_size);
1193				writel(u32, mouse_buf32[i * 16 + j]);
1194				break;
1195			case 16:
1196				/* FALLTHROUGH */
1197			case 15:
1198				u16 = (uint16_t*)(p + j * pixel_size);
1199				writew(u16, mouse_buf16[i * 16 + j]);
1200				break;
1201			case 8:
1202				u8 = (uint8_t*)(p + j * pixel_size);
1203				writeb(u8, mouse_buf8[i * 16 + j]);
1204				break;
1205			}
1206		}
1207
1208		p += line_width;
1209	}
1210
1211	p = scp->sc->adp->va_window + y * line_width + x * pixel_size;
1212
1213	for (i = 0; i < (yend - y); i++) {
1214		for (j = (xend - x - 1); j >= 0; j--) {
1215			switch (bpp) {
1216			case 32:
1217				u32 = (uint32_t*)(p + j * pixel_size);
1218				mouse_buf32[i * 16 + j] = *u32;
1219				if (mouse_or_mask[i] & (1 << (15 - j)))
1220					writel(u32, vga_palette32[15]);
1221				else if (mouse_and_mask[i] & (1 << (15 - j)))
1222					writel(u32, 0);
1223				break;
1224			case 16:
1225				u16 = (uint16_t*)(p + j * pixel_size);
1226				mouse_buf16[i * 16 + j] = *u16;
1227				if (mouse_or_mask[i] & (1 << (15 - j)))
1228					writew(u16, vga_palette16[15]);
1229				else if (mouse_and_mask[i] & (1 << (15 - j)))
1230					writew(u16, 0);
1231				break;
1232			case 15:
1233				u16 = (uint16_t*)(p  + j * pixel_size);
1234				mouse_buf16[i * 16 + j] = *u16;
1235				if (mouse_or_mask[i] & (1 << (15 - j)))
1236					writew(u16, vga_palette15[15]);
1237				else if (mouse_and_mask[i] & (1 << (15 - j)))
1238					writew(u16, 0);
1239				break;
1240			case 8:
1241				u8 = (uint8_t*)(p + j * pixel_size);
1242				mouse_buf8[i * 16 + j] = *u8;
1243				if (mouse_or_mask[i] & (1 << (15 - j)))
1244					writeb(u8, 15);
1245				else if (mouse_and_mask[i] & (1 << (15 - j)))
1246					writeb(u8, 0);
1247				break;
1248			}
1249		}
1250
1251		p += line_width;
1252	}
1253
1254	x_old = x;
1255	y_old = y;
1256	xend_old = xend;
1257	yend_old = yend;
1258}
1259
1260static void
1261vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
1262{
1263	if (on)
1264		draw_pxlmouse_planar(scp, x, y);
1265	else
1266		remove_pxlmouse_planar(scp, x, y);
1267}
1268
1269#endif /* SC_NO_CUTPASTE */
1270#endif /* SC_PIXEL_MODE */
1271
1272#ifndef SC_NO_MODE_CHANGE
1273
1274/* graphics mode renderer */
1275
1276static void
1277vga_grborder(scr_stat *scp, int color)
1278{
1279	vidd_set_border(scp->sc->adp, color);
1280}
1281
1282#endif
1283