scgdcrndr.c revision 130070
148187Skato/*-
248516Skato * Copyright (c) 1999 FreeBSD(98) Porting Team.
348516Skato * All rights reserved.
448516Skato *
548516Skato * Redistribution and use in source and binary forms, with or without
648516Skato * modification, are permitted provided that the following conditions
748516Skato * are met:
848516Skato * 1. Redistributions of source code must retain the above copyright
948516Skato *    notice, this list of conditions and the following disclaimer as
1048516Skato *    the first lines of this file unmodified.
1148516Skato * 2. Redistributions in binary form must reproduce the above copyright
1248516Skato *    notice, this list of conditions and the following disclaimer in the
1348516Skato *    documentation and/or other materials provided with the distribution.
1448516Skato *
1548516Skato * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1648516Skato * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1748516Skato * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1848516Skato * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1948516Skato * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2048516Skato * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2148516Skato * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2248516Skato * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2348516Skato * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2448516Skato * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2548516Skato *
2650477Speter * $FreeBSD: head/sys/pc98/cbus/scgdcrndr.c 130070 2004-06-04 13:04:10Z phk $
2748187Skato */
2848187Skato
2948187Skato#include "opt_syscons.h"
3048187Skato#include "opt_gdc.h"
3148187Skato
3248187Skato#include <sys/param.h>
3383875Snyan#include <sys/systm.h>
3448187Skato#include <sys/kernel.h>
35130070Sphk#include <sys/module.h>
3683875Snyan#include <sys/fbio.h>
3766870Skato#include <sys/consio.h>
3848187Skato
3948187Skato#include <dev/fb/fbreg.h>
4048187Skato#include <dev/syscons/syscons.h>
4148187Skato
4248187Skato#ifndef SC_RENDER_DEBUG
4348187Skato#define SC_RENDER_DEBUG		0
4448187Skato#endif
4548187Skato
4648187Skatostatic vr_clear_t		gdc_txtclear;
4748187Skatostatic vr_draw_border_t		gdc_txtborder;
4848187Skatostatic vr_draw_t		gdc_txtdraw;
4948187Skatostatic vr_set_cursor_t		gdc_txtcursor_shape;
5048187Skatostatic vr_draw_cursor_t		gdc_txtcursor;
5148187Skato#ifndef SC_NO_CUTPASTE
5248187Skatostatic vr_draw_mouse_t		gdc_txtmouse;
5348187Skato#else
5448187Skato#define gdc_txtmouse		(vr_draw_mouse_t *)gdc_nop
5548187Skato#endif
5648187Skato
5748187Skato#ifndef SC_NO_MODE_CHANGE
5848187Skatostatic vr_draw_border_t		gdc_grborder;
5948187Skato#endif
6048187Skato
6148187Skatostatic void			gdc_nop(scr_stat *scp, ...);
6248187Skato
6348187Skatostatic sc_rndr_sw_t txtrndrsw = {
6448187Skato	gdc_txtclear,
6548187Skato	gdc_txtborder,
6648187Skato	gdc_txtdraw,
6748187Skato	gdc_txtcursor_shape,
6848187Skato	gdc_txtcursor,
6948187Skato	(vr_blink_cursor_t *)gdc_nop,
7048187Skato	(vr_set_mouse_t *)gdc_nop,
7148187Skato	gdc_txtmouse,
7248187Skato};
7356337SkatoRENDERER(gdc, 0, txtrndrsw, gdc_set);
7448187Skato
7548187Skato#ifndef SC_NO_MODE_CHANGE
7648187Skatostatic sc_rndr_sw_t grrndrsw = {
7748187Skato	(vr_clear_t *)gdc_nop,
7848187Skato	gdc_grborder,
7948187Skato	(vr_draw_t *)gdc_nop,
8048187Skato	(vr_set_cursor_t *)gdc_nop,
8148187Skato	(vr_draw_cursor_t *)gdc_nop,
8248187Skato	(vr_blink_cursor_t *)gdc_nop,
8348187Skato	(vr_set_mouse_t *)gdc_nop,
8448187Skato	(vr_draw_mouse_t *)gdc_nop,
8548187Skato};
8656337SkatoRENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set);
8748187Skato#endif /* SC_NO_MODE_CHANGE */
8848187Skato
8956337SkatoRENDERER_MODULE(gdc, gdc_set);
9056337Skato
9148187Skatostatic void
9248187Skatogdc_nop(scr_stat *scp, ...)
9348187Skato{
9448187Skato}
9548187Skato
9648187Skato/* text mode renderer */
9748187Skato
9848187Skatostatic void
9948187Skatogdc_txtclear(scr_stat *scp, int c, int attr)
10048187Skato{
10148187Skato	sc_vtb_clear(&scp->scr, c, attr);
10248187Skato}
10348187Skato
10448187Skatostatic void
10548187Skatogdc_txtborder(scr_stat *scp, int color)
10648187Skato{
10748187Skato	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
10848187Skato}
10948187Skato
11048187Skatostatic void
11148187Skatogdc_txtdraw(scr_stat *scp, int from, int count, int flip)
11248187Skato{
11348187Skato	vm_offset_t p;
11448187Skato	int c;
11548187Skato	int a;
11648187Skato
11748187Skato	if (from + count > scp->xsize*scp->ysize)
11848187Skato		count = scp->xsize*scp->ysize - from;
11948187Skato
12048187Skato	if (flip) {
12190464Snyan		for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
12248187Skato			c = sc_vtb_getc(&scp->vtb, from);
12390464Snyan			a = sc_vtb_geta(&scp->vtb, from);
12490464Snyan#if 0
12590464Snyan			a ^= 0x0800;
12690464Snyan#else
12790464Snyan			a = (a & 0x8800) | ((a & 0x7000) >> 4)
12890464Snyan				| ((a & 0x0700) << 4);
12990464Snyan#endif
13087886Snyan			p = sc_vtb_putchar(&scp->scr, p, c, a);
13148187Skato		}
13248187Skato	} else {
13348187Skato		sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
13448187Skato	}
13548187Skato}
13648187Skato
13748187Skatostatic void
13848187Skatogdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
13948187Skato{
14048187Skato	if (base < 0 || base >= scp->font_size)
14148187Skato		return;
14248187Skato	/* the caller may set height <= 0 in order to disable the cursor */
14348187Skato	(*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
14448187Skato							base, height,
14548187Skato							scp->font_size, blink);
14648187Skato}
14748187Skato
14848187Skatostatic void
14948187Skatogdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
15048187Skato{
15148187Skato	if (on) {
15248187Skato		scp->status |= VR_CURSOR_ON;
15348187Skato		(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
15448187Skato						 at%scp->xsize, at/scp->xsize);
15548187Skato	} else {
15648187Skato		if (scp->status & VR_CURSOR_ON)
15748187Skato			(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
15848187Skato								  -1, -1);
15948187Skato		scp->status &= ~VR_CURSOR_ON;
16048187Skato	}
16148187Skato}
16248187Skato
16348187Skato#ifndef SC_NO_CUTPASTE
16448187Skato
16548187Skatostatic void
16648187Skatodraw_txtmouse(scr_stat *scp, int x, int y)
16748187Skato{
16848187Skato	int at;
16990464Snyan	int a;
17048187Skato
17148187Skato	at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
17290464Snyan	a = sc_vtb_geta(&scp->vtb, at);
17390464Snyan#if 0
17490464Snyan	a ^= 0x0800;
17590464Snyan#else
17690464Snyan	a = (a & 0x8800) | ((a & 0x7000) >> 4)
17790464Snyan		| ((a & 0x0700) << 4);
17890464Snyan#endif
17990464Snyan	sc_vtb_putc(&scp->scr, at, sc_vtb_getc(&scp->scr, at), a);
18048187Skato}
18148187Skato
18248187Skatostatic void
18348187Skatoremove_txtmouse(scr_stat *scp, int x, int y)
18448187Skato{
18548187Skato}
18648187Skato
18748187Skatostatic void
18848187Skatogdc_txtmouse(scr_stat *scp, int x, int y, int on)
18948187Skato{
19048187Skato	if (on)
19148187Skato		draw_txtmouse(scp, x, y);
19248187Skato	else
19348187Skato		remove_txtmouse(scp, x, y);
19448187Skato}
19548187Skato
19648187Skato#endif /* SC_NO_CUTPASTE */
19748187Skato
19848187Skato#ifndef SC_NO_MODE_CHANGE
19948187Skato
20048187Skato/* graphics mode renderer */
20148187Skato
20248187Skatostatic void
20348187Skatogdc_grborder(scr_stat *scp, int color)
20448187Skato{
20548187Skato	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
20648187Skato}
20748187Skato
20848187Skato#endif /* SC_NO_MODE_CHANGE */
209