~kris/9p

9hist

24aa6ec2a5453a84fe04bca39e964663b386240c — David du Colombier 32 years ago 27806be
Plan 9 from Bell Labs 1993-10-03
4 files changed, 91 insertions(+), 28 deletions(-)

M carrera/clock.c
M carrera/kbd.c
M carrera/screen.c
M port/devbit.c
M carrera/clock.c => carrera/clock.c +1 -0
@@ 87,6 87,7 @@ clock(Ureg *ur)
	}

	checkalarms();
	mouseclock();

	if(up == 0 || (ur->status&IE) == 0 || up->state != Running)
		return;

M carrera/kbd.c => carrera/kbd.c +63 -4
@@ 19,6 19,7 @@ enum
	Ktest=		0xAB,	/* keyboard test */
	Kdisable=	0xAD,	/* disable keyboard */
	Kenable=	0xAE,	/* enable keyboard */
	Kmseena=	0xA8,	/* enable mouse */
	Krdin=		0xC0,	/* read input port */
	Krdout=		0xD0,	/* read output port */
	Kwrout=		0xD1,	/* write output port */


@@ 46,6 47,7 @@ enum
	 *  command register bits
	 */
	Cintena=	1<<0,	/* enable output interrupt */
	Cmseint=	1<<1,	/* enable mouse interrupt */
	Csystem=	1<<2,	/* set system */
	Cinhibit=	1<<3,	/* inhibit override */
	Cdisable=	1<<4,	/* disable keyboard */


@@ 187,11 189,34 @@ kbdackwait(void)
void
mouseintr(void)
{
	uchar code;
	uchar c;
	static int nb;
	int buttons, dx, dy;
	static short msg[3];
	static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 5, 2, 3, 6, 7 };

	kbdwait();
	code = KBDDAT;
	print("mouse intr %d\n", code);
	c = KBDDAT;

	/* 
	 *  check byte 0 for consistency
	 */
	if(nb==0 && (c&0xc8)!=0x08)
		return;

	msg[nb] = c;
	if(++nb == 3){
		nb = 0;
		if(msg[0] & 0x10)
			msg[1] |= 0xFF00;
		if(msg[0] & 0x20)
			msg[2] |= 0xFF00;

		buttons = b[msg[0]&7];
		dx = msg[1];
		dy = -msg[2];
		mousetrack(buttons, dx, dy);
	}
}

int


@@ 342,6 367,35 @@ empty(void)
	}
}

/*
 *  send a command to the mouse
 */
static int
mousecmd(int cmd)
{
	int tries;
	unsigned int c;

	c = 0;
	tries = 0;
	do{
		if(tries++ > 2)
			break;
		OUTWAIT;
		KBDCTL = 0xD4;
		OUTWAIT;
		KBDDAT = cmd;
		OUTWAIT;
		kbdwait();
		c = KBDDAT;
	} while(c == 0xFE || c == 0);
	if(c != 0xFA){
		print("mouse returns %2.2ux to the %2.2ux command\n", c, cmd);
		return -1;
	}
	return 0;
}

int
kbdinit(void)
{


@@ 387,10 441,15 @@ kbdinit(void)
	OUTWAIT;
	KBDCTL = Kwrcmd;
	OUTWAIT;
	KBDDAT = Csystem | Cinhibit | Cintena;
	KBDDAT = Csystem | Cinhibit | Cintena | Cmseint;
	OUTWAIT;
	KBDCTL = Kenable;
	OUTWAIT;
	KBDCTL = Kmseena;
	empty();

	mousecmd(0xEA);
	mousecmd(0xF4);

	return 1;
}

M carrera/screen.c => carrera/screen.c +23 -22
@@ 128,22 128,6 @@ GBitmap bgrnd =
	0
};

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

static Rectangle window;
static Point cursor;
static int h, w;


@@ 202,8 186,6 @@ screeninit(void)

	gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0);

	memmove(&arrow, &fatarrow, sizeof(fatarrow));

	screenwin();
}



@@ 502,9 484,10 @@ twizzle(uchar *f, uchar *t)
void
screenupdate(void)
{
	Rectangle r;
	ulong *s, *h, in1, in2;
	uchar *sp, *hp, *edisp;
	int i, y, len, off, page, inc;
	Rectangle r;

	r = mbb;
	mbb = NULLMBB;


@@ 529,11 512,13 @@ screenupdate(void)

	inc = gscreen.width*4;
	off = r.min.y * inc + r.min.x;

	sp = ((uchar*)gscreen.base) + off;

	page = off>>16;
	off &= (1<<16)-1;
	hp = edisp = 0;
	hp = 0;
	edisp = 0;
	for(y = r.min.y; y < r.max.y; y++){
		if(hp >= edisp){
			hp = ((uchar*)vgascreen.base) + off;


@@ 542,13 527,29 @@ screenupdate(void)
			off = r.min.x;
			page++;
		}
		for(i = 0; i < len; i += 8)
			twizzle(sp+i, hp+i);
		for(i = 0; i < len; i += 8) {
			s = (ulong*)(sp+i);
			h = (ulong*)(hp+i);
			in1 = s[0];
			in2 = s[1];
			h[0] = swiz(in2);
			h[1] = swiz(in1);
		}
		hp += inc;
		sp += inc;
	}
}

void
mousescreenupdate(void)
{
	if(canlock(&screenlock) == 0)
		return;

	screenupdate();
	unlock(&screenlock);
}

/*
 * graphics
 */

M port/devbit.c => port/devbit.c +4 -2
@@ 105,7 105,8 @@ extern	GBitmap	gscreen;
typedef struct Mouseinfo	Mouseinfo;
typedef struct Cursorinfo	Cursorinfo;

struct Mouseinfo{
struct Mouseinfo
{
	/*
	 * First three fields are known in some l.s's
	 */


@@ 119,7 120,8 @@ struct Mouseinfo{
	Rendez	r;
};

struct Cursorinfo{
struct Cursorinfo
{
	Cursor;
	Lock;
	int	visible;	/* on screen */