| plan 9 kernel history: overview | file list | diff list |
2000/1005/pc/mouse.c (diff list | history)
| pc/mouse.c on 1997/0327 | ||
| 1997/0327 | #include "u.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "../port/error.h" #include "io.h" | |
| 1997/1101 | #define Image IMAGE #include <draw.h> #include <memdraw.h> | |
| 1999/0119 | #include <cursor.h> | |
| 1997/0327 | #include "screen.h" | |
| 1997/1101 | /* * mouse types */ enum { Mouseother= 0, Mouseserial= 1, MousePS2= 2, }; static int mousetype; | |
| 1997/0327 | /* * setup a serial mouse */ static void serialmouse(int port, char *type, int setspeed) { if(mousetype == Mouseserial) error(Emouseset); if(port >= 3 || port < 0) error(Ebadarg); /* set up /dev/eia? as the mouse */ if(setspeed) setspeed = 1200; if(type && *type == 'M') ns16552special(port, setspeed, 0, 0, m3mouseputc); else ns16552special(port, setspeed, 0, 0, mouseputc); mousetype = Mouseserial; } /* * ps/2 mouse message is three bytes * * byte 0 - 0 0 SDY SDX 1 M R L * byte 1 - DX * byte 2 - DY * | |
| 2000/0731 | * shift & right button is the same as middle button | |
| 1997/0327 | */ static void ps2mouseputc(int c, int shift) { static short msg[3]; static int nb; | |
| 2000/0716 | static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 3, 2, 3, 6, 7 }; | |
| 1997/0327 | int buttons, dx, dy; /* * 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) | (shift ? 8 : 0)]; dx = msg[1]; dy = -msg[2]; mousetrack(buttons, dx, dy); } return; } /* * set up a ps2 mouse */ static void ps2mouse(void) { if(mousetype == MousePS2) return; i8042auxenable(ps2mouseputc); /* make mouse streaming, enabled */ i8042auxcmd(0xEA); i8042auxcmd(0xF4); mousetype = MousePS2; } | |
| 1999/0225 | static void setaccelerated(int x) { accelerated = x; switch(mousetype){ case MousePS2: i8042auxcmd(0xE7); break; default: mouseaccelerate(x); break; } } static void setlinear(void) { accelerated = 0; switch(mousetype){ case MousePS2: i8042auxcmd(0xE6); break; default: mouseaccelerate(0); break; } } static void setres(int n) { resolution = n; switch(mousetype){ case MousePS2: i8042auxcmd(0xE8); i8042auxcmd(n); break; } } static void setintellimouse(void) { intellimouse = 1; switch(mousetype){ case MousePS2: i8042auxcmd(0xF3); /* set sample */ i8042auxcmd(0xC8); i8042auxcmd(0xF3); /* set sample */ i8042auxcmd(0x64); i8042auxcmd(0xF3); /* set sample */ i8042auxcmd(0x50); break; } } static void resetmouse(void) { switch(mousetype){ case MousePS2: i8042auxcmd(0xF6); i8042auxcmd(0xEA); /* streaming */ i8042auxcmd(0xE8); /* set resolution */ i8042auxcmd(3); i8042auxcmd(0xF4); /* enabled */ break; } } | |
| 1997/0327 | void | |
| 1998/0417 | mousectl(char* field[], int n) | |
| 1997/0327 | { if(strncmp(field[0], "serial", 6) == 0){ 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(); | |
| 1999/0225 | } else if(strcmp(field[0], "ps2intellimouse") == 0){ ps2mouse(); setintellimouse(); | |
| 1997/0327 | } else if(strcmp(field[0], "accelerated") == 0){ | |
| 1999/0225 | setaccelerated(n == 1 ? 1 : atoi(field[1])); | |
| 1997/0327 | } else if(strcmp(field[0], "linear") == 0){ | |
| 1999/0225 | setlinear(); | |
| 1997/0327 | } else if(strcmp(field[0], "res") == 0){ | |
| 1999/0225 | if(n >= 2) | |
| 1997/0327 | n = atoi(field[1]); | |
| 1999/0225 | setres(n); | |
| 1999/0224 | } else if(strcmp(field[0], "reset") == 0){ | |
| 1999/0225 | resetmouse(); if(accelerated) setaccelerated(accelerated); if(resolution) setres(resolution); if(intellimouse) setintellimouse(); } else if(strcmp(field[0], "intellimouse") == 0){ setintellimouse(); | |
| 1998/0417 | } | |
| 1997/0327 | else error(Ebadctl); } | |