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

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


## diffname pc/vgatvp3026.c 1997/0603
## diff -e /dev/null /n/emeliedump/1997/0603/sys/src/brazil/pc/vgatvp3026.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"

extern Cursor curcursor;

/*
 * TVP3026 Viewpoint Video Interface Pallette.
 * Assumes hooked up to an S3 Vision968.
 */
enum {
	Index		= 0x00,		/* Index */
	Data		= 0x0A,		/* Data */

	CaddrW		= 0x04,		/* Colour Write Address */
	Cdata		= 0x05,		/* Colour Data */

	Cctl		= 0x09,		/* Direct Cursor Control */
	Cram		= 0x0B,		/* Cursor Ram Data */
	Cxlsb		= 0x0C,		/* Cursor X LSB */
	Cxmsb		= 0x0D,		/* Cursor X MSB */
	Cylsb		= 0x0E,		/* Cursor Y LSB */
	Cymsb		= 0x0F,		/* Cursor Y MSB */

	Icctl		= 0x06,		/* Indirect Cursor Control */
};

/*
 * Lower 2-bits of indirect DAC register
 * addressing.
 */
static ushort dacxreg[4] = {
	PaddrW, Pdata, Pixmask, PaddrR
};

static Point hotpoint;

static uchar
tvp3026io(uchar reg, uchar data)
{
	uchar crt55;

	crt55 = vgaxi(Crtx, 0x55) & 0xFC;
	vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
	vgao(dacxreg[reg & 0x03], data);

	return crt55;
}

static void
tvp3026o(uchar reg, uchar data)
{
	uchar crt55;

	crt55 = tvp3026io(reg, data);
	vgaxo(Crtx, 0x55, crt55);
}

void
tvp3026xo(uchar index, uchar data)
{
	uchar crt55;

	crt55 = tvp3026io(Index, index);
	vgaxo(Crtx, 0x55, crt55|((Data>>2) & 0x03));
	vgao(dacxreg[Data & 0x03], data);
	vgaxo(Crtx, 0x55, crt55);
}

static void
load(Cursor *c)
{
	int x, y;

	/*
	 * Lock the DAC registers so we can update the
	 * cursor bitmap if necessary.
	 * If it's the same as the last cursor we loaded,
	 * just make sure it's enabled.
	 */
	lock(&palettelock);
	if(memcmp(c, &curcursor, sizeof(Cursor)) == 0){
		tvp3026o(Cctl, 0x01);
		unlock(&palettelock);
		return;
	}
	memmove(&curcursor, c, sizeof(Cursor));

	/*
	 * Make sure cursor is off by initialising the cursor
	 * control to defaults.
	 * Write to the indirect control register to make sure
	 * direct register is enabled and upper 2 bits of cursor
	 * RAM address are 0.
	 * The LSBs of the cursor RAM address are in PaddrW.
	 */
	tvp3026xo(Icctl, 0x90);
	tvp3026o(Cctl, 0x00);
	vgao(PaddrW, 0x00);

	/*
	 * Initialise the 64x64 cursor RAM array. There are 2 planes,
	 * p0 and p1. Data is written 8 pixels per byte, with p0 in the
	 * first 512 bytes of the array and p1 in the second.
	 * The cursor is set in 3-colour mode which gives the following
	 * truth table:
	 *	p1 p0	colour
	 *	 0  0	transparent
	 *	 0  1	cursor colour 0
	 *	 1  0	cursor colour 1
	 *	 1  1	cursor colour 2
	 * Put the cursor into the top-left of the 64x64 array.
	 * The 0,0 cursor point is bottom-right, so positioning will
	 * have to take that into account.
	 */
	for(y = 0; y < 64; y++){
		for(x = 0; x < 64/8; x++){
			if(x < 16/8 && y < 16)
				tvp3026o(Cram, c->clr[x+y*2]);
			else
				tvp3026o(Cram, 0x00);
		}
	}
	for(y = 0; y < 64; y++){
		for(x = 0; x < 64/8; x++){
			if(x < 16/8 && y < 16)
				tvp3026o(Cram, c->set[x+y*2]);
			else
				tvp3026o(Cram, 0x00);
		}
	}

	/*
	 * Initialise the cursor hot-point
	 * and enable the cursor in 3-colour mode.
	 */
	hotpoint.x = 64+c->offset.x;
	hotpoint.y = 64+c->offset.y;

	tvp3026o(Cctl, 0x01);

	unlock(&palettelock);
}

static void
enable(void)
{
	lock(&palettelock);

	/*
	 * Make sure cursor is off and direct control enabled.
	 */
	tvp3026xo(Icctl, 0x90);
	tvp3026o(Cctl, 0x00);

	/*
	 * Overscan colour,
	 * cursor colour 1 (white),
	 * cursor colour 2, 3 (black).
	 */
	tvp3026o(CaddrW, 0x00);
	tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
	tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
	tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
	tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);

	/*
	 * Enable the cursor in 3-colour mode.
	 */
	tvp3026o(Cctl, 0x01);

	unlock(&palettelock);
}

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

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

	x = p.x+hotpoint.x;
	y = p.y+hotpoint.y;

	tvp3026o(Cxlsb, x & 0xFF);
	tvp3026o(Cxmsb, (x>>8) & 0x0F);
	tvp3026o(Cylsb, y & 0xFF);
	tvp3026o(Cymsb, (y>>8) & 0x0F);

	unlock(&palettelock);

	return 0;
}

static void
disable(void)
{
	lock(&palettelock);
	tvp3026xo(Icctl, 0x90);
	tvp3026o(Cctl, 0x00);
	unlock(&palettelock);
}

Hwgc tvp3026hwgc = {
	"tvp3026hwgc",
	enable,
	load,
	move,
	disable,

	0,
};

void
vgatvp3026link(void)
{
	addhwgclink(&tvp3026hwgc);
}
.
## diffname pc/vgatvp3026.c 1997/1101
## diff -e /n/emeliedump/1997/0603/sys/src/brazil/pc/vgatvp3026.c /n/emeliedump/1997/1101/sys/src/brazil/pc/vgatvp3026.c
221,226d
219c
	tvp3026enable,
	tvp3026disable,
	tvp3026load,
	tvp3026move,
.
214,217d
203,212c
VGAcur vgatvp3026cur = {
.
198,199d
190,192d
187,188c
	x = p.x+scr->offset.x;
	y = p.y+scr->offset.y;
.
183c
tvp3026move(VGAscr* scr, Point p)
.
152,181d
148,149d
144,146c
	scr->offset.x = 64+curs->offset.x;
	scr->offset.y = 64+curs->offset.y;
.
141c
	 * Initialise the cursor hotpoint
.
134c
				tvp3026o(Cram, curs->set[x+y*2]);
.
126c
				tvp3026o(Cram, curs->clr[x+y*2]);
.
96a
	 * Overscan colour,
	 * cursor colour 1 (white),
	 * cursor colour 2, 3 (black).
	 */
	tvp3026o(CaddrW, 0x00);
	tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
	tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
	tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
	tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);

	/*
	 * Enable the cursor in 3-colour mode.
	 */
	tvp3026o(Cctl, 0x01);
}

static void
tvp3026load(VGAscr* scr, Cursor* curs)
{
	int x, y;

	/*
.
88,94c
	tvp3026xo(Icctl, 0x90);
	tvp3026o(Cctl, 0x00);
.
83,86c
	 * Make sure cursor is off and direct control enabled.
.
81a
static void
tvp3026enable(VGAscr*)
{
.
80c
	tvp3026xo(Icctl, 0x90);
	tvp3026o(Cctl, 0x00);
}
.
78c
tvp3026disable(VGAscr*)
.
43,44d
12,13d
10d
8c
#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
.
## diffname pc/vgatvp3026.c 1999/0119
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/vgatvp3026.c /n/emeliedump/1999/0119/sys/src/brazil/pc/vgatvp3026.c
10a
#include <cursor.h>
.

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.