plan 9 kernel history: overview | file list | diff list

1998/0512/pc/vgaclgd542x.c (diff list | history)

pc/vgaclgd542x.c on 1995/02021
1995/02021    
#include "u.h" 
#include "../port/lib.h" 
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
1997/0717    
#include "io.h" 
1995/02021    
#include "../port/error.h" 
 
1997/1101    
#define	Image	IMAGE 
#include <draw.h> 
#include <memdraw.h> 
1995/02021    
#include "screen.h" 
 
1997/1004    
static int 
1997/1101    
clgd542xpageset(VGAscr*, int page) 
1997/0718    
{ 
1997/1101    
	uchar gr09; 
1997/1004    
	int opage; 
1997/1101    
	 
1997/0718    
	if(vgaxi(Seqx, 0x07) & 0xF0) 
		page = 0; 
1997/1101    
	gr09 = vgaxi(Grx, 0x09); 
1997/1007    
	if(vgaxi(Grx, 0x0B) & 0x20){ 
1997/0718    
		vgaxo(Grx, 0x09, page<<2); 
1997/1101    
		opage = gr09>>2; 
1997/1004    
	} 
	else{ 
1997/0718    
		vgaxo(Grx, 0x09, page<<4); 
1997/1101    
		opage = gr09>>4; 
1997/1004    
	} 
 
	return opage; 
1997/0718    
} 
 
static void 
1997/1101    
clgd542xpage(VGAscr* scr, int page) 
1995/02021    
{ 
1997/1101    
	lock(&scr->devlock); 
	clgd542xpageset(scr, page); 
	unlock(&scr->devlock); 
1995/02021    
} 
 
1998/0512    
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; 
} 
 
1997/0716    
static void 
1997/1101    
clgd542xdisable(VGAscr*) 
1997/0716    
{ 
	uchar sr12; 
 
	sr12 = vgaxi(Seqx, 0x12); 
	vgaxo(Seqx, 0x12, sr12 & ~0x01); 
} 
 
static void 
1997/1101    
clgd542xenable(VGAscr* scr) 
1997/0716    
{ 
	uchar sr12; 
1997/0717    
	int mem, x; 
1997/0716    
  
	/* 
	 * Disable the cursor. 
	 */ 
1998/0312    
	sr12 = vgaxi(Seqx, 0x12); 
	vgaxo(Seqx, 0x12, sr12 & ~0x01); 
1997/0716    
 
	/* 
1997/1101    
	 * Cursor colours. 
	 * Can't call setcolor here as cursor is already locked. 
1997/0716    
	 */ 
	vgaxo(Seqx, 0x12, sr12|0x02); 
1997/1101    
	vgao(PaddrW, 0x00); 
	vgao(Pdata, Pwhite); 
	vgao(Pdata, Pwhite); 
	vgao(Pdata, Pwhite); 
	vgao(PaddrW, 0x0F); 
	vgao(Pdata, Pblack); 
	vgao(Pdata, Pblack); 
	vgao(Pdata, Pblack); 
1997/0716    
	vgaxo(Seqx, 0x12, sr12); 
 
1997/0717    
	mem = 0; 
	switch(vgaxi(Crtx, 0x27) & ~0x03){ 
1997/0716    
 
1997/0717    
	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; 
1997/0716    
		break; 
 
1997/0717    
	case 0xA0:				/* CL-GD5430 */ 
	case 0xA8:				/* CL-GD5434 */ 
	case 0xAC:				/* CL-GD5436 */ 
1998/0106    
	case 0xB8:				/* CL-GD5446 */ 
1997/0717    
		/* 
		 * 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++; 
1997/0716    
		break; 
 
1997/0717    
	default:				/* uh, ah dunno */ 
1997/0716    
		break; 
	} 
1997/1101    
	scr->storage = ((256<<mem)-16)*1024; 
1997/0717    
 
1997/0716    
	/* 
	 * Set the current cursor to index 0 
	 * and turn the 64x64 cursor on. 
	 */ 
	vgaxo(Seqx, 0x13, 0); 
	vgaxo(Seqx, 0x12, sr12|0x05); 
} 
 
static void 
1997/1101    
clgd542xinitcursor(VGAscr* scr, int xo, int yo, int index) 
1997/0716    
{ 
1997/1007    
	uchar *p, seq07; 
1997/0716    
	uint p0, p1; 
1997/1004    
	int opage, x, y; 
1997/0716    
 
	/* 
	 * Is linear addressing turned on? This will determine 
	 * how we access the cursor storage. 
	 */ 
1997/1007    
	seq07 = vgaxi(Seqx, 0x07); 
1997/1004    
	opage = 0; 
1997/1101    
	p = KADDR(scr->aperture); 
1997/1007    
	if(!(seq07 & 0xF0)){ 
1997/1101    
		lock(&scr->devlock); 
		opage = clgd542xpageset(scr, scr->storage>>16); 
		p += (scr->storage & 0xFFFF); 
1997/0716    
	} 
1997/1007    
	else 
1997/1101    
		p += scr->storage; 
1997/0718    
	p += index*1024; 
1997/0716    
 
	for(y = yo; y < 16; y++){ 
1997/1101    
		p0 = scr->set[2*y]; 
		p1 = scr->set[2*y+1]; 
1997/0716    
		if(xo){ 
			p0 = (p0<<xo)|(p1>>(8-xo)); 
			p1 <<= xo; 
		} 
		*p++ = p0; 
		*p++ = p1; 
 
		for(x = 16; x < 64; x += 8) 
			*p++ = 0x00; 
 
1997/1101    
		p0 = scr->clr[2*y]|scr->set[2*y]; 
		p1 = scr->clr[2*y+1]|scr->set[2*y+1]; 
1997/0716    
		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++; 
	} 
1997/1004    
 
1997/1101    
	if(!(seq07 & 0xF0)){ 
		clgd542xpageset(scr, opage); 
		unlock(&scr->devlock); 
	} 
1997/0716    
} 
 
static void 
1997/1101    
clgd542xload(VGAscr* scr, Cursor* curs) 
1997/0716    
{ 
	uchar sr12; 
 
	/* 
	 * Disable the cursor. 
	 */ 
	sr12 = vgaxi(Seqx, 0x12); 
	vgaxo(Seqx, 0x12, sr12 & ~0x01); 
 
1997/1101    
	memmove(&scr->Cursor, curs, sizeof(Cursor)); 
	clgd542xinitcursor(scr, 0, 0, 0); 
1997/0716    
 
	/* 
	 * Enable the cursor. 
	 */ 
	vgaxo(Seqx, 0x13, 0); 
	vgaxo(Seqx, 0x12, sr12|0x05); 
} 
 
static int 
1997/1101    
clgd542xmove(VGAscr* scr, Point p) 
1997/0716    
{ 
	int index, x, xo, y, yo; 
 
	index = 0; 
1997/1101    
	if((x = p.x+scr->offset.x) < 0){ 
1997/0716    
		xo = -x; 
		x = 0; 
	} 
	else 
		xo = 0; 
1997/1101    
	if((y = p.y+scr->offset.y) < 0){ 
1997/0716    
		yo = -y; 
		y = 0; 
	} 
	else 
		yo = 0; 
 
	if(xo || yo){ 
1997/1101    
		clgd542xinitcursor(scr, xo, yo, 1); 
1997/0716    
		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); 
 
	return 0; 
} 
 
1997/1101    
VGAdev vgaclgd542xdev = { 
	"clgd542x", 
1997/0716    
 
	0, 
1997/1101    
	0, 
1995/02021    
	clgd542xpage, 
1998/0512    
	clgd542xlinear, 
1995/02021    
}; 
 
1997/1101    
VGAcur vgaclgd542xcur = { 
	"clgd542xhwgc", 
 
	clgd542xenable, 
	clgd542xdisable, 
	clgd542xload, 
	clgd542xmove, 
}; 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)