~kris/9p

9hist

3142365c438e8f1e56fcfe0858ebf85405383c4a — David du Colombier 33 years ago 469d80a
Plan 9 from Bell Labs 1992-10-20
9 files changed, 152 insertions(+), 90 deletions(-)

M gnot/screen.c
M pc/devconfig.c
M pc/kbd.c
M port/devbit.c
M port/devscc.c
M port/portfns.h
M ss/fns.h
M ss/main.c
M ss/screen.c
M gnot/screen.c => gnot/screen.c +7 -0
@@ 178,3 178,10 @@ mousetry(Ureg *ur)
		wakeup(&mouse.r);
	}
}

/* only 1 flavor mouse */
void
mousectl(char *x)
{
	USED(x);
}

M pc/devconfig.c => pc/devconfig.c +0 -12
@@ 30,12 30,10 @@ enum {
	Qvgatype=	3,
	Qvgaport=	4,
	Qvgamem=	5,
	Qmouse=		6,
	Nvga=		6,
};

Dirtab vgadir[]={
	"mouseconf",	{Qmouse},	0,		0666,
	"vgamonitor",	{Qvgamonitor},	0,		0666,
	"vgatype",	{Qvgatype},	0,		0666,
	"vgasize",	{Qvgasize},	0,		0666,


@@ 185,16 183,6 @@ configwrite(Chan *c, void *buf, long n, ulong offset)
			error(Ebadarg);
		memmove((void *)(SCREENMEM+offset), buf, n);
		return n;
	case Qmouse:
		if(n >= sizeof(cbuf))
			n = sizeof(cbuf) - 1;
		memmove(cbuf, buf, n);
		cbuf[n] = 0;
		cp = strchr(cbuf, '\n');
		if(cp)
			*cp = 0;
		mousectl(cbuf);
		return n;
	}
	error(Eperm);
	return 0;

M pc/kbd.c => pc/kbd.c +22 -73
@@ 10,6 10,8 @@
#include	<gnot.h>
#include	"screen.h"

extern Mouseinfo mouse;

enum {
	Data=		0x60,	/* data port */



@@ 109,13 111,12 @@ uchar kbtabesc1[] =
 */
KIOQ	kbdq;

static int mousebuttons;
static int keybuttons;
static uchar ccc;
static int mousetype;
static int mouseport;
static int shift;

extern int mouseshifted;

enum
{


@@ 135,7 136,6 @@ enum

static void	kbdintr(Ureg*);
static int	ps2mouseputc(IOQ*, int);
static int	m3mouseputc(IOQ*, int);

/*
 *  wait for output no longer busy


@@ 279,6 279,9 @@ serialmouse(int port, char *type, int setspeed)
	if(mousetype)
		error(Emouseset);

	if(port >= 2 || port < 0)
		error(Ebadarg);

	/* set up /dev/eia0 as the mouse */
	uartspecial(port, 0, &mouseq, setspeed ? 1200 : 0);
	if(type && *type == 'M')


@@ 338,7 341,6 @@ ps2mouseputc(IOQ *q, int c)
	static short msg[3];
	static int nb;
	static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 5, 2, 3, 6, 7 };
	extern Mouseinfo mouse;

	USED(q);		/* not */
	/* 


@@ 355,8 357,7 @@ ps2mouseputc(IOQ *q, int c)
		if(msg[0] & 0x20)
			msg[2] |= 0xFF00;

		mousebuttons = b[(msg[0]&7) | (shift ? 8 : 0)];
		mouse.newbuttons = mousebuttons | keybuttons;
		mouse.newbuttons = b[(msg[0]&7) | (shift ? 8 : 0)] | keybuttons;
		mouse.dx = msg[1];
		mouse.dy = -msg[2];
		mouse.track = 1;


@@ 367,54 368,6 @@ ps2mouseputc(IOQ *q, int c)
}

/*
 *  microsoft 3 button, 7 bit bytes
 *
 *	byte 0 -	1  L  R Y7 Y6 X7 X6
 *	byte 1 -	0 X5 X4 X3 X2 X1 X0
 *	byte 2 -	0 Y5 Y4 Y3 Y2 Y1 Y0
 *	byte 3 -	0  M  x  x  x  x  x	(optional)
 *
 *  shift & left button is the same as middle button (for 2 button mice)
 */
static int
m3mouseputc(IOQ *q, int c)
{
	static uchar msg[3];
	static int nb;
	static uchar b[] = { 0, 4, 1, 5, 0, 4, 3, 7 };
	extern Mouseinfo mouse;

	USED(q);		/* not */

	/* 
	 *  check bit 6 for consistency
	 */
	if(nb==0){
		if((c&0x40) != 0){
			/* must be 4th (M button) byte */
			mousebuttons = (mousebuttons & ~Mbutton) | ((c&0x2)?Mbutton:0);
			mouse.newbuttons = mousebuttons | keybuttons;
			mouse.dx = 0;
			mouse.dy = 0;
			mouse.track = 0;
			mouseclock();
			return 0;
		}
	}
	msg[nb] = c;
	if(++nb == 3){
		nb = 0;
		mousebuttons = b[(msg[0]>>4)&3 | (shift ? 4 : 0)];
		mouse.newbuttons = mousebuttons | keybuttons;
		mouse.dx = (((msg[0]&3)<<7) | msg[1]) - 128;
		mouse.dy = (((msg[0]&0xc)<<5) | msg[2]) - 128;
		mouse.track = 1;
		mouseclock();
	}
	return 0;
}

/*
 *  set/change mouse configuration
 */
void


@@ 424,13 377,19 @@ mousectl(char *arg)
	char *field[3];

	n = getfields(arg, field, 3, ' ');
	if(n < 1)
		return;
	if(strncmp(field[0], "serial", 6) == 0){
		if(n > 1)
			serialmouse(atoi(field[1]), field[2], 0);
		else
		switch(n){
		case 1:
			serialmouse(atoi(field[0]+6), 0, 1);
			break;
		case 2:
			serialmouse(atoi(field[1]), 0, 0);
			break;
		case 3:
		default:
			serialmouse(atoi(field[1]), field[2], 0);
			break;
		}
	} else if(strcmp(field[0], "ps2") == 0){
		ps2mouse();
	} else if(strcmp(field[0], "accelerated") == 0){


@@ 472,23 431,13 @@ static void
mbon(int val)
{
	keybuttons |= val;
	mouse.newbuttons = mousebuttons | keybuttons;
	mouse.dx = 0;
	mouse.dy = 0;
	mouse.track = 1;
	spllo();		/* mouse tracking kills uart0 */
	mouseclock();
	mousebuttons(keybuttons);
}
static void
mboff(int val)
{
	keybuttons &= ~val;
	mouse.newbuttons = mousebuttons | keybuttons;
	mouse.dx = 0;
	mouse.dy = 0;
	mouse.track = 1;
	spllo();		/* mouse tracking kills uart0 */
	mouseclock();
	mousebuttons(keybuttons);
}

/*


@@ 564,7 513,7 @@ kbdintr0(void)
	if(keyup){
		switch(c){
		case Shift:
			shift = 0;
			mouseshifted = shift = 0;
			break;
		case Ctrl:
			ctl = 0;


@@ 631,7 580,7 @@ kbdintr0(void)
			num ^= 1;
			return 0;
		case Shift:
			shift = 1;
			mouseshifted = shift = 1;
			return 0;
		case Latin:
			lstate = 1;

M port/devbit.c => port/devbit.c +60 -0
@@ 108,6 108,7 @@ extern	islcd;
Mouseinfo	mouse;
Cursorinfo	cursor;
Rendez		lcdmouse;
int		mouseshifted;

Cursor	arrow =
{


@@ 168,12 169,14 @@ enum{
	Qdir,
	Qbitblt,
	Qmouse,
	Qmousectl,
	Qscreen,
};

Dirtab bitdir[]={
	"bitblt",	{Qbitblt},	0,			0666,
	"mouse",	{Qmouse},	0,			0666,
	"mousectl",	{Qmousectl},	0,			0220,
	"screen",	{Qscreen},	0,			0444,
};



@@ 837,6 840,7 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
	BSubfont *f, *tf, **fp;
	GFont *ff, **ffp;
	GCacheinfo *gc;
	char buf[64];

	if(!conf.monitor)
		error(Egreg);


@@ 845,6 849,15 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
	if(c->qid.path == CHDIR)
		error(Eisdir);

	if(c->qid.path == Qmousectl){
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, va, n);
		buf[n] = 0;
		mousectl(buf);
		return n;
	}

	if(c->qid.path != Qbitblt)
		error(Egreg);



@@ 2026,6 2039,53 @@ mouseupdate(int dolock)
	}
}

/*
 *  microsoft 3 button, 7 bit bytes
 *
 *	byte 0 -	1  L  R Y7 Y6 X7 X6
 *	byte 1 -	0 X5 X4 X3 X2 X1 X0
 *	byte 2 -	0 Y5 Y4 Y3 Y2 Y1 Y0
 *	byte 3 -	0  M  x  x  x  x  x	(optional)
 *
 *  shift & left button is the same as middle button (for 2 button mice)
 */
int
m3mouseputc(IOQ *q, int c)
{
	static uchar msg[3];
	static int nb;
	static uchar b[] = { 0, 4, 1, 5, 0, 4, 3, 7 };
	short x;

	USED(q);
	/* 
	 *  check bit 6 for consistency
	 */
	if(nb==0){
		if((c&0x40) == 0){
			/* an extra byte gets sent for the middle button */
			mousebuttons((mouse.buttons & ~2) | ((c&0x20) ? 2 : 0));
			return 0;
		}
	}
	msg[nb] = c;
	if(++nb == 3){
		nb = 0;
		mouse.newbuttons = (mouse.buttons & 2)
				 | b[(msg[0]>>4)&3 | (mouseshifted ? 4 : 0)];
		x = (msg[0]&0x3)<<14;
		mouse.dx = (x>>8) | msg[1];
		x = (msg[0]&0xc)<<12;
		mouse.dy = (x>>8) | msg[2];
		mouse.track = 1;
		mouseclock();
	}
	return 0;
}

/*
 *  Logitech 5 byte packed binary mouse format, 8 bit bytes
 */
int
mouseputc(IOQ *q, int c)
{

M port/devscc.c => port/devscc.c +7 -4
@@ 98,7 98,7 @@ struct SCC
	ulong	freq;		/* clock frequency */

	/* console interface */
	int	nostream;	/* can't use the stream interface */
	int	special;	/* can't use the stream interface */
	IOQ	*iq;		/* input character queue */
	IOQ	*oq;		/* output character queue */



@@ 473,7 473,7 @@ sccspecial(int port, IOQ *oq, IOQ *iq, int baud)
{
	SCC *sp = scc[port];

	sp->nostream = 1;
	sp->special = 1;
	sp->oq = oq;
	sp->iq = iq;
	sccenable(sp);


@@ 543,6 543,9 @@ sccstclose(Queue *q)
{
	SCC *sp = q->ptr;

	if(sp->special)
		return;

	qlock(sp);
	sp->wq = 0;
	sp->iq->putc = 0;


@@ 679,7 682,7 @@ sccreset(void)

		/* set up queues if a stream port */
		sp = scc[i];
		if(sp->nostream)
		if(sp->special)
			continue;
		sp->iq = xalloc(sizeof(IOQ));
		initq(sp->iq);


@@ 735,7 738,7 @@ sccopen(Chan *c, int omode)

	if(c->qid.path != CHDIR){
		sp = scc[STREAMID(c->qid.path)];
		if(sp->nostream)
		if(sp->special)
			error(Einuse);
		streamopen(c, &sccinfo);
	}

M port/portfns.h => port/portfns.h +3 -0
@@ 103,6 103,7 @@ void		lights(int);
void		lock(Lock*);
void		lockinit(void);
Page*		lookpage(Image*, ulong);
int		m3mouseputc(IOQ*, int);
void		machinit(void);
void*		malloc(ulong);
void		mapstack(Proc*);


@@ 111,6 112,8 @@ void		mmurelease(Proc*);
void		mntdump(void);
int		mount(Chan*, Chan*, int);
void		mountfree(Mount*);
void		mousebuttons(int);
void		mousectl(char*);
void		mouseclock(void);
int		mouseputc(IOQ*, int);
int		msize(void*);

M ss/fns.h => ss/fns.h +1 -0
@@ 1,5 1,6 @@
#include "../port/portfns.h"

void	bootargs(ulong);
void	cacheinit(void);
ulong	call(void*, ...);
void	clearftt(ulong);

M ss/main.c => ss/main.c +44 -1
@@ 19,6 19,7 @@ char	mempres[256];
char	fbstr[32];
ulong	fbslot;
Label	catch;
uchar	*sp;

typedef struct Sysparam Sysparam;
struct Sysparam


@@ 152,7 153,7 @@ init0(void)
		poperror();
	}

	touser(USTKTOP-(1+MAXSYSARG)*BY2WD);
	touser((long)sp);
}

FPsave	*initfpp;


@@ 166,6 167,7 @@ userinit(void)
	User *up;
	KMap *k;
	ulong l;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();


@@ 207,6 209,11 @@ userinit(void)
	 */
	s = newseg(SG_STACK, USTKTOP-BY2PG, 1);
	p->seg[SSEG] = s;
	pg = newpage(1, 0, USTKTOP-BY2PG);
	segpage(s, pg);
	k = kmap(pg);
	bootargs(VA(k));
	kunmap(k);

	/*
	 * Text


@@ 221,6 228,42 @@ userinit(void)
	ready(p);
}

uchar *
pusharg(char *p)
{
	int n;

	n = strlen(p)+1;
	sp -= n;
	memmove(sp, p, n);
	return sp;
}

void
bootargs(ulong base)
{
 	int i, ac;
	uchar *av[32];
	uchar **lsp;

	sp = (uchar*)base + BY2PG - MAXSYSARG*BY2WD;

	ac = 0;
	av[ac++] = pusharg("/sparc/9ss");
	av[ac++] = pusharg("-p");

	/* 4 byte word align stack */
	sp = (uchar*)((ulong)sp & ~3);

	/* build argc, argv on stack */
	sp -= (ac+1)*sizeof(sp);
	lsp = (uchar**)sp;
	for(i = 0; i < ac; i++)
		*lsp++ = av[i] + ((USTKTOP - BY2PG) - base);
	*lsp = 0;
	sp += (USTKTOP - BY2PG) - base - sizeof(sp);
}

void
exit(int ispanic)
{

M ss/screen.c => ss/screen.c +8 -0
@@ 14,6 14,7 @@

extern	GSubfont	defont0;
GSubfont		*defont;
int	islcd;

struct{
	Point	pos;


@@ 544,3 545,10 @@ rep(ulong v, int n)
		rv |= (v << o);
	return rv;
}

/* only 1 flavor mouse */
void
mousectl(char *x)
{
	USED(x);
}