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

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


## diffname pc/cga.c 1991/0724
## diff -e /dev/null /n/bootesdump/1991/0724/sys/src/9/safari/cga.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

#define	WIDTH	160
#define	HEIGHT	24
#define SCREEN	((char *)(0xB8000|KZERO))
int pos;

void
screeninit(void)
{
	memset(SCREEN+pos, 0, WIDTH*HEIGHT-pos);
}

void
screenputc(int c)
{
	int i;
	static int color;

	if(c == '\n'){
		pos = pos/WIDTH;
		pos = (pos+1)*WIDTH;
	} else if(c == '\t'){
		i = 8 - ((pos/2)&7);
		while(i-->0)
			screenputc(' ');
	} else if(c == '\b'){
		if(pos >= 2)
			pos -= 2;
		screenputc(' ');
		pos -= 2;
	} else {
		SCREEN[pos++] = c;
		SCREEN[pos++] = 0x1d;
	}
	if(pos >= WIDTH*HEIGHT){
		memmove(SCREEN, &SCREEN[WIDTH], WIDTH*(HEIGHT-1));
		memset(&SCREEN[WIDTH*(HEIGHT-1)], 0, WIDTH);
		pos = WIDTH*(HEIGHT-1);
	}
}

void
screenputs(char *s, int n)
{
	while(n-- > 0)
		screenputc(*s++);
}

int
screenbits(void)
{
	return 4;
}
.
## diffname pc/cga.c 1991/1210
## diff -e /n/bootesdump/1991/0724/sys/src/9/safari/cga.c /n/bootesdump/1991/1210/sys/src/9/safari/cga.c
57a
}


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

/*
 *  screen dimensions
 */
#define MAXX	640
#define MAXY	480

#define SCREENMEM	(0xA0000 | KZERO)
GBitmap	gscreen =
{
	(ulong*)SCREENMEM,
	0,
	640/32,
	0,
	0, 0, MAXX, MAXY,
	0
};

typedef struct VGAmode	VGAmode;
struct VGAmode
{
	uchar	general[4];
	uchar	sequencer[5];
	uchar	crt[0x19];
	uchar	graphics[9];
	uchar	attribute[0x15];
};

enum
{
	EMISCR=		0x3CC,		/* control sync polarity */
	EMISCW=		0x3C2,
	EFCW=		0x3DA,		/* feature control */
	EFCR=		0x3CA,
	GRX=		0x3CE,		/* index to graphics registers */
	GR=		0x3CF,		/* graphics registers */
	 Grms=		 0x04,		/*  read map select register */
	SRX=		0x3C4,		/* index to sequence registers */
	SR=		0x3C5,		/* sequence registers */
	 Smmask=	 0x02,		/*  map mask */
	CRX=		0x3D4,		/* index to crt registers */
	CR=		0x3D5,		/* crt registers */
	 Cvre=		 0x11,		/*  vertical retrace end */
	ARX=		0x3C0,		/* index to attribute registers */
	AR=		0x3C1,		/* attribute registers */
};

uchar
genin(int reg)
{
	if(reg == 0)
		return inb(EMISCR);
	else if (reg == 1)
		return inb(EFCR);
}
uchar
srin(int reg)
{
	outb(SRX, reg);
	return inb(SR);
}
uchar
grin(int reg)
{
	outb(GRX, reg);
	return inb(GR);
}
uchar
arin(int reg)
{
	inb(0x3DA);
	outb(ARX, reg | 0x20);
	return inb(AR);
}
uchar
crin(int reg)
{
	outb(CRX, reg);
	return inb(CR);
}

void
vgadump(void)
{
	int i;
	VGAmode *v;

	print("GEN ");
	for(i = 0; i < sizeof(v->general); i++)
		print("%d-%ux ", i, genin(i));
	print("\nSR ");
	for(i = 0; i < sizeof(v->sequencer); i++)
		print("%d-%ux ", i, srin(i));
	print("\nCR ");
	for(i = 0; i < sizeof(v->crt); i++)
		print("%d-%ux ", i, crin(i));
	print("\nGR ");
	for(i = 0; i < sizeof(v->graphics); i++)
		print("%d-%ux ", i, grin(i));
	print("\nAR ");
	for(i = 0; i < sizeof(v->attribute); i++)
		print("%d-%ux ", i, arin(i));
	print("\n ");
}

void
bigcursor(void)
{}

void
getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
{
	ulong ans;

	/*
	 * The safari monochrome says 0 is black (zero intensity)
	 */
	if(p == 0)
		ans = 0;
	else
		ans = ~0;
	*pr = *pg = *pb = ans;
}


int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
	return 0;	/* can't change mono screen colormap */
}

void
mouseclock(void)
{
	mouseupdate(1);
.
15a
	vgadump();
.
14a
	void vgadump(void);

.
## diffname pc/cga.c 1992/0321
## diff -e /n/bootesdump/1991/1210/sys/src/9/safari/cga.c /n/bootesdump/1992/0321/sys/src/9/safari/cga.c
2c
#include	"../port/lib.h"
.
## diffname pc/cga.c 1997/0327
## diff -e /n/bootesdump/1992/0808/sys/src/9/safari/cga.c /n/emeliedump/1997/0327/sys/src/brazil/pc/cga.c
198,201c
	qunlock(&screenlock);
.
192,196c
	while(n > 0) {
		i = chartorune(&r, s);
		if(i == 0){
			s++;
			--n;
			continue;
		}
		memmove(buf, s, i);
		buf[i] = 0;
		n -= i;
		s += i;
		vgascreenputc(buf);
	}
.
190a
	if(vgascreenputc == nil){
		while(n-- > 0)
			cgascreenputc(*s++);
		qunlock(&screenlock);
		return;
	}
.
187,189c
		qlock(&screenlock);
.
154,185c
	if(!islo()){
		if(!canqlock(&screenlock))
			return;
	}
.
152c
	Rune r;
	char buf[4];
.
149c
screenputs(char* s, int n)
.
57,147d
53,54c
	pos = cgaregr(0x0E)<<8;
	pos |= cgaregr(0x0F);
	pos *= 2;
	screeninitdone = 1;
.
51c
screeninit(void)
.
47a
	if(pos >= Width*Height){
		memmove(CGASCREENBASE, &CGASCREENBASE[Width], Width*(Height-1));
		memset(&CGASCREENBASE[Width*(Height-1)], 0, Width);
		pos = Width*(Height-1);
	}
	movecursor();
.
43,46c
	else{
		CGASCREENBASE[pos++] = c;
		CGASCREENBASE[pos++] = Attr;
.
39,41d
37c
		cgascreenputc(' ');
.
33,34c
			cgascreenputc(' ');
	}
	else if(c == '\b'){
.
28,30c
		pos = pos/Width;
		pos = (pos+1)*Width;
	}
	else if(c == '\t'){
.
25d
23a
	cgaregw(0x0E, (pos/2>>8) & 0xFF);
	cgaregw(0x0F, pos/2 & 0xFF);
	CGASCREENBASE[pos+1] = Attr;
}

static void
cgascreenputc(int c)
{
.
21,22c
static void
movecursor(void)
.
17,18c
static void
cgaregw(int index, int data)
{
	outb(0x3D4, index);
	outb(0x3D4+1, data);
.
15c
	outb(0x3D4, index);
	return inb(0x3D4+1) & 0xFF;
}
.
12,13c
	Attr		= 7,		/* white on black */
};

#define CGASCREENBASE	((uchar*)KADDR(0xB8000))

static int pos;
static int screeninitdone;
QLock screenlock;
void (*vgascreenputc)(char*);

static uchar
cgaregr(int index)
.
7,10c
enum {
	Width		= 160,
	Height		= 25,
.
1,5c
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"
.
## diffname pc/cga.c 1997/1101
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/cga.c /n/emeliedump/1997/1101/sys/src/brazil/pc/cga.c
122a

void (*screenputs)(char*, int) = cgascreenputs;
.
107,121c
	unlock(&cgascreenlock);
.
100,105c
	while(n-- > 0)
		cgascreenputc(*s++);
.
98c
		lock(&cgascreenlock);
.
94c
		/*
		 * Don't deadlock trying to
		 * print in an interrupt.
		 */
		if(!canlock(&cgascreenlock))
.
89,92d
86,87c
static void
cgascreenputs(char* s, int n)
.
80,82c
	cgapos = cgaregr(0x0E)<<8;
	cgapos |= cgaregr(0x0F);
	cgapos *= 2;
.
72c
		cgapos = Width*(Height-1);
.
69c
	if(cgapos >= Width*Height){
.
66,67c
		CGASCREENBASE[cgapos++] = c;
		CGASCREENBASE[cgapos++] = Attr;
.
63c
		cgapos -= 2;
.
60,61c
		if(cgapos >= 2)
			cgapos -= 2;
.
55c
		i = 8 - ((cgapos/2)&7);
.
51,52c
		cgapos = cgapos/Width;
		cgapos = (cgapos+1)*Width;
.
40,42c
	cgaregw(0x0E, (cgapos/2>>8) & 0xFF);
	cgaregw(0x0F, cgapos/2 & 0xFF);
	CGASCREENBASE[cgapos+1] = Attr;
.
20,21c
static Lock cgascreenlock;
.
18c
static int cgapos;
.
6d
## diffname pc/cga.c 1999/0715
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/cga.c /n/emeliedump/1999/0715/sys/src/brazil/pc/cga.c
87c
	if(!islo()) {
.
8c
enum
{
.
## diffname pc/cga.c 1999/1005
## diff -e /n/emeliedump/1999/0715/sys/src/brazil/pc/cga.c /n/emeliedump/1999/1005/sys/src/brazil/pc/cga.c
88c
	if(!islo()){
.
70c
		p = &CGASCREENBASE[Width*(Height-1)];
		for(i=0; i<Width/2; i++){
			*p++ = ' ';
			*p++ = Attr;
		}
.
47a
	uchar *p;
.
13c
	Attr		= (Black<<4)|White,		/* high nibble background, low foreground */
.
8,10c
enum {
	Black,
	Blue,
	Green,
	Cyan,
	Red,
	Magenta,
	Brown,
	Grey,

	Bright = 0x08,
	Blinking = 0x80,

	Yellow = Bright|Brown,
	White = Bright|Grey,
};
	
enum {
	Width		= 80*2,
.
## diffname pc/cga.c 1999/1006
## diff -e /n/emeliedump/1999/1005/sys/src/brazil/pc/cga.c /n/emeliedump/1999/1006/sys/src/brazil/pc/cga.c
29c
	Attr		= (Black<<4)|Grey,	/* high nibble background
						 * low foreground
						 */
.
## diffname pc/cga.c 2001/0527
## diff -e /n/emeliedump/1999/1006/sys/src/brazil/pc/cga.c /n/emeliedump/2001/0527/sys/src/9/pc/cga.c
128c
void
screeninit(void)
{

	cgapos = cgaregr(0x0E)<<8;
	cgapos |= cgaregr(0x0F);
	cgapos *= 2;

	screenputs = cgascreenputs;
}
.
99,107d
37d

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].