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

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


## diffname bitsy/screen.c 2000/0902
## diff -e /dev/null /n/emeliedump/2000/0902/sys/src/9/bitsy/screen.c
0a
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "ureg.h"
#include "../port/error.h"

#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
#include <cursor.h>
#include "screen.h"

void
flushmemscreen(Rectangle)
{
}

uchar*
attachscreen(Rectangle*, ulong*, int*, int*, int*)
{
	return nil;
}

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

int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
	USED(p,r,g,b);
	return 0;
}

void
blankscreen(int blank)
{
	USED(blank);
}
.
## diffname bitsy/screen.c 2000/1015
## diff -e /n/emeliedump/2000/0902/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1015/sys/src/9/bitsy/screen.c
44a

void
screenputs(char *s, int n)
{
	USED(s, n);
}
.
## diffname bitsy/screen.c 2000/1017
## diff -e /n/emeliedump/2000/1015/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1017/sys/src/9/bitsy/screen.c
24c
	*r = gscreen->r;
	*d = gscreen->depth;
	*chan = gscreen->chan;
	*width = gscreen->width;
	*softscreen = 0;

	return (uchar*)gscreen->data;
.
22c
attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
.
20a
/* 
 * export screen to devdraw
 */
.
16a
screeninit(void)
{
	framebuf = xspanalloc(sizeof *framebuf, 0x10, 0);
	memset(framebuf->palette, 0, sizeof framebuf->palette);
	framebuf->palette[0] = Pal0;

	lcdinit();

	gscreen = &xgscreen;
	gscreen->data = (struct Memdata *)framebuf->pixel;
}

void
.
15a
enum {
	Wid		= 320,
	Ht		= 240,
	Pal0	= 0x2000,	/* 16-bit pixel data in active mode (12 in passive) */

	hsw		= 0x4,
	elw		= 0x11,
	blw		= 0xc,

	vsw		= 0x3,
	efw		= 0x1,
	bfw		= 0xa,

	pcd		= 0x10,
};

struct sa1110fb {
	/* Frame buffer for 16-bit active color */
	short	palette[16];		/* entry 0 set to Pal0, the rest to 0 */
	ushort	pixel[Wid*Ht];		/* Pixel data */
} *framebuf;

enum {
/* LCD Control Register 0, lcd->lccr0 */
	LEN	=  0,	/*  1 bit */
	CMS	=  1,	/*  1 bit */
	SDS	=  2,	/*  1 bit */
	LDM	=  3,	/*  1 bit */
	BAM	=  4,	/*  1 bit */
	ERM	=  5,	/*  1 bit */
	PAS	=  7,	/*  1 bit */
	BLE	=  8,	/*  1 bit */
	DPD	=  9,	/*  1 bit */
	PDD	= 12,	/*  8 bits */
};

enum {
/* LCD Control Register 1, lcd->lccr1 */
	PPL	=  0,	/* 10 bits */
	HSW	= 10,	/*  6 bits */
	ELW	= 16,	/*  8 bits */
	BLW	= 24,	/*  8 bits */
};

enum {
/* LCD Control Register 2, lcd->lccr2 */
	LPP	=  0,	/* 10 bits */
	VSW	= 10,	/*  6 bits */
	EFW	= 16,	/*  8 bits */
	BFW	= 24,	/*  8 bits */
};

enum {
/* LCD Control Register 3, lcd->lccr3 */
	PCD	=  0,	/*  8 bits */
	ACB	=  8,	/*  8 bits */
	API	= 16,	/*  4 bits */
	VSP	= 20,	/*  1 bit */
	HSP	= 21,	/*  1 bit */
	PCP	= 22,	/*  1 bit */
	OEP	= 23,	/*  1 bit */
};

enum {
/* LCD Status Register, lcd->lcsr */
	LFD	=  0,	/*  1 bit */
	BAU	=  1,	/*  1 bit */
	BER	=  2,	/*  1 bit */
	ABC	=  3,	/*  1 bit */
	IOL	=  4,	/*  1 bit */
	IUL	=  5,	/*  1 bit */
	OIU	=  6,	/*  1 bit */
	IUU	=  7,	/*  1 bit */
	OOL	=  8,	/*  1 bit */
	OUL	=  9,	/*  1 bit */
	OOU	= 10,	/*  1 bit */
	OUU	= 11,	/*  1 bit */
};

struct sa1110regs {
	ulong	lccr0;	/* 0xb0100000 */
	ulong	lcsr;	/* 0xb0100004 */
	ulong	dummies[2];	/* unused  0xb0100008 and 0xb010000c */
	short*	dbar1;	/* 0xb0100010 */
	ulong	dcar1;	/* 0xb0100014 */
	ulong	dbar2;	/* 0xb0100018 */
	ulong	dcar2;	/* 0xb010001c */
	ulong	lccr1;	/* 0xb0100020 */
	ulong	lccr2;	/* 0xb0100024 */
	ulong	lccr3;	/* 0xb0100028 */
} *lcd;

Point	ZP = {0, 0};

static Memimage xgscreen =
{
	{ 0, 0, Wid, Ht },	/* r */
	{ 0, 0, Wid, Ht },	/* clipr */
	16,					/* depth */
	1,					/* nchan */
	RGB16,				/* chan */
	nil,				/* cmap */
	nil,				/* data */
	0,					/* zero */
	Wid/2,				/* width */
	0,					/* layer */
	Frepl,				/* flags */
};

Memimage *gscreen;
Memimage *conscol;
Memimage *back;
Memimage *hwcursor;

static void
lcdinit(void)
{
	lcd = (struct sa1110regs*)0xb0100000;

	lcd->dbar1 = framebuf->palette;
	lcd->lccr3 = (pcd << PCD) | (0 << ACB) | (0 << API) | (1 << VSP) | (1 << HSP);
	lcd->lccr2 = ((Ht-1) << LPP) | (vsw << VSW) | (efw << EFW) | (bfw << BFW);
	lcd->lccr1 = (Wid << PPL) | (hsw << HSW) | (elw << ELW) | (blw << BLW);
	lcd->lccr0 = 1<<LEN | 1 << CMS | 0<<SDS | 1<<LDM | 1<<BAM | 1<<ERM | 1<<PAS | 0<<BLE | 0<<PDD;

}

.
## diffname bitsy/screen.c 2000/1018
## diff -e /n/emeliedump/2000/1017/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1018/sys/src/9/bitsy/screen.c
150a
	print("LCD status after lcdinit: 0x%lux\n", lcd->lcsr);
.
149a
	print("LCD status before power up: 0x%lux\n", lcd->lcsr);
	lcdpower(1);
	print("LCD status after power up: 0x%lux\n", lcd->lcsr);
.
147a
	memset(framebuf->pixel, 0xf8, sizeof framebuf->pixel);
.
136,139c
	lcd->lccr3 = pcd<<PCD | 0<<ACB | 0<<API | 1<<VSP | 1<<HSP | 0<<PCP | 0<<OEP;
	lcd->lccr2 = (Ht-1)<<LPP | vsw<<VSW | efw<<EFW | bfw<<BFW;
	lcd->lccr1 = (Wid-16)<<PPL | hsw<<HSW | elw<<ELW | blw<<BLW;
	lcd->lccr0 = 1<<LEN | 0<<CMS | 0<<SDS | 1<<LDM | 1<<BAM | 1<<ERM | 1<<PAS | 0<<BLE | 0<<DPD | 0<<PDD;
.
134a
	/* the following works because main memory is direct mapped */
	lcd->lccr0 &= ~(0<<LEN);	/* disable the LCD */
	while((lcd->lcsr & LDD) == 0)
		sleep(1);

.
133c
	/* map the lcd regs into the kernel's virtual space */
	lcd = (struct sa1110regs*)mapspecial(LCDREGS, sizeof(struct sa1110regs));;
.
130a
lcdstop(void) {
	ulong	lccr0;

	lcd->lccr0 &= ~(0<<LEN);	/* disable the LCD */
	while((lcd->lcsr & LDD) == 0)
		sleep(1);
	lcdpower(0);
}

static void
.
96,105c
	ulong	lccr0;
	ulong	lcsr;
	ulong	dummies[2];
	short*	dbar1;
	ulong	dcar1;
	ulong	dbar2;
	ulong	dcar2;
	ulong	lccr1;
	ulong	lccr2;
	ulong	lccr3;
.
25,27c
	vsw		= 0x03,
	efw		= 0x01,
	bfw		= 0x0a,
.
23c
	blw		= 0x0c,
.
21c
	hsw		= 0x04,
.
## diffname bitsy/screen.c 2000/1019
## diff -e /n/emeliedump/2000/1018/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1019/sys/src/9/bitsy/screen.c
219c
	int i;
	Rune r;
	char buf[4];

	if(!islo()) {
		/* don't deadlock trying to print in interrupt */
		if(!canlock(&screenlock))
			return;	
	}
	else
		lock(&screenlock);

	while(n > 0){
		i = chartorune(&r, s);
		if(i == 0){
			s++;
			--n;
			continue;
		}
		memmove(buf, s, i);
		buf[i] = 0;
		n -= i;
		s += i;
		screenputc(buf);
	}
	unlock(&screenlock);
}

static void
screenwin(void)
{
	Point p, q;
	char *greet;
	Memimage *grey;

	memsetchan(gscreen, RGB16);

	back = memwhite;
	conscol = memblack;

	memfillcolor(gscreen, 0x444488FF);

	w = memdefont->info[' '].width;
	h = memdefont->height;

	window.min = Pt(8, 8);
	window.max = addpt(window.min, Pt(8+w*32, 8+h*14));

	memimagedraw(gscreen, window, memblack, ZP, memopaque, ZP);
	window = insetrect(window, 4);
	memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP);

	/* a lot of work to get a grey color */
	grey = allocmemimage(Rect(0,0,1,1), RGB16);
	grey->flags |= Frepl;
	grey->clipr = gscreen->r;
	grey->data->bdata[0] = 0x77;
	grey->data->bdata[1] = 0x77;
	memimagedraw(gscreen, Rect(window.min.x, window.min.y,
			window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP);
	freememimage(grey);
	window = insetrect(window, 5);

	greet = " Plan 9 Console ";
	p = addpt(window.min, Pt(10, 0));
	q = memsubfontwidth(memdefont, greet);
	memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
	window.min.y += h+6;
	curpos = window.min;
	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
}

static void
screenputc(char *buf)
{
	Point p;
	int w, pos;
	Rectangle r;
	static int *xp;
	static int xbuf[256];

	if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
		xp = xbuf;

	switch(buf[0]) {
	case '\n':
		if(curpos.y+h >= window.max.y)
			scroll();
		curpos.y += h;
		screenputc("\r");
		break;
	case '\r':
		xp = xbuf;
		curpos.x = window.min.x;
		break;
	case '\t':
		p = memsubfontwidth(memdefont, " ");
		w = p.x;
		*xp++ = curpos.x;
		pos = (curpos.x-window.min.x)/w;
		pos = 8-(pos%8);
		r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		curpos.x += pos*w;
		break;
	case '\b':
		if(xp <= xbuf)
			break;
		xp--;
		r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		curpos.x = *xp;
		break;
	default:
		p = memsubfontwidth(memdefont, buf);
		w = p.x;

		if(curpos.x >= window.max.x-w)
			screenputc("\n");

		*xp++ = curpos.x;
		r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
		curpos.x += w;
	}
}

static void
scroll(void)
{
	int o;
	Point p;
	Rectangle r;

	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(gscreen, r, gscreen, p, nil, p);
	r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
	memimagedraw(gscreen, r, back, ZP, nil, ZP);

	curpos.y -= o;
.
179a
	/* no-op, screen is direct mapped */
.
174c
	xgdata.bdata = (uchar *)framebuf->pixel;

	memimageinit();
	memdefont = getmemdefont();

	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = memdefont->info[' '].width;

	screenwin();
.
171d
169c

.
167c
	iprint("LCD power up\n");
.
163,164c
	/* the following works because main memory is direct mapped */

.
161a

	/* map the lcd regs into the kernel's virtual space */
	lcd = (struct sa1110regs*)mapspecial(LCDREGS, sizeof(struct sa1110regs));;

.
143,150d
136c
		delay(10);
.
132,133d
129a
Memsubfont	*memdefont;

struct{
	Point	pos;
	int	bwid;
}out;

Lock	screenlock;

Point	ZP = {0, 0};

static Rectangle window;
static Point curpos;
static int h, w;
int drawdebug;

static	ulong	rep(ulong, int);
static	void	screenwin(void);
static	void	screenputc(char *buf);
static	void	scroll(void);

.
128d
118c
	&xgdata,			/* data */
.
109a
static Memdata xgdata =
{
	nil,				/* *base */
	nil,				/* *bdata */
	1,					/* ref */
	nil,				/* *imref */
	0,					/* allocd */
};

.
81c
	LDD	=  0,	/*  1 bit */
.
15a
#define	MINX	8

.
## diffname bitsy/screen.c 2000/1020
## diff -e /n/emeliedump/2000/1019/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1020/sys/src/9/bitsy/screen.c
305,310d
298,299c
	window.min = Pt(4, 4);
	window.max = addpt(window.min, Pt(4+w*33, 4+h*15));
.
293c
	/* a lot of work to get a grey color */
	grey = allocmemimage(Rect(0,0,1,1), RGB16);
	grey->flags |= Frepl;
	grey->clipr = gscreen->r;
	grey->data->bdata[0] = 0x77;
	grey->data->bdata[1] = 0x77;
.
199a
	i = 0;
	while (i < Wid*Ht*1/3)	framebuf->pixel[i++] = 0xf800;	/* red */
	while (i < Wid*Ht*2/3)	framebuf->pixel[i++] = 0xffff;	/* white */
	while (i < Wid*Ht*3/3)	framebuf->pixel[i++] = 0x001f;	/* blue */

.
182a
	int i;
.
## diffname bitsy/screen.c 2000/1021
## diff -e /n/emeliedump/2000/1020/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1021/sys/src/9/bitsy/screen.c
337a
return;
.
195d
193d
188c
	framebuf = xspanalloc(sizeof *framebuf, 0x20, 0);
.
177d
133c
	0,					/* flags */
.
126c
	3,					/* nchan */
.
## diffname bitsy/screen.c 2000/1024
## diff -e /n/emeliedump/2000/1021/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1024/sys/src/9/bitsy/screen.c
335d
231c
	return (uchar*)gscreen->data->bdata;
.
## diffname bitsy/screen.c 2000/1026
## diff -e /n/emeliedump/2000/1024/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1026/sys/src/9/bitsy/screen.c
300,301c
	grey->data->bdata[0] = 0x40;
	grey->data->bdata[1] = 0xfd;
.
## diffname bitsy/screen.c 2000/1101
## diff -e /n/emeliedump/2000/1026/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1101/sys/src/9/bitsy/screen.c
314,315c
			window.max.x, window.min.y+h+5+6), orange, ZP, nil, ZP);
	freememimage(orange);
.
307c
	window.max = addpt(window.min, Pt(4+w*33, 4+h*12));
.
296,301c
	/* a lot of work to get a orange color */
	orange = allocmemimage(Rect(0,0,1,1), RGB16);
	orange->flags |= Frepl;
	orange->clipr = gscreen->r;
	orange->data->bdata[0] = 0x40;
	orange->data->bdata[1] = 0xfd;
.
289c
	Memimage *orange;
.
## diffname bitsy/screen.c 2000/1102
## diff -e /n/emeliedump/2000/1101/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1102/sys/src/9/bitsy/screen.c
366a
		break;
	case '\0':
.
355c
		pos = 4-(pos%4);
		*xp++ = curpos.x;
.
353c
		if(curpos.x >= window.max.x-4*w)
			screenputc("\n");

.
306,307c
	window = Rect(4, 4, 320-4, 240-60);
.
183a
iprint("%lux %lux\n", (ulong)framebuf, (ulong)framebuf->pixel);

.
## diffname bitsy/screen.c 2000/1103
## diff -e /n/emeliedump/2000/1102/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1103/sys/src/9/bitsy/screen.c
203a
	for(i = 0; i < Wid*Ht; i += Wid)
		framebuf->pixel[i] = 0xffff;	/* white */
	for(i = Wid-1; i < Wid*Ht; i += Wid)
		framebuf->pixel[i] = 0x001f;	/* blue */
.
198a
	xgdata.ref = 1;
.
191a
iprint("framebuf %lux\n", framebuf);

.
189c
	framebuf = xspanalloc(sizeof *framebuf, 0x100, 0);
.
184,185d
179a
lcdtweak(Cmdbuf *cmd)
{
	if(cmd->nf < 4)
		return;
	if(*cmd->f[0] == 'h')
		lcd->lccr1 = ((Wid-16)<<PPL)
			| (atoi(cmd->f[1])<<HSW)
			| (atoi(cmd->f[2])<<ELW)
			| (atoi(cmd->f[3])<<BLW);
	if(*cmd->f[0] == 'v')
		lcd->lccr2 = ((Ht-1)<<LPP)
			| (atoi(cmd->f[1])<<VSW)
			| (atoi(cmd->f[2])<<EFW)
			| (atoi(cmd->f[3])<<BFW);
}

void
.
112,119c
static Memdata xgdata;
.
27c
	vsw		= 0x02,
.
23,25c
	hsw		= 0x00,
	elw		= 0x0e,
	blw		= 0x0d,
.
21c
	Pal0		= 0x2000,	/* 16-bit pixel data in active mode (12 in passive) */
.
## diffname bitsy/screen.c 2000/1104
## diff -e /n/emeliedump/2000/1103/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1104/sys/src/9/bitsy/screen.c
416a
	flushmemscreen(r);
.
414a
	flushmemscreen(r);
.
399a
		flushmemscreen(r);
.
384a
		flushmemscreen(r);
.
376a
		flushmemscreen(r);
.
337a
	flushmemscreen(r);
.
325,326c
	memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP);
	window = insetrect(r, 4);
.
323c
	r = Rect(4, 4, Wid-4, Ht-60);
.
306a
	Rectangle r;
.
248c
	return (uchar*)vscreen;
.
246c
	*softscreen = 1;
.
236c
/*
.
233c
	int x, y;

	for (x = r.min.x; x < r.max.x; x++)
		for (y = r.min.y; y < r.max.y; y++)
			framebuf->pixel[(x+1)*Ht-y-1] = vscreen[y*Wid+x];
	cachewb();
.
231c
flushmemscreen(Rectangle r)
.
219a
	flushmemscreen(gscreen->r);

.
212,218c
	while (i < Wid*Ht*1/3)	vscreen[i++] = 0xf800;	/* red */
	while (i < Wid*Ht*2/3)	vscreen[i++] = 0xffff;	/* white */
	while (i < Wid*Ht*3/3)	vscreen[i++] = 0x001f;	/* blue */
.
208c
	xgdata.bdata = (uchar *)vscreen;
.
200c
	vscreen = xalloc(sizeof(ushort)*Wid*Ht);
.
167,168c
	lcd->lccr2 = (Wid-1)<<LPP | vsw<<VSW | efw<<EFW | bfw<<BFW;
	lcd->lccr1 = (Ht-16)<<PPL | hsw<<HSW | elw<<ELW | blw<<BLW;
.
148a
Point		ZP = {0, 0};
ushort		*vscreen;	/* virtual screen */
Rectangle	window;
Point		curpos;
int			h, w;
int			drawdebug;

.
144,147c
Lock		screenlock;
.
142c
Memsubfont	*memdefont;
.
140c
Memimage *gscreen;
Memimage *conscol;
Memimage *back;
.
129,134d
19,21c
	Wid		= 240,
	Ht		= 320,
	Pal0	= 0x2000,	/* 16-bit pixel data in active mode (12 in passive) */
.
## diffname bitsy/screen.c 2000/1105
## diff -e /n/emeliedump/2000/1104/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1105/sys/src/9/bitsy/screen.c
327c
	r = insetrect(gscreen->r, 4);
	r.max.y -= 56;
.
251c
	return (uchar*)gscreen->data->bdata;
.
249c
	*softscreen = landscape == 0;
.
233,235c
	if (landscape == 0)
		for (x = r.min.x; x < r.max.x; x++)
			for (y = r.min.y; y < r.max.y; y++)
				framebuf->pixel[(x+1)*Ht-y-1] = vscreen[y*Wid+x];
.
212,217c
	if (landscape) {
		xgdata.bdata = (uchar *)framebuf->pixel;
		while (i < Wid*Ht*1/3)	framebuf->pixel[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	framebuf->pixel[i++] = 0xffff;	/* white */
		while (i < Wid*Ht*3/3)	framebuf->pixel[i++] = 0x001f;	/* blue */
	} else {
		xgdata.bdata = (uchar *)vscreen;
		while (i < Wid*Ht*1/3)	vscreen[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	vscreen[i++] = 0xffff;	/* white */
		while (i < Wid*Ht*3/3)	vscreen[i++] = 0x001f;	/* blue */
		flushmemscreen(gscreen->r);
	}
.
210d
208d
183c
		lcd->lccr2 = ((Wid-1)<<LPP)
.
178c
		lcd->lccr1 = ((Ht-16)<<PPL)
.
172a
flipscreen(int ls) {
	if (ls == landscape)
		return;
	if (ls) {
		gscreen->r = Rect(0, 0, Ht, Wid);
		gscreen->clipr = gscreen->r;
		xgdata.bdata = (uchar *)framebuf->pixel;
	} else {
		gscreen->r = Rect(0, 0, Wid, Ht);
		gscreen->clipr = gscreen->r;
		xgdata.bdata = (uchar *)vscreen;
	}
	landscape = ls;
}

void
.
17a
int landscape;	/* orientation of the screen, default is 0: portait */

.
## diffname bitsy/screen.c 2000/1106
## diff -e /n/emeliedump/2000/1105/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1106/sys/src/9/bitsy/screen.c
340d
272c
	*softscreen = (landscape == 0);
.
258,259c
				framebuf->pixel[(x+1)*Ht-1-y] = vscreen[y*Wid+x];
		start = (ulong)&framebuf->pixel[(r.min.x+1)*Ht-1-(r.max.y-1)];
		end = (ulong)&framebuf->pixel[(r.max.x-1+1)*Ht-1-(r.min.y)];
	} else {
		start = (ulong)&framebuf->pixel[r.min.y*Ht + r.min.x];
		end = (ulong)&framebuf->pixel[(r.max.y-1)*Ht + r.max.x - 1];
	}
	cachewbregion(start, end-start);
.
255c
	if (landscape == 0) {
		if (r.min.x <   0) r.min.x = 0;
		if (r.max.x > Wid) r.max.x = Wid;
		if (r.min.y <   0) r.min.y = 0;
		if (r.max.y >  Ht) r.max.y = Ht;
.
253a
	ulong start, end;
.
216d
166a
	/* the following line works because main memory is direct mapped */
.
18c
int landscape = 0;	/* orientation of the screen, default is 0: portait */
.
## diffname bitsy/screen.c 2000/1130
## diff -e /n/emeliedump/2000/1106/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1130/sys/src/9/bitsy/screen.c
304c
	if (blank) {
		lcdpower(0);
	} else {
		lcdpower(1);
		lcdinit();
	}
.
246a
	blanktime = 3;	/* minutes */

.
## diffname bitsy/screen.c 2000/1207
## diff -e /n/emeliedump/2000/1130/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1207/sys/src/9/bitsy/screen.c
265c
				framebuf->pixel[(x+1)*Ht-1-y] = gamma[vscreen[y*Wid+x]];
.
14a
#include "gamma.h"
.
## diffname bitsy/screen.c 2000/1214
## diff -e /n/emeliedump/2000/1207/sys/src/9/bitsy/screen.c /n/emeliedump/2000/1214/sys/src/9/bitsy/screen.c
369d
## diffname bitsy/screen.c 2001/0529
## diff -e /n/emeliedump/2000/1214/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0529/sys/src/9/bitsy/screen.c
315,316c
static void
bitsyscreenputs(char *s, int n)
.
250a
	screenputs = bitsyscreenputs;
.
154a
static	void	bitsyscreenputs(char *s, int n);
.
## diffname bitsy/screen.c 2001/0618
## diff -e /n/emeliedump/2001/0529/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0618/sys/src/9/bitsy/screen.c
207a
}

void
screenpower(int on)
{
	if (on == 0){
		memmove(savedpalette, framebuf->palette, sizeof framebuf->palette);
		blankscreen(1);
	} else {
		memmove(framebuf->palette, savedpalette, sizeof framebuf->palette);
		blankscreen(0);
	}
.
42a
short savedpalette[16];	/* saved during suspend mode */

.
## diffname bitsy/screen.c 2001/0621
## diff -e /n/emeliedump/2001/0618/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0621/sys/src/9/bitsy/screen.c
154,486c
static	ulong	rep(u
.
## diffname bitsy/screen.c 2001/0622
## diff -e /n/emeliedump/2001/0621/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0622/sys/src/9/bitsy/screen.c
154c
static	ulong	rep(ulong, int);
static	void	screenwin(void);
static	void	screenputc(char *buf);
static	void	bitsyscreenputs(char *s, int n);
static	void	scroll(void);

static void
lcdstop(void) {
	lcd->lccr0 &= ~(0<<LEN);	/* disable the LCD */
	while((lcd->lcsr & LDD) == 0)
		delay(10);
	lcdpower(0);
}

static void
lcdinit(void)
{
	/* the following line works because main memory is direct mapped */
	lcd->dbar1 = framebuf->palette;
	lcd->lccr3 = pcd<<PCD | 0<<ACB | 0<<API | 1<<VSP | 1<<HSP | 0<<PCP | 0<<OEP;
	lcd->lccr2 = (Wid-1)<<LPP | vsw<<VSW | efw<<EFW | bfw<<BFW;
	lcd->lccr1 = (Ht-16)<<PPL | hsw<<HSW | elw<<ELW | blw<<BLW;
	lcd->lccr0 = 1<<LEN | 0<<CMS | 0<<SDS | 1<<LDM | 1<<BAM | 1<<ERM | 1<<PAS | 0<<BLE | 0<<DPD | 0<<PDD;
}

void
flipscreen(int ls) {
	if (ls == landscape)
		return;
	if (ls) {
		gscreen->r = Rect(0, 0, Ht, Wid);
		gscreen->clipr = gscreen->r;
		xgdata.bdata = (uchar *)framebuf->pixel;
	} else {
		gscreen->r = Rect(0, 0, Wid, Ht);
		gscreen->clipr = gscreen->r;
		xgdata.bdata = (uchar *)vscreen;
	}
	landscape = ls;
}

void
lcdtweak(Cmdbuf *cmd)
{
	if(cmd->nf < 4)
		return;
	if(*cmd->f[0] == 'h')
		lcd->lccr1 = ((Ht-16)<<PPL)
			| (atoi(cmd->f[1])<<HSW)
			| (atoi(cmd->f[2])<<ELW)
			| (atoi(cmd->f[3])<<BLW);
	if(*cmd->f[0] == 'v')
		lcd->lccr2 = ((Wid-1)<<LPP)
			| (atoi(cmd->f[1])<<VSW)
			| (atoi(cmd->f[2])<<EFW)
			| (atoi(cmd->f[3])<<BFW);
}

void
screenpower(int on)
{
	if (on == 0){
		memmove(savedpalette, framebuf->palette, sizeof framebuf->palette);
		blankscreen(1);
	} else {
		memmove(framebuf->palette, savedpalette, sizeof framebuf->palette);
		blankscreen(0);
	}
}

void
screeninit(void)
{
	int i;

	/* map the lcd regs into the kernel's virtual space */
	lcd = (struct sa1110regs*)mapspecial(LCDREGS, sizeof(struct sa1110regs));;

	framebuf = xspanalloc(sizeof *framebuf, 0x100, 0);

	vscreen = xalloc(sizeof(ushort)*Wid*Ht);

	framebuf->palette[0] = Pal0;

	lcdpower(1);
	lcdinit();

	gscreen = &xgscreen;
	xgdata.ref = 1;
	i = 0;
	if (landscape) {
		xgdata.bdata = (uchar *)framebuf->pixel;
		while (i < Wid*Ht*1/3)	framebuf->pixel[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	framebuf->pixel[i++] = 0xffff;	/* white */
		while (i < Wid*Ht*3/3)	framebuf->pixel[i++] = 0x001f;	/* blue */
	} else {
		xgdata.bdata = (uchar *)vscreen;
		while (i < Wid*Ht*1/3)	vscreen[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	vscreen[i++] = 0xffff;	/* white */
		while (i < Wid*Ht*3/3)	vscreen[i++] = 0x001f;	/* blue */
		flushmemscreen(gscreen->r);
	}
	memimageinit();
	memdefont = getmemdefont();

	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = memdefont->info[' '].width;

	blanktime = 3;	/* minutes */

	screenwin();
	screenputs = bitsyscreenputs;
}

void
flushmemscreen(Rectangle r)
{
	int x, y;
	ulong start, end;

	if (landscape == 0) {
		if (r.min.x <   0) r.min.x = 0;
		if (r.max.x > Wid) r.max.x = Wid;
		if (r.min.y <   0) r.min.y = 0;
		if (r.max.y >  Ht) r.max.y = Ht;
		for (x = r.min.x; x < r.max.x; x++)
			for (y = r.min.y; y < r.max.y; y++)
				framebuf->pixel[(x+1)*Ht-1-y] = gamma[vscreen[y*Wid+x]];
		start = (ulong)&framebuf->pixel[(r.min.x+1)*Ht-1-(r.max.y-1)];
		end = (ulong)&framebuf->pixel[(r.max.x-1+1)*Ht-1-(r.min.y)];
	} else {
		start = (ulong)&framebuf->pixel[r.min.y*Ht + r.min.x];
		end = (ulong)&framebuf->pixel[(r.max.y-1)*Ht + r.max.x - 1];
	}
	cachewbregion(start, end-start);
}

/*
 * export screen to devdraw
 */
uchar*
attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
{
	*r = gscreen->r;
	*d = gscreen->depth;
	*chan = gscreen->chan;
	*width = gscreen->width;
	*softscreen = (landscape == 0);

	return (uchar*)gscreen->data->bdata;
}

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

int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
	USED(p,r,g,b);
	return 0;
}

void
blankscreen(int blank)
{
	if (blank) {
		lcdpower(0);
	} else {
		lcdpower(1);
		lcdinit();
	}
}

static void
bitsyscreenputs(char *s, int n)
{
	int i;
	Rune r;
	char buf[4];

	if(!islo()) {
		/* don't deadlock trying to print in interrupt */
		if(!canlock(&screenlock))
			return;	
	}
	else
		lock(&screenlock);

	while(n > 0){
		i = chartorune(&r, s);
		if(i == 0){
			s++;
			--n;
			continue;
		}
		memmove(buf, s, i);
		buf[i] = 0;
		n -= i;
		s += i;
		screenputc(buf);
	}
	unlock(&screenlock);
}

static void
screenwin(void)
{
	Point p, q;
	char *greet;
	Memimage *orange;
	Rectangle r;

	memsetchan(gscreen, RGB16);

	back = memwhite;
	conscol = memblack;

	orange = allocmemimage(Rect(0,0,1,1), RGB16);
	orange->flags |= Frepl;
	orange->clipr = gscreen->r;
	orange->data->bdata[0] = 0x40;
	orange->data->bdata[1] = 0xfd;

	w = memdefont->info[' '].width;
	h = memdefont->height;

	r = insetrect(gscreen->r, 4);

	memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP);
	window = insetrect(r, 4);
	memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP);

	memimagedraw(gscreen, Rect(window.min.x, window.min.y,
			window.max.x, window.min.y+h+5+6), orange, ZP, nil, ZP);
	freememimage(orange);
	window = insetrect(window, 5);

	greet = " Plan 9 Console ";
	p = addpt(window.min, Pt(10, 0));
	q = memsubfontwidth(memdefont, greet);
	memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
	flushmemscreen(r);
	window.min.y += h+6;
	curpos = window.min;
	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
}

static void
screenputc(char *buf)
{
	Point p;
	int w, pos;
	Rectangle r;
	static int *xp;
	static int xbuf[256];

	if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
		xp = xbuf;

	switch(buf[0]) {
	case '\n':
		if(curpos.y+h >= window.max.y)
			scroll();
		curpos.y += h;
		screenputc("\r");
		break;
	case '\r':
		xp = xbuf;
		curpos.x = window.min.x;
		break;
	case '\t':
		p = memsubfontwidth(memdefont, " ");
		w = p.x;
		if(curpos.x >= window.max.x-4*w)
			screenputc("\n");

		pos = (curpos.x-window.min.x)/w;
		pos = 4-(pos%4);
		*xp++ = curpos.x;
		r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		flushmemscreen(r);
		curpos.x += pos*w;
		break;
	case '\b':
		if(xp <= xbuf)
			break;
		xp--;
		r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		flushmemscreen(r);
		curpos.x = *xp;
		break;
	case '\0':
		break;
	default:
		p = memsubfontwidth(memdefont, buf);
		w = p.x;

		if(curpos.x >= window.max.x-w)
			screenputc("\n");

		*xp++ = curpos.x;
		r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min);
		memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
		flushmemscreen(r);
		curpos.x += w;
	}
}

static void
scroll(void)
{
	int o;
	Point p;
	Rectangle r;

	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(gscreen, r, gscreen, p, nil, p);
	flushmemscreen(r);
	r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
	memimagedraw(gscreen, r, back, ZP, nil, ZP);
	flushmemscreen(r);

	curpos.y -= o;
}
.
## diffname bitsy/screen.c 2001/0808
## diff -e /n/emeliedump/2001/0622/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0808/sys/src/9/bitsy/screen.c
215,221c
	blankscreen(on == 0);
.
## diffname bitsy/screen.c 2001/0809
## diff -e /n/emeliedump/2001/0808/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0809/sys/src/9/bitsy/screen.c
317a
		lcd->lccr0 &= ~(0<<LEN);	/* disable the LCD */
		delay(100);
.
161,168d
43,44d
## diffname bitsy/screen.c 2001/0810
## diff -e /n/emeliedump/2001/0809/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0810/sys/src/9/bitsy/screen.c
308,309c
		lcd->lccr0 &= ~(1<<LEN);	/* disable the LCD */
		cnt = 0;
		while((lcd->lcsr & (1<<LDD)) == 0) {
			delay(10);
			if (++cnt == 100) {
				iprint("LCD doesn't stop\n");
				break;
			}
		}
.
306a
	int cnt;

.
220,221d
161a
	gpioregs->direction |= 
		GPIO_LDD8_o|GPIO_LDD9_o|GPIO_LDD10_o|GPIO_LDD11_o
		|GPIO_LDD12_o|GPIO_LDD13_o|GPIO_LDD14_o|GPIO_LDD15_o;
	gpioregs->altfunc |= 
		GPIO_LDD8_o|GPIO_LDD9_o|GPIO_LDD10_o|GPIO_LDD11_o
		|GPIO_LDD12_o|GPIO_LDD13_o|GPIO_LDD14_o|GPIO_LDD15_o;
	framebuf->palette[0] = Pal0;
.
## diffname bitsy/screen.c 2001/0816
## diff -e /n/emeliedump/2001/0810/sys/src/9/bitsy/screen.c /n/emeliedump/2001/0816/sys/src/9/bitsy/screen.c
255c
//	screenputs = bitsyscreenputs;
	screenputs = nil;
.
## diffname bitsy/screen.c 2001/1130
## diff -e /n/emeliedump/2001/0816/sys/src/9/bitsy/screen.c /n/emeliedump/2001/1130/sys/src/9/bitsy/screen.c
238a
		gscreen->r = Rect(0, 0, Wid, Ht);
		gscreen->clipr = gscreen->r;
		gscreen->width = Wid/2;
.
236c
		while (i < Wid*Ht*2/3)	framebuf->pixel[i++] = 0xffff;		/* white */
.
233a
		gscreen->r = Rect(0, 0, Ht, Wid);
		gscreen->clipr = gscreen->r;
		gscreen->width = Ht/2;
.
230a

.
186a
		gscreen->width = Wid/2;
.
182a
		gscreen->width = Ht/2;
.
126,129c
	0,				/* zero */
	Wid/2,			/* width */
	0,				/* layer */
	0,				/* flags */
.
119,123c
	{ 0, 0, Wid, Ht },		/* r */
	{ 0, 0, Wid, Ht },		/* clipr */
	16,				/* depth */
	3,				/* nchan */
	RGB16,			/* chan */
.
19c
int landscape = 1;	/* orientation of the screen, default is 0: portait */
.
## diffname bitsy/screen.c 2002/1205
## diff -e /n/emeliedump/2001/1130/sys/src/9/bitsy/screen.c /n/emeliedump/2002/1205/sys/src/9/bitsy/screen.c
492c
	memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
.
489c
	memimagedraw(gscreen, r, gscreen, p, nil, p, S);
.
472c
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
.
457c
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
.
448c
		memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
.
401c
			window.max.x, window.min.y+h+5+6), orange, ZP, nil, ZP, S);
.
398c
	memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
.
396c
	memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, 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.