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

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


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

enum
{
	GRX=		0x3CE,		/* index to graphics registers */
	GR=		0x3CF,		/* graphics registers 0-8 */
};

/*
 *  look at VGA registers
 */
void
vgainit(void)
{
	int i;
	uchar x;

	for(i = 0; i < 9; i++){
		outb(GRX, i);
		x = inb(GR);
		print("GR%d == %ux\n", i, x);
	}
	panic("for the hell of it");
}
.
## diffname pc/vga.c 1991/0724
## diff -e /n/bootesdump/1991/0723/sys/src/9/safari/vga.c /n/bootesdump/1991/0724/sys/src/9/safari/vga.c
23,28c
	srout(2, 0x0f);		/* enable all 4 color planes */
	srout(4, 0x08);		/* quad mode */
	grout(5, 0x40);		/* pixel bits are sequential */
	grout(6, 0x01);		/* graphics mode - display starts at 0xA0000 */

	for(;;);
	display = (uchar*)(0xA0000 | KZERO);
	for(i = 0; i < 128*1024; i++)
		display[i] = 0x00;

	for(i = 0; i < 4*640; i++)
		display[i] = 0xff;
.
21d
19a
	uchar *display;
.
13a
void
srout(int reg, int val)
{
	outb(SRX, reg);
	outb(SR, val);
}

void
grout(int reg, int val)
{
	outb(GRX, reg);
	outb(GR, val);
}

.
11a
	SRX=		0x3C4,		/* index to sequence registers */
	SR=		0x3C5,		/* sequence registers 0-7 */
.
## diffname pc/vga.c 1991/0727
## diff -e /n/bootesdump/1991/0724/sys/src/9/safari/vga.c /n/bootesdump/1991/0727/sys/src/9/safari/vga.c
51a

.
44,50c
	/*
	 *  zero out display
	 */
	srout(Smmask, 0x0f);	/* enable all 4 color planes for writing */
	for(i=0; i<MAXY*(MAXX/8); i++)
		display[i] = 0;
	
	munch();
.
39,42c
	display = (uchar *)(0xA0000 | KZERO);
	arout(Acpe, 0x0f);	/* enable all planes */
	arout(Amode, 0x01);	/* graphics mode - 4 bit pixels */
	grout(Gmisc, 0x01);	/* graphics mode */
	grout(Gmode, 0x00);	/* write mode 0, read mode 0 */
	grout(Grot, 0x00);	/* CPU writes bytes to video mem without modifications */
	crout(Cmode, 0xe3);	/* turn off address wrap & word mode */
	crout(Cmsl, 0x40);	/* 1 pixel per scan line */
	srout(Smode, 0x06);	/* extended memory, odd/even off */
	srout(Sclock, 0x01);	/* 8 bits/char */
.
37c
	int i, j, k;
	int c;
.
33a
munch(void)
{
	ulong x,y,i,d;
	uchar *screen, tab[8], *p;

	screen = (uchar *)(0xA0000 | KZERO);
	d=0;
	tab[0] = 0x80;
	tab[1] = 0x40;
	tab[2] = 0x20;
	tab[3] = 0x10;
	tab[4] = 0x08;
	tab[5] = 0x04;
	tab[6] = 0x02;
	tab[7] = 0x01;

	for(i=0; i<MAXY*(MAXX/8); i++)
		screen[i]=0;

	for(;;){
		for(x=0; x<SIDE; x++){
			y = (x^d) % SIDE;
			p = &screen[y*(MAXX/8) + (x/8)];
			y = *p;
			*p = y ^ tab[x&7];
		}
		d+=DELTA;
	}
}

/*
 *  Set up for 4 separately addressed bit planes.  Each plane is 
 */
void
.
32a
vgawrmask(int m)
{
	srout(Smmask, m&0xf);
}

/*
 *  p is the plane that will respond to CPU reads
 */
vgardplane(int p)
{
	grout(Grms, p&3);
}

/*
 *  partial screen munching squares
 */
#define	DELTA	1
#define	DADDR	((long *) 0)
#define	SIDE	256
.
31c
 *  m is a bit mask of planes to be affected by CPU writes
.
28a
void
arout(int reg, int val)
{
	inb(0x3DA);
	outb(ARX, reg | 0x20);
	outb(AR, val);
}
void
crout(int reg, int val)
{
	outb(CRX, reg);
	outb(CR, val);
}
.
22d
15a
/*
 *  screen dimensions
 */
#define MAXX	640
#define MAXY	480

/*
 *  routines for setting vga registers
 */
.
13c
	SR=		0x3C5,		/* sequence registers */
	 Sclock=	 0x01,		/*  clocking register */
	 Smode=		 0x04,		/*  mode register */
	 Smmask=	 0x02,		/*  map mask */
	CRX=		0x3D4,		/* index to crt registers */
	CR=		0x3D5,		/* crt registers */
	 Cmode=		 0x17,		/*  mode register */
	 Cmsl=		 0x09,		/*  max scan line */
	ARX=		0x3C0,		/* index to attribute registers */
	AR=		0x3C1,		/* attribute registers */
	 Amode=		 0x10,		/*  mode register */
	 Acpe=		 0x12,		/*  color plane enable */
.
11c
	GR=		0x3CF,		/* graphics registers */
	 Grot=		 0x03,		/*  data rotate register */
	 Gmode=		 0x05,		/*  mode register */
	 Gmisc=		 0x06,		/*  miscillaneous register */
	 Grms=		 0x04,		/*  read map select register */
.
## diffname pc/vga.c 1991/0730
## diff -e /n/bootesdump/1991/0727/sys/src/9/safari/vga.c /n/bootesdump/1991/0730/sys/src/9/safari/vga.c
149a
void
screenputc(int c)
{
	char buf[2];
	int nx;

	if(c == '\n'){
		out.pos.x = MINX;
		out.pos.y += defont0.height;
		if(out.pos.y > gscreen.r.max.y-defont0.height)
			out.pos.y = gscreen.r.min.y;
		gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen,
		    Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), 0);
	}else if(c == '\t'){
		out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid;
		if(out.pos.x >= gscreen.r.max.x)
			screenputc('\n');
	}else if(c == '\b'){
		if(out.pos.x >= out.bwid+MINX){
			out.pos.x -= out.bwid;
			screenputc(' ');
			out.pos.x -= out.bwid;
		}
	}else{
		if(out.pos.x >= gscreen.r.max.x-out.bwid)
			screenputc('\n');
		buf[0] = c&0x7F;
		buf[1] = 0;
		out.pos = gstring(&gscreen, out.pos, defont, buf, S);
	}
}

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

int
screenbits(void)
{
	return 1;	/* bits per pixel */
}

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

	/*
	 * The magnum 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 */
}

int
hwcursset(uchar *s, uchar *c, int ox, int oy)
{
	return 0;
}

int
hwcursmove(int x, int y)
{
	return 0;
}

void
mouseclock(void)	/* called splhi */
{
	mouseupdate(1);
}
.
143,147c
	defont = &defont0;	/* save space; let bitblt do the conversion work */
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0); /**/

	/*
	 *  stick print at the top
	 */
	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = defont0.info[' '].width;

	/*
	 *  swizzle the damn font longs.
	 *  we do it here since the font is in a machine independent (i.e.
	 *  made for the 68020) format.
	 */
	l = defont->bits->base;
	for(i = defont->bits->width*Dy(defont->bits->r); i > 0; i--, l++)
		*l = (*l<<24) | ((*l>>8)&0x0000ff00) | ((*l<<8)&0x00ff0000) | (*l>>24);
.
138a
	srout(Smmask, 0x0f);	/* enable all 4 color planes for writing */
.
129c
	display = (uchar *)SCREENMEM;

.
127a
	ulong *l;
.
123c
screeninit(void)
.
94c
	screen = (uchar *)SCREENMEM;
.
32,37d
7a
#include	<libg.h>
#include	<gnot.h>
#include	"screen.h"

#define	MINX	8

extern	GFont	defont0;
GFont		*defont;

struct{
	Point	pos;
	int	bwid;
}out;

/*
 *  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
};

.
## diffname pc/vga.c 1991/0731
## diff -e /n/bootesdump/1991/0730/sys/src/9/safari/vga.c /n/bootesdump/1991/0731/sys/src/9/safari/vga.c
243c
	 * The safari monochrome says 0 is black (zero intensity)
.
## diffname pc/vga.c 1991/0801
## diff -e /n/bootesdump/1991/0731/sys/src/9/safari/vga.c /n/bootesdump/1991/0801/sys/src/9/safari/vga.c
220c
		out.pos = gstring(&gscreen, out.pos, defont, buf, flipD[S]);
.
204c
		    Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), flipD[0]);
.
181,189d
176c
	 *  start printing at the top of screen
.
172,173c
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, flipD[0]);
.
169a
	 *  swizzle the font longs.
	 *  we do it here since the font is initialized with big endian longs.
	 */
	defont = &defont0;
	l = defont->bits->base;
	for(i = defont->bits->width*Dy(defont->bits->r); i > 0; i--, l++)
		*l = (*l<<24) | ((*l>>8)&0x0000ff00) | ((*l<<8)&0x00ff0000) | (*l>>24);

	/*
.
## diffname pc/vga.c 1991/0904
## diff -e /n/bootesdump/1991/0801/sys/src/9/safari/vga.c /n/bootesdump/1991/0904/sys/src/9/safari/vga.c
271c
mouseclock(void)
.
156,157d
151d
## diffname pc/vga.c 1991/0921
## diff -e /n/bootesdump/1991/0904/sys/src/9/safari/vga.c /n/bootesdump/1991/0921/sys/src/9/safari/vga.c
168c
	 *  we do it here since the font is initialized with big
	 *  endian longs.
.
## diffname pc/vga.c 1991/0927
## diff -e /n/bootesdump/1991/0921/sys/src/9/safari/vga.c /n/bootesdump/1991/0927/sys/src/9/safari/vga.c
271a
}

vgaset(char *cmd)
{
	int set;
	int reg;
	int val;

	set = *cmd++;
	cmd++;
	reg = strtoul(cmd, &cmd, 0);
	cmd++;
	val = strtoul(cmd, &cmd, 0);
	switch(set){
	case 'a':
		arout(reg, val);
		break;
	case 'g':
		grout(reg, val);
		break;
	case 'c':
		crout(reg, val);
		break;
	case 's':
		srout(reg, val);
		break;
	}
.
109,145d
## diffname pc/vga.c 1991/0928
## diff -e /n/bootesdump/1991/0927/sys/src/9/safari/vga.c /n/bootesdump/1991/0928/sys/src/9/safari/vga.c
118,128c
	vga1();
.
108a
 *  2 bit deep display.  the bits are adjacent.  maybe this
 *  will work
 *	4 color
 *	640x480
 */
vga2(void)
{
	int i;
	arout(Acpe, 0x00);	/* disable planes for output */

	gscreen.ldepth = 1;
	arout(Amode, 0x01);	/* color graphics mode */
	grout(Gmisc, 0x01);	/* graphics mode */
	grout(Gmode, 0x30);	/* 2 bits deep, even bytes are
				 * planes 0 and 2, odd are planes
				 * 1 and 3 */
	grout(Grot, 0x00);	/* CPU writes bytes to video
				 * mem without modifications */
	crout(Cmode, 0xe3);	/* turn off address wrap &
				 * word mode */
	crout(Cmsl, 0x40);	/* 1 pixel per scan line */
	crout(Cvertend, MAXY);	/* 480 lne display */
	srout(Smode, 0x06);	/* extended memory, odd/even */
	srout(Sclock, 0x01);	/* 8 bits/char */
	srout(Smmask, 0x0f);	/* enable 2 planes for writing */

	arout(Acpe, 0x0f);	/* enable 2 planes for output */
	for(i = 0; i < 128*1024;){
		((uchar*)SCREENMEM)[i++] = 0x1b;
		((uchar*)SCREENMEM)[i++] = 0xe4;
	}
	for(;;);
}

/*
 *  set up like vga mode 0x11
 *	2 color
 *	640x480
 */
vga1(void)
{
	arout(Acpe, 0x00);	/* disable planes for output */

	gscreen.ldepth = 0;
	arout(Amode, 0x01);	/* color graphics mode */
	grout(Gmisc, 0x01);	/* graphics mode */
	grout(Gmode, 0x00);	/* 1 bit deep */
	grout(Grot, 0x00);	/* CPU writes bytes to video
				 * mem without modifications */
	crout(Cmode, 0xe3);	/* turn off address wrap &
				 * word mode */
	crout(Cmsl, 0x40);	/* 1 pixel per scan line */
	crout(Cvertend, MAXY);	/* 480 lne display */
	srout(Smode, 0x06);	/* extended memory,
				 * odd/even off */
	srout(Sclock, 0x01);	/* 8 bits/char */
	srout(Smmask, 0x0f);	/* enable 4 planes for writing */

	arout(Acpe, 0x0f);	/* enable 4 planes for output */
}

/*
.
54a
	 Cvertend=	 0x12,		/*  vertical display end */
.
## diffname pc/vga.c 1991/0929
## diff -e /n/bootesdump/1991/0928/sys/src/9/safari/vga.c /n/bootesdump/1991/0929/sys/src/9/safari/vga.c
196,199d
192,194d
181a

.
171,173d
## diffname pc/vga.c 1991/1002
## diff -e /n/bootesdump/1991/0929/sys/src/9/safari/vga.c /n/bootesdump/1991/1002/sys/src/9/safari/vga.c
162c
	crout(Cvertend, MAXY-1);	/* 480 lne display */
.
## diffname pc/vga.c 1991/1107
## diff -e /n/bootesdump/1991/1002/sys/src/9/safari/vga.c /n/bootesdump/1991/1107/sys/src/9/safari/vga.c
91a
crdump(void)
{
	uchar x;
	int i;

	for(i = 0; i < 0x16; i++){
		outb(CRX, i);
		x = inb(CR);
		print("cr[0x%lux] = %ux\n", i, x);
	}
}
.
## diffname pc/vga.c 1991/1109
## diff -e /n/bootesdump/1991/1107/sys/src/9/safari/vga.c /n/bootesdump/1991/1109/sys/src/9/safari/vga.c
189c
	vga12();
.
172,173c
	/* last scan line displayed (first is 0) */
	crout(Cvde, MAXY-1);
	overflow |= ((MAXY-1)&0x200) ? 0x40 : 0;
	overflow |= ((MAXY-1)&0x100) ? 0x2 : 0;
	/* total scan lines (including retrace) - 2 */
	crout(Cvt, (YPERIOD-2));
	overflow |= ((YPERIOD-2)&0x200) ? 0x20 : 0;
	overflow |= ((YPERIOD-2)&0x100) ? 0x1 : 0;
	/* scan lines at which vertcal retrace starts & ends */
	crout(Cvrs, (MAXY+10));
	overflow |= ((MAXY+10)&0x200) ? 0x80 : 0;
	overflow |= ((MAXY+10)&0x100) ? 0x4 : 0;
	crout(Cvre, ((YPERIOD-1)&0xf)|0xa0);	/* also disable vertical interrupts */
	/* scan lines at which vertical blanking starts & ends */
	crout(Cvbs, (MAXY+YBORDER));
	msl |= ((MAXY+YBORDER)&0x200) ? 0x20 : 0;
	overflow |= ((MAXY+YBORDER)&0x100) ? 0x8 : 0;
	crout(Cvbe, (YPERIOD-YBORDER)&0x7f);
	/* pixels per scan line (always 0 for graphics) */
	crout(Cmsl, 0x40|msl);	/* also 10th bit of line compare */
	/* the overflow bits from the other registers */
	crout(Cvover, 0x10|overflow);	/* also 9th bit of line compare */

.
169a

	msl = overflow = 0;
.
131,161d
128,129c
	int overflow;
	int msl;
.
126c
vga12(void)
.
124a
 *
 *  we assume the BIOS left the registers in a
 *  CGA-like mode.  Thus we don't set all the registers.
.
121,123c
 *  set up like vga mode 0x12
 *	16 color (though we only use values 0x0 and 0xf)
.
97,103d
92,95d
57a
	 Cvrs=		 0x10,		/*  vertical retrace start */
	 Cvre=		 0x11,		/*  vertical retrace end */
	 Cvde=	 	 0x12,		/*  vertical display end */
	 Cvbs=		 0x15,		/*  vertical blank start */
	 Cvbe=		 0x16,		/*  vertical blank end */
	 Cmode=		 0x17,		/*  mode register */
.
55,56c
	 Cvt=		 0x06,		/*  vertical total */
	 Cvover=	 0x07,		/*  bits that didn't fit elsewhere */
.
26a
#define XPERIOD	800	/* Hsync freq == 31.47 KHZ */
#define YPERIOD	525	/* Vsync freq == 59.9 HZ */
#define YBORDER 2
.
## diffname pc/vga.c 1991/1112
## diff -e /n/bootesdump/1991/1109/sys/src/9/safari/vga.c /n/bootesdump/1991/1112/sys/src/9/safari/vga.c
164a
	/* pixels per scan line (always 0 for graphics) */
	crout(Cmsl, 0x40|msl);	/* also 10th bit of line compare */
.
157,162c
	crout(Cvbs, (MAXY+yborder));
	msl |= ((MAXY+yborder)&0x100) ? 0x20 : 0;
	overflow |= ((MAXY+yborder)&0x100) ? 0x8 : 0;
	crout(Cvbe, (yperiod-yborder)&0x7f);
.
152,155c
	crout(Cvrs, (MAXY+0x0a)); /**/
	overflow |= ((MAXY+0x0a)&0x200) ? 0x80 : 0;
	overflow |= ((MAXY+0x0a)&0x100) ? 0x4 : 0;
	crout(Cvre, ((yperiod-1)&0xf)|0xa0);	/* also disable vertical interrupts */
.
148,150c
	crout(Cvt, (yperiod-2));
	overflow |= ((yperiod-2)&0x200) ? 0x20 : 0;
	overflow |= ((yperiod-2)&0x100) ? 0x1 : 0;
.
141,142c
	/* turn off address wrap & word mode */
	crout(Cmode, 0xe3);
.
117a
vgadump(void)
{
	print("misc is 0x%ux fc is 0x%ux\n", inb(EMISCR), inb(EFCR));
	outb(EMISCW, 0xc7);/**/
}

vgaclock(void)
{
	outb(EMISCW, 0xc7);/**/
}

.
44a
	EMISCR=		0x3CC,		/* control sync polarity */
	EMISCW=		0x3C2,
	EFCW=		0x3DA,		/* feature control */
	EFCR=		0x3CA,
.
27,29c
int	xperiod = 800;	/* Hsync freq == 31.47 KHZ */
int	yperiod	= 525;	/* Vsync freq == 59.9 HZ */
int	yborder = 7;	/* top/bottom border of screen */
.
## diffname pc/vga.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/safari/vga.c /n/bootesdump/1991/1113/sys/src/9/safari/vga.c
323a
}


/*
 *  a fatter than usual cursor for the safari
 */
Cursor fatarrow = {
	{ -1, -1 },
	{
		0xff, 0xff, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0c, 
		0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04, 
		0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8c, 0x04, 
		0x92, 0x08, 0x91, 0x10, 0xa0, 0xa0, 0xc0, 0x40, 
	},
	{
		0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfc, 0x7f, 0xf0, 
		0x7f, 0xe0, 0x7f, 0xe0, 0x7f, 0xf0, 0x7f, 0xf8, 
		0x7f, 0xfc, 0x7f, 0xfe, 0x7f, 0xfc, 0x73, 0xf8, 
		0x61, 0xf0, 0x60, 0xe0, 0x40, 0x40, 0x00, 0x00, 
	},
};
void
bigcursor(void)
{
	extern Cursor arrow;

	memmove(&arrow, &fatarrow, sizeof(fatarrow));
.
196c
	setmode(&mode12);
	bigcursor();
.
181,186c
	for(i = 0; i < sizeof(v->attribute); i++)
		arout(i, v->attribute[i]);
.
155,179c
	for(i = 0; i < sizeof(v->graphics); i++)
		grout(i, v->graphics[i]);
.
148,153c
	crout(Cvre, 0);	/* allow writes to CRT registers 0-7 */
	for(i = 0; i < sizeof(v->crt); i++)
		crout(i, v->crt[i]);
.
146c
	for(i = 0; i < sizeof(v->sequencer); i++)
		srout(i, v->sequencer[i]);
.
133,144c
	for(i = 0; i < sizeof(v->general); i++)
		genout(i, v->general[i]);
.
130,131c
	int i;
.
128c
void
setmode(VGAmode *v)
.
125d
80a
genout(int reg, int val)
{
	if(reg == 0)
		outb(EMISCW, val);
	else if (reg == 1)
		outb(EFCW, val);
}
void
.
79a
VGAmode mode12 = 
{
	/* general */
	0xe3, 0x00, 0x70, 0x04,
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x06,
	/* crt */
	0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
	0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59,
	0xea, 0x0c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
	0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
	0x01, 0x00, 0x0f, 0x00, 0x00,
};

.
78c
 *  640x480 display, 16 bit color
.
76a
typedef struct VGAmode	VGAmode;
struct VGAmode
{
	uchar	general[4];
	uchar	sequencer[5];
	uchar	crt[0x19];
	uchar	graphics[9];
	uchar	attribute[0x15];
};

.
73,74d
67,70d
62,65d
57,58d
51,53d
27,29d
## diffname pc/vga.c 1991/1211
## diff -e /n/bootesdump/1991/1113/sys/src/9/safari/vga.c /n/bootesdump/1991/1211/sys/src/9/safari/vga.c
116,117c
	outb(ARW, reg | 0x20);
	outb(ARW, val);
.
55,56c
	ARW=		0x3C0,		/* attribute registers (writing) */
	ARR=		0x3C1,		/* attribute registers (reading) */
.
## diffname pc/vga.c 1991/1228
## diff -e /n/bootesdump/1991/1211/sys/src/9/safari/vga.c /n/bootesdump/1991/1228/sys/src/9/safari/vga.c
230,231c
	Rune r;
	int i;
	char buf[4];

	lock(&printq);
	while(n > 0){
		i = chartorune(&r, s);
		if(i == 0){
			s++;
			--n;
			continue;
		}
		memmove(buf, s, i);
		buf[i] = 0;
		n -= i;
		s += i;
		if(r == '\n')
			screenputnl();
		else if(r == '\t'){
			out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid;
			if(out.pos.x >= gscreen.r.max.x)
				screenputnl();
		}else if(r == '\b'){
			if(out.pos.x >= out.bwid+MINX){
				out.pos.x -= out.bwid;
				gstring(&gscreen, out.pos, defont, " ", flipD[S]);
			}
		}else{
			if(out.pos.x >= gscreen.r.max.x-out.bwid)
				screenputnl();
			out.pos = gstring(&gscreen, out.pos, defont, buf, flipD[S]);
		}
	}
	unlock(&printq);
.
198,224c
	out.pos.x = MINX;
	out.pos.y += defont0.height;
	if(out.pos.y > gscreen.r.max.y-defont0.height)
		out.pos.y = gscreen.r.min.y;
	gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen,
	    Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), flipD[0]);
.
196c
screenputnl(void)
.
## diffname pc/vga.c 1992/0208
## diff -e /n/bootesdump/1991/1228/sys/src/9/safari/vga.c /n/bootesdump/1992/0208/sys/src/9/safari/vga.c
239c
			out.pos = gsubfstring(&gscreen, out.pos, defont, buf, flipD[S]);
.
234c
				gsubfstring(&gscreen, out.pos, defont, " ", flipD[S]);
.
14,15c
extern	GSubfont	defont0;
GSubfont		*defont;
.
## diffname pc/vga.c 1992/0321
## diff -e /n/bootesdump/1992/0208/sys/src/9/safari/vga.c /n/bootesdump/1992/0321/sys/src/9/safari/vga.c
2c
#include	"../port/lib.h"
.
## diffname pc/vga.c 1992/0401
## diff -e /n/bootesdump/1992/0321/sys/src/9/safari/vga.c /n/bootesdump/1992/0401/sys/src/9/safari/vga.c
189a
	delay(2000);
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, flipD[F]);
	delay(2000);
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, flipD[0]);
.
## diffname pc/vga.c 1992/0402
## diff -e /n/bootesdump/1992/0401/sys/src/9/safari/vga.c /n/bootesdump/1992/0402/sys/src/9/safari/vga.c
246c
	unlock(&screenlock);
.
217c
	lock(&screenlock);
.
209a
Lock screenlock;

.
190,193d
## diffname pc/vga.c 1992/0409
## diff -e /n/bootesdump/1992/0402/sys/src/9/safari/vga.c /n/bootesdump/1992/0409/sys/src/9/safari/vga.c
177d
## diffname pc/vga.c 1992/0414
## diff -e /n/bootesdump/1992/0409/sys/src/9/safari/vga.c /n/bootesdump/1992/0414/sys/src/9/safari/vga.c
121a
	delay(1000);	/* needed for 16bit VGA path on Ultra SVGA */
.
114a
	/*
	 * if this print is missing, we are left with a blank white screen.
	 */
	print("arout %d %2x\n", reg, val);
.
102a
	/*
	 * needed or the screen goes blank on an ultra VGA card
	 */
	delay(1000);
.
94a
delay(1000);
.
90a
#else
/*
 *  640x480 display, 16 bit color - attempt at SVGA version...ches
 */
VGAmode mode12 = 
{
	/* general */
	0xe7, 0x00, 0x70, 0x04,
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x06,
	/* crt */
	0x65, 0x4f, 0x50, 0x88, 0x55, 0x9a, 0x09, 0x3e,
	0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0xe8, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
	0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
	0x01, 0x00, 0x0f, 0x00, 0x00,
};
#endif
.
68a
#ifdef ORIGINALSAFARI
.
## diffname pc/vga.c 1992/0417
## diff -e /n/bootesdump/1992/0414/sys/src/9/safari/vga.c /n/bootesdump/1992/0417/sys/src/9/safari/vga.c
113c
	0x01, 0x07, 0x0f, 0x00, 0x00,
.
## diffname pc/vga.c 1992/0418
## diff -e /n/bootesdump/1992/0417/sys/src/9/safari/vga.c /n/bootesdump/1992/0418/sys/src/9/safari/vga.c
226a
print("PEL Mask Register = %02x\n", inb(0x3c6)&0xff);
.
156c
	delay(TESTDELAY);	/* needed for 16bit VGA path on Ultra SVGA */
.
132c
	delay(TESTDELAY);
.
120c
delay(TESTDELAY);
.
116a
#define TESTDELAY	1

.
111,113c
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0d, 0x0f,
	0x01, 0x10, 0x0f, 0x00, 0x00,
.
## diffname pc/vga.c 1992/0423
## diff -e /n/bootesdump/1992/0418/sys/src/9/safari/vga.c /n/bootesdump/1992/0423/sys/src/9/safari/vga.c
229d
206a
dumpmodes(VGAmode *v)
{
	int i;

	print("general registers: %02x %02x %02x %02x\n",
		inb(0x3cc), inb(0x3ca), inb(0x3c2), inb(0x3da));

	print("sequence registers: ");
	for(i = 0; i < sizeof(v->sequencer); i++) {
		outb(SRX, i);
		print(" %02x", inb(SR));
	}

	print("\nCRT registers: ");
	for(i = 0; i < sizeof(v->crt); i++) {
		outb(CRX, i);
		print(" %02x", inb(CR));
	}

	print("\nGraphics registers: ");
	for(i = 0; i < sizeof(v->graphics); i++) {
		outb(GRX, i);
		print(" %02x", inb(GR));
	}

	print("\nAttribute registers: ");
	for(i = 0; i < sizeof(v->attribute); i++) {
		inb(0x3DA);
		outb(ARW, i | 0x20);
		print(" %02x", inb(ARR));
	}

	print("\nPEL Mask Register = %02x\n\n", inb(0x3c6)&0xff);
}
#endif

void
.
205a
#ifdef VGATROUBLE
.
158d
154a

.
152,153c
	if (reg <= 0xf) {
		outb(ARW, reg | 0x0);
		outb(ARW, val);
		inb(0x3DA);
		outb(ARW, reg | 0x20);
	} else {
		outb(ARW, reg | 0x20);
		outb(ARW, val);
	}
.
150d
134d
122d
112c
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x3f,
.
99c
	0xe7, 0x00,  /* 0x70, 0x04, these are read-only */
.
76c
	0xe3, 0x00, /* 0x70, 0x04, these are read-only */
.
62c
	uchar	general[2];
.
## diffname pc/vga.c 1992/0424
## diff -e /n/bootesdump/1992/0423/sys/src/9/safari/vga.c /n/bootesdump/1992/0424/sys/src/9/safari/vga.c
115,117d
71,93d
69d
## diffname pc/vga.c 1992/0430
## diff -e /n/bootesdump/1992/0424/sys/src/9/safari/vga.c /n/bootesdump/1992/0430/sys/src/9/safari/vga.c
228c
	setmode(&mode41);
.
91a
/*
 *  800x600 display, 16 bit color 
 */
VGAmode mode41 = 
{
	/* general */
	0xe7, 0x00,  /* 0x70, 0x04, these are read-only */
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x06,
	/* crt */
	0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
	0x00, 0x40, 0x0d, 0x0e, 0x00, 0x00, 0x07, 0x80,
	0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x3f,
	0x01, 0x10, 0x0f, 0x00, 0x00,
};

.
70c
 *  640x480 display, 16 bit color.
.
25,26c
#define MAXX	800
#define MAXY	600
.
## diffname pc/vga.c 1992/0501
## diff -e /n/bootesdump/1992/0430/sys/src/9/safari/vga.c /n/bootesdump/1992/0501/sys/src/9/safari/vga.c
251c
	setmode(&mode12);
.
102,105c
	0x7f, 0x63, 0x64, 0x9d, 0x67, 0x92, 0x77, 0xf0,
	0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x5d, 0x8f, 0x57, 0x32, 0x00, 0x5b, 0x74, 0xc3,
	0xff,  
.
98c
	0x2f, 0x00,  /* 0x70, 0x04, these are read-only */
.
95c
VGAmode mode6a = 
.
93c
 *  VESA standard (?) 800x600 display, 16 bit color 
.
## diffname pc/vga.c 1992/0502
## diff -e /n/bootesdump/1992/0501/sys/src/9/safari/vga.c /n/bootesdump/1992/0502/sys/src/9/safari/vga.c
249a
	VGAmode v;
.
239,240d
211a
void
printmode(VGAmode *v) {
	int i;
	print("general registers: %02x %02x\n",
		v->general[0], v->general[1]);

	print("sequence registers: ");
	for(i = 0; i < sizeof(v->sequencer); i++) {
		print(" %02x", v->sequencer[i]);
	}

	print("\nCRT registers: ");
	for(i = 0; i < sizeof(v->crt); i++) {
		print(" %02x", v->crt[i]);
	}

	print("\nGraphics registers: ");
	for(i = 0; i < sizeof(v->graphics); i++) {
		print(" %02x", v->graphics[i]);
	}

	print("\nAttribute registers: ");
	for(i = 0; i < sizeof(v->attribute); i++) {
		print(" %02x", v->attribute[i]);
	}
	print("\n");
}

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

.
210a
	v->general[0] = inb(0x3cc);
	v->general[1] = inb(0x3ca);
	for(i = 0; i < sizeof(v->sequencer); i++) {
		outb(SRX, i);
		v->sequencer[i] = inb(SR);
	}
	for(i = 0; i < sizeof(v->crt); i++) {
		outb(CRX, i);
		v->crt[i] = inb(CR);
	}
	for(i = 0; i < sizeof(v->graphics); i++) {
		outb(GRX, i);
		v->graphics[i] = inb(GR);
	}
	for(i = 0; i < sizeof(v->attribute); i++) {
		inb(0x3DA);
		outb(ARW, i | 0x20);
		v->attribute[i] = inb(ARR);
	}
}
.
208,209c
getmode(VGAmode *v) {
.
102,103c
	0x7f, 0x63, 0x64, 0x02, 0x6a, 0x1d, 0x77, 0xf0,
	0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
.
98c
	0xe3, 0x00,  /* 0x70, 0x04, these are read-only */
.
93c
 *  VESA standard (?) 800x600 display, 16 bit color. 
.
75c
	0xe7, 0x00,
.
26a
*/
#define MAXX	640
#define MAXY	480
.
24a

/*
.
## diffname pc/vga.c 1992/0519
## diff -e /n/bootesdump/1992/0502/sys/src/9/safari/vga.c /n/bootesdump/1992/0519/sys/src/9/safari/vga.c
322a
delay(50000);
	setmode(&mode12);
	printmode(&testmode);
.
307c
	setmode(&mode6a);
	getmode(&testmode);
.
305c
	VGAmode testmode;
.
259c
		print(" %2.2x", v->attribute[i]);
.
257c
	print("\na ");
.
254c
		print(" %2.2x", v->graphics[i]);
.
252c
	print("\ng ");
.
249c
		print(" %2.2x", v->crt[i]);
.
247c
	print("\nc ");
.
244c
		print(" %2.2x", v->sequencer[i]);
.
242c
	print("s ");
.
239c
	print("g %2.2x %2x\n",
.
211d
107,110c
	0x7a, 0x63, 0x65, 0x9d, 0x67, 0x92, 0x39, 0x1f,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x33, 0x82, 0x2b, 0x32, 0x0f, 0x33, 0x36, 0xe7,
	0xff,
.
103c
	0x2f, 0x00,  /* 0x70, 0x04, these are read-only */
.
## diffname pc/vga.c 1992/0520
## diff -e /n/bootesdump/1992/0519/sys/src/9/safari/vga.c /n/bootesdump/1992/0520/sys/src/9/safari/vga.c
324a
	printmode(&testmode);
	getmode(&testmode);
.
117a
#endif
.
106a
	0x7a, 0x63, 0x65, 0x9d, 0x68, 0x99, 0x38, 0x1f,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x2c, 0x8e, 0x2b, 0x32, 0x0f, 0x32, 0x34, 0xe7,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x3f,
	0x01, 0x10, 0x0f, 0x00, 0x00,
#ifdef almost
	/* general */
	0xe7, 0x00,  /* 0x70, 0x04, these are read-only */
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x06,
	/* crt */
.
103c
	0x67, 0x00,  /* 0x70, 0x04, these are read-only */
.
31a
*/
#define MAXX	800
#define MAXY	600
.
27,29d
## diffname pc/vga.c 1992/0527
## diff -e /n/bootesdump/1992/0520/sys/src/9/safari/vga.c /n/bootesdump/1992/0527/sys/src/9/safari/vga.c
341,345d
324,325c
	setmode(&mode12);
.
164,166d
118,135d
107,109c
	0x5f, 0x4f, 0x50, 0x02, 0x54, 0x80, 0x0b, 0x3e,
	0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0,
	0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
.
103c
	0xe3, 0x00,  /* 0x70, 0x04, these are read-only */
.
100c
VGAmode mode25 = 
.
98c
 *  cardinal (tseng labs) 800x600 display, 16 bit color. 
.
31a
*/
.
29c
/*
.
26d
## diffname pc/vga.c 1992/0528
## diff -e /n/bootesdump/1992/0527/sys/src/9/safari/vga.c /n/bootesdump/1992/0528/sys/src/9/safari/vga.c
131,133d
45,63d
10a
#include	"vga.h"
.
## diffname pc/vga.c 1992/0603
## diff -e /n/bootesdump/1992/0528/sys/src/9/safari/vga.c /n/bootesdump/1992/0603/sys/src/9/safari/vga.c
397,424d
293,297c
	setscreen(MAXX, MAXY, 1);
.
274a
setscreen(int maxx, int maxy, int bpp) {
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, flipD[S]);
	gscreen.width = maxx/32;
	gscreen.r.max = Pt(maxx, maxy);
	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, flipD[0]);
	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = defont0.info[' '].width;
}

void
.
144,164d
79,100d
29,32d
## diffname pc/vga.c 1992/0604
## diff -e /n/bootesdump/1992/0603/sys/src/9/safari/vga.c /n/bootesdump/1992/0604/sys/src/9/safari/vga.c
231a
	gscreen.clipr.max = gscreen.r.max;
.
38c
	{ 0, 0, MAXX, MAXY, },
	{ 0, 0, MAXX, MAXY, },
.
30,31d
## diffname pc/vga.c 1992/0711
## diff -e /n/bootesdump/1992/0604/sys/src/9/safari/vga.c /n/bootesdump/1992/0711/sys/src/9/safari/vga.c
348a
	USED(x, y);
.
342a
	USED(s, c, ox, oy);
.
336a
	USED(p, r, g, b);
.
244d
241,242c
	int i;
.
227c
setscreen(int maxx, int maxy, int bpp)
{
	USED(bpp);
.
## diffname pc/vga.c 1992/0914
## diff -e /n/bootesdump/1992/0808/sys/src/9/safari/vga.c /n/bootesdump/1992/0914/sys/src/9/pc/vga.c
309d
280d
## diffname pc/vga.c 1992/1013
## diff -e /n/bootesdump/1992/0914/sys/src/9/pc/vga.c /n/bootesdump/1992/1013/sys/src/9/pc/vga.c
71c
	0x01, 0x00, 0x0f, 0x00, 0x00,
.
63c
	0xea, 0x2c, 0xdf, 0x28, 0x00, 0xea, 0xeb, 0xe3,
.
61c
	0x63, 0x4f, 0x58, 0x81, 0x59, 0x81, 0x0b, 0x3e,
.
57c
	0xe3, 0x00,
.
52c
 *  640x480 display, 16 bit color.  
.
## diffname pc/vga.c 1992/1015
## diff -e /n/bootesdump/1992/1013/sys/src/9/pc/vga.c /n/bootesdump/1992/1015/sys/src/9/pc/vga.c
71c
	0x01, 0x10, 0x0f, 0x00, 0x00,
.
63c
	0xe8, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
.
61c
	0x65, 0x4f, 0x50, 0x88, 0x55, 0x9a, 0x09, 0x3e,
.
57c
	0xe7, 0x00,
.
52c
 *  640x480 display, 16 bit color.
.
## diffname pc/vga.c 1992/1030
## diff -e /n/bootesdump/1992/1015/sys/src/9/pc/vga.c /n/bootesdump/1992/1030/sys/src/9/pc/vga.c
383a

void
screenupdate(Rectangle r)
{
	USED(r);
}
.
## diffname pc/vga.c 1992/1104
## diff -e /n/bootesdump/1992/1030/sys/src/9/pc/vga.c /n/bootesdump/1992/1104/sys/src/9/pc/vga.c
384,389d
## diffname pc/vga.c 1992/1105
## diff -e /n/bootesdump/1992/1104/sys/src/9/pc/vga.c /n/bootesdump/1992/1105/sys/src/9/pc/vga.c
383a

/*
 *  collect changes to the 'soft' screen
 */
static Rectangle mbb;

void
mbbrect(Rectangle r)
{
	if(!islcd)
		return;
	if (r.min.x < mbb.min.x)
		mbb.min.x = r.min.x;
	if (r.min.y < mbb.min.y)
		mbb.min.y = r.min.y;
	if (r.max.x > mbb.max.x)
		mbb.max.x = r.max.x;
	if (r.max.y > mbb.max.y)
		mbb.max.y = r.max.y;
}

void
mbbpt(Point p)
{
	if(!islcd)
		return;
	if (p.x < mbb.min.x)
		mbb.min.x = p.x;
	if (p.y < mbb.min.y)
		mbb.min.y = p.y;
	if (p.x >= mbb.max.x)
		mbb.max.x = p.x+1;
	if (p.y >= mbb.max.y)
		mbb.max.y = p.y+1;
}

void
screenupdate(void)
{
}

void
mousescreenupdate(void)
{
}

.
## diffname pc/vga.c 1992/1106
## diff -e /n/bootesdump/1992/1105/sys/src/9/pc/vga.c /n/bootesdump/1992/1106/sys/src/9/pc/vga.c
384,429d
382a
	bitreverse(arrow.set, 2*16);
	bitreverse(arrow.clr, 2*16);
.
380,381d
376a

.
316a
screenupdate(void)
{
	uchar *sp, *hp, *se;
	int y, len, inc;
	Rectangle r=mbb;

	if(Dy(r) < 0)
		return;

	sp = (uchar*)gaddr(&gscreen, r.min);
	hp = (uchar*)gaddr(&vgascreen, r.min);

	len = (r.max.x * (1<<gscreen.ldepth) + 31)/32
		- (r.min.x * (1<<gscreen.ldepth))/32;
	len *= BY2WD;

	inc = gscreen.width * BY2WD - len;

	for (y = r.min.y; y < r.max.y; y++){
		for(se = sp + len; sp < se;)
			*hp++ = cswizzle[*sp++];
		sp += inc;
		hp += inc;
	}
	mbb = NULLMBB;
}

void
mousescreenupdate(void)
{
	screenupdate();
}

void
.
315a

/*
 *  copy litte endian soft screen to big endian hard screen
 */
.
307a
	rs.max = Pt(gscreen.r.max.x, out.pos.y+defont0.height);
	unlock(&screenlock);
	mbbrect(rs);
	screenupdate();
.
279a
	rs.min = Pt(0, out.pos.y);
.
277a
	Rectangle rs;
.
267,268c
	r = Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height);
	gbitblt(&gscreen, r.min, &gscreen, r, flipD[0]);
	mbbrect(r);
	screenupdate();
.
262a
	Rectangle r;

.
260a
mbbrect(Rectangle r)
{
	if (r.min.x < mbb.min.x)
		mbb.min.x = r.min.x;
	if (r.min.y < mbb.min.y)
		mbb.min.y = r.min.y;
	if (r.max.x > mbb.max.x)
		mbb.max.x = r.max.x;
	if (r.max.y > mbb.max.y)
		mbb.max.y = r.max.y;
	screenupdate();
}

void
mbbpt(Point p)
{
	if (p.x < mbb.min.x)
		mbb.min.x = p.x;
	if (p.y < mbb.min.y)
		mbb.min.y = p.y;
	if (p.x >= mbb.max.x)
		mbb.max.x = p.x+1;
	if (p.y >= mbb.max.y)
		mbb.max.y = p.y+1;
	screenupdate();
}

void
.
259a
/*
 *  collect changes to the 'soft' screen
 */
.
257c
	bitreverse((uchar*)defont->bits->base,
		defont->bits->width*BY2WD*Dy(defont->bits->r));

	/*
	 *  set up 'soft' and hard screens
	 */
	if(conf.maxx == 0)
		conf.maxx = MAXX;
	if(conf.maxy == 0)
		conf.maxy = MAXY;

	setscreen(conf.maxx, conf.maxy, conf.ldepth);
.
252a
	bitreverse(arrow.set, 2*16);
	bitreverse(arrow.clr, 2*16);

	/*
	 *  swizzle the font longs.  we do both byte and bit swizzling
	 *  since the font is initialized with big endian longs.
	 */
.
249,251c
	 *  arrow is defined as a big endian
.
234c
	len = gscreen.width * 4 * maxy;
	gscreen.base = malloc(len);
	memset((void*)gscreen.base, 0xff, len);

	/*
	 *  set string pointer to upper left
	 */
.
229,231c
	int len;

	mbb = NULLMBB;

	/*
	 *  zero hard screen
	 */
	memset((void*)SCREENMEM, 0xff, 64*1024);
	vgascreen.ldepth = 0;
	vgascreen.base = (void*)SCREENMEM;
	vgascreen.width = (maxx*(1<<ldepth))/32;
	vgascreen.r.max = Pt(maxx, maxy);
	vgascreen.clipr.max = vgascreen.r.max;

	/*
	 *  setup new soft screen
	 */
	gscreen.ldepth = ldepth;
	gscreen.width = (maxx*(1<<ldepth))/32;
.
227c
setscreen(int maxx, int maxy, int ldepth)
.
73a
static Rectangle mbb;
static Rectangle NULLMBB = {10000, 10000, -10000, -10000};
.
30,39c
/*
 *  'soft' screen bitmap
 */
GBitmap	gscreen;
GBitmap	vgascreen;
.
26d
22a
int islittle = 1;		/* little endian bit ordering in bytes */

extern Cursor arrow;
extern uchar cswizzle[256];


.
## diffname pc/vga.c 1992/1107
## diff -e /n/bootesdump/1992/1106/sys/src/9/pc/vga.c /n/bootesdump/1992/1107/sys/src/9/pc/vga.c
426d
421,424c
		l0update(sp, hp, len);
		sp += inc+len;
		hp += inc+len;
.
416a
	if(len <= 0)
		return;
.
410a
	if(r.min.x < 0)
		r.min.x = 0;
	if(r.min.y < 0)
		r.min.y = 0;
	if(r.max.x > gscreen.r.max.x)
		r.max.x = gscreen.r.max.x;
	if(r.max.y > gscreen.r.max.y)
		r.max.y = gscreen.r.max.y;

.
407a
	r = mbb;
	mbb = NULLMBB;

.
406c
	Rectangle r;
.
328d
253,254c
	gscreen.base = ((ulong*)malloc(len+2*1024))+256;
	memset((char*)gscreen.base, 0xff, len);
.
## diffname pc/vga.c 1992/1108
## diff -e /n/bootesdump/1992/1107/sys/src/9/pc/vga.c /n/bootesdump/1992/1108/sys/src/9/pc/vga.c
514a

/*
 *  Table for separating and reversing bits in a ldepth 1 bitmap.
 *  This aids in coverting a little endian ldepth 1 bitmap into the
 *  2 big-endian ldepth 0 bitmaps used for the VGA bit planes.
 *
 *	if the bits in uchar x are labeled
 *		76543210
 *	then l1revsep[x] yields a ushort with bits
 *		____0246____1357
 *	where _ represents a bit whose value is 0.
 *
 *  This table is used by l1update() in l.s.  l1update is implemented
 *  in assembler for speed (yech).
 *
 */
ushort l1revsep[] = {
	0x0000,	0x0800,	0x0008,	0x0808,	0x0400,	0x0c00,	0x0408,	0x0c08,
	0x0004,	0x0804,	0x000c,	0x080c,	0x0404,	0x0c04,	0x040c,	0x0c0c,
	0x0200,	0x0a00,	0x0208,	0x0a08,	0x0600,	0x0e00,	0x0608,	0x0e08,
	0x0204,	0x0a04,	0x020c,	0x0a0c,	0x0604,	0x0e04,	0x060c,	0x0e0c,
	0x0002,	0x0802,	0x000a,	0x080a,	0x0402,	0x0c02,	0x040a,	0x0c0a,
	0x0006,	0x0806,	0x000e,	0x080e,	0x0406,	0x0c06,	0x040e,	0x0c0e,
	0x0202,	0x0a02,	0x020a,	0x0a0a,	0x0602,	0x0e02,	0x060a,	0x0e0a,
	0x0206,	0x0a06,	0x020e,	0x0a0e,	0x0606,	0x0e06,	0x060e,	0x0e0e,
	0x0100,	0x0900,	0x0108,	0x0908,	0x0500,	0x0d00,	0x0508,	0x0d08,
	0x0104,	0x0904,	0x010c,	0x090c,	0x0504,	0x0d04,	0x050c,	0x0d0c,
	0x0300,	0x0b00,	0x0308,	0x0b08,	0x0700,	0x0f00,	0x0708,	0x0f08,
	0x0304,	0x0b04,	0x030c,	0x0b0c,	0x0704,	0x0f04,	0x070c,	0x0f0c,
	0x0102,	0x0902,	0x010a,	0x090a,	0x0502,	0x0d02,	0x050a,	0x0d0a,
	0x0106,	0x0906,	0x010e,	0x090e,	0x0506,	0x0d06,	0x050e,	0x0d0e,
	0x0302,	0x0b02,	0x030a,	0x0b0a,	0x0702,	0x0f02,	0x070a,	0x0f0a,
	0x0306,	0x0b06,	0x030e,	0x0b0e,	0x0706,	0x0f06,	0x070e,	0x0f0e,
	0x0001,	0x0801,	0x0009,	0x0809,	0x0401,	0x0c01,	0x0409,	0x0c09,
	0x0005,	0x0805,	0x000d,	0x080d,	0x0405,	0x0c05,	0x040d,	0x0c0d,
	0x0201,	0x0a01,	0x0209,	0x0a09,	0x0601,	0x0e01,	0x0609,	0x0e09,
	0x0205,	0x0a05,	0x020d,	0x0a0d,	0x0605,	0x0e05,	0x060d,	0x0e0d,
	0x0003,	0x0803,	0x000b,	0x080b,	0x0403,	0x0c03,	0x040b,	0x0c0b,
	0x0007,	0x0807,	0x000f,	0x080f,	0x0407,	0x0c07,	0x040f,	0x0c0f,
	0x0203,	0x0a03,	0x020b,	0x0a0b,	0x0603,	0x0e03,	0x060b,	0x0e0b,
	0x0207,	0x0a07,	0x020f,	0x0a0f,	0x0607,	0x0e07,	0x060f,	0x0e0f,
	0x0101,	0x0901,	0x0109,	0x0909,	0x0501,	0x0d01,	0x0509,	0x0d09,
	0x0105,	0x0905,	0x010d,	0x090d,	0x0505,	0x0d05,	0x050d,	0x0d0d,
	0x0301,	0x0b01,	0x0309,	0x0b09,	0x0701,	0x0f01,	0x0709,	0x0f09,
	0x0305,	0x0b05,	0x030d,	0x0b0d,	0x0705,	0x0f05,	0x070d,	0x0f0d,
	0x0103,	0x0903,	0x010b,	0x090b,	0x0503,	0x0d03,	0x050b,	0x0d0b,
	0x0107,	0x0907,	0x010f,	0x090f,	0x0507,	0x0d07,	0x050f,	0x0d0f,
	0x0303,	0x0b03,	0x030b,	0x0b0b,	0x0703,	0x0f03,	0x070b,	0x0f0b,
	0x0307,	0x0b07,	0x030f,	0x0b0f,	0x0707,	0x0f07,	0x070f,	0x0f0f,
};
.
401,440d
397,399d
330a
screenupdate(void)
{
	uchar *sp, *hp;
	int y, len, incs, inch;
	Rectangle r;

	r = mbb;
	mbb = NULLMBB;

	if(Dy(r) < 0)
		return;

	if(r.min.x < 0)
		r.min.x = 0;
	if(r.min.y < 0)
		r.min.y = 0;
	if(r.max.x > gscreen.r.max.x)
		r.max.x = gscreen.r.max.x;
	if(r.max.y > gscreen.r.max.y)
		r.max.y = gscreen.r.max.y;

	sp = (uchar*)gaddr(&gscreen, r.min);
	hp = (uchar*)gaddr(&vgascreen, r.min);
	len = (r.max.x + 31)/32 - r.min.x/32;
	len *= BY2WD;
	if(len <= 0)
		return;

	incs = gscreen.width * BY2WD;
	inch = vgascreen.width * BY2WD;

	switch(gscreen.ldepth){
	case 0:
		for (y = r.min.y; y < r.max.y; y++){
			l0update(sp, hp, len);
			sp += incs;
			hp += inch;
		}
		break;
	case 1:
		for (y = r.min.y; y < r.max.y; y++){
			l1update(sp, hp, len);
			sp += incs;
			hp += inch;
		}
		break;
	}
}

void
.
329a
/*
 *  copy litte endian soft screen to big endian hard screen
 */
.
## diffname pc/vga.c 1992/1109
## diff -e /n/bootesdump/1992/1108/sys/src/9/pc/vga.c /n/bootesdump/1992/1109/sys/src/9/pc/vga.c
373a
		/* reverse the bits and split into 2 bitmaps */
.
366a
	case 3:
		/* reverse the bits */
.
357c
	len = (r.max.x*bits + 31)/32 - (r.min.x*bits)/32;
.
354a
	bits = 1<<vgascreen.ldepth;
.
337c
	int y, len, incs, inch, bits;
.
253c
	if(gscreen.base){
		free(gscreen.base);
		gscreen.base = ((ulong*)smalloc(len+2*1024))+256;
	} else
		gscreen.base = ((ulong*)malloc(len+2*1024))+256;
.
246c
	 *  setup new soft screen, free memory for old screen
.
239c
	if(ldepth == 3)
		vgascreen.ldepth = 3;
	else
		vgascreen.ldepth = 0;
.
236c
	 *  zero hard screen and setup a bitmap for the new size
.
## diffname pc/vga.c 1992/1110
## diff -e /n/bootesdump/1992/1109/sys/src/9/pc/vga.c /n/bootesdump/1992/1110/sys/src/9/pc/vga.c
457c
	return 1<<gscreen.ldepth;	/* bits per pixel */
.
449d
363,366c
	off = (r.min.x*bits)>>(3-vgascreen.ldepth);
	hp = (uchar*)(vgascreen.base+(r.min.y*vgascreen.width)) + off;
	off <<= gscreen.ldepth - vgascreen.ldepth;
	sp = (uchar*)(gscreen.base+(r.min.y*gscreen.width)) + off;
	len = (r.max.x*bits + 7)/8 - (r.min.x*bits)/8;
.
344c
	int y, len, incs, inch, bits, off;
.
304a

	/*
	 *  set up default grey scale color map
	 */
	outb(CMWX, 0);
	for(i = 0; i < 16; i++){
		x = (i*63)/15;
		outb(CM, x);
		outb(CM, x);
		outb(CM, x);
	}
.
303d
274c
	int i, x;
.
255c
	len = gscreen.width * BY2WD * maxy;
.
244c
	vgascreen.width = (maxx*(1<<vgascreen.ldepth))/32;
.
## diffname pc/vga.c 1992/1111
## diff -e /n/bootesdump/1992/1110/sys/src/9/pc/vga.c /n/bootesdump/1992/1111/sys/src/9/pc/vga.c
562,594c
ulong l1revsep[] =
{
	0x00000, 0x80000, 0x00008, 0x80008, 0x40000, 0xc0000, 0x40008, 0xc0008,
	0x00004, 0x80004, 0x0000c, 0x8000c, 0x40004, 0xc0004, 0x4000c, 0xc000c,
	0x20000, 0xa0000, 0x20008, 0xa0008, 0x60000, 0xe0000, 0x60008, 0xe0008,
	0x20004, 0xa0004, 0x2000c, 0xa000c, 0x60004, 0xe0004, 0x6000c, 0xe000c,
	0x00002, 0x80002, 0x0000a, 0x8000a, 0x40002, 0xc0002, 0x4000a, 0xc000a,
	0x00006, 0x80006, 0x0000e, 0x8000e, 0x40006, 0xc0006, 0x4000e, 0xc000e,
	0x20002, 0xa0002, 0x2000a, 0xa000a, 0x60002, 0xe0002, 0x6000a, 0xe000a,
	0x20006, 0xa0006, 0x2000e, 0xa000e, 0x60006, 0xe0006, 0x6000e, 0xe000e,
	0x10000, 0x90000, 0x10008, 0x90008, 0x50000, 0xd0000, 0x50008, 0xd0008,
	0x10004, 0x90004, 0x1000c, 0x9000c, 0x50004, 0xd0004, 0x5000c, 0xd000c,
	0x30000, 0xb0000, 0x30008, 0xb0008, 0x70000, 0xf0000, 0x70008, 0xf0008,
	0x30004, 0xb0004, 0x3000c, 0xb000c, 0x70004, 0xf0004, 0x7000c, 0xf000c,
	0x10002, 0x90002, 0x1000a, 0x9000a, 0x50002, 0xd0002, 0x5000a, 0xd000a,
	0x10006, 0x90006, 0x1000e, 0x9000e, 0x50006, 0xd0006, 0x5000e, 0xd000e,
	0x30002, 0xb0002, 0x3000a, 0xb000a, 0x70002, 0xf0002, 0x7000a, 0xf000a,
	0x30006, 0xb0006, 0x3000e, 0xb000e, 0x70006, 0xf0006, 0x7000e, 0xf000e,
	0x00001, 0x80001, 0x00009, 0x80009, 0x40001, 0xc0001, 0x40009, 0xc0009,
	0x00005, 0x80005, 0x0000d, 0x8000d, 0x40005, 0xc0005, 0x4000d, 0xc000d,
	0x20001, 0xa0001, 0x20009, 0xa0009, 0x60001, 0xe0001, 0x60009, 0xe0009,
	0x20005, 0xa0005, 0x2000d, 0xa000d, 0x60005, 0xe0005, 0x6000d, 0xe000d,
	0x00003, 0x80003, 0x0000b, 0x8000b, 0x40003, 0xc0003, 0x4000b, 0xc000b,
	0x00007, 0x80007, 0x0000f, 0x8000f, 0x40007, 0xc0007, 0x4000f, 0xc000f,
	0x20003, 0xa0003, 0x2000b, 0xa000b, 0x60003, 0xe0003, 0x6000b, 0xe000b,
	0x20007, 0xa0007, 0x2000f, 0xa000f, 0x60007, 0xe0007, 0x6000f, 0xe000f,
	0x10001, 0x90001, 0x10009, 0x90009, 0x50001, 0xd0001, 0x50009, 0xd0009,
	0x10005, 0x90005, 0x1000d, 0x9000d, 0x50005, 0xd0005, 0x5000d, 0xd000d,
	0x30001, 0xb0001, 0x30009, 0xb0009, 0x70001, 0xf0001, 0x70009, 0xf0009,
	0x30005, 0xb0005, 0x3000d, 0xb000d, 0x70005, 0xf0005, 0x7000d, 0xf000d,
	0x10003, 0x90003, 0x1000b, 0x9000b, 0x50003, 0xd0003, 0x5000b, 0xd000b,
	0x10007, 0x90007, 0x1000f, 0x9000f, 0x50007, 0xd0007, 0x5000f, 0xd000f,
	0x30003, 0xb0003, 0x3000b, 0xb000b, 0x70003, 0xf0003, 0x7000b, 0xf000b,
	0x30007, 0xb0007, 0x3000f, 0xb000f, 0x70007, 0xf0007, 0x7000f, 0xf000f,
};

/*
 *  Table for separating and reversing bits in a ldepth 2 bitmap.
 *  This aids in coverting a little endian ldepth 1 bitmap into the
 *  4 big-endian ldepth 0 bitmaps used for the VGA bit planes.
 *
 *	if the bits in uchar x are labeled
 *		76543210
 *	then l1revsep[x] yields a ushort with bits
 *		______04______15______26______37
 *	where _ represents a bit whose value is 0.
 *
 *  This table is used by l2update() in l.s.  l2update is implemented
 *  in assembler for speed.
 *
 */
ulong l2revsep[] =
{
 0x0000000, 0x2000000, 0x0020000, 0x2020000, 0x0000200, 0x2000200, 0x0020200, 0x2020200,
 0x0000002, 0x2000002, 0x0020002, 0x2020002, 0x0000202, 0x2000202, 0x0020202, 0x2020202,
 0x1000000, 0x3000000, 0x1020000, 0x3020000, 0x1000200, 0x3000200, 0x1020200, 0x3020200,
 0x1000002, 0x3000002, 0x1020002, 0x3020002, 0x1000202, 0x3000202, 0x1020202, 0x3020202,
 0x0010000, 0x2010000, 0x0030000, 0x2030000, 0x0010200, 0x2010200, 0x0030200, 0x2030200,
 0x0010002, 0x2010002, 0x0030002, 0x2030002, 0x0010202, 0x2010202, 0x0030202, 0x2030202,
 0x1010000, 0x3010000, 0x1030000, 0x3030000, 0x1010200, 0x3010200, 0x1030200, 0x3030200,
 0x1010002, 0x3010002, 0x1030002, 0x3030002, 0x1010202, 0x3010202, 0x1030202, 0x3030202,
 0x0000100, 0x2000100, 0x0020100, 0x2020100, 0x0000300, 0x2000300, 0x0020300, 0x2020300,
 0x0000102, 0x2000102, 0x0020102, 0x2020102, 0x0000302, 0x2000302, 0x0020302, 0x2020302,
 0x1000100, 0x3000100, 0x1020100, 0x3020100, 0x1000300, 0x3000300, 0x1020300, 0x3020300,
 0x1000102, 0x3000102, 0x1020102, 0x3020102, 0x1000302, 0x3000302, 0x1020302, 0x3020302,
 0x0010100, 0x2010100, 0x0030100, 0x2030100, 0x0010300, 0x2010300, 0x0030300, 0x2030300,
 0x0010102, 0x2010102, 0x0030102, 0x2030102, 0x0010302, 0x2010302, 0x0030302, 0x2030302,
 0x1010100, 0x3010100, 0x1030100, 0x3030100, 0x1010300, 0x3010300, 0x1030300, 0x3030300,
 0x1010102, 0x3010102, 0x1030102, 0x3030102, 0x1010302, 0x3010302, 0x1030302, 0x3030302,
 0x0000001, 0x2000001, 0x0020001, 0x2020001, 0x0000201, 0x2000201, 0x0020201, 0x2020201,
 0x0000003, 0x2000003, 0x0020003, 0x2020003, 0x0000203, 0x2000203, 0x0020203, 0x2020203,
 0x1000001, 0x3000001, 0x1020001, 0x3020001, 0x1000201, 0x3000201, 0x1020201, 0x3020201,
 0x1000003, 0x3000003, 0x1020003, 0x3020003, 0x1000203, 0x3000203, 0x1020203, 0x3020203,
 0x0010001, 0x2010001, 0x0030001, 0x2030001, 0x0010201, 0x2010201, 0x0030201, 0x2030201,
 0x0010003, 0x2010003, 0x0030003, 0x2030003, 0x0010203, 0x2010203, 0x0030203, 0x2030203,
 0x1010001, 0x3010001, 0x1030001, 0x3030001, 0x1010201, 0x3010201, 0x1030201, 0x3030201,
 0x1010003, 0x3010003, 0x1030003, 0x3030003, 0x1010203, 0x3010203, 0x1030203, 0x3030203,
 0x0000101, 0x2000101, 0x0020101, 0x2020101, 0x0000301, 0x2000301, 0x0020301, 0x2020301,
 0x0000103, 0x2000103, 0x0020103, 0x2020103, 0x0000303, 0x2000303, 0x0020303, 0x2020303,
 0x1000101, 0x3000101, 0x1020101, 0x3020101, 0x1000301, 0x3000301, 0x1020301, 0x3020301,
 0x1000103, 0x3000103, 0x1020103, 0x3020103, 0x1000303, 0x3000303, 0x1020303, 0x3020303,
 0x0010101, 0x2010101, 0x0030101, 0x2030101, 0x0010301, 0x2010301, 0x0030301, 0x2030301,
 0x0010103, 0x2010103, 0x0030103, 0x2030103, 0x0010303, 0x2010303, 0x0030303, 0x2030303,
 0x1010101, 0x3010101, 0x1030101, 0x3030101, 0x1010301, 0x3010301, 0x1030301, 0x3030301,
 0x1010103, 0x3010103, 0x1030103, 0x3030103, 0x1010303, 0x3010303, 0x1030303, 0x3030303,
.
559c
 *  in assembler for speed.
.
555c
 *		________0246________1357
.
401a
	case 2:
		off = r.min.x>>3;
		hp = (uchar*)(vgascreen.base+(r.min.y*vgascreen.width)) + off;
		sp = (uchar*)(gscreen.base+(r.min.y*gscreen.width)) + 4*off;
		len = (r.max.x + 7)/8 - r.min.x/8;
		if(len < 1)
			len = 1;

		/* reverse the bits and split into 2 bit planes */
		for (y = r.min.y; y < r.max.y; y++){
			l2update(sp, hp, len);
			sp += incs;
			hp += inch;
		}
		break;
	case 3:
		y2pg = (64*1024/BY2WD)/gscreen.width;
		off = (r.min.y % y2pg) * gscreen.width * BY2WD + r.min.x;
		hp = (uchar*)(vgascreen.base) + off;
		sp = (uchar*)(gscreen.base) + off;
		len = r.max.x - r.min.x;
		if(len < 1)
			return;

		y = r.min.y;
		for(page = y/y2pg; y < r.max.y; page++){
			unlocktseng();
			outb(0x3cd, (page<<4)|page);
			ey = (page+1)*y2pg;
			if(ey > r.max.y)
				ey = r.max.y;
			for (; y < ey; y++){
				memmove(sp, hp, len);
				sp += incs;
				hp += inch;
			}
			hp = (uchar*)(vgascreen.base) + r.min.x;
		}
		break;
.
395c
		r.min.x &= ~15;		/* 16 bit allignment for l1update() */
		off = r.min.x>>3;
		hp = (uchar*)(vgascreen.base+(r.min.y*vgascreen.width)) + off;
		sp = (uchar*)(gscreen.base+(r.min.y*gscreen.width)) + 2*off;
		len = (r.max.x + 15)/8 - r.min.x/8;
		if(len < 2)
			len = 2;

		/* reverse the bits and split into 2 bit planes */
.
386c
		off = r.min.x>>3;
		hp = (uchar*)(vgascreen.base+(r.min.y*vgascreen.width)) + off;
		sp = (uchar*)(gscreen.base+(r.min.y*gscreen.width)) + off;
		len = (r.max.x + 7)/8 - r.min.x/8;
		if(len < 1)
			return;

.
372,380d
354c
	int y, len, incs, inch, off, page, y2pg, ey;
.
346a
void
unlocktseng(void) {
	outb(0x3bf, 0x03);
	outb(0x3d8, 0xa0);
}

.
314a
	outb(CMWX, 5);
	outb(CM, 21);
	outb(CM, 21);
	outb(CM, 21);
	outb(CMWX, 0xa);
	outb(CM, 42);
	outb(CM, 42);
	outb(CM, 42);
.
310,313c
		outb(CM, colourxpnd(i<<1));
		outb(CM, colourxpnd(i>>2));
		outb(CM, colourxpnd(i&~1));
.
306c
	 *  set up color map
.
270a
int
colourxpnd(int x)
{
	x &= 3;
	return (x<<4)|(x<<2)|x;
}

.
258,260c
		p = smalloc(len+2*1024));
		gscreen.base = ((ulong*)p) + 256;
	} else {
		p = malloc(len+2*1024));
		gscreen.base = ((ulong*)p) + 256;
	}
	pad1 = p;
	pad2 = p + len + 1024;
	memset(pad1, 0, 1024);
	memset(pad2, 0, 1024);
.
231a
	uchar *p;
.
227a
uchar *pad1, *pad2;

.
## diffname pc/vga.c 1992/1112
## diff -e /n/bootesdump/1992/1111/sys/src/9/pc/vga.c /n/bootesdump/1992/1112/sys/src/9/pc/vga.c
570,571c
	p &= (1<<(1<<gscreen.ldepth))-1;
	lock(&colorlock);
	outb(CMWX, p);
	outb(CM, r>>(32-6));
	outb(CM, g>>(32-6));
	outb(CM, b>>(32-6));
	unlock(&colorlock);
	return ~0;
.
566d
554,563c
	p &= (1<<(1<<gscreen.ldepth))-1;
	lock(&colorlock);
	outb(CMRX, p);
	*pr = expand(inb(CM));
	*pg = expand(inb(CM));
	*pb = expand(inb(CM));
	unlock(&colorlock);
.
550a
static ulong
expand(uchar x)
{
	return (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24));
}

.
476a

	if(nocheck==0 && memcmp(pad1, pad2, 1024)){
		nocheck = 1;
		print("a: %d %d %d %d\n", r.min.x, r.min.y, r.max.x, r.max.y);
		nocheck = 0;
		memset(pad1, 0, 1024);
		memset(pad2, 0, 1024);
	}
.
427,428c
		if(len < 0)
			return;
.
389a
	if(nocheck==0 && memcmp(pad1, pad2, 1024)){
		nocheck = 1;
		print("b: %d %d %d %d\n", r.min.x, r.min.y, r.max.x, r.max.y);
		nocheck = 0;
		memset(pad1, 0, 1024);
		memset(pad2, 0, 1024);
	}

.
385a
	static int nocheck;
.
331,338c
	unlock(&colorlock);
.
327,329c
		x = (i*63)/15;
		outb(CM, x);
		outb(CM, x);
		outb(CM, x);
.
324a
	lock(&colorlock);
.
281,287d
273a
	 *  set depth of cursor backup area
	 */
	bitdepth();

	/*
.
271a
	memset((void*)SCREENMEM, 0xff, vgascreen.width * BY2WD * maxy);
.
270a
	gscreen.base = (ulong*)(p+1024);
.
268c
	pad2 = p + 1024 + len;
.
261,266c
		p = smalloc(len + 2*1024);
	} else
		p = malloc(len + 2*1024);
.
257c
	gscreen.clipr = gscreen.r;
.
255a
	gscreen.r.min = Pt(0, 0);
.
249c
	vgascreen.clipr = vgascreen.r;
.
247a
	vgascreen.r.min = Pt(0, 0);
.
241d
70c
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
.
28d
25,26c
extern	GSubfont defont0;
GSubfont *defont;
extern	Cursor arrow;
extern	GBitmap cursorback;
static	Lock colorlock;		/* color map lock */
.
15,17d
## diffname pc/vga.c 1992/1113
## diff -e /n/bootesdump/1992/1112/sys/src/9/pc/vga.c /n/bootesdump/1992/1113/sys/src/9/pc/vga.c
607a
	spllo();	/* so we don't cause lost chars on the uart */
.
587c
	unlock(&vgalock);
.
582c
	lock(&vgalock);
	colormap[p][0] = r;
	colormap[p][1] = g;
	colormap[p][2] = b;
.
570,575c
	lock(&vgalock);
	*pr = colormap[p][0];
	*pg = colormap[p][1];
	*pb = colormap[p][2];
	unlock(&vgalock);
.
555,566d
544c
	vgaupdate();
.
503,504d
500c
	vgaupdate();
.
479,484c
void
screenupdate(void)
{
	lock(&vgalock);
	vgaupdate();
	unlock(&vgalock);
}

void
mousescreenupdate(void)
{
	if(canlock(&vgalock)){
		vgaupdate();
		unlock(&vgalock);
.
477a
}
.
456a
		off = r.min.y * gscreen.width * BY2WD + r.min.x;
.
383,390d
372,373c
static void
vgaupdate(void)
.
347c
	if (Dy(mbb) > 32 || Dx(mbb) > 32)
		mousescreenupdate();
.
318,330d
291,292d
288c
	int i;
.
282a

	/*
	 *  default color map
	 */
	switch(ldepth){
	case 3:
		for(i = 0; i < 256; i++)
			setcolor(i, x3to32(i>>5), x3to32(i>>2), x3to32(i<<1));
		break;
	case 2:
	case 1:
	case 0:
		gscreen.ldepth = 3;
		for(i = 0; i < 16; i++){
			x = x6to32((i*63)/15);
			setcolor(i, x, x, x);
		}
		gscreen.ldepth = ldepth;
		break;
	}
.
258,270c
	gscreen.base = (ulong*)p;
	memset(gscreen.base, 0xff, len);
.
254c
	gscreen.width = width;
.
252a
	if(gscreen.base)
		xfree(gscreen.base);
.
248a
	memset(vgascreen.base, 0xff, vgascreen.width * BY2WD * vgamaxy);
.
247c
	vgascreen.r.max = Pt(maxx, vgamaxy);
.
245a
	vgamaxy = maxy % ((64*1024)/vgascreen.width);
	vgascreen.base = (void*)SCREENMEM;
.
244d
234a
	if(ldepth == 3)
		setmode(&mode13);
	else
		setmode(&mode12);

	/* allocate a new soft bitmap area */
	width = (maxx*(1<<ldepth))/32;
	len = width * BY2WD * maxy;
	p = xalloc(len);
	if(p == 0)
		panic("can't alloc screen bitmap");
.
232c
	int len, vgamaxy, width, i, x;
.
228a
	x = x&7;
	x= (x<<3)|x;
	y = (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24))|(x<<(32-30));
	return y;
}
static ulong
x6to32(uchar x)
{
	ulong y;

	x = x&0x3f;
	y = (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24))|(x<<(32-30));
	return y;
}

.
227c
/*
 *  expand 3 and 6 bits of color to 32
 */
static ulong
x3to32(uchar x)
{
	ulong y;
.
225c
#endif asdf
.
191a
#ifdef asdf
.
72a
/*
 *  640x480 display, 8 bit color.
 */
VGAmode mode13 = 
{
	/* general */
	0xe7, 0x00,
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x0e,
	/* crt */
	0x65, 0x4f, 0x50, 0x88, 0x55, 0x9a, 0x09, 0x3e,
	0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0xe8, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xA3,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
	0x41, 0x10, 0x0f, 0x00, 0x00,
};

.
51c
 *  640x480 display, 1, 2, or 4 bit color.
.
37,38d
27a
/* exported */
GSubfont *defont;
int islittle = 1;		/* little endian bit ordering in bytes */
GBitmap	gscreen;

/* local */
static	Lock vgalock;
static	GBitmap	vgascreen;
static	ulong colormap[256][3];

.
26d
23d
20,21c
/* imported */
.
## diffname pc/vga.c 1992/1114
## diff -e /n/bootesdump/1992/1113/sys/src/9/pc/vga.c /n/bootesdump/1992/1114/sys/src/9/pc/vga.c
632a
	if(vgascreen.ldepth == 3)
		p = bitrevtab[p];
.
627a
	extern uchar bitrevtab[];

.
613d
602,603d
599a
			mbbpt(Pt(out.pos.x, out.pos.y+defont0.height));
.
595a
			mbbpt(Pt(out.pos.x + out.bwid, out.pos.y+defont0.height));
.
573c
	mbbpt(out.pos);
.
570d
558a
	}
.
557c
	if(out.pos.y > gscreen.r.max.y-defont0.height){
		vgaupdate();
.
523c
				memmove(hp, sp, len);
.
519c
			ey = (page+1)*vgascreen.r.max.y;
.
516c
		for(page = y/vgascreen.r.max.y; y < r.max.y; page++){
.
506,507c
		off = (r.min.y % vgascreen.r.max.y) * vgascreen.width * BY2WD + r.min.x;
.
436c
	int y, len, incs, inch, off, page, ey;
.
312a
		v = (uchar*)vgascreen.base;
		for(x = 0; x < vgamaxy; x++)
			for(i = 0; i < vgascreen.width*BY2WD; i+=8)
				*v = 0;
	}

.
311a
	if(ldepth == 3){
		uchar *v;
.
306c
	if(maxy > (64*1024)/(vgascreen.width*BY2WD))
		vgamaxy = (64*1024)/(vgascreen.width*BY2WD);
	else
		vgamaxy = maxy;
.
220,255d
88,90c
	0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
	0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28,
	0x9c, 0x8e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
.
84c
	0x63, 0x00,
.
79c
 *  320x200 display, 8 bit color.
.
## diffname pc/vga.c 1992/1115
## diff -e /n/bootesdump/1992/1114/sys/src/9/pc/vga.c /n/bootesdump/1992/1115/sys/src/9/pc/vga.c
733,766c
ulong l2revsep[] = {
 0x0000000, 0x0000002, 0x0000200, 0x0000202, 0x0020000, 0x0020002, 0x0020200, 0x0020202,
 0x2000000, 0x2000002, 0x2000200, 0x2000202, 0x2020000, 0x2020002, 0x2020200, 0x2020202,
 0x0000001, 0x0000003, 0x0000201, 0x0000203, 0x0020001, 0x0020003, 0x0020201, 0x0020203,
 0x2000001, 0x2000003, 0x2000201, 0x2000203, 0x2020001, 0x2020003, 0x2020201, 0x2020203,
 0x0000100, 0x0000102, 0x0000300, 0x0000302, 0x0020100, 0x0020102, 0x0020300, 0x0020302,
 0x2000100, 0x2000102, 0x2000300, 0x2000302, 0x2020100, 0x2020102, 0x2020300, 0x2020302,
 0x0000101, 0x0000103, 0x0000301, 0x0000303, 0x0020101, 0x0020103, 0x0020301, 0x0020303,
 0x2000101, 0x2000103, 0x2000301, 0x2000303, 0x2020101, 0x2020103, 0x2020301, 0x2020303,
 0x0010000, 0x0010002, 0x0010200, 0x0010202, 0x0030000, 0x0030002, 0x0030200, 0x0030202,
 0x2010000, 0x2010002, 0x2010200, 0x2010202, 0x2030000, 0x2030002, 0x2030200, 0x2030202,
 0x0010001, 0x0010003, 0x0010201, 0x0010203, 0x0030001, 0x0030003, 0x0030201, 0x0030203,
 0x2010001, 0x2010003, 0x2010201, 0x2010203, 0x2030001, 0x2030003, 0x2030201, 0x2030203,
 0x0010100, 0x0010102, 0x0010300, 0x0010302, 0x0030100, 0x0030102, 0x0030300, 0x0030302,
 0x2010100, 0x2010102, 0x2010300, 0x2010302, 0x2030100, 0x2030102, 0x2030300, 0x2030302,
 0x0010101, 0x0010103, 0x0010301, 0x0010303, 0x0030101, 0x0030103, 0x0030301, 0x0030303,
 0x2010101, 0x2010103, 0x2010301, 0x2010303, 0x2030101, 0x2030103, 0x2030301, 0x2030303,
 0x1000000, 0x1000002, 0x1000200, 0x1000202, 0x1020000, 0x1020002, 0x1020200, 0x1020202,
 0x3000000, 0x3000002, 0x3000200, 0x3000202, 0x3020000, 0x3020002, 0x3020200, 0x3020202,
 0x1000001, 0x1000003, 0x1000201, 0x1000203, 0x1020001, 0x1020003, 0x1020201, 0x1020203,
 0x3000001, 0x3000003, 0x3000201, 0x3000203, 0x3020001, 0x3020003, 0x3020201, 0x3020203,
 0x1000100, 0x1000102, 0x1000300, 0x1000302, 0x1020100, 0x1020102, 0x1020300, 0x1020302,
 0x3000100, 0x3000102, 0x3000300, 0x3000302, 0x3020100, 0x3020102, 0x3020300, 0x3020302,
 0x1000101, 0x1000103, 0x1000301, 0x1000303, 0x1020101, 0x1020103, 0x1020301, 0x1020303,
 0x3000101, 0x3000103, 0x3000301, 0x3000303, 0x3020101, 0x3020103, 0x3020301, 0x3020303,
 0x1010000, 0x1010002, 0x1010200, 0x1010202, 0x1030000, 0x1030002, 0x1030200, 0x1030202,
 0x3010000, 0x3010002, 0x3010200, 0x3010202, 0x3030000, 0x3030002, 0x3030200, 0x3030202,
 0x1010001, 0x1010003, 0x1010201, 0x1010203, 0x1030001, 0x1030003, 0x1030201, 0x1030203,
 0x3010001, 0x3010003, 0x3010201, 0x3010203, 0x3030001, 0x3030003, 0x3030201, 0x3030203,
 0x1010100, 0x1010102, 0x1010300, 0x1010302, 0x1030100, 0x1030102, 0x1030300, 0x1030302,
 0x3010100, 0x3010102, 0x3010300, 0x3010302, 0x3030100, 0x3030102, 0x3030300, 0x3030302,
 0x1010101, 0x1010103, 0x1010301, 0x1010303, 0x1030101, 0x1030103, 0x1030301, 0x1030303,
 0x3010101, 0x3010103, 0x3010301, 0x3010303, 0x3030101, 0x3030103, 0x3030301, 0x3030303,
.
726c
 *		______37______26______15______04
.
682,715c
ulong l1revsep[] = {
 0x00000, 0x00008, 0x80000, 0x80008, 0x00004, 0x0000c, 0x80004, 0x8000c,
 0x40000, 0x40008, 0xc0000, 0xc0008, 0x40004, 0x4000c, 0xc0004, 0xc000c,
 0x00002, 0x0000a, 0x80002, 0x8000a, 0x00006, 0x0000e, 0x80006, 0x8000e,
 0x40002, 0x4000a, 0xc0002, 0xc000a, 0x40006, 0x4000e, 0xc0006, 0xc000e,
 0x20000, 0x20008, 0xa0000, 0xa0008, 0x20004, 0x2000c, 0xa0004, 0xa000c,
 0x60000, 0x60008, 0xe0000, 0xe0008, 0x60004, 0x6000c, 0xe0004, 0xe000c,
 0x20002, 0x2000a, 0xa0002, 0xa000a, 0x20006, 0x2000e, 0xa0006, 0xa000e,
 0x60002, 0x6000a, 0xe0002, 0xe000a, 0x60006, 0x6000e, 0xe0006, 0xe000e,
 0x00001, 0x00009, 0x80001, 0x80009, 0x00005, 0x0000d, 0x80005, 0x8000d,
 0x40001, 0x40009, 0xc0001, 0xc0009, 0x40005, 0x4000d, 0xc0005, 0xc000d,
 0x00003, 0x0000b, 0x80003, 0x8000b, 0x00007, 0x0000f, 0x80007, 0x8000f,
 0x40003, 0x4000b, 0xc0003, 0xc000b, 0x40007, 0x4000f, 0xc0007, 0xc000f,
 0x20001, 0x20009, 0xa0001, 0xa0009, 0x20005, 0x2000d, 0xa0005, 0xa000d,
 0x60001, 0x60009, 0xe0001, 0xe0009, 0x60005, 0x6000d, 0xe0005, 0xe000d,
 0x20003, 0x2000b, 0xa0003, 0xa000b, 0x20007, 0x2000f, 0xa0007, 0xa000f,
 0x60003, 0x6000b, 0xe0003, 0xe000b, 0x60007, 0x6000f, 0xe0007, 0xe000f,
 0x10000, 0x10008, 0x90000, 0x90008, 0x10004, 0x1000c, 0x90004, 0x9000c,
 0x50000, 0x50008, 0xd0000, 0xd0008, 0x50004, 0x5000c, 0xd0004, 0xd000c,
 0x10002, 0x1000a, 0x90002, 0x9000a, 0x10006, 0x1000e, 0x90006, 0x9000e,
 0x50002, 0x5000a, 0xd0002, 0xd000a, 0x50006, 0x5000e, 0xd0006, 0xd000e,
 0x30000, 0x30008, 0xb0000, 0xb0008, 0x30004, 0x3000c, 0xb0004, 0xb000c,
 0x70000, 0x70008, 0xf0000, 0xf0008, 0x70004, 0x7000c, 0xf0004, 0xf000c,
 0x30002, 0x3000a, 0xb0002, 0xb000a, 0x30006, 0x3000e, 0xb0006, 0xb000e,
 0x70002, 0x7000a, 0xf0002, 0xf000a, 0x70006, 0x7000e, 0xf0006, 0xf000e,
 0x10001, 0x10009, 0x90001, 0x90009, 0x10005, 0x1000d, 0x90005, 0x9000d,
 0x50001, 0x50009, 0xd0001, 0xd0009, 0x50005, 0x5000d, 0xd0005, 0xd000d,
 0x10003, 0x1000b, 0x90003, 0x9000b, 0x10007, 0x1000f, 0x90007, 0x9000f,
 0x50003, 0x5000b, 0xd0003, 0xd000b, 0x50007, 0x5000f, 0xd0007, 0xd000f,
 0x30001, 0x30009, 0xb0001, 0xb0009, 0x30005, 0x3000d, 0xb0005, 0xb000d,
 0x70001, 0x70009, 0xf0001, 0xf0009, 0x70005, 0x7000d, 0xf0005, 0xf000d,
 0x30003, 0x3000b, 0xb0003, 0xb000b, 0x30007, 0x3000f, 0xb0007, 0xb000f,
 0x70003, 0x7000b, 0xf0003, 0xf000b, 0x70007, 0x7000f, 0xf0007, 0xf000f,
.
675c
 *		________1357________0246
.
663,664c
	pixreverse(arrow.set, 2*16, 0);
	pixreverse(arrow.clr, 2*16, 0);
.
609,610d
602,603d
576c
			mbbrect(rect);
.
574a
			rect.min = Pt(out.pos.x, out.pos.y);
			rect.max = Pt(out.pos.x+out.bwid, out.pos.y+defont0.height);
.
571c
			rect.min = Pt(out.pos.x, out.pos.y);
			rect.max = Pt(out.pos.x+out.bwid, out.pos.y+defont0.height);
			mbbrect(rect);
.
548d
546a
	Rectangle rect;
.
354,355c
	pixreverse((uchar*)defont->bits->base,
		defont->bits->width*BY2WD*Dy(defont->bits->r), 0);
.
343,344c
	pixreverse(arrow.set, 2*16, 0);
	pixreverse(arrow.clr, 2*16, 0);
.
282,287d
279,280d
165a

	/* turn screen on */
	srout(1, v->sequencer[1]);
.
155c
		if(i == 1)
			srout(i, v->sequencer[i]|0x20);		/* avoid enabling screen */
		else
			srout(i, v->sequencer[i]);
.
150a
	/* turn screen off (to avoid damage) */
	srout(1, 0x21);

.
## diffname pc/vga.c 1992/1117
## diff -e /n/bootesdump/1992/1115/sys/src/9/pc/vga.c /n/bootesdump/1992/1117/sys/src/9/pc/vga.c
548a

	if(cga) {
		cgascreenputs(s, n);
		return;
	}
.
525a
cgascreenputs(char *s, int n)
{
	while(n-- > 0)
		cgascreenputc(*s++);
}

void
.
524a
static void
cgascreenputc(int c)
{
	int i;
	static int color;
	static int pos;

	if(c == '\n'){
		pos = pos/CGAWIDTH;
		pos = (pos+1)*CGAWIDTH;
	} else if(c == '\t'){
		i = 8 - ((pos/2)&7);
		while(i-->0)
			cgascreenputc(' ');
	} else if(c == '\b'){
		if(pos >= 2)
			pos -= 2;
		cgascreenputc(' ');
		pos -= 2;
	} else {
		CGASCREEN[pos++] = c;
		CGASCREEN[pos++] = 2;	/* green on black */
	}
	if(pos >= CGAWIDTH*CGAHEIGHT){
		memmove(CGASCREEN, &CGASCREEN[CGAWIDTH], CGAWIDTH*(CGAHEIGHT-1));
		memset(&CGASCREEN[CGAWIDTH*(CGAHEIGHT-1)], 0, CGAWIDTH);
		pos = CGAWIDTH*(CGAHEIGHT-1);
	}
}

.
504d
502c
			sp += incs;
			hp += inch - 64*1024;
.
490,500c
	edisp = ((uchar*)vgascreen.base) + 64*1024;
	outb(0x3cd, (page<<4)|page);
	for(y = r.min.y; y < r.max.y; y++){
		if(hp + inch < edisp){
			f(hp, sp, len);
			sp += incs;
			hp += inch;
		} else {
			off = edisp - hp;
			if(off <= len){
				f(hp, sp, off);
				page++;
				outb(0x3cd, (page<<4)|page);
				f(vgascreen.base, sp+off, len - off);
			} else {
				f(hp, sp, len);
				page++;
				outb(0x3cd, (page<<4)|page);
.
487,488c
		break;
	}
	if(len < 1)
		return;
.
482,485c
		f = memmove;
.
471,479d
467,469c
		f = l2update;
.
456,464d
451,454c
		f = l1update;
.
440,448d
436,438c
		f = l0update;
.
433a
	off = r.min.y * vgascreen.width * BY2WD + (r.min.x>>(3 - vgascreen.ldepth));
	page = off>>16;
	off &= (1<<16)-1;
	hp = ((uchar*)vgascreen.base) + off;
	off = r.min.y * gscreen.width * BY2WD + (r.min.x>>(3 - gscreen.ldepth));
	sp = ((uchar*)gscreen.base) + off;

.
430a
	outb(0x3bf, 0x03);
	outb(0x3d8, 0xa0);

.
414c
	void* (*f)(void*, void*, long);
.
411,412c
	uchar *sp, *hp, *edisp;
	int y, len, incs, inch, off, page;
.
399,404d
358,365c
	cga = 1;
	crout(0x0a, 0xff);		/* turn off cursor */
	memset(CGASCREEN, 0, CGAWIDTH*CGAHEIGHT);
.
340a
	unlocktseng();

.
269a
	cga = 0;
.
104a
unlocktseng(void) {
	outb(0x3bf, 0x03);
	outb(0x3d8, 0xa0);
}

void
.
33a
static	int cga = 1;		/* true if in cga mode */
.
## diffname pc/vga.c 1992/1118
## diff -e /n/bootesdump/1992/1117/sys/src/9/pc/vga.c /n/bootesdump/1992/1118/sys/src/9/pc/vga.c
477c
				if(len - off > 0)
					f(vgascreen.base, sp+off, len - off);
.
474c
				if(off > 0)
					f(hp, sp, off);
.
459a
	default:
		return;
.
430,432d
349,350d
340a
	cga = 0;
.
277d
106,111d
## diffname pc/vga.c 1997/1101
## diff -e /n/bootesdump/1992/1118/sys/src/9/pc/vga.c /n/emeliedump/1997/1101/sys/src/brazil/pc/vga.c
649,782d
643,647c
	screenputs = vgascreenputs;
.
636,641c
	window.min = Pt(48, 48);
	window.max = addpt(window.min, Pt(10+w*80, 10+h*50));
	if(window.max.y >= scr->gscreen->r.max.y)
		window.max.y = scr->gscreen->r.max.y-1;
	if(window.max.x >= scr->gscreen->r.max.x)
		window.max.x = scr->gscreen->r.max.x-1;
	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
	curpos = window.min;
.
620,634c
	h = scr->memdefont->height;
	w = scr->memdefont->info[' '].width;
.
612,618c
	int h, w;
.
610c
vgascreenwin(VGAscr* scr)
.
603,606c
	unlock(&vgascreenlock);
.
600,601c
	flushmemscreen(flushr);
.
577,598c
		vgascreenputc(scr, buf, &flushr);
.
565a
	flushr = Rect(10000, 10000, -10000, -10000);

.
564a
	else
		lock(&vgascreenlock);
.
561,563c
	scr = &vgascreen[0];

	if(!islo()){
		/*
		 * Don't deadlock trying to
		 * print in an interrupt.
		 */
		if(!canlock(&vgascreenlock))
			return;
.
559c
	VGAscr *scr;
	Rectangle flushr;
.
557d
503,555d
500c
vgascreenputs(char* s, int n)
.
482,495c
		*xp++ = curpos.x;
		r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h);
		memimagedraw(scr->gscreen, r, back, back->r.min, memones, back->r.min);
		memimagestring(scr->gscreen, curpos, &conscol, scr->memdefont, buf);
		bbox(flushr, r);
		curpos.x += w;
.
455,480c
		if(curpos.x >= window.max.x-w)
			vgascreenputc(scr, "\n", flushr);
.
450,453c
		p = memsubfontwidth(scr->memdefont, buf);
		w = p.x;
.
437,448c

.
432,435c
	case '\b':
		if(xp <= xbuf)
			break;
		xp--;
		r = Rect(*xp, curpos.y, curpos.x, curpos.y+h);
		memimagedraw(scr->gscreen, r, back, back->r.min, memones, back->r.min);
		bbox(flushr, r);
		curpos.x = *xp;
.
425,430c
	case '\t':
		p = memsubfontwidth(scr->memdefont, " ");
		w = p.x;
		*xp++ = curpos.x;
		pos = (curpos.x-window.min.x)/w;
		pos = 4-(pos%4);
		r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y+h);
		memimagedraw(scr->gscreen, r, back, back->r.min, memones, back->r.min);
		bbox(flushr, r);
		curpos.x += pos*w;
		break;
.
422,423c
	case '\r':
		xp = xbuf;
		curpos.x = window.min.x;
		break;
.
413,420c
	case '\n':
		if(curpos.y+h >= window.max.y){
			vgascroll(scr);
			*flushr = window;
		}
		curpos.y += h;
		vgascreenputc(scr, "\r", flushr);
		break;
.
410,411c
	h = scr->memdefont->height;
	switch(buf[0]){
.
407,408c
	if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
		xp = xbuf;
.
405d
402,403c
	Point p;
	int h, w, pos;
.
400c
vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr)
.
337,398d
303,334c
	curpos.y -= o;
.
140,301c
	h = scr->memdefont->height;
	o = 8*h;
	r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
	p = Pt(window.min.x, window.min.y+o);
	memimagedraw(scr->gscreen, r, scr->gscreen, p, memones, p);
	r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
	memimagedraw(scr->gscreen, r, back, ZP, memones, ZP);
.
108,138c
	int h, o;
	Point p;
	Rectangle r;
.
105,106c
static void
vgascroll(VGAscr* scr)
.
102,103c
static Point curpos;
static Rectangle window;
static int *xp;
static int xbuf[256];
static Lock vgascreenlock;
.
100a
static Memimage conscol = {
	{ 0, 0, 1, 1 },
	{ -100000, -100000, 100000, 100000 },
	3,
	1,
	&consdata,
	0,
	1
};
.
79,99c
static ulong consbits = 0;
static Memdata consdata = {
	nil,
	&consbits
.
77a
static Memimage* back = &xback;
.
55,76c
static Memimage xback = {
	{ 0, 0, 1, 1 },
	{ -100000, -100000, 100000, 100000 },
	3,
	1,
	&backdata,
	0,
	1
.
13,53c
static ulong backbits = (Backgnd<<24)|(Backgnd<<16)|(Backgnd<<8)|Backgnd;
static Memdata backdata = {
	nil,
	&backbits
.
8,11c
#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
#include "screen.h"
.
1,6c
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
.
## diffname pc/vga.c 1999/0119
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/vga.c /n/emeliedump/1999/0119/sys/src/brazil/pc/vga.c
10a
#include <cursor.h>
.
## diffname pc/vga.c 1999/1005
## diff -e /n/emeliedump/1999/0119/sys/src/brazil/pc/vga.c /n/emeliedump/1999/1005/sys/src/brazil/pc/vga.c
194a

.
131a
//	drawdebug = 0;
.
127,128c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min);
		memimagestring(scr->gscreen, curpos, conscol, scr->memdefont, buf);
.
113c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP);
.
103c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP);
.
75a
//	drawdebug = 1;
.
64c
	memimagedraw(scr->gscreen, r, back, ZP, nil, ZP);
.
62c
	memimagedraw(scr->gscreen, r, scr->gscreen, p, nil, p);
.
50a
void
vgaimageinit(ulong chan)
{
	if(back == nil){
		back = allocmemimage(Rect(0,0,1,1), chan);	/* RSC BUG */
		if(back == nil)
			panic("back alloc");		/* RSC BUG */
		back->flags |= Frepl;
		back->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
		memfillcolor(back, DBlack);
	}

	if(conscol == nil){
		conscol = allocmemimage(Rect(0,0,1,1), chan);	/* RSC BUG */
		if(conscol == nil)
			panic("conscol alloc");	/* RSC BUG */
		conscol->flags |= Frepl;
		conscol->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
		memfillcolor(conscol, DWhite);
	}
}

.
49a
int drawdebug;
.
30,44d
14,28c
static Memimage* back;
static Memimage *conscol;
.
## diffname pc/vga.c 1999/1106
## diff -e /n/emeliedump/1999/1005/sys/src/brazil/pc/vga.c /n/emeliedump/1999/1106/sys/src/9/pc/vga.c
125c
		combinerect(flushr, r);
.
110c
		combinerect(flushr, r);
.
100c
		combinerect(flushr, r);
.
## diffname pc/vga.c 2000/0104
## diff -e /n/emeliedump/1999/1106/sys/src/9/pc/vga.c /n/emeliedump/2000/0104/sys/src/9/pc/vga.c
124c
		memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf);
.
## diffname pc/vga.c 2000/0330
## diff -e /n/emeliedump/2000/0104/sys/src/9/pc/vga.c /n/emeliedump/2000/0330/sys/src/9/pc/vga.c
192a
/*
 * Supposedly this is the way to turn DPMS
 * monitors off using just the VGA registers.
 * Unfortunately, it seems to mess up the video mode
 * on the cards I've tried.
 */
void
vgablank(VGAscr*, int blank)
{
	uchar seq1, crtc17;

	if(blank) {
		seq1 = 0x00;
		crtc17 = 0x80;
	} else {
		seq1 = 0x20;
		crtc17 = 0x00;
	}

	outs(Seqx, 0x0100);			/* synchronous reset */
	seq1 |= vgaxi(Seqx, 1) & ~0x20;
	vgaxo(Seqx, 1, seq1);
	crtc17 |= vgaxi(Crtx, 0x17) & ~0x80;
	delay(10);
	vgaxo(Crtx, 0x17, crtc17);
	outs(Crtx, 0x0300);				/* end synchronous reset */
}
.
## diffname pc/vga.c 2000/1102
## diff -e /n/emeliedump/2000/0330/sys/src/9/pc/vga.c /n/emeliedump/2000/1102/sys/src/9/pc/vga.c
111a
		break;

	case '\0':
.
98,100c
		*xp++ = curpos.x;
		r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min);
.
95c
		if(curpos.x >= window.max.x-4*w)
			vgascreenputc(scr, "\n", flushr);

.
## diffname pc/vga.c 2001/0104
## diff -e /n/emeliedump/2000/1102/sys/src/9/pc/vga.c /n/emeliedump/2001/0104/sys/src/9/pc/vga.c
186,191c
	window = insetrect(scr->gscreen->r, 48);
	window.max.x = window.min.x+((window.max.x-window.min.x)/w)*w;
.
## diffname pc/vga.c 2001/0410
## diff -e /n/emeliedump/2001/0104/sys/src/9/pc/vga.c /n/emeliedump/2001/0410/sys/src/9/pc/vga.c
220a

void
addvgaseg(char *name, ulong pa, ulong size)
{
	Physseg seg;

	memset(&seg, 0, sizeof seg);
	seg.attr = SG_PHYSICAL;
	/* can we just seg.name = name; ? */
	seg.name = smalloc(NAMELEN);
	snprint(seg.name, NAMELEN, name);
	seg.pa = pa;
	seg.size = size;
	addphysseg(&seg);
}

.
## diffname pc/vga.c 2001/0527
## diff -e /n/emeliedump/2001/0410/sys/src/9/pc/vga.c /n/emeliedump/2001/0527/sys/src/9/pc/vga.c
221,236d
## diffname pc/vga.c 2001/0822
## diff -e /n/emeliedump/2001/0527/sys/src/9/pc/vga.c /n/emeliedump/2001/0822/sys/src/9/pc/vga.c
191a

.
## diffname pc/vga.c 2001/0908
## diff -e /n/emeliedump/2001/0822/sys/src/9/pc/vga.c /n/emeliedump/2001/0908/sys/src/9/pc/vga.c
221a

void
addvgaseg(char *name, ulong pa, ulong size)
{
	Physseg seg;

	memset(&seg, 0, sizeof seg);
	seg.attr = SG_PHYSICAL;
	seg.name = name;
	seg.pa = pa;
	seg.size = size;
	addphysseg(&seg);
}

.
192d
## diffname pc/vga.c 2002/0920
## diff -e /n/emeliedump/2001/0908/sys/src/9/pc/vga.c /n/emeliedump/2002/0920/sys/src/9/pc/vga.c
234a
void
cornerstring(char *s)
{
	int h, w;
	VGAscr *scr;
	Rectangle r;
	Point p;

	scr = &vgascreen[0];
	if(scr->aperture == 0 || screenputs != vgascreenputs)
		return;
	p = memsubfontwidth(scr->memdefont, s);
	w = p.x;
	h = scr->memdefont->height;

	r = Rect(0, 0, w, h);
	memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min);
	memimagestring(scr->gscreen, r.min, conscol, ZP, scr->memdefont, s);
//	flushmemscreen(r);
}
.
## diffname pc/vga.c 2002/1205
## diff -e /n/emeliedump/2002/0920/sys/src/9/pc/vga.c /n/emeliedump/2002/1205/sys/src/9/pc/vga.c
251c
	memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S);
.
128c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S);
.
111c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP, S);
.
102c
		memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S);
.
59c
	memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S);
.
57c
	memimagedraw(scr->gscreen, r, scr->gscreen, p, nil, p, S);
.

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.