scgdcrndr.c revision 66870
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 66870 2000-10-09 11:07:18Z kato $
2748187Skato */
2848187Skato
2948187Skato#include "opt_syscons.h"
3048187Skato#include "opt_gdc.h"
3148187Skato
3248187Skato#include <sys/param.h>
3348187Skato#include <sys/kernel.h>
3466870Skato#include <sys/consio.h>
3566870Skato#include <sys/fbio.h>
3648187Skato
3748187Skato#include <dev/fb/fbreg.h>
3848187Skato#include <dev/syscons/syscons.h>
3948187Skato
4048187Skato#ifndef SC_RENDER_DEBUG
4148187Skato#define SC_RENDER_DEBUG		0
4248187Skato#endif
4348187Skato
4448187Skatostatic vr_clear_t		gdc_txtclear;
4548187Skatostatic vr_draw_border_t		gdc_txtborder;
4648187Skatostatic vr_draw_t		gdc_txtdraw;
4748187Skatostatic vr_set_cursor_t		gdc_txtcursor_shape;
4848187Skatostatic vr_draw_cursor_t		gdc_txtcursor;
4948187Skato#ifndef SC_NO_CUTPASTE
5048187Skatostatic vr_draw_mouse_t		gdc_txtmouse;
5148187Skato#else
5248187Skato#define gdc_txtmouse		(vr_draw_mouse_t *)gdc_nop
5348187Skato#endif
5448187Skato
5548187Skato#ifndef SC_NO_MODE_CHANGE
5648187Skatostatic vr_draw_border_t		gdc_grborder;
5748187Skato#endif
5848187Skato
5948187Skatostatic void			gdc_nop(scr_stat *scp, ...);
6048187Skato
6156337Skatostatic struct linker_set	gdc_set;
6256337Skato
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) {
12148187Skato		p = sc_vtb_pointer(&scp->scr, from);
12248187Skato		for (; count-- > 0; ++from) {
12348187Skato			c = sc_vtb_getc(&scp->vtb, from);
12448187Skato			a = sc_vtb_geta(&scp->vtb, from) ^ 0x4;
12548187Skato			sc_vtb_putchar(&scp->scr, p, c, a);
12648187Skato		}
12748187Skato	} else {
12848187Skato		sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
12948187Skato	}
13048187Skato}
13148187Skato
13248187Skatostatic void
13348187Skatogdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
13448187Skato{
13548187Skato	if (base < 0 || base >= scp->font_size)
13648187Skato		return;
13748187Skato	/* the caller may set height <= 0 in order to disable the cursor */
13848187Skato	(*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
13948187Skato							base, height,
14048187Skato							scp->font_size, blink);
14148187Skato}
14248187Skato
14348187Skatostatic void
14448187Skatogdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
14548187Skato{
14648187Skato	if (on) {
14748187Skato		scp->status |= VR_CURSOR_ON;
14848187Skato		(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
14948187Skato						 at%scp->xsize, at/scp->xsize);
15048187Skato	} else {
15148187Skato		if (scp->status & VR_CURSOR_ON)
15248187Skato			(*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp,
15348187Skato								  -1, -1);
15448187Skato		scp->status &= ~VR_CURSOR_ON;
15548187Skato	}
15648187Skato}
15748187Skato
15848187Skato#ifndef SC_NO_CUTPASTE
15948187Skato
16048187Skatostatic void
16148187Skatodraw_txtmouse(scr_stat *scp, int x, int y)
16248187Skato{
16348187Skato	int at;
16448187Skato
16548187Skato	at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
16648187Skato	sc_vtb_putc(&scp->scr, at,
16748187Skato		    sc_vtb_getc(&scp->scr, at),
16848187Skato		    sc_vtb_geta(&scp->scr, at) ^ 0x4);
16948187Skato}
17048187Skato
17148187Skatostatic void
17248187Skatoremove_txtmouse(scr_stat *scp, int x, int y)
17348187Skato{
17448187Skato}
17548187Skato
17648187Skatostatic void
17748187Skatogdc_txtmouse(scr_stat *scp, int x, int y, int on)
17848187Skato{
17948187Skato	if (on)
18048187Skato		draw_txtmouse(scp, x, y);
18148187Skato	else
18248187Skato		remove_txtmouse(scp, x, y);
18348187Skato}
18448187Skato
18548187Skato#endif /* SC_NO_CUTPASTE */
18648187Skato
18748187Skato#ifndef SC_NO_MODE_CHANGE
18848187Skato
18948187Skato/* graphics mode renderer */
19048187Skato
19148187Skatostatic void
19248187Skatogdc_grborder(scr_stat *scp, int color)
19348187Skato{
19448187Skato	(*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
19548187Skato}
19648187Skato
19748187Skato#endif /* SC_NO_MODE_CHANGE */
198