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

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


## diffname pc/vgacyber938x.c 1998/0205
## diff -e /dev/null /n/emeliedump/1998/0205/sys/src/brazil/pc/vgacyber938x.c
0a
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"

#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
#include "screen.h"

static int
cyber938xpageset(VGAscr*, int page)
{
	int opage;

	opage = inb(0x3D8);

	outb(0x3D8, page);
	outb(0x3D9, page);

	return opage;
}

static void
cyber938xpage(VGAscr* scr, int page)
{
	lock(&scr->devlock);
	cyber938xpageset(scr, page);
	unlock(&scr->devlock);
}

static ulong
cyber938xlinear(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, 0x1023, 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;
}

static void
cyber938xcurdisable(VGAscr*)
{
	vgaxo(Crtx, 0x50, 0);
}

static void
cyber938xcurenable(VGAscr* scr)
{
	int i;
	ulong storage;

	cyber938xcurdisable(scr);

	/*
	 * Cursor colours.
	 */
	for(i = 0x48; i < 0x4C; i++)
		vgaxo(Crtx, i, Pwhite);
	for(i = 0x4C; i < 0x50; i++)
		vgaxo(Crtx, i, Pblack);

	/*
	 * Find a place for the cursor data in display memory.
	 */
	storage = ((scr->gscreen->width*BY2WD*scr->gscreen->r.max.y+1023)/1024)*2;
	vgaxo(Crtx, 0x44, storage & 0xFF);
	vgaxo(Crtx, 0x45, (storage>>8) & 0xFF);
	storage *= 512;
	scr->storage = storage;

	/*
	 * Enable the 32x32 cursor.
	 * (64x64 is bit 0, X11 format is bit 6 and
	 * cursor enable is bit 7).
	 */
	vgaxo(Crtx, 0x50, 0xC0);
}

static void
cyber938xcurload(VGAscr* scr, Cursor* curs)
{
	uchar *p;
	int islinear, opage, y;

	cyber938xcurdisable(scr);

	opage = 0;
	p = KADDR(scr->aperture);
	islinear = vgaxi(Crtx, 0x21) & 0x20;
	if(!islinear){
		lock(&scr->devlock);
		opage = cyber938xpageset(scr, scr->storage>>16);
		p += (scr->storage & 0xFFFF);
	}
	else
		p += scr->storage;

	for(y = 0; y < 16; y++){
		*p++ = curs->set[2*y]|curs->clr[2*y];
		*p++ = curs->set[2*y + 1]|curs->clr[2*y + 1];
		*p++ = 0x00;
		*p++ = 0x00;
	}
	while(y < 32){
		*p++ = 0x00;
		*p++ = 0x00;
		*p++ = 0x00;
		*p++ = 0x00;
		y++;
	}

	/*
	 * This is clearly not what's supposed to be done, but
	 * without a proper datasheet this is what binary search
	 * through the display memory gives as the place for the
	 * pattern.
	 * Note also that is seems the cursor image offset (CRT44
	 * and CRT45) cannot be set above 512KB.
	 * This will do for now as the ThinkPad 560E has 1MB and
	 * can only manage 800x600x8.
	 */
	p += 512*1024 - 128;
	for(y = 0; y < 16; y++){
		*p++ = curs->set[2*y];
		*p++ = curs->set[2*y + 1];
		*p++ = 0x00;
		*p++ = 0x00;
	}
	while(y < 32){
		*p++ = 0x00;
		*p++ = 0x00;
		*p++ = 0x00;
		*p++ = 0x00;
		y++;
	}

	if(!islinear){
		cyber938xpageset(scr, opage);
		unlock(&scr->devlock);
	}

	/*
	 * Save the cursor hotpoint and enable the cursor.
	 */
	scr->offset = curs->offset;
	vgaxo(Crtx, 0x50, 0xC0);
}

static int
cyber938xcurmove(VGAscr* scr, Point p)
{
	int x, xo, y, yo;

	/*
	 * Mustn't position the cursor offscreen even partially,
	 * or it might disappear. Therefore, if x or y is -ve, adjust the
	 * cursor origins instead.
	 */
	if((x = p.x+scr->offset.x) < 0){
		xo = -x;
		x = 0;
	}
	else
		xo = 0;
	if((y = p.y+scr->offset.y) < 0){
		yo = -y;
		y = 0;
	}
	else
		yo = 0;

	/*
	 * Load the new values.
	 */
	vgaxo(Crtx, 0x46, xo);
	vgaxo(Crtx, 0x47, yo);
	vgaxo(Crtx, 0x40, x & 0xFF);
	vgaxo(Crtx, 0x41, (x>>8) & 0xFF);
	vgaxo(Crtx, 0x42, y & 0xFF);
	vgaxo(Crtx, 0x43, (y>>8) & 0xFF);

	return 0;
}

VGAdev vgacyber938xdev = {
	"cyber938x",

	0,				/* enable */
	0,				/* disable */
	cyber938xpage,			/* page */
	cyber938xlinear,		/* linear */
};

VGAcur vgacyber938xcur = {
	"cyber938xhwgc",

	cyber938xcurenable,		/* enable */
	cyber938xcurdisable,		/* disable */
	cyber938xcurload,		/* load */
	cyber938xcurmove,		/* move */
};
.
## diffname pc/vgacyber938x.c 1998/0209
## diff -e /n/emeliedump/1998/0205/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1998/0209/sys/src/brazil/pc/vgacyber938x.c
209a
}

static void
cyber938xcurenable(VGAscr* scr)
{
	int i;
	ulong storage;

	cyber938xcurdisable(scr);

	/*
	 * Cursor colours.
	 */
	for(i = 0x48; i < 0x4C; i++)
		vgaxo(Crtx, i, Pwhite);
	for(i = 0x4C; i < 0x50; i++)
		vgaxo(Crtx, i, Pblack);

	/*
	 * Find a place for the cursor data in display memory.
	 */
	storage = ((scr->gscreen->width*BY2WD*scr->gscreen->r.max.y+1023)/1024)*2;
	vgaxo(Crtx, 0x44, storage & 0xFF);
	vgaxo(Crtx, 0x45, (storage>>8) & 0xFF);
	storage *= 512;
	scr->storage = storage;

	/*
	 * Load, locate and enable the 32x32 cursor.
	 * (64x64 is bit 0, X11 format is bit 6 and cursor
	 * enable is bit 7).
	 */
	cyber938xcurload(scr, &arrow);
	cyber938xcurmove(scr, ZP);
	vgaxo(Crtx, 0x50, 0xC0);
.
74,106d
## diffname pc/vgacyber938x.c 1998/0214
## diff -e /n/emeliedump/1998/0209/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1998/0214/sys/src/brazil/pc/vgacyber938x.c
211c
	vgaxo(Crtx, 0x50, 0xC8);
.
207c
	 * enable is bit 7). Bit 3 needs to be set on 9382
	 * chips otherwise even the white bits are black.
.
140c
	vgaxo(Crtx, 0x50, 0xC8);
.
## diffname pc/vgacyber938x.c 1998/0522
## diff -e /n/emeliedump/1998/0214/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1998/0522/sys/src/brazil/pc/vgacyber938x.c
111c
	 * Note also that it seems the cursor image offset (CRT44
.
## diffname pc/vgacyber938x.c 1998/0829
## diff -e /n/emeliedump/1998/0522/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1998/0829/sys/src/brazil/pc/vgacyber938x.c
212c
	vgaxo(Crtx, 0x50, CursorON);
.
201c
	storage *= 1024;
.
198c
	storage = ((scr->gscreen->width*BY2WD*scr->gscreen->r.max.y+1023)/1024);
.
140c
	vgaxo(Crtx, 0x50, CursorON);
.
123,129c
	memset(p, 0, (32-y)*8);
.
97,117d
70c
	vgaxo(Crtx, 0x50, CursorOFF);
.
13a
enum {
	CursorON	= 0xC8,
	CursorOFF	= 0x00,
};

.
## diffname pc/vgacyber938x.c 1999/0119
## diff -e /n/emeliedump/1998/0829/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1999/0119/sys/src/brazil/pc/vgacyber938x.c
11a
#include <cursor.h>
.
## diffname pc/vgacyber938x.c 1999/1005
## diff -e /n/emeliedump/1999/0119/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/1999/1005/sys/src/brazil/pc/vgacyber938x.c
172c
		vgaxo(Crtx, i, 0xFF);
.
170c
		vgaxo(Crtx, i, 0x00);
.
## diffname pc/vgacyber938x.c 2001/0410
## diff -e /n/emeliedump/1999/1005/sys/src/brazil/pc/vgacyber938x.c /n/emeliedump/2001/0410/sys/src/9/pc/vgacyber938x.c
200a
	cyber938xdrawinit,		/* drawinit */
.
193a
static void
cyber938xdrawinit(VGAscr *scr)
{
}

.
69a
	if(aperture)
		addvgaseg("cyber938xscreen", aperture, osize);
	if(scr->mmio)
		addvgaseg("cyber938xmmio", (ulong)scr->mmio, 0x20000);

.
57a
		/*
		 * Heuristic to detect the MMIO space.  We're flying blind
		 * here, with only the XFree86 source to guide us.
		 */
		if(p->mem[1].size == 0x20000)
			scr->mmio = (ulong*)(p->mem[1].bar & ~0x0F);
.
53a
	scr->mmio = 0;
.
47a
	osize = *size;
.
45a
	int osize;
.
## diffname pc/vgacyber938x.c 2001/0430
## diff -e /n/emeliedump/2001/0410/sys/src/9/pc/vgacyber938x.c /n/emeliedump/2001/0430/sys/src/9/pc/vgacyber938x.c
220c
	nil,				/* drawinit */
.
216,217c
	nil,				/* enable */
	nil,				/* disable */
.
208,212d
## diffname pc/vgacyber938x.c 2001/0527
## diff -e /n/emeliedump/2001/0430/sys/src/9/pc/vgacyber938x.c /n/emeliedump/2001/0527/sys/src/9/pc/vgacyber938x.c
215d
211,212c
	0,				/* enable */
	0,				/* disable */
.
79,83d
61,66d
56d
49d
46d
## diffname pc/vgacyber938x.c 2001/0908
## diff -e /n/emeliedump/2001/0527/sys/src/9/pc/vgacyber938x.c /n/emeliedump/2001/0908/sys/src/9/pc/vgacyber938x.c
200a
	nil,				/* drawinit */
.
197,198c
	nil,				/* enable */
	nil,				/* disable */
.
69a
	if(aperture)
		addvgaseg("cyber938xscreen", aperture, osize);
	if(scr->mmio)
		addvgaseg("cyber938xmmio", (ulong)scr->mmio, 0x20000);

.
57a
		/*
		 * Heuristic to detect the MMIO space.  We're flying blind
		 * here, with only the XFree86 source to guide us.
		 */
		if(p->mem[1].size == 0x20000)
			scr->mmio = (ulong*)(p->mem[1].bar & ~0x0F);
.
53a
	scr->mmio = 0;
.
47a
	osize = *size;
.
45a
	int osize;
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.