plan 9 kernel history: overview | file list | diff list

1992/1017/pc/kbd.c (diff list | history)

1992/1016/sys/src/9/pc/kbd.c:4,91992/1017/sys/src/9/pc/kbd.c:4,10 (short | long | prev | next)
1991/0702    
#include	"dat.h" 
#include	"fns.h" 
1991/0703    
#include	"io.h" 
1992/1017    
#include	"../port/error.h" 
1991/0702    
 
1991/0731    
#include	<libg.h> 
#include	<gnot.h> 
1992/1016/sys/src/9/pc/kbd.c:49,541992/1017/sys/src/9/pc/kbd.c:50,59
1991/0703    
	Pgdown=	View, 
1991/0731    
	Ins=	KF|20, 
1991/0703    
	Del=	0x7F, 
1992/1017    
 
	Rbutton=4, 
	Mbutton=2, 
	Lbutton=1, 
1991/0702    
}; 
 
1991/0703    
uchar kbtab[] =  
1992/1016/sys/src/9/pc/kbd.c:107,1171992/1017/sys/src/9/pc/kbd.c:112,121
1991/0911    
static int mousebuttons; 
1992/0811    
static int keybuttons; 
1992/1015    
static uchar ccc; 
1992/1017    
static int mousetype; 
static int mouseport; 
static int shift; 
1991/0911    
 
1991/0905    
/* 
 *  predeclared 
 */ 
static void	kbdintr(Ureg*); 
 
1992/0904    
enum 
{ 
1992/1016/sys/src/9/pc/kbd.c:128,1361992/1017/sys/src/9/pc/kbd.c:132,141
1992/0904    
	Mouseserial=	1, 
	MousePS2=	2, 
}; 
static int mousetype; 
1991/0703    
 
1992/1015    
static int	mymouseputc(IOQ*, int); 
1992/1017    
static void	kbdintr(Ureg*); 
static int	ps2mouseputc(IOQ*, int); 
static int	m3mouseputc(IOQ*, int); 
1992/1015    
 
1991/0803    
/* 
 *  wait for output no longer busy 
1992/1016/sys/src/9/pc/kbd.c:238,2431992/1017/sys/src/9/pc/kbd.c:243,249
1992/0711    
	int c; 
1991/0730    
 
1991/0716    
	setvec(Kbdvec, kbdintr); 
1992/1017    
	bigcursor(); 
1991/0730    
 
	/* wait for a quiescent controller */ 
	while((c = inb(Status)) & (Outbusy | Inready)) 
1992/1016/sys/src/9/pc/kbd.c:267,2801992/1017/sys/src/9/pc/kbd.c:273,289
1992/0904    
/* 
 *  setup a serial mouse 
 */ 
void 
mouseserial(int port) 
1992/1017    
static void 
serialmouse(int port, char *type, int setspeed) 
1992/0904    
{ 
1992/1016    
	if(mousetype) 
1992/0904    
		return; 
1992/1017    
		error(Emouseset); 
1992/0811    
 
1992/0904    
	/* set up /dev/eia0 as the mouse */ 
	uartspecial(port, 0, &mouseq, 1200); 
1992/1017    
	uartspecial(port, 0, &mouseq, setspeed ? 1200 : 0); 
	if(type && *type == 'M') 
		mouseq.putc = m3mouseputc; 
	mouseport = port; 
1992/0904    
	mousetype = Mouseserial; 
} 
1992/0408    
 
1992/1016/sys/src/9/pc/kbd.c:281,2951992/1017/sys/src/9/pc/kbd.c:290,305
1992/0904    
/* 
 *  set up a ps2 mouse 
 */ 
void 
mouseps2(void) 
1992/1017    
static void 
ps2mouse(void) 
1992/0904    
{ 
1992/1015    
	int x; 
1992/0904    
 
	bigcursor(); 
	setvec(Mousevec, kbdintr); 
1992/1017    
	if(mousetype) 
		error(Emouseset); 
1992/0904    
 
	/* enable kbd/mouse xfers and interrupts */ 
1992/1017    
	setvec(Mousevec, kbdintr); 
1992/1015    
	x = splhi(); 
	ccc &= ~Cmousedis; 
	ccc |= Cmouseint; 
1992/1016/sys/src/9/pc/kbd.c:306,3121992/1017/sys/src/9/pc/kbd.c:316,322
1992/1015    
		print("mouse init failed\n"); 
1992/0904    
 
	/* make mouse streaming, enabled */ 
1992/1016    
	mousecmd(0xF6); 
1992/1017    
	mousecmd(0xEA); 
1992/0904    
	mousecmd(0xF4); 
1992/1015    
	splx(x); 
 
1992/1016/sys/src/9/pc/kbd.c:314,3601992/1017/sys/src/9/pc/kbd.c:324,330
1992/0825    
} 
 
/* 
 *  turn mouse acceleration on/off 
 */ 
void 
mouseaccelerate(int on) 
{ 
1992/1016    
	int x; 
1992/0825    
                 
1992/0902    
	switch(mousetype){ 
	case MousePS2: 
1992/1016    
		x = splhi(); 
1992/0825    
		if(on) 
			mousecmd(0xE7); 
		else 
			mousecmd(0xE6); 
1992/1016    
		splx(x); 
1992/0904    
		break; 
	} 
} 
                 
/* 
 *  set mouse resolution 
 */ 
void 
mouseres(int res) 
{ 
1992/1016    
	int x; 
1992/0904    
                 
	switch(mousetype){ 
	case MousePS2: 
1992/1016    
		x = splhi(); 
1992/0904    
		mousecmd(0xE8); 
		mousecmd(res); 
1992/1016    
		splx(x); 
1991/1210    
		break; 
	} 
1991/0731    
} 
1991/0730    
                 
1992/0918    
static int shift; 
                 
1991/0731    
/* 
 *  mouse message is three bytes 
1992/1017    
 *  ps/2 mouse message is three bytes 
1991/0731    
 * 
 *	byte 0 -	0 0 SDY SDX 1 M R L 
 *	byte 1 -	DX 
1992/1016/sys/src/9/pc/kbd.c:363,3741992/1017/sys/src/9/pc/kbd.c:333,343
1992/0918    
 *  shift & left button is the same as middle button 
1991/0731    
 */ 
1992/1015    
static int 
mymouseputc(IOQ *q, int c) 
1992/1017    
ps2mouseputc(IOQ *q, int c) 
1991/0731    
{ 
	static short msg[3]; 
	static int nb; 
1992/0918    
	static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 5, 2, 3, 6, 7 }; 
1991/0731    
	static lastdx, lastdy; 
	extern Mouseinfo mouse; 
 
1992/1015    
	USED(q);		/* not */ 
1992/1016/sys/src/9/pc/kbd.c:398,4031992/1017/sys/src/9/pc/kbd.c:367,471
1991/0703    
} 
 
/* 
1992/1017    
 *  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 
mousectl(char *arg) 
{ 
	int n, x; 
	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 
			serialmouse(atoi(field[0]+6), 0, 1); 
	} else if(strcmp(field[0], "ps2") == 0){ 
		ps2mouse(); 
	} else if(strcmp(field[0], "accelerated") == 0){ 
		switch(mousetype){ 
		case MousePS2: 
			x = splhi(); 
			mousecmd(0xE7); 
			splx(x); 
			break; 
		} 
	} else if(strcmp(field[0], "linear") == 0){ 
		switch(mousetype){ 
		case MousePS2: 
			x = splhi(); 
			mousecmd(0xE6); 
			splx(x); 
			break; 
		} 
	} else if(strcmp(field[0], "res") == 0){ 
		if(n < 2) 
			n = 1; 
		else 
			n = atoi(field[1]); 
		switch(mousetype){ 
		case MousePS2: 
			x = splhi(); 
			mousecmd(0xE8); 
			mousecmd(n); 
			splx(x); 
			break; 
		} 
	} 
} 
 
/* 
1991/0911    
 *  Ctrl key used as middle button pressed 
 */ 
static void 
1992/1016/sys/src/9/pc/kbd.c:454,4601992/1017/sys/src/9/pc/kbd.c:522,528
1991/0730    
	 *  if it's the mouse... 
	 */ 
	if(s & Minready){ 
1992/1015    
		mymouseputc(&mouseq, c); 
1992/1017    
		ps2mouseputc(&mouseq, c); 
1991/0731    
		return 0; 
1991/0730    
	} 
1991/0703    
 
1992/1016/sys/src/9/pc/kbd.c:502,5141992/1017/sys/src/9/pc/kbd.c:570,582
1991/0703    
			ctl = 0; 
			break; 
1992/0811    
		case KF|1: 
			mboff(4); 
1992/1017    
			mboff(Rbutton); 
1991/0911    
			break; 
1992/0811    
		case KF|2: 
			mboff(2); 
1992/1017    
			mboff(Mbutton); 
1992/0811    
			break; 
		case KF|3: 
			mboff(1); 
1992/1017    
			mboff(Lbutton); 
1992/0811    
			break; 
1991/0703    
		} 
1991/0731    
		return 0; 
1992/1016/sys/src/9/pc/kbd.c:572,5841992/1017/sys/src/9/pc/kbd.c:640,652
1991/0703    
			ctl = 1; 
1991/0911    
			return 0; 
1992/0811    
		case KF|1: 
			mbon(4); 
1992/1017    
			mbon(Rbutton); 
1992/0811    
			return 0; 
		case KF|2: 
			mbon(2); 
1992/1017    
			mbon(Mbutton); 
1992/0811    
			return 0; 
		case KF|3: 
			mbon(1); 
1992/1017    
			mbon(Lbutton); 
1991/0731    
			return 0; 
1991/0703    
		} 
	} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)