scgdcrndr.c revision 146744
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 146744 2005-05-29 11:53:14Z nyan $
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 = {
64146744Snyan	(vr_init_t *)gdc_nop,
6548187Skato	gdc_txtclear,
6648187Skato	gdc_txtborder,
6748187Skato	gdc_txtdraw,
6848187Skato	gdc_txtcursor_shape,
6948187Skato	gdc_txtcursor,
7048187Skato	(vr_blink_cursor_t *)gdc_nop,
7148187Skato	(vr_set_mouse_t *)gdc_nop,
7248187Skato	gdc_txtmouse,
7348187Skato};
7456337SkatoRENDERER(gdc, 0, txtrndrsw, gdc_set);
7548187Skato
7648187Skato#ifndef SC_NO_MODE_CHANGE
7748187Skatostatic sc_rndr_sw_t grrndrsw = {
78146744Snyan	(vr_init_t *)gdc_nop,
7948187Skato	(vr_clear_t *)gdc_nop,
8048187Skato	gdc_grborder,
8148187Skato	(vr_draw_t *)gdc_nop,
8248187Skato	(vr_set_cursor_t *)gdc_nop,
8348187Skato	(vr_draw_cursor_t *)gdc_nop,
8448187Skato	(vr_blink_cursor_t *)gdc_nop,
8548187Skato	(vr_set_mouse_t *)gdc_nop,
8648187Skato	(vr_draw_mouse_t *)gdc_nop,
8748187Skato};
8856337SkatoRENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set);
8948187Skato#endif /* SC_NO_MODE_CHANGE */
9048187Skato
9156337SkatoRENDERER_MODULE(gdc, gdc_set);
9256337Skato
9348187Skatostatic void
9448187Skatogdc_nop(scr_stat *scp, ...)
9548187Skato{
9648187Skato}
9748187Skato
9848187Skato/* text mode renderer */
9948187Skato
10048187Skatostatic void
10148187Skatogdc_txtclear(scr_stat *scp, int c, int attr)
10248187Skato{
10348187Skato	sc_vtb_clear(&scp->scr, c, attr);
10448187Skato}
10548187Skato
10648187Skatostatic void
10748187Skatogdc_txtborder(scr_stat *scp, int color)
10848187Skato{
10948187Skato	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
11048187Skato}
11148187Skato
11248187Skatostatic void
11348187Skatogdc_txtdraw(scr_stat *scp, int from, int count, int flip)
11448187Skato{
11548187Skato	vm_offset_t p;
11648187Skato	int c;
11748187Skato	int a;
11848187Skato
11948187Skato	if (from + count > scp->xsize*scp->ysize)
12048187Skato		count = scp->xsize*scp->ysize - from;
12148187Skato
12248187Skato	if (flip) {
12390464Snyan		for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
12448187Skato			c = sc_vtb_getc(&scp->vtb, from);
12590464Snyan			a = sc_vtb_geta(&scp->vtb, from);
12690464Snyan#if 0
12790464Snyan			a ^= 0x0800;
12890464Snyan#else
12990464Snyan			a = (a & 0x8800) | ((a & 0x7000) >> 4)
13090464Snyan				| ((a & 0x0700) << 4);
13190464Snyan#endif
13287886Snyan			p = sc_vtb_putchar(&scp->scr, p, c, a);
13348187Skato		}
13448187Skato	} else {
13548187Skato		sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
13648187Skato	}
13748187Skato}
13848187Skato
13948187Skatostatic void
14048187Skatogdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
14148187Skato{
14248187Skato	if (base < 0 || base >= scp->font_size)
14348187Skato		return;
14448187Skato	/* the caller may set height <= 0 in order to disable the cursor */
14548187Skato	(*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
14648187Skato							base, height,
14748187Skato							scp->font_size, blink);
14848187Skato}
14948187Skato
15048187Skatostatic void
15148187Skatogdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
15248187Skato{
15348187Skato	if (on) {
15448187Skato		scp->status |= VR_CURSOR_ON;
15548187Skato		(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
15648187Skato						 at%scp->xsize, at/scp->xsize);
15748187Skato	} else {
15848187Skato		if (scp->status & VR_CURSOR_ON)
15948187Skato			(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
16048187Skato								  -1, -1);
16148187Skato		scp->status &= ~VR_CURSOR_ON;
16248187Skato	}
16348187Skato}
16448187Skato
16548187Skato#ifndef SC_NO_CUTPASTE
16648187Skato
16748187Skatostatic void
16848187Skatodraw_txtmouse(scr_stat *scp, int x, int y)
16948187Skato{
17048187Skato	int at;
17190464Snyan	int a;
17248187Skato
17348187Skato	at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
17490464Snyan	a = sc_vtb_geta(&scp->vtb, at);
17590464Snyan#if 0
17690464Snyan	a ^= 0x0800;
17790464Snyan#else
17890464Snyan	a = (a & 0x8800) | ((a & 0x7000) >> 4)
17990464Snyan		| ((a & 0x0700) << 4);
18090464Snyan#endif
18190464Snyan	sc_vtb_putc(&scp->scr, at, sc_vtb_getc(&scp->scr, at), a);
18248187Skato}
18348187Skato
18448187Skatostatic void
18548187Skatoremove_txtmouse(scr_stat *scp, int x, int y)
18648187Skato{
18748187Skato}
18848187Skato
18948187Skatostatic void
19048187Skatogdc_txtmouse(scr_stat *scp, int x, int y, int on)
19148187Skato{
19248187Skato	if (on)
19348187Skato		draw_txtmouse(scp, x, y);
19448187Skato	else
19548187Skato		remove_txtmouse(scp, x, y);
19648187Skato}
19748187Skato
19848187Skato#endif /* SC_NO_CUTPASTE */
19948187Skato
20048187Skato#ifndef SC_NO_MODE_CHANGE
20148187Skato
20248187Skato/* graphics mode renderer */
20348187Skato
20448187Skatostatic void
20548187Skatogdc_grborder(scr_stat *scp, int color)
20648187Skato{
20748187Skato	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
20848187Skato}
20948187Skato
21048187Skato#endif /* SC_NO_MODE_CHANGE */
211