Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/vgaclgd542x.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/vgaclgd542x.c 1995/02021
## diff -e /dev/null /n/fornaxdump/1995/02021/sys/src/brazil/pc/vgaclgd542x.c
0a
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"

#include <libg.h>
#include "screen.h"
#include "vga.h"

static void
clgd542xpage(int page)
{
	vgaxo(Grx, 0x09, page<<4);
}

static Vgac clgd542x = {
	"clgd542x",
	clgd542xpage,

	0,
};

void
vgaclgd542xlink(void)
{
	addvgaclink(&clgd542x);
}
.
## diffname pc/vgaclgd542x.c 1997/0327
## diff -e /n/fornaxdump/1995/02021/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/0327/sys/src/brazil/pc/vgaclgd542x.c
15a
	unlock(&clgd542xlock);
.
14a
	lock(&clgd542xlock);
.
11a
static Lock clgd542xlock;

.
## diffname pc/vgaclgd542x.c 1997/0716
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/0716/sys/src/brazil/pc/vgaclgd542x.c
32a
	addhwgclink(&clgd542xhwgc);
.
21a
static void
disable(void)
{
	uchar sr12;

	lock(&clgd542xlock);
	sr12 = vgaxi(Seqx, 0x12);
	vgaxo(Seqx, 0x12, sr12 & ~0x01);
	unlock(&clgd542xlock);
}

static void
enable(void)
{
	uchar sr12;
 
	/*
	 * Disable the cursor.
	 */
	lock(&clgd542xlock);
	sr12 = vgaxi(Seqx, 0x12);
	vgaxo(Seqx, 0x12, sr12 & ~0x01);

	/*
	 * Cursor colours.  
	 */
	vgaxo(Seqx, 0x12, sr12|0x02);
	setcolor(0x00, Pwhite<<(32-6), Pwhite<<(32-6), Pwhite<<(32-6));
	setcolor(0x0F, Pblack<<(32-6), Pblack<<(32-6), Pblack<<(32-6));
	vgaxo(Seqx, 0x12, sr12);

	/*
	 * Memory size. The BIOS leaves this in Seq0A, bits 4 and 3.
	 * See Technical Reference Manual Appendix E1, Section 1.3.2.
	 *
	 * The storage area for the 64x64 cursors is the last 16Kb of
	 * display memory.
	 */
	switch((vgaxi(Seqx, 0x0A)>>3) & 0x03){

	case 0:
		storage = (256-16)*1024;
		break;

	case 1:
		storage = (512-16)*1024;
		break;

	case 2:
		storage = (1024-16)*1024;
		break;

	case 3:
		storage = (2048-16)*1024;
		break;
	}
 
	/*
	 * Set the current cursor to index 0
	 * and turn the 64x64 cursor on.
	 */
	vgaxo(Seqx, 0x13, 0);
	vgaxo(Seqx, 0x12, sr12|0x05);

	unlock(&clgd542xlock);
}

static void
initcursor(Cursor* c, int xo, int yo, int index)
{
	uchar *p;
	uint p0, p1;
	int x, y;

	/*
	 * Is linear addressing turned on? This will determine
	 * how we access the cursor storage.
	 */
	if(vgaxi(Seqx, 0x07) & 0xF0)
		p = ((uchar*)gscreen.base) + storage;
	else {
		vgaxo(Grx, 0x09, (storage>>16)<<4);
		p = ((uchar*)gscreen.base) + (storage & 0xFFFF);
	}
	p += index*1024;

	for(y = yo; y < 16; y++){
		p0 = c->clr[2*y];
		p1 = c->clr[2*y+1];
		if(xo){
			p0 = (p0<<xo)|(p1>>(8-xo));
			p1 <<= xo;
		}
		*p++ = p0;
		*p++ = p1;

		for(x = 16; x < 64; x += 8)
			*p++ = 0x00;

		p0 = c->clr[2*y]|c->set[2*y];
		p1 = c->clr[2*y+1]|c->set[2*y+1];
		if(xo){
			p0 = (p0<<xo)|(p1>>(8-xo));
			p1 <<= xo;
		}
		*p++ = p0;
		*p++ = p1;

		for(x = 16; x < 64; x += 8)
			*p++ = 0x00;
	}
	while(y < 64+yo){
		for(x = 0; x < 64; x += 8){
			*p++ = 0x00;
			*p++ = 0x00;
		}
		y++;
	}
}

static void
load(Cursor* c)
{
	uchar sr12;

	/*
	 * Lock the display memory so we can update the
	 * cursor bitmap if necessary.
	 * Disable the cursor.
	 * If it's the same as the last cursor loaded,
	 * just make sure it's enabled and index 0.
	 */
	lock(&clgd542xlock);
	sr12 = vgaxi(Seqx, 0x12);
	vgaxo(Seqx, 0x12, sr12 & ~0x01);

	if(memcmp(c, &curcursor, sizeof(Cursor)) == 0){
		vgaxo(Seqx, 0x13, 0);
		vgaxo(Seqx, 0x12, sr12|0x05);
		unlock(&clgd542xlock);
		return;
	}
	memmove(&curcursor, c, sizeof(Cursor));
	initcursor(c, 0, 0, 0);

	/*
	 * Enable the cursor.
	 */
	vgaxo(Seqx, 0x13, 0);
	vgaxo(Seqx, 0x12, sr12|0x05);

	unlock(&clgd542xlock);
}

static int
move(Point p)
{
	int index, x, xo, y, yo;

	if(canlock(&clgd542xlock) == 0)
		return 1;

	index = 0;
	if((x = p.x+curcursor.offset.x) < 0){
		xo = -x;
		x = 0;
	}
	else
		xo = 0;
	if((y = p.y+curcursor.offset.y) < 0){
		yo = -y;
		y = 0;
	}
	else
		yo = 0;

	if(xo || yo){
		initcursor(&curcursor, xo, yo, 1);
		index = 1;
	}
	vgaxo(Seqx, 0x13, index<<2);
	
	vgaxo(Seqx, 0x10|((x & 0x07)<<5), (x>>3) & 0xFF);
	vgaxo(Seqx, 0x11|((y & 0x07)<<5), (y>>3) & 0xFF);

	unlock(&clgd542xlock);
	return 0;
}

static Hwgc clgd542xhwgc = {
	"clgd542xhwgc",
	enable,
	load,
	move,
	disable,

	0,
};

.
12a
static ulong storage;
.
11a
extern Bitmap gscreen;
extern Cursor curcursor;

.
## diffname pc/vgaclgd542x.c 1997/0717
## diff -e /n/emeliedump/1997/0716/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/0717/sys/src/brazil/pc/vgaclgd542x.c
227a
	clgd542xlinear,
.
110c
//	p += index*1024;
memset(p, 0xFF, 16*1024);
return;
.
82c
	storage = ((256<<mem)-16)*1024;

.
77,80d
74,75c
	default:				/* uh, ah dunno */
.
70,71c
	case 0xA0:				/* CL-GD5430 */
	case 0xA8:				/* CL-GD5434 */
	case 0xAC:				/* CL-GD5436 */
		/*
		 * Attempt to intuit the memory size from the DRAM control
		 * register. Minimum is 512KB.
		 * If DRAM bank switching is on then there's double.
		 */
		x = vgaxi(Seqx, 0x0F);
		mem = (x>>3) & 0x03;
		if(x & 0x80)
			mem++;
.
66,67c
	case 0x88:				/* CL-GD5420 */
	case 0x8C:				/* CL-GD5422 */
	case 0x94:				/* CL-GD5424 */
	case 0x80:				/* CL-GD5425 */
	case 0x90:				/* CL-GD5426 */
	case 0x98:				/* CL-GD5427 */
	case 0x9C:				/* CL-GD5429 */
		/*
		 * The BIOS leaves the memory size in Seq0A, bits 4 and 3.
		 * See Technical Reference Manual Appendix E1, Section 1.3.2.
		 *
		 * The storage area for the 64x64 cursors is the last 16Kb of
		 * display memory.
		 */
		mem = (vgaxi(Seqx, 0x0A)>>3) & 0x03;
.
57,64c
	mem = 0;
	switch(vgaxi(Crtx, 0x27) & ~0x03){
.
40a
	int mem, x;
.
25a
static int
clgd542xlinear(ulong* mem, ulong* size, ulong* align)
{
	ulong baseaddr;
	static Pcidev *p;

	if((*size && *size < 16*MB) || (*align && (*align & (16*MB-1))))
		return 0;

	*mem = 0;

	/*
	 * This obviously isn't good enough on a system with
	 * more than one PCI card from Cirrus.
	 */
	if(p == 0 && (p = pcimatch(p, 0x1013, 0)) == 0)
		return 0;

	switch(p->did){

	case 0xA0:
	case 0xA8:
	case 0xAC:
		break;

	default:
		return 0;
	}

	if((baseaddr = upamalloc(0, *size, *align)) == 0)
		return 0;
	*mem = baseaddr;
	baseaddr = PADDR(baseaddr);
	pcicfgw32(p, PciBAR0, baseaddr);

	return *mem;
}

.
5a
#include "io.h"
.
## diffname pc/vgaclgd542x.c 1997/0718
## diff -e /n/emeliedump/1997/0717/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/0718/sys/src/brazil/pc/vgaclgd542x.c
230a
{
for(storage = 0; storage < (2048-32)*1024; storage += 16*1024)
    initcursor(c, 0, 0, 0);
}
.
163,165c
	p += index*1024;
.
160c
		setclgd542xpage(storage>>16);
.
55a
	/*
	 * This doesn't work if the card is on the other side of a
	 * a bridge. Need to coordinate with PCI support.
	 */
.
34a
	if(*align == 0)
		*align = 16*MB;
	else if(*align & (16*MB-1))
		return 0;
.
33c
	if(*size != 16*MB)
.
23c
	setclgd542xpage(page);
.
19a
setclgd542xpage(int page)
{
	if(vgaxi(Seqx, 0x07) & 0xF0)
		page = 0;
	if(vgaxi(Seqx, 0x0B) & 0x20)
		vgaxo(Grx, 0x09, page<<2);
	else
		vgaxo(Grx, 0x09, page<<4);
}

static void
.
## diffname pc/vgaclgd542x.c 1997/1004
## diff -e /n/emeliedump/1997/0718/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/1004/sys/src/brazil/pc/vgaclgd542x.c
248,251d
215a

#ifdef notdef
	buggery(0);
#endif /* notdef */

	if(!(vgaxi(Seqx, 0x07) & 0xF0))
		setclgd542xpage(opage);
.
180a
#endif /* notdef */
.
178,179c
	else{
#ifdef notdef
		p = buggery(1);
#else
		opage = setclgd542xpage(storage>>16);
.
175a
	opage = 0;
.
170c
	int opage, x, y;
.
164a
static uchar*
buggery(int on)
{
	static uchar gr9, grA, grB;
	uchar *p;

	p = 0;
	if(on){
		gr9 = vgaxi(Grx, 0x09);
		grA = vgaxi(Grx, 0x0A);
		grB = vgaxi(Grx, 0x0B);

		vgaxo(Grx, 0x0B, 0x21|grB);
		vgaxo(Grx, 0x09, storage>>14);
		p = ((uchar*)gscreen.base) + (storage & 0x3FFF);
	}
	else{
		vgaxo(Grx, 0x09, gr9);
		vgaxo(Grx, 0x0A, grA);
		vgaxo(Grx, 0x0B, grB);
	}

	return p;
}

.
27a
		opage = gr9>>4;
	}

	return opage;
.
26c
		opage = gr9>>2;
	}
	else{
.
24c
	gr9 = vgaxi(Grx, 0x09);
	grB = vgaxi(Grx, 0x0B);
	if(grB & 0x20){
.
21a
	uchar gr9, grB;
	int opage;

.
19c
static int
.
## diffname pc/vgaclgd542x.c 1997/1007
## diff -e /n/emeliedump/1997/1004/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/1007/sys/src/brazil/pc/vgaclgd542x.c
348c
	0,
.
258,262c
	if(!(seq07 & 0xF0))
.
226,227c
		p0 = c->set[2*y];
		p1 = c->set[2*y+1];
.
222a
	else
		p += storage;
.
220,221c
		p += (storage & 0xFFFF);
.
213,218c
	p = ((uchar*)gscreen.base);
	if(!(seq07 & 0xF0)){
.
211a
	seq07 = vgaxi(Seqx, 0x07);
.
204c
	uchar *p, seq07;
.
176,200d
123,124c
	setcolor(0x00, Pblack<<(32-6), Pblack<<(32-6), Pblack<<(32-6));
	setcolor(0x0F, Pwhite<<(32-6), Pwhite<<(32-6), Pwhite<<(32-6));
.
49,94d
28,29c
	if(vgaxi(Grx, 0x0B) & 0x20){
.
22c
	uchar gr9;
.
## diffname pc/vgaclgd542x.c 1997/1101
## diff -e /n/emeliedump/1997/1007/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1997/1101/sys/src/brazil/pc/vgaclgd542x.c
275,280c
VGAcur vgaclgd542xcur = {
	"clgd542xhwgc",

	clgd542xenable,
	clgd542xdisable,
	clgd542xload,
	clgd542xmove,
};
.
271,272d
265,268c
	0,
.
257,262c
VGAdev vgaclgd542xdev = {
	"clgd542x",
.
253d
245c
		clgd542xinitcursor(scr, xo, yo, 1);
.
237c
	if((y = p.y+scr->offset.y) < 0){
.
231c
	if((x = p.x+scr->offset.x) < 0){
.
227,229d
223c
clgd542xmove(VGAscr* scr, Point p)
.
218,219d
204,211c
	memmove(&scr->Cursor, curs, sizeof(Cursor));
	clgd542xinitcursor(scr, 0, 0, 0);
.
200d
197,198d
194,195d
189c
clgd542xload(VGAscr* scr, Cursor* curs)
.
184,185c
	if(!(seq07 & 0xF0)){
		clgd542xpageset(scr, opage);
		unlock(&scr->devlock);
	}
.
164,165c
		p0 = scr->clr[2*y]|scr->set[2*y];
		p1 = scr->clr[2*y+1]|scr->set[2*y+1];
.
152,153c
		p0 = scr->set[2*y];
		p1 = scr->set[2*y+1];
.
148c
		p += scr->storage;
.
144,145c
		lock(&scr->devlock);
		opage = clgd542xpageset(scr, scr->storage>>16);
		p += (scr->storage & 0xFFFF);
.
142c
	p = KADDR(scr->aperture);
.
130c
clgd542xinitcursor(VGAscr* scr, int xo, int yo, int index)
.
125,126d
117c
	scr->storage = ((256<<mem)-16)*1024;
.
76,77c
	vgao(PaddrW, 0x00);
	vgao(Pdata, Pwhite);
	vgao(Pdata, Pwhite);
	vgao(Pdata, Pwhite);
	vgao(PaddrW, 0x0F);
	vgao(Pdata, Pblack);
	vgao(Pdata, Pblack);
	vgao(Pdata, Pblack);
.
73c
	 * Cursor colours.
	 * Can't call setcolor here as cursor is already locked.
.
68d
60c
clgd542xenable(VGAscr* scr)
.
56d
53d
49c
clgd542xdisable(VGAscr*)
.
43,45c
	lock(&scr->devlock);
	clgd542xpageset(scr, page);
	unlock(&scr->devlock);
.
41c
clgd542xpage(VGAscr* scr, int page)
.
34c
		opage = gr09>>4;
.
30c
		opage = gr09>>2;
.
27c
	gr09 = vgaxi(Grx, 0x09);
.
24c
	
.
22c
	uchar gr09;
.
20c
clgd542xpageset(VGAscr*, int page)
.
13,18d
11d
9c
#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
.
## diffname pc/vgaclgd542x.c 1998/0106
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1998/0106/sys/src/brazil/pc/vgaclgd542x.c
101a
	case 0xB8:				/* CL-GD5446 */
.
## diffname pc/vgaclgd542x.c 1998/0308
## diff -e /n/emeliedump/1998/0106/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1998/0308/sys/src/brazil/pc/vgaclgd542x.c
61,62c
	sr12 = vgaxi(Seqx, 0x12) & ~0x01;
	vgaxo(Seqx, 0x12, sr12);
.
## diffname pc/vgaclgd542x.c 1998/0312
## diff -e /n/emeliedump/1998/0308/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1998/0312/sys/src/brazil/pc/vgaclgd542x.c
61,62c
	sr12 = vgaxi(Seqx, 0x12);
	vgaxo(Seqx, 0x12, sr12 & ~0x01);
.
## diffname pc/vgaclgd542x.c 1998/0512
## diff -e /n/emeliedump/1998/0312/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1998/0512/sys/src/brazil/pc/vgaclgd542x.c
247c
	clgd542xlinear,
.
42a
static ulong
clgd542xlinear(VGAscr* scr, int* size, int* align)
{
	ulong aperture, oaperture;
	int oapsize, wasupamem;
	Pcidev *p;

	oaperture = scr->aperture;
	oapsize = scr->apsize;
	wasupamem = scr->isupamem;
	if(wasupamem)
		upafree(oaperture, oapsize);
	scr->isupamem = 0;

	if(p = pcimatch(nil, 0x1013, 0)){
		aperture = p->mem[0].bar & ~0x0F;
		*size = p->mem[0].size;
	}
	else
		aperture = 0;

	aperture = upamalloc(aperture, *size, *align);
	if(aperture == 0){
		if(wasupamem && upamalloc(oaperture, oapsize, 0))
			scr->isupamem = 1;
	}
	else
		scr->isupamem = 1;

	return aperture;
}

.
## diffname pc/vgaclgd542x.c 1999/0119
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/1999/0119/sys/src/brazil/pc/vgaclgd542x.c
11a
#include <cursor.h>
.
## diffname pc/vgaclgd542x.c 2000/0927
## diff -e /n/emeliedump/1999/0119/sys/src/brazil/pc/vgaclgd542x.c /n/emeliedump/2000/0927/sys/src/9/pc/vgaclgd542x.c
135a
	case 0x30:				/* CL-GD7543 */
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].