2 * Acess2 Mouse Driver
\r
8 #include <Input/Mouse/include/mouse.h>
\r
12 #define NUM_AXIES 2 // X+Y
\r
13 #define NUM_BUTTONS 5 // Left, Right, Scroll Click, Scroll Up, Scroll Down
\r
17 int PS2Mouse_Install(char **Arguments);
\r
18 void PS2Mouse_HandleInterrupt(Uint8 InputByte);
\r
21 void (*gpPS2Mouse_EnableFcn)(void);
\r
23 int giPS2Mouse_Sensitivity = 1;
\r
25 int giPS2Mouse_Cycle = 0; // IRQ Position
\r
26 Uint8 gaPS2Mouse_Bytes[4] = {0,0,0,0};
\r
27 tMouse *gpPS2Mouse_Handle;
\r
30 int PS2Mouse_Install(char **Arguments)
\r
32 gpPS2Mouse_Handle = Mouse_Register("PS2Mouse", NUM_AXIES, NUM_BUTTONS);
\r
34 // Initialise Mouse Controller
\r
35 giPS2Mouse_Cycle = 0; // Set Current Cycle position
\r
36 gpPS2Mouse_EnableFcn();
\r
38 return MODULE_ERR_OK;
\r
41 /* Handle Mouse Interrupt
\r
43 void PS2Mouse_HandleInterrupt(Uint8 InputByte)
\r
46 int d[2], d_accel[2];
\r
48 // Gather mouse data
\r
49 gaPS2Mouse_Bytes[giPS2Mouse_Cycle] = InputByte;
\r
50 // - If bit 3 of the first byte is not set, it's not a valid packet?
\r
51 if(giPS2Mouse_Cycle == 0 && !(gaPS2Mouse_Bytes[0] & 0x08) )
\r
54 // 3 bytes per packet
\r
56 if(giPS2Mouse_Cycle < 3)
\r
58 giPS2Mouse_Cycle = 0;
\r
60 // Actual Processing (once we have all bytes)
\r
61 flags = gaPS2Mouse_Bytes[0];
\r
63 LOG("flags = 0x%x", flags);
\r
65 // Check for X/Y Overflow
\r
66 if(flags & 0xC0) return;
\r
68 // Calculate dX and dY
\r
69 d[0] = gaPS2Mouse_Bytes[1]; if(flags & 0x10) d[0] = -(256-d[0]); // x
\r
70 d[1] = gaPS2Mouse_Bytes[2]; if(flags & 0x20) d[1] = -(256-d[1]); // y
\r
71 d[1] = -d[1]; // Y is negated
\r
72 LOG("RAW dx=%i, dy=%i\n", d[0], d[1]);
\r
74 // TODO: Apply a form of curve to the mouse movement (dx*log(dx), dx^k?)
\r
75 // TODO: Independent sensitivities?
\r
76 // TODO: Disable acceleration via a flag?
\r
77 d_accel[0] = d[0]*giPS2Mouse_Sensitivity;
\r
78 d_accel[1] = d[1]*giPS2Mouse_Sensitivity;
\r
80 // TODO: Scroll wheel?
\r
81 Mouse_HandleEvent(gpPS2Mouse_Handle, (flags & 7), d_accel);
\r