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

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


## diffname pc/screen.c 1993/1113
## diff -e /dev/null /n/fornaxdump/1993/1113/sys/src/brazil/pc/screen.c
0a
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"

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

/*
 * CGA-only hack.
 */
/* imported */
extern	GSubfont defont0;
extern	Cursor arrow;
extern	GBitmap cursorback;

/* exported */
GSubfont *defont;
int islittle = 1;		/* little endian bit ordering in bytes */
GBitmap	gscreen;

/* local */
static	Lock vgalock;
static	ulong colormap[256][3];
static	Rectangle mbb;

/*
 *  reverse pixels into little endian order
 */
uchar revtab0[] = {
 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0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b3, 0xf3,
 0x07, 0x47, 0x87, 0xc7, 0x17, 0x57, 0x97, 0xd7,
 0x27, 0x67, 0xa7, 0xe7, 0x37, 0x77, 0xb7, 0xf7,
 0x0b, 0x4b, 0x8b, 0xcb, 0x1b, 0x5b, 0x9b, 0xdb,
 0x2b, 0x6b, 0xab, 0xeb, 0x3b, 0x7b, 0xbb, 0xfb,
 0x0f, 0x4f, 0x8f, 0xcf, 0x1f, 0x5f, 0x9f, 0xdf,
 0x2f, 0x6f, 0xaf, 0xef, 0x3f, 0x7f, 0xbf, 0xff,
};
uchar revtab2[] = {
 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
 0x81, 0x91, 0xa1, 0xb1, 0xc1, 0xd1, 0xe1, 0xf1,
 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
 0x82, 0x92, 0xa2, 0xb2, 0xc2, 0xd2, 0xe2, 0xf2,
 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
 0x83, 0x93, 0xa3, 0xb3, 0xc3, 0xd3, 0xe3, 0xf3,
 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
 0x84, 0x94, 0xa4, 0xb4, 0xc4, 0xd4, 0xe4, 0xf4,
 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
 0x85, 0x95, 0xa5, 0xb5, 0xc5, 0xd5, 0xe5, 0xf5,
 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
 0x86, 0x96, 0xa6, 0xb6, 0xc6, 0xd6, 0xe6, 0xf6,
 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
 0x87, 0x97, 0xa7, 0xb7, 0xc7, 0xd7, 0xe7, 0xf7,
 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
 0x88, 0x98, 0xa8, 0xb8, 0xc8, 0xd8, 0xe8, 0xf8,
 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
 0x89, 0x99, 0xa9, 0xb9, 0xc9, 0xd9, 0xe9, 0xf9,
 0x0a, 0x1a, 0x2a, 0x3a, 0x4a, 0x5a, 0x6a, 0x7a,
 0x8a, 0x9a, 0xaa, 0xba, 0xca, 0xda, 0xea, 0xfa,
 0x0b, 0x1b, 0x2b, 0x3b, 0x4b, 0x5b, 0x6b, 0x7b,
 0x8b, 0x9b, 0xab, 0xbb, 0xcb, 0xdb, 0xeb, 0xfb,
 0x0c, 0x1c, 0x2c, 0x3c, 0x4c, 0x5c, 0x6c, 0x7c,
 0x8c, 0x9c, 0xac, 0xbc, 0xcc, 0xdc, 0xec, 0xfc,
 0x0d, 0x1d, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x7d,
 0x8d, 0x9d, 0xad, 0xbd, 0xcd, 0xdd, 0xed, 0xfd,
 0x0e, 0x1e, 0x2e, 0x3e, 0x4e, 0x5e, 0x6e, 0x7e,
 0x8e, 0x9e, 0xae, 0xbe, 0xce, 0xde, 0xee, 0xfe,
 0x0f, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f, 0x7f,
 0x8f, 0x9f, 0xaf, 0xbf, 0xcf, 0xdf, 0xef, 0xff,
};

void
pixreverse(uchar *p, int len, int ldepth)
{
	uchar *e;
	uchar *tab;

	switch(ldepth){
	case 0:
		tab = revtab0;
		break;
	case 1:
		tab = revtab1;
		break;
	case 2:
		tab = revtab2;
		break;
	default:
		return;
	}

	for(e = p + len; p < e; p++)
		*p = tab[*p];
}

static void
crout(int reg, int val)
{
	outb(CRX, reg);
	outb(CR, val);
}

void
screeninit(void)
{
	int i;
	ulong *l;

	/*
	 *  arrow is defined as a big endian
	 */
	pixreverse(arrow.set, 2*16, 0);
	pixreverse(arrow.clr, 2*16, 0);

	/*
	 *  swizzle the font longs.  we do both byte and bit swizzling
	 *  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);
	pixreverse((uchar*)defont->bits->base,
		defont->bits->width*BY2WD*Dy(defont->bits->r), 0);

	crout(0x0a, 0xff);		/* turn off cursor */
	memset(CGASCREEN, 0, CGAWIDTH*CGAHEIGHT);
}

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);
	}
}

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

/*
 *  collect changes to the 'soft' screen
 */
void
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;
	mousescreenupdate();
}

void
hwcursset(ulong *s, ulong *c, int ox, int oy)
{
	USED(s, c, ox, oy);
}

void
hwcursmove(int x, int y)
{
	USED(x, y);
}

void
screenload(Rectangle r, uchar *data, int tl, int l)
{
	USED(r, data, tl, l);
}

void
getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
{
	p &= (1<<(1<<gscreen.ldepth))-1;
	lock(&vgalock);
	*pr = colormap[p][0];
	*pg = colormap[p][1];
	*pb = colormap[p][2];
	unlock(&vgalock);
}

void
mousescreenupdate(void)
{
}

/*
 *  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)
{
	memmove(&arrow, &fatarrow, sizeof(fatarrow));
	pixreverse(arrow.set, 2*16, 0);
	pixreverse(arrow.clr, 2*16, 0);
}
.
## diffname pc/screen.c 1997/1101
## diff -e /n/fornaxdump/1993/1113/sys/src/brazil/pc/screen.c /n/emeliedump/1997/1101/sys/src/brazil/pc/screen.c
303,308c
	scr->cur->load(scr, curs);
.
284,301c
	scr = &vgascreen[0];
	if(scr->cur == nil || scr->cur->load == nil)
		return;
.
282c
	VGAscr *scr;
.
280c
setcursor(Cursor* curs)
.
271,276d
269c
cursoroff(int)
.
265c
	VGAscr *scr;
	int v;

	scr = &vgascreen[0];
	if(scr->cur == nil || scr->cur->move == nil)
		return 0;

	if(dolock)
		lock(&cursor);
	v = scr->cur->move(scr, mousexy());
	if(dolock)
		unlock(&cursor);

	return v;
.
262,263c
int
cursoron(int dolock)
.
259c
	VGAscr *scr;
	ulong x;

	scr = &vgascreen[0];
	if(scr->gscreen == nil)
		return 0;

	switch(scr->gscreen->ldepth){
	default:
		x = 0x0F;
		break;
	case 3:
		x = 0xFF;
		break;
	}
	p &= x;
	p ^= x;

	lock(&cursor);
	scr->colormap[p][0] = r;
	scr->colormap[p][1] = g;
	scr->colormap[p][2] = b;
	vgao(PaddrW, p);
	vgao(Pdata, r>>(32-6));
	vgao(Pdata, g>>(32-6));
	vgao(Pdata, b>>(32-6));
	unlock(&cursor);

	return ~0;
.
256,257c
int
setcolor(ulong p, ulong r, ulong g, ulong b)
.
253c
	VGAscr *scr;
	ulong x;

	scr = &vgascreen[0];
	if(scr->gscreen == nil)
		return;

	switch(scr->gscreen->ldepth){
	default:
		x = 0x0F;
		break;
	case 3:
		x = 0xFF;
		break;
	}
	p &= x;
	p ^= x;

	lock(&cursor);
	*pr = scr->colormap[p][0];
	*pg = scr->colormap[p][1];
	*pb = scr->colormap[p][2];
	unlock(&cursor);
.
251c
getcolor(ulong p, ulong* pr, ulong* pg, ulong* pb)
.
239,247c
	VGAscr *scr;
	uchar *sp, *disp, *sdisp, *edisp;
	int y, len, incs, off, page;

	scr = &vgascreen[0];
	if(scr->gscreen == nil || scr->useflush == 0)
		return;
	if(scr->dev == nil || scr->dev->page == nil)
		return;

	if(rectclip(&r, scr->gscreen->r) == 0)
		return;

	incs = scr->gscreen->width * BY2WD;

	switch(scr->gscreen->ldepth){
	default:
		len = 0;
		panic("flushmemscreen: ldepth\n");
		break;
	case 3:
		len = Dx(r);
		break;
	}
	if(len < 1)
		return;

	off = r.min.y*scr->gscreen->width*BY2WD+(r.min.x>>(3-scr->gscreen->ldepth));
	page = off/scr->apsize;
	off %= scr->apsize;
	disp = KADDR(scr->aperture);
	sdisp = disp+off;
	edisp = disp+scr->apsize;

	off = r.min.y*scr->gscreen->width*BY2WD+(r.min.x>>(3-scr->gscreen->ldepth));
	sp = ((uchar*)scr->gscreendata->data) + off;

	scr->dev->page(scr, page);
	for(y = r.min.y; y < r.max.y; y++) {
		if(sdisp + incs < edisp) {
			memmove(sdisp, sp, len);
			sp += incs;
			sdisp += incs;
		}
		else {
			off = edisp - sdisp;
			page++;
			if(off <= len){
				if(off > 0)
					memmove(sdisp, sp, off);
				scr->dev->page(scr, page);
				if(len - off > 0)
					memmove(disp, sp+off, len - off);
			}
			else {
				memmove(sdisp, sp, len);
				scr->dev->page(scr, page);
			}
			sp += incs;
			sdisp += incs - scr->apsize;
		}
	}
.
237c
flushmemscreen(Rectangle r)
.
233,235d
229,230c
	VGAscr *scr;

	scr = &vgascreen[0];
	if(scr->gscreen == nil || scr->gscreendata == nil)
		return nil;

	*r = scr->gscreen->r;
	*ld = scr->gscreen->ldepth;
	*width = scr->gscreen->width;

	return scr->gscreendata->data;
.
226,227c
ulong*
attachscreen(Rectangle* r, int* ld, int* width)
.
223a
	else{
		aperture = upamalloc(0, size, align);
		if(aperture == 0)
			return 1;

		if(scr->aperture && scr->isupamem)
			upafree(scr->aperture, scr->apsize);
		scr->isupamem = 1;
	}

	scr->aperture = aperture;
	scr->apsize = size;

	return 0;
.
219,222c
	if(scr->dev && scr->dev->linear){
		aperture = scr->dev->linear(scr, &size, &align);
		if(aperture == 0)
			return 1;
.
203,217c
	scr = &vgascreen[0];

	if(size == 0){
		if(scr->aperture && scr->isupamem)
			upafree(scr->aperture, scr->apsize);
		scr->aperture = 0;
		scr->isupamem = 0;
		return 0;
.
199,201c
	VGAscr *scr;
	ulong aperture;
.
196,197c
int
screenaperture(int size, int align)
.
192,193c
		scr->aperture = 0xA0000;
		scr->apsize = 1<<16;
	}
	else
		gscreendata.data = KADDR(scr->aperture);

	gscreen.data = &gscreendata;
	gscreen.ldepth = z;
	gscreen.width = (x*(1<<gscreen.ldepth)+31)/32;
	gscreen.r.min = ZP;
	gscreen.r.max = Pt(x, y);
	gscreen.clipr = gscreen.r;
	gscreen.repl = 0;

	scr->gscreendata = gscreen.data;
	scr->memdefont = getmemdefont();
	scr->gscreen = &gscreen;

//	memset(gscreen.data->data, Backgnd, scr->apsize);

	drawcmap(0);

	return 0;
.
181,190c
		gscreendata.data = xalloc(width*BY2WD*y);
		if(gscreendata.data == 0)
			error("screensize: vga soft memory");
		memset(gscreendata.data, Backgnd, width*BY2WD*y);
		scr->useflush = 1;
.
178,179c
	if(scr->aperture == 0){
		int width = (x*(1<<z))/BI2WD;
.
176c
	 * BUG: need to check if any xalloc'ed memory needs to
	 * be given back if aperture is set.
.
169,173c
	scr = &vgascreen[0];
.
165,167c
	VGAscr *scr;
.
162,163c
int
screensize(int x, int y, int z)
.
158,160c
VGAscr vgascreen[1];
.
144,156c
Memdata gscreendata;
Memimage gscreen;
.
138,142c
Point ZP = {0, 0};
.
103,136c
Memimage *memones = &xones;
.
69,101c
static Memimage xones = {
	{ 0, 0, 1, 1 },
	{ -100000, -100000, 100000, 100000 },
	3,
	1,
	&onesdata,
	0,
	1
.
14,67c
static ulong onesbits = ~0;
static Memdata onesdata = {
	nil,
	&onesbits,
.
12d
9,10c
#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
.
6a
#include "ureg.h"
.
## diffname pc/screen.c 1998/0109
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/screen.c /n/emeliedump/1998/0109/sys/src/brazil/pc/screen.c
130a
	*softscreen = scr->useflush;
.
120c
attachscreen(Rectangle* r, int* ld, int* width, int *softscreen)
.
## diffname pc/screen.c 1998/0209
## diff -e /n/emeliedump/1998/0109/sys/src/brazil/pc/screen.c /n/emeliedump/1998/0209/sys/src/brazil/pc/screen.c
37a
Cursor	arrow = {
	{ -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, 
	},
};

.
## diffname pc/screen.c 1999/0119
## diff -e /n/emeliedump/1998/0209/sys/src/brazil/pc/screen.c /n/emeliedump/1999/0119/sys/src/brazil/pc/screen.c
12a
#include <cursor.h>
.
## diffname pc/screen.c 1999/1005
## diff -e /n/emeliedump/1999/0119/sys/src/brazil/pc/screen.c /n/emeliedump/1999/1005/sys/src/brazil/pc/screen.c
314a

static ulong
pixelbits(Memimage *i, Point pt)
{
	uchar *p;
	ulong val;
	int off, bpp, npack;

	val = 0;
	p = byteaddr(i, pt);
	switch(bpp=i->depth){
	case 1:
	case 2:
	case 4:
		npack = 8/bpp;
		off = pt.x%npack;
		val = p[0] >> bpp*(npack-1-off);
		val &= (1<<bpp)-1;
		break;
	case 8:
		val = p[0];
		break;
	case 16:
		val = p[0]|(p[1]<<8);
		break;
	case 24:
		val = p[0]|(p[1]<<8)|(p[2]<<16);
		break;
	case 32:
		val = p[0]|(p[1]<<8)|(p[2]<<16)|(p[3]<<24);
		break;
	}
	while(bpp<32){
		val |= val<<bpp;
		bpp *= 2;
	}
	return val;
}


static ulong
imgtorgba(Memimage *img, ulong val)
{
	uchar r, g, b, a;
	int nb, ov, v;
	ulong chan;
	uchar *p;

	a = 0xFF;
	r = g = b = 0xAA;	/* garbage */
	for(chan=img->chan; chan; chan>>=8){
		nb = NBITS(chan);
		ov = v = val&((1<<nb)-1);
		val >>= nb;

		while(nb < 8){
			v |= v<<nb;
			nb *= 2;
		}
		v >>= (nb-8);

		switch(TYPE(chan)){
		case CRed:
			r = v;
			break;
		case CGreen:
			g = v;
			break;
		case CBlue:
			b = v;
			break;
		case CAlpha:
			a = v;
			break;
		case CGrey:
			r = g = b = v;
			break;
		case CMap:
			p = img->cmap->cmap2rgb+3*ov;
			r = *p++;
			g = *p++;	
			b = *p;
			break;
		}
	}
	return (r<<24)|(g<<16)|(b<<8)|a;	
}

static ulong
rgbatoimg(Memimage *img, ulong rgba)
{
	ulong chan;
	int d, nb;
	ulong v;
	uchar *p, r, g, b, a, m;

	v = 0;
	r = rgba>>24;
	g = rgba>>16;
	b = rgba>>8;
	a = rgba;
	d = 0;
	for(chan=img->chan; chan; chan>>=8){
		nb = NBITS(chan);
		switch(TYPE(chan)){
		case CRed:
			v |= (r>>(8-nb))<<d;
			break;
		case CGreen:
			v |= (g>>(8-nb))<<d;
			break;
		case CBlue:
			v |= (b>>(8-nb))<<d;
			break;
		case CAlpha:
			v |= (a>>(8-nb))<<d;
			break;
		case CMap:
			p = img->cmap->rgb2cmap;
			m = p[(r>>4)*256+(g>>4)*16+(b>>4)];
			v |= m<<d;
			break;
		case CGrey:
			m = RGB2K(r,g,b);
			v |= m<<d;
			break;
		}
		d += nb;
	}
//	print("rgba2img %.8lux = %.*lux\n", rgba, 2*d/8, v);
	return v;
}

Memimage *lastbadi;
Memdata *lastbad;
Memimage *lastbadsrc, *lastbaddst;

#ifndef SDFSDF
int
hwdraw(Memdrawparam *par)
{
	VGAscr *scr;
	Memimage *dst, *src;

	dst = par->dst;
	scr = &vgascreen[0];
	if(dst == nil || dst->data == nil)
		return 0;

	if(dst->data->bdata != gscreendata.bdata)
		return 0;

//	if(dst->data != &gscreendata){
//		lastbad = dst->data;
//		lastbadi = dst;
//		return 0;
//	}

	if(scr->fill==nil && scr->scroll==nil)
		return 0;

	/*
	 * If we have an opaque mask and source is one opaque pixel we can convert to the
	 * destination format and just replicate with memset.
	 */
	if(scr->fill && (par->state&(Simplemask|Simplesrc|Fullmask))==(Simplemask|Simplesrc|Fullmask))
		return scr->fill(scr, par->r, par->sdval);

	/*
	 * If no source alpha, an opaque mask, we can just copy the
	 * source onto the destination.  If the channels are the same and
	 * the source is not replicated, memmove suffices.
	 */
	src = par->src;
	if(scr->scroll && src->data->bdata==dst->data->bdata && !(src->flags&Falpha)
	&& (par->state&(Simplemask|Fullmask))==(Simplemask|Fullmask)){
		if(src->zero != dst->zero){
			lastbadsrc = src;
			lastbaddst = dst;
			iprint("#");
		}
		return scr->scroll(scr, par->r, par->sr);
	}

	return 0;	
}
#endif
.
267,277c
	return setpalette(p, r, g, b);
.
262a
	default:
		return 0;
.
260c
	case 8:
.
256,257c
	switch(scr->gscreen->depth){
	case 1:
	case 2:
	case 4:
.
250c
	int x;
.
246a
setpalette(ulong p, ulong r, ulong g, ulong b)
{
	VGAscr *scr;
	int d;

	scr = &vgascreen[0];
	d = scr->palettedepth;

	lock(&cursor);
	scr->colormap[p][0] = r;
	scr->colormap[p][1] = g;
	scr->colormap[p][2] = b;
	vgao(PaddrW, p);
	vgao(Pdata, r>>(32-d));
	vgao(Pdata, g>>(32-d));
	vgao(Pdata, b>>(32-d));
	unlock(&cursor);

	return ~0;
}

/*
 * On some video cards (e.g. Mach64), the palette is used as the 
 * DAC registers for >8-bit modes.  We don't want to set them when the user
 * is trying to set a colormap and the card is in one of these modes.
 */
int
.
232c
	case 8:
.
228c
	switch(scr->gscreen->depth){
.
190a
	sp = scr->gscreendata->bdata + off;

.
188,189c
	off = r.min.y*scr->gscreen->width*BY2WD+(r.min.x*scr->gscreen->depth)/8;
.
181c
	off = r.min.y*scr->gscreen->width*BY2WD+(r.min.x*scr->gscreen->depth)/8;
.
174c
	case 8:
.
172c
		panic("flushmemscreen: depth\n");
.
169c
	switch(scr->gscreen->depth){
.
150a
/*
 * It would be fair to say that this doesn't work for >8-bit screens.
 */
.
148c
	return scr->gscreendata->bdata;
.
144c
	*chan = scr->gscreen->chan;
	*d = scr->gscreen->depth;
.
134,135c
uchar*
attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
.
117,118c
	}else{
.
94a
	physgscreenr = gscreen->r;

	drawcmap(1);
.
93c
	scr->palettedepth = 6;	/* default */
	scr->gscreendata = &gscreendata;
	scr->memdefont = getmemdefont();
	scr->gscreen = gscreen;
.
91c
/*	memset(gscreen->data->bdata, 0x15, (x*y*z+7)/8);	/* RSC BUG */
	memfillcolor(gscreen, DRed);
.
87,89c
	gscreen = allocmemimaged(Rect(0,0,x,y), chan, &gscreendata);
	vgaimageinit(chan);
	if(gscreen == nil)
		return -1;
.
79,85c
	if(gscreen)
		freememimage(gscreen);
.
77c
		gscreendata.bdata = KADDR(scr->aperture);
.
72d
70c
/*		memset(gscreendata.bdata, 0x72, width*BY2WD*y);	/* not really black */
.
67,68c
		gscreendata.bdata = xalloc(width*BY2WD*y);
		if(gscreendata.bdata == 0)
.
65c
		int width = (x*z)/BI2WD;
.
57a
	memimageinit();
.
54c
screensize(int x, int y, int z, ulong chan)
.
35c
Memimage *gscreen;
.
33a
Rectangle physgscreenr;

.
16,30c
#define RGB2K(r,g,b)	((156763*(r)+307758*(g)+59769*(b))>>19)
.
## diffname pc/screen.c 1999/1006
## diff -e /n/emeliedump/1999/1005/sys/src/brazil/pc/screen.c /n/emeliedump/1999/1006/sys/src/brazil/pc/screen.c
517d
474a
	if(hwaccel == 0)
		return 0;

.
468d
466a
int hwaccel = 1;
.
## diffname pc/screen.c 1999/1013
## diff -e /n/emeliedump/1999/1006/sys/src/brazil/pc/screen.c /n/emeliedump/1999/1013/sys/src/brazil/pc/screen.c
291d
85c
	drawcmap();
.
## diffname pc/screen.c 1999/1014
## diff -e /n/emeliedump/1999/1013/sys/src/brazil/pc/screen.c /n/emeliedump/1999/1014/sys/src/brazil/pc/screen.c
232d
## diffname pc/screen.c 1999/1127
## diff -e /n/emeliedump/1999/1014/sys/src/brazil/pc/screen.c /n/emeliedump/1999/1127/sys/src/9/pc/screen.c
508,512c
//		if(src->zero != dst->zero){
//			lastbadsrc = src;
//			lastbaddst = dst;
//			iprint("#");
//		}
.
494,495c
	 * If we have an opaque mask and source is one opaque
	 * pixel we can convert to the destination format and just
	 * replicate with memset.
.
## diffname pc/screen.c 2000/0326
## diff -e /n/emeliedump/1999/1127/sys/src/9/pc/screen.c /n/emeliedump/2000/0326/sys/src/9/pc/screen.c
517a
}

void
blankscreen(int blank)
{
	VGAscr *scr;

	scr = &vgascreen[0];
	if(hwblank && scr->blank)
		scr->blank(scr, blank);
.
465a
int hwblank = 1;
.
## diffname pc/screen.c 2000/0711
## diff -e /n/emeliedump/2000/0326/sys/src/9/pc/screen.c /n/emeliedump/2000/0711/sys/src/9/pc/screen.c
499c
	m = Simplesrc|Simplemask|Fullmask;
	if(scr->fill && (par->state&m)==m && ((par->srgba&0xFF) == 0xFF))
.
472a
	int m;
.
## diffname pc/screen.c 2001/0124
## diff -e /n/emeliedump/2000/0711/sys/src/9/pc/screen.c /n/emeliedump/2001/0124/sys/src/9/pc/screen.c
76c
//	memfillcolor(gscreen, DRed);
.
## diffname pc/screen.c 2001/0527
## diff -e /n/emeliedump/2001/0124/sys/src/9/pc/screen.c /n/emeliedump/2001/0527/sys/src/9/pc/screen.c
512,516d
486,491d
330,464d
76c
	memfillcolor(gscreen, DRed);
.
## diffname pc/screen.c 2001/0822
## diff -e /n/emeliedump/2001/0527/sys/src/9/pc/screen.c /n/emeliedump/2001/0822/sys/src/9/pc/screen.c
75,77d
## diffname pc/screen.c 2001/1014
## diff -e /n/emeliedump/2001/0822/sys/src/9/pc/screen.c /n/emeliedump/2001/1014/sys/src/9/pc/screen.c
73a

	gscreen->r.max.x = x;	/* we used round16(x) to allocate */
.
70c
	gscreen = allocmemimaged(Rect(0,0,round16(x),y), chan, &gscreendata);
.
54c
		int width = (round16(x)*z)/BI2WD;
.
15a
#define round16(x) (((x)+15)&~15)

.
## diffname pc/screen.c 2001/1015
## diff -e /n/emeliedump/2001/1014/sys/src/9/pc/screen.c /n/emeliedump/2001/1015/sys/src/9/pc/screen.c
332c
int hwblank = 0;	/* turned on by drivers that are known good */
int panning = 0;
.
134c
	*r = scr->gscreen->clipr;
.
77,78d
72c
	gscreen = allocmemimaged(Rect(0,0,x,y), chan, &gscreendata);
.
56c
		int width = (x*z)/BI2WD;
.
16,17d
## diffname pc/screen.c 2001/1130
## diff -e /n/emeliedump/2001/1015/sys/src/9/pc/screen.c /n/emeliedump/2001/1130/sys/src/9/pc/screen.c
381,382c
	if(hwblank){
		if(scr->blank)
			scr->blank(scr, blank);
		else
			vgablank(scr, blank);
	}
.
## diffname pc/screen.c 2002/0404
## diff -e /n/emeliedump/2001/1130/sys/src/9/pc/screen.c /n/emeliedump/2002/0404/sys/src/9/pc/screen.c
149a
	if(scr->dev && scr->dev->flush){
		scr->dev->flush(scr, r);
		return;
	}
.
74a
	if(scr->dev && scr->dev->flush)
		scr->useflush = 1;

.
## diffname pc/screen.c 2002/0919
## diff -e /n/emeliedump/2002/0404/sys/src/9/pc/screen.c /n/emeliedump/2002/0919/sys/src/9/pc/screen.c
394a

void
screensignal(int x)
{
	VGAscr *scr;

	scr = &vgascreen[0];
	if(scr->aperture == 0)
		return;

	memset(scr->aperture, x, 8*1024);
}
.
## diffname pc/screen.c 2002/0920
## diff -e /n/emeliedump/2002/0919/sys/src/9/pc/screen.c /n/emeliedump/2002/0920/sys/src/9/pc/screen.c
395,406d
## diffname pc/screen.c 2002/1201
## diff -e /n/emeliedump/2002/0920/sys/src/9/pc/screen.c /n/emeliedump/2002/1201/sys/src/9/pc/screen.c
387a
	scr->isblank = blank;
.
## diffname pc/screen.c 2002/1205
## diff -e /n/emeliedump/2002/1201/sys/src/9/pc/screen.c /n/emeliedump/2002/1205/sys/src/9/pc/screen.c
388d
377d
374,375c
	if(scr->scroll
	&& src->data->bdata==dst->data->bdata
	&& !(src->flags&Falpha)
	&& (par->state&m)==m
	&& (par->op&S) == S)
.
372a
	m = Simplemask|Fullmask;
.
365c
	if(scr->fill
	&& (par->state&m)==m
	&& ((par->srgba&0xFF) == 0xFF)
	&& (par->op&S) == S)
.
61c
		scr->aperture = VGAMEM();
.

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.