3 * - By thePowersGang (John Hodge)
5 * 8042 (or comaptible) Driver
11 void KBC8042_Init(void);
12 void KBC8042_KeyboardHandler(int IRQ, void *Ptr);
13 void KBC8042_MouseHandler(int IRQ, void *Ptr);
14 void KBC8042_EnableMouse(void);
15 static inline void KBC8042_SendDataAlt(Uint8 data);
16 static inline void KBC8042_SendData(Uint8 data);
17 static inline Uint8 KBC8042_ReadData(void);
18 static void KBC8042_SendMouseCommand(Uint8 cmd);
21 void KBC8042_Init(void)
23 IRQ_AddHandler(1, KBC8042_KeyboardHandler, NULL);
24 IRQ_AddHandler(12, KBC8042_MouseHandler, NULL); // Set IRQ
28 // Attempt to get around a strange bug in Bochs/Qemu by toggling
29 // the controller on and off
31 outb(0x61, temp | 0x80);
32 outb(0x61, temp & 0x7F);
33 inb(0x60); // Clear keyboard buffer
37 void KBC8042_KeyboardHandler(int IRQ, void *Ptr)
39 Uint8 scancode = inb(0x60);
40 KB_HandleScancode( scancode );
43 void KBC8042_MouseHandler(int IRQ, void *Ptr)
45 PS2Mouse_HandleInterrupt( inb(0x60) );
48 void KBC8042_SetLEDs(Uint8 leds)
50 while( inb(0x64) & 2 ); // Wait for bit 2 to unset
51 outb(0x60, 0xED); // Send update command
53 while( inb(0x64) & 2 ); // Wait for bit 2 to unset
57 void KBC8042_EnableMouse(void)
60 Log_Log("8042", "Enabling Mouse...");
63 KBC8042_SendDataAlt(0xA8);
65 // Enable AUX PS/2 (Compaq Status Byte)
66 KBC8042_SendDataAlt(0x20); // Send Command
67 status = KBC8042_ReadData(); // Get Status
68 status &= ~0x20; // Clear "Disable Mouse Clock"
69 status |= 0x02; // Set IRQ12 Enable
70 KBC8042_SendDataAlt(0x60); // Send Command
71 KBC8042_SendData(status); // Set Status
73 //mouseSendCommand(0xF6); // Set Default Settings
74 KBC8042_SendMouseCommand(0xF4); // Enable Packets
77 static inline void KBC8042_SendDataAlt(Uint8 data)
80 while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear
81 outb(0x64, data); // Send Command
83 static inline void KBC8042_SendData(Uint8 data)
86 while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear
87 outb(0x60, data); // Send Command
89 static inline Uint8 KBC8042_ReadData(void)
92 while( timeout-- && (inb(0x64) & 1) == 0); // Wait for Flag to set
95 static inline void KBC8042_SendMouseCommand(Uint8 cmd)
97 KBC8042_SendDataAlt(0xD4);
98 KBC8042_SendData(cmd);