scgdcrndr.c revision 87886
1/*-
2 * Copyright (c) 1999 FreeBSD(98) Porting Team.
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 *    notice, this list of conditions and the following disclaimer as
10 *    the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
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/pc98/cbus/scgdcrndr.c 87886 2001-12-14 15:27:15Z nyan $
27 */
28
29#include "opt_syscons.h"
30#include "opt_gdc.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 <dev/fb/fbreg.h>
39#include <dev/syscons/syscons.h>
40
41#ifndef SC_RENDER_DEBUG
42#define SC_RENDER_DEBUG		0
43#endif
44
45static vr_clear_t		gdc_txtclear;
46static vr_draw_border_t		gdc_txtborder;
47static vr_draw_t		gdc_txtdraw;
48static vr_set_cursor_t		gdc_txtcursor_shape;
49static vr_draw_cursor_t		gdc_txtcursor;
50#ifndef SC_NO_CUTPASTE
51static vr_draw_mouse_t		gdc_txtmouse;
52#else
53#define gdc_txtmouse		(vr_draw_mouse_t *)gdc_nop
54#endif
55
56#ifndef SC_NO_MODE_CHANGE
57static vr_draw_border_t		gdc_grborder;
58#endif
59
60static void			gdc_nop(scr_stat *scp, ...);
61
62static sc_rndr_sw_t txtrndrsw = {
63	gdc_txtclear,
64	gdc_txtborder,
65	gdc_txtdraw,
66	gdc_txtcursor_shape,
67	gdc_txtcursor,
68	(vr_blink_cursor_t *)gdc_nop,
69	(vr_set_mouse_t *)gdc_nop,
70	gdc_txtmouse,
71};
72RENDERER(gdc, 0, txtrndrsw, gdc_set);
73
74#ifndef SC_NO_MODE_CHANGE
75static sc_rndr_sw_t grrndrsw = {
76	(vr_clear_t *)gdc_nop,
77	gdc_grborder,
78	(vr_draw_t *)gdc_nop,
79	(vr_set_cursor_t *)gdc_nop,
80	(vr_draw_cursor_t *)gdc_nop,
81	(vr_blink_cursor_t *)gdc_nop,
82	(vr_set_mouse_t *)gdc_nop,
83	(vr_draw_mouse_t *)gdc_nop,
84};
85RENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set);
86#endif /* SC_NO_MODE_CHANGE */
87
88RENDERER_MODULE(gdc, gdc_set);
89
90static void
91gdc_nop(scr_stat *scp, ...)
92{
93}
94
95/* text mode renderer */
96
97static void
98gdc_txtclear(scr_stat *scp, int c, int attr)
99{
100	sc_vtb_clear(&scp->scr, c, attr);
101}
102
103static void
104gdc_txtborder(scr_stat *scp, int color)
105{
106	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
107}
108
109static void
110gdc_txtdraw(scr_stat *scp, int from, int count, int flip)
111{
112	vm_offset_t p;
113	int c;
114	int a;
115
116	if (from + count > scp->xsize*scp->ysize)
117		count = scp->xsize*scp->ysize - from;
118
119	if (flip) {
120		p = sc_vtb_pointer(&scp->scr, from);
121		for (; count-- > 0; ++from) {
122			c = sc_vtb_getc(&scp->vtb, from);
123			a = sc_vtb_geta(&scp->vtb, from) ^ 0x0800;
124			p = sc_vtb_putchar(&scp->scr, p, c, a);
125		}
126	} else {
127		sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
128	}
129}
130
131static void
132gdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
133{
134	if (base < 0 || base >= scp->font_size)
135		return;
136	/* the caller may set height <= 0 in order to disable the cursor */
137	(*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
138							base, height,
139							scp->font_size, blink);
140}
141
142static void
143gdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
144{
145	if (on) {
146		scp->status |= VR_CURSOR_ON;
147		(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
148						 at%scp->xsize, at/scp->xsize);
149	} else {
150		if (scp->status & VR_CURSOR_ON)
151			(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
152								  -1, -1);
153		scp->status &= ~VR_CURSOR_ON;
154	}
155}
156
157#ifndef SC_NO_CUTPASTE
158
159static void
160draw_txtmouse(scr_stat *scp, int x, int y)
161{
162	int at;
163
164	at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
165	sc_vtb_putc(&scp->scr, at,
166		    sc_vtb_getc(&scp->scr, at),
167		    sc_vtb_geta(&scp->vtb, at) ^ 0x0800);
168}
169
170static void
171remove_txtmouse(scr_stat *scp, int x, int y)
172{
173}
174
175static void
176gdc_txtmouse(scr_stat *scp, int x, int y, int on)
177{
178	if (on)
179		draw_txtmouse(scp, x, y);
180	else
181		remove_txtmouse(scp, x, y);
182}
183
184#endif /* SC_NO_CUTPASTE */
185
186#ifndef SC_NO_MODE_CHANGE
187
188/* graphics mode renderer */
189
190static void
191gdc_grborder(scr_stat *scp, int color)
192{
193	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
194}
195
196#endif /* SC_NO_MODE_CHANGE */
197