summaryrefslogtreecommitdiffstats
path: root/sys/dev/syscons/scgfbrndr.c
blob: 20679b70d452d0bc5e8c77600acfe04bdb5ae2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*-
 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer as
 *    the first lines of this file unmodified.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright (c) 2000 Andrew Miklic
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include "opt_syscons.h"
#include "opt_gfb.h"
#ifdef __powerpc__
#include "opt_ofwfb.h"
#endif

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/fbio.h>
#include <sys/consio.h>

#include <machine/bus.h>

#include <dev/fb/fbreg.h>
#include <dev/syscons/syscons.h>

#ifndef SC_RENDER_DEBUG
#define SC_RENDER_DEBUG		0
#endif

static vr_clear_t		gfb_clear;
static vr_draw_border_t		gfb_border;
static vr_draw_t		gfb_draw;
static vr_set_cursor_t		gfb_cursor_shape;
static vr_draw_cursor_t		gfb_cursor;
static vr_blink_cursor_t	gfb_blink;
#ifndef SC_NO_CUTPASTE
static vr_draw_mouse_t		gfb_mouse;
#else
#define gfb_mouse		(vr_draw_mouse_t *)gfb_nop
#endif

static void			gfb_nop(scr_stat *scp);

sc_rndr_sw_t txtrndrsw = {
	(vr_init_t *)gfb_nop,
	gfb_clear,
	gfb_border,
	gfb_draw,	
	gfb_cursor_shape,
	gfb_cursor,
	gfb_blink,
	(vr_set_mouse_t *)gfb_nop,
	gfb_mouse,
};

#ifdef SC_PIXEL_MODE
sc_rndr_sw_t gfbrndrsw = {
	(vr_init_t *)gfb_nop,
	gfb_clear,
	gfb_border,
	gfb_draw,
	gfb_cursor_shape,
	gfb_cursor,
	gfb_blink,
	(vr_set_mouse_t *)gfb_nop,
	gfb_mouse,
};
#endif /* SC_PIXEL_MODE */

#ifndef SC_NO_MODE_CHANGE
sc_rndr_sw_t grrndrsw = {
	(vr_init_t *)gfb_nop,
	(vr_clear_t *)gfb_nop,
	gfb_border,
	(vr_draw_t *)gfb_nop,
	(vr_set_cursor_t *)gfb_nop,
	(vr_draw_cursor_t *)gfb_nop,
	(vr_blink_cursor_t *)gfb_nop,
	(vr_set_mouse_t *)gfb_nop,
	(vr_draw_mouse_t *)gfb_nop,
};
#endif /* SC_NO_MODE_CHANGE */

#ifndef SC_NO_CUTPASTE
#ifdef __sparc64__
static u_char mouse_pointer[22 * 2] = {
	0x00, 0x00,	/* ............ */
	0x80, 0x00,	/* *........... */
	0xc0, 0x00,	/* **.......... */
	0xe0, 0x00,	/* ***......... */
	0xf0, 0x00,	/* ****........ */
	0xf8, 0x00,	/* *****....... */
	0xfc, 0x00,	/* ******...... */
	0xfe, 0x00,	/* *******..... */
	0xff, 0x00,	/* ********.... */
	0xff, 0x80,	/* *********... */
	0xfc, 0xc0,	/* ******..**.. */
	0xdc, 0x00,	/* **.***...... */
	0x8e, 0x00,	/* *...***..... */
	0x0e, 0x00,	/* ....***..... */
	0x07, 0x00,	/* .....***.... */
	0x04, 0x00,	/* .....*...... */
	0x00, 0x00,	/* ............ */
	0x00, 0x00,	/* ............ */
	0x00, 0x00,	/* ............ */
	0x00, 0x00,	/* ............ */
	0x00, 0x00,	/* ............ */
	0x00, 0x00	/* ............ */
};
#else
static u_char mouse_pointer[16] = {
	0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
	0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
};
#endif
#endif

static void
gfb_nop(scr_stat *scp)
{
}

/* text mode renderer */

static void
gfb_clear(scr_stat *scp, int c, int attr)
{
	vidd_clear(scp->sc->adp);
}

static void
gfb_border(scr_stat *scp, int color)
{
	vidd_set_border(scp->sc->adp, color);
}

static void
gfb_draw(scr_stat *scp, int from, int count, int flip)
{
	int c;
	int a;
	int i, n;
	video_adapter_t *adp;

	adp = scp->sc->adp;

	/*
	   Determine if we need to scroll based on the offset
	   and the number of characters to be displayed...
	 */
	if (from + count > scp->xsize*scp->ysize) {

		/*
		   Calculate the number of characters past the end of the
		   visible screen...
		*/
		count = (from + count) -
		    (adp->va_info.vi_width * adp->va_info.vi_height);

		/*
		   Calculate the number of rows past the end of the visible
		   screen...
		*/
		n = (count / adp->va_info.vi_width) + 1;

		/* Scroll to make room for new text rows... */
		vidd_copy(adp, n, 0, n);
#if 0
		vidd_clear(adp, n);
#endif

		/* Display new text rows... */
		vidd_puts(adp, from,
		    (u_int16_t *)sc_vtb_pointer(&scp->vtb, from), count);
	}

	/*
	   We don't need to scroll, so we can just put the characters
	   all-at-once...
	*/
	else {

		/*
		   Determine the method by which we are to display characters
		   (are we going to print forwards or backwards?
		   do we need to do a character-by-character copy, then?)...
		*/
		if (flip)
			for (i = count; i-- > 0; ++from) {
				c = sc_vtb_getc(&scp->vtb, from);
				a = sc_vtb_geta(&scp->vtb, from) >> 8;
				vidd_putc(adp, from, c,
				    (a >> 4) | ((a & 0xf) << 4));
			}
		else {
			vidd_puts(adp, from,
			    (u_int16_t *)sc_vtb_pointer(&scp->vtb, from),
			    count);
		}
	}
}

static void 
gfb_cursor_shape(scr_stat *scp, int base, int height, int blink)
{
	if (base < 0 || base >= scp->font_size)
		return;
	/* the caller may set height <= 0 in order to disable the cursor */
#if 0
	scp->cursor_base = base;
	scp->cursor_height = height;
#endif
	vidd_set_hw_cursor_shape(scp->sc->adp, base, height, scp->font_size,
	    blink);
}

static int pxlblinkrate = 0;

#if defined(__sparc64__) || defined(SC_OFWFB)
static void
gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
{
	video_adapter_t *adp;
	int a, c;

	if (scp->curs_attr.height <= 0)	/* the text cursor is disabled */
		return;

	adp = scp->sc->adp;
	if(blink) {
		scp->status |= VR_CURSOR_BLINK;
		if (on) {
			scp->status |= VR_CURSOR_ON;
			vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
		} else {
			if (scp->status & VR_CURSOR_ON)
				vidd_set_hw_cursor(adp, -1, -1);
			scp->status &= ~VR_CURSOR_ON;
		}
	} else {
		scp->status &= ~VR_CURSOR_BLINK;
		if(on) {
			scp->status |= VR_CURSOR_ON;
			vidd_putc(scp->sc->adp, scp->cursor_oldpos,
			    sc_vtb_getc(&scp->vtb, scp->cursor_oldpos),
			    sc_vtb_geta(&scp->vtb, scp->cursor_oldpos) >> 8);
			a = sc_vtb_geta(&scp->vtb, at) >> 8;
			c = sc_vtb_getc(&scp->vtb, at);
			vidd_putc(scp->sc->adp, at, c,
			    (a >> 4) | ((a & 0xf) << 4));
			scp->cursor_saveunder_attr = a;
			scp->cursor_saveunder_char = c;
		} else {
			if (scp->status & VR_CURSOR_ON)
				vidd_putc(scp->sc->adp, at,
				    scp->cursor_saveunder_char,
				    scp->cursor_saveunder_attr);
			scp->status &= ~VR_CURSOR_ON;
		}
	}
}
#else
static void 
gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
{
	video_adapter_t *adp;

	adp = scp->sc->adp;
	if (scp->curs_attr.height <= 0) 
		/* the text cursor is disabled */
		return;

	if (on) {
		if (!blink) {
			scp->status |= VR_CURSOR_ON;
			vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
		} else if (++pxlblinkrate & 4) {
			pxlblinkrate = 0;
			scp->status ^= VR_CURSOR_ON;
			if(scp->status & VR_CURSOR_ON)
				vidd_set_hw_cursor(adp, at%scp->xsize,
				    at/scp->xsize);
			else
				vidd_set_hw_cursor(adp, -1, -1);
		}
	} else {
		if (scp->status & VR_CURSOR_ON)
			vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
		scp->status &= ~VR_CURSOR_ON;
	}
	if (blink)
		scp->status |= VR_CURSOR_BLINK;
	else
		scp->status &= ~VR_CURSOR_BLINK;
}
#endif

static void
gfb_blink(scr_stat *scp, int at, int flip)
{
	if (!(scp->status & VR_CURSOR_BLINK))
		return;
	if (!(++pxlblinkrate & 4))
		return;
	pxlblinkrate = 0;
	scp->status ^= VR_CURSOR_ON;
	gfb_cursor(scp, at, scp->status & VR_CURSOR_BLINK,
	    scp->status & VR_CURSOR_ON, flip);
}

#ifndef SC_NO_CUTPASTE

static void 
gfb_mouse(scr_stat *scp, int x, int y, int on)
{
#ifdef __sparc64__
		vidd_putm(scp->sc->adp, x, y, mouse_pointer,
		    on ? 0xffffffff : 0x0, 22, 12);
#else
	int i, pos;

	if (on) {

		/* Display the mouse pointer image... */
		vidd_putm(scp->sc->adp, x, y, mouse_pointer,
		    0xffffffff, 16, 8);
	} else {

		/*
		   Erase the mouse cursor image by redrawing the text
		   underneath it...
		*/
		return;
		pos = x*scp->xsize + y;
		i = (y < scp->xsize - 1) ? 2 : 1;
		(*scp->rndr->draw)(scp, pos, i, FALSE);
		if (x < scp->ysize - 1)
			(*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
	}
#endif
}

#endif /* SC_NO_CUTPASTE */
OpenPOWER on IntegriCloud