X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FInput%2FPS2KbMouse%2Fps2mouse.c;h=e80a14131d489b2c7113eae31a201487ddac7901;hb=ec0a3c65da8c3d47895ab2e5b4cec8cf2070f6eb;hp=f67c8b15a5e70b86dd09c7a752a095c527662cde;hpb=98cd1835ab04e5f69dc6f0bd6faeff3744a89ad2;p=tpg%2Facess2.git diff --git a/Modules/Input/PS2KbMouse/ps2mouse.c b/Modules/Input/PS2KbMouse/ps2mouse.c index f67c8b15..e80a1413 100644 --- a/Modules/Input/PS2KbMouse/ps2mouse.c +++ b/Modules/Input/PS2KbMouse/ps2mouse.c @@ -6,28 +6,24 @@ #include #include #include -#include -#include - -static inline int MIN(int a, int b) { return (a < b) ? a : b; } -static inline int MAX(int a, int b) { return (a > b) ? a : b; } +#include +#include +#include "common.h" // == CONSTANTS == #define NUM_AXIES 2 // X+Y #define NUM_BUTTONS 5 // Left, Right, Scroll Click, Scroll Up, Scroll Down -#define PS2_IO_PORT 0x60 // == PROTOTYPES == // - Internal - int PS2Mouse_Install(char **Arguments); -void PS2Mouse_IRQ(int Num); -static void mouseSendCommand(Uint8 cmd); -void PS2Mouse_Enable(); +void PS2Mouse_HandleInterrupt(Uint8 InputByte); // - Filesystem - Uint64 PS2Mouse_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data); // == GLOBALS == +void (*gpMouse_EnableFcn)(void); // - Settings int giMouse_Sensitivity = 1; int giMouse_MaxX = 640, giMouse_MaxY = 480; @@ -54,14 +50,19 @@ tDevFS_Driver gMouse_DriverStruct = { // == CODE == int PS2Mouse_Install(char **Arguments) { + + // Set up variables - gMouse_Axies = (void*)&gMouse_FileData[1]; + gMouse_Axies = (void*)&gMouse_FileData[4]; gMouse_Buttons = (void*)&gMouse_Axies[NUM_AXIES]; + + gMouse_FileHeader->NAxies = 2; gMouse_FileHeader->NButtons = 3; + gMouse_Axies[0].MinValue = -10; gMouse_Axies[0].MaxValue = 10; + gMouse_Axies[1].MinValue = -10; gMouse_Axies[1].MaxValue = 10; // Initialise Mouse Controller - IRQ_AddHandler(12, PS2Mouse_IRQ); // Set IRQ giMouse_Cycle = 0; // Set Current Cycle position - PS2Mouse_Enable(); // Enable the mouse + gpMouse_EnableFcn(); DevFS_AddDevice(&gMouse_DriverStruct); @@ -70,14 +71,14 @@ int PS2Mouse_Install(char **Arguments) /* Handle Mouse Interrupt */ -void PS2Mouse_IRQ(int Num) +void PS2Mouse_HandleInterrupt(Uint8 InputByte) { Uint8 flags; int d[2], d_accel[2]; int i; // Gather mouse data - gaMouse_Bytes[giMouse_Cycle] = inb(0x60); + gaMouse_Bytes[giMouse_Cycle] = InputByte; LOG("gaMouse_Bytes[%i] = 0x%02x", gMouse_Axies[0].MaxValue); // - If bit 3 of the first byte is not set, it's not a valid packet? if(giMouse_Cycle == 0 && !(gaMouse_Bytes[0] & 0x08) ) @@ -137,11 +138,9 @@ void PS2Mouse_IRQ(int Num) gMouse_Axies[i].CurValue = d_accel[i]; gMouse_Axies[i].CursorPos = newCursor; } - -// Log_Debug("PS2Mouse", "gMouse_Buttons = {0x%x,0x%x,0x%x}, gMouse_Axies={%i,%i}", -// gMouse_Buttons[0], gMouse_Buttons[1], gMouse_Buttons[2], -// gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos); - + +// Log("Mouse at %ix%i", gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos); + VFS_MarkAvaliable(&gMouse_DriverStruct.RootNode, 1); } @@ -201,47 +200,3 @@ int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data) } } -//== Internal Functions == -static inline void mouseOut64(Uint8 data) -{ - int timeout=100000; - while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear - outb(0x64, data); // Send Command -} -static inline void mouseOut60(Uint8 data) -{ - int timeout=100000; - while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear - outb(0x60, data); // Send Command -} -static inline Uint8 mouseIn60(void) -{ - int timeout=100000; - while( timeout-- && (inb(0x64) & 1) == 0); // Wait for Flag to set - return inb(0x60); -} -static inline void mouseSendCommand(Uint8 cmd) -{ - mouseOut64(0xD4); - mouseOut60(cmd); -} - -void PS2Mouse_Enable(void) -{ - Uint8 status; - Log_Log("PS2Mouse", "Enabling Mouse..."); - - // Enable AUX PS/2 - mouseOut64(0xA8); - - // Enable AUX PS/2 (Compaq Status Byte) - mouseOut64(0x20); // Send Command - status = mouseIn60(); // Get Status - status &= ~0x20; // Clear "Disable Mouse Clock" - status |= 0x02; // Set IRQ12 Enable - mouseOut64(0x60); // Send Command - mouseOut60(status); // Set Status - - //mouseSendCommand(0xF6); // Set Default Settings - mouseSendCommand(0xF4); // Enable Packets -}