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

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


## diffname pc/vgatvp3020.c 1994/0624
## diff -e /dev/null /n/fornaxdump/1994/0624/sys/src/brazil/pc/vgatvp3020.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"

/*
 * TVP3020 Viewpoint Video Interface Pallette.
 * Assumes hooked up to an S3 86C928.
 */
enum {
	AddrW		= 0x00,		/* Palette address register - write mode */
	Palette		= 0x01,		/* Color palette holding register */
	Pmask		= 0x02,		/* Pixel read mask */
	AddrR		= 0x03,		/* Palette address register - read mode */

	Index		= 0x06,		/* Index register */
	Data		= 0x07,		/* Data register */
};

/*
 * Lower 2-bits of indirect DAC register
 * addressing.
 */
static ushort dacxreg[4] = {
	DACWx, DACData, DACMask, DACSts
};

static uchar
tvp3020io(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
tvp3020xo(uchar index, uchar data)
{
	uchar crt55;

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

static void
load(Cursor *c)
{
	uchar p, p0, p1;
	int x, y;

	lock(&pallettelock);

	/*
	 * Make sure cursor is off by initialising the cursor
	 * control to defaults + X-Windows cursor mode.
	 */
	tvp3020xo(0x06, 0x10);				/* Cursor Control Register */

	/*
	 * Initialise the cursor RAM LS and MS address
	 * (LS must be first).
	 */
	tvp3020xo(0x08, 0x00);				/* Cursor RAM LS Address */
	tvp3020xo(0x09, 0x00);				/* Cursor RAM MS Address */

	/*
	 * Initialise the 64x64 cursor RAM array. There are 2 planes,
	 * p0 and p1. Data is written 4 pixels per byte, with p1 the
	 * MS bit of each pixel.
	 * The cursor is set in X-Windows mode which gives the following
	 * truth table:
	 *	p1 p0	colour
	 *	 0  0	underlying pixel colour
	 *	 0  1	underlying pixel colour
	 *	 1  0	cursor colour 1
	 *	 1  1	cursor colour 2
	 * Put the cursor into the top-left of the 64x64 array.
	 */
	for(y = 0; y < 64; y++){
		for(x = 0; x < 64/8; x++){
			if(x < 16/8 && y < 16){
				p0 = c->clr[x+y*2];
				p1 = c->set[x+y*2];

				p = 0x00;
				if(p1 & 0x10)
					p |= 0x03;
				else if(p0 & 0x10)
					p |= 0x02;
				if(p1 & 0x20)
					p |= 0x0C;
				else if(p0 & 0x20)
					p |= 0x08;
				if(p1 & 0x40)
					p |= 0x30;
				else if(p0 & 0x40)
					p |= 0x20;
				if(p1 & 0x80)
					p |= 0xC0;
				else if(p0 & 0x80)
					p |= 0x80;
				tvp3020xo(0x0A, p);	/* Cursor RAM Data */

				p = 0x00;
				if(p1 & 0x01)
					p |= 0x03;
				else if(p0 & 0x01)
					p |= 0x02;
				if(p1 & 0x02)
					p |= 0x0C;
				else if(p0 & 0x02)
					p |= 0x08;
				if(p1 & 0x04)
					p |= 0x30;
				else if(p0 & 0x04)
					p |= 0x20;
				if(p1 & 0x08)
					p |= 0xC0;
				else if(p0 & 0x08)
					p |= 0x80;
				tvp3020xo(0x0A, p);	/* Cursor RAM Data */
			}
			else{
				tvp3020xo(0x0A, 0x00);	/* Cursor RAM Data */
				tvp3020xo(0x0A, 0x00);
			}
		}
	}

	/*
	 * Initialise the cursor hot-point
	 * and enable the cursor.
	 */
	tvp3020xo(0x04, -c->offset.x);			/* Sprite Origin X */
	tvp3020xo(0x05, -c->offset.y);			/* Sprite Origin Y */

	tvp3020xo(0x06, 0x40|0x10);			/* Cursor Control Register */

	unlock(&pallettelock);
}

static void
enable(void)
{
	uchar r;

	lock(&pallettelock);

	/*
	 * Make sure cursor is off by initialising the cursor
	 * control to defaults + X-Windows cursor mode.
	 */
	tvp3020xo(0x06, 0x10);				/* Cursor Control Register */

	/*
	 * Overscan colour,
	 * cursor colour 1 (white),
	 * cursor colour 2 (black).
	 */
	tvp3020xo(0x20, 0xFF); tvp3020xo(0x21, 0xFF); tvp3020xo(0x22, 0xFF);
	tvp3020xo(0x23, 0xFF); tvp3020xo(0x24, 0xFF); tvp3020xo(0x25, 0xFF);
	tvp3020xo(0x26, 0x00); tvp3020xo(0x27, 0x00); tvp3020xo(0x28, 0x00);

	unlock(&pallettelock);

	/*
	 * Finally, enable
	 *	the hardware cursor external operation mode;
	 *	cursor control enable for Bt485 DAC (!).
	 */
	r = vgaxi(Crtx, 0x55)|0x20;
	vgaxo(Crtx, 0x55, r);

	r = vgaxi(Crtx, 0x45)|0x20;
	vgaxo(Crtx, 0x45, r);
}

static int
move(Point p)
{
	if(canlock(&pallettelock) == 0)
		return 1;

	tvp3020xo(0x00, p.x & 0xFF);			/* Cursor Position X LSB */
	tvp3020xo(0x01, (p.x>>8) & 0x0F);		/* Cursor Position X MSB */
	tvp3020xo(0x02, p.y & 0xFF);			/* Cursor Position Y LSB */
	tvp3020xo(0x03, (p.y>>8) & 0x0F);		/* Cursor Position Y MSB */

	unlock(&pallettelock);
	return 0;
}

static void
disable(void)
{
	uchar r;

	/*
	 * Disable 
	 *	cursor;
	 *	cursor control enable for Bt485 DAC (!);
	 *	the hardware cursor external operation mode.
	 */
	lock(&pallettelock);
	tvp3020xo(0x06, 0x10);				/* Cursor Control Register */
	unlock(&pallettelock);

	r = vgaxi(Crtx, 0x45) & ~0x20;
	vgaxo(Crtx, 0x45, r);

	r = vgaxi(Crtx, 0x55) & ~0x20;
	vgaxo(Crtx, 0x55, r);
}

Hwgc tvp3020hwgc = {
	"tvp3020hwgc",
	enable,
	load,
	move,
	disable,
};
.
## diffname pc/vgatvp3020.c 1994/0729
## diff -e /n/fornaxdump/1994/0624/sys/src/brazil/pc/vgatvp3020.c /n/fornaxdump/1994/0729/sys/src/brazil/pc/vgatvp3020.c
217c
	unlock(&palettelock);
.
215c
	lock(&palettelock);
.
200c
	unlock(&palettelock);
.
192c
	if(canlock(&palettelock) == 0)
.
175c
	unlock(&palettelock);
.
158c
	lock(&palettelock);
.
150c
	unlock(&palettelock);
.
62c
	lock(&palettelock);
.
## diffname pc/vgatvp3020.c 1994/0810
## diff -e /n/fornaxdump/1994/0729/sys/src/brazil/pc/vgatvp3020.c /n/fornaxdump/1994/0810/sys/src/brazil/pc/vgatvp3020.c
62a
	if(memcmp(c, &curcursor, sizeof(Cursor)) == 0){
		tvp3020xo(0x06, 0x40|0x10);		/* Cursor Control Register */
		unlock(&palettelock);
		return;
	}
	memmove(&curcursor, c, sizeof(Cursor));
.
61a
	/*
	 * 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.
	 */
.
11a
extern Cursor curcursor;

.
## diffname pc/vgatvp3020.c 1995/0126
## diff -e /n/fornaxdump/1994/0810/sys/src/brazil/pc/vgatvp3020.c /n/fornaxdump/1995/0126/sys/src/brazil/pc/vgatvp3020.c
246a

void
vgatvp3020link(void)
{
	addhwgclink(&tvp3020hwgc);
}
.
245a

	0,
.
185,187c
	tvp3020xo(0x20, Pwhite); tvp3020xo(0x21, Pwhite); tvp3020xo(0x22, Pwhite);
	tvp3020xo(0x23, Pwhite); tvp3020xo(0x24, Pwhite); tvp3020xo(0x25, Pwhite);
	tvp3020xo(0x26, Pblack); tvp3020xo(0x27, Pblack); tvp3020xo(0x28, Pblack);
.
33c
	PaddrW, Pdata, Pixmask, PaddrR
.
## diffname pc/vgatvp3020.c 1997/1101
## diff -e /n/fornaxdump/1995/0126/sys/src/brazil/pc/vgatvp3020.c /n/emeliedump/1997/1101/sys/src/brazil/pc/vgatvp3020.c
249,254d
247c
	tvp3020enable,
	tvp3020disable,
	tvp3020load,
	tvp3020move,
.
242,245d
218,240c
VGAcur vgatvp3020cur = {
.
214d
206,208d
204c
tvp3020move(VGAscr*, Point p)
.
167,202d
163,164d
159,160c
	tvp3020xo(0x04, -curs->offset.x);		/* Sprite Origin X */
	tvp3020xo(0x05, -curs->offset.y);		/* Sprite Origin Y */
.
156c
	 * Initialise the cursor hotpoint
.
107,108c
				p0 = curs->clr[x+y*2];
				p1 = curs->set[x+y*2];
.
84a
	 * Overscan colour,
	 * cursor colour 1 (white),
	 * cursor colour 2 (black).
	 */
	tvp3020xo(0x20, Pwhite); tvp3020xo(0x21, Pwhite); tvp3020xo(0x22, Pwhite);
	tvp3020xo(0x23, Pwhite); tvp3020xo(0x24, Pwhite); tvp3020xo(0x25, Pwhite);
	tvp3020xo(0x26, Pblack); tvp3020xo(0x27, Pblack); tvp3020xo(0x28, Pblack);

	/*
	 * Finally, enable
	 *	the hardware cursor external operation mode;
	 *	cursor control enable for Bt485 DAC (!).
	 */
	r = vgaxi(Crtx, 0x55)|0x20;
	vgaxo(Crtx, 0x55, r);

	r = vgaxi(Crtx, 0x45)|0x20;
	vgaxo(Crtx, 0x45, r);
}

static void
tvp3020load(VGAscr*, Cursor* curs)
{
	uchar p, p0, p1;
	int x, y;

	/*
	 * Make sure cursor is off by initialising the cursor
	 * control to defaults + X-Windows cursor mode.
	 */
	tvp3020xo(0x06, 0x10);				/* Cursor Control Register */

	/*
.
77a
	r = vgaxi(Crtx, 0x45) & ~0x20;
	vgaxo(Crtx, 0x45, r);

	r = vgaxi(Crtx, 0x55) & ~0x20;
	vgaxo(Crtx, 0x55, r);
}

static void
tvp3020enable(VGAscr*)
{
	uchar r;

.
70,76c
	tvp3020xo(0x06, 0x10);				/* Cursor Control Register */
.
65,68c
	 * Disable 
	 *	cursor;
	 *	cursor control enable for Bt485 DAC (!);
	 *	the hardware cursor external operation mode.
.
61,62c
	uchar r;
.
59c
tvp3020disable(VGAscr*)
.
19,25c
	Index		= 0x06,				/* Index register */
	Data		= 0x07,				/* Data register */
.
12,13d
10d
8c
#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
.
## diffname pc/vgatvp3020.c 1999/0119
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/vgatvp3020.c /n/emeliedump/1999/0119/sys/src/brazil/pc/vgatvp3020.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.