#include #include #include "keyus.h" #include "../irq/irq.h" extern void reboot(); const char kbdus_map[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t', '`', 0, 0, 0, 0, 0, 0, 'q', '1', 0, 0, 0, 'z', 's', 'a', 'w', '2', 0, 0, 'c', 'x', 'd', 'e', '4', '3', 0, 0, ' ', 'v', 'f', 't', 'r', '5', 0, 0, 'n', 'b', 'h', 'g', 'y', '6', 0, 0, 0, 'm', 'j', 'u', '7', '8', 0, 0, ',', 'k', 'i', 'o', '0', '9', 0, 0, '.', '/', 'l', ';', 'p', '-', 0, 0, 0, '\'', 0, '[', '=', 0, 0, 0, '\n', '\n', ']', 0, '\\', 0, 0, 0, 0, 0x7F, 0, 0, 0, '\b', 0, 0, '1', '/', '4', '7', 0, 0, 0, '0', '.', '2', '5', '6', '8', 0, 0, 0, '+', '3', '-', '*', '9', 0, 0 }; const char kbdus_map_shift[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t', '~', 0, 0, 0, 0, 0, 0, 'Q', '!', 0, 0, 0, 'Z', 'S', 'A', 'W', '@', 0, 0, 'C', 'X', 'D', 'E', '$', '#', 0, 0, ' ', 'V', 'F', 'T', 'R', '%', 0, 0, 'N', 'B', 'H', 'G', 'Y', '^', 0, 0, 0, 'M', 'J', 'U', '&', '*', 0, 0, '<', 'K', 'I', 'O', ')', '(', 0, 0, '>', '?', 'L', ':', 'P', '_', 0, 0, 0, '\"', 0, '{', '+', 0, 0, 0, '\n', '\n', '}', 0, '|', 0, 0, 0, 0, 0x7F, 0, 0, 0, '\b', 0, 0, '1', '/', '4', '7', 0, 0, 0, '0', '.', '2', '5', '6', '8', 0, 0, 0, '+', '3', '-', '*', '9', 0, 0 }; volatile unsigned char kb_array[16]; volatile unsigned char kb_newdata; volatile unsigned char kb_modifier_status; volatile unsigned char kb_prefix; volatile unsigned char kb_lights_status; unsigned char kb_scancode_set; void i86_kb_set_key(unsigned char scancode, unsigned char val) { unsigned char pos = scancode/8; unsigned char offset = scancode%8; if (val) { kb_array[pos] |= 1<3 || delay>31) return; unsigned char out = rate<<5 | delay; while ((inportb(0x64)&2) != 0); outportb(0x60, 0xF3); while ((inportb(0x64)&2) != 0); outportb(0x60, out); } /*************************************** * Set keyboard LEDs * *************************************** +-----------+-------+-------+--------+ | Bits 7-3 | Bit 2 | Bit 1 | Bit 0 | | 0 | Caps | Num | Scroll | |(reserved) | lock | lock | lock | +-----------+-------+-------+--------+ ***************************************/ void i86_kb_set_LEDs(unsigned char status) { while ((inportb (0x64)&2)!=0); outportb (0x60, 0xED); while ((inportb (0x64)&2)!=0); outportb (0x60, status); } /*************************************** * Set scancode set * *************************************** 0 Get current scancode set 1 Set to scancode set 1 2 Set to scancode set 2 3 Set to scancode set 3 ***************************************/ void i86_kb_set_scancodeset(unsigned char set) { if (set>3) return; while ((inportb (0x64)&2)!=0); outportb (0x60, 0xF0); while ((inportb (0x64)&2)!=0); outportb (0x60, set); kb_scancode_set = set; } unsigned char i86_kb_get_scancodeset() { return kb_scancode_set; } void i86_kb_waitin() { int fail_safe=200000; while ((inportb(0x64)&2)!=0 && fail_safe>0) fail_safe--; } void i86_kb_waitout() { int fail_safe=200000; while ((inportb(0x64)&1)==0 && fail_safe>0) fail_safe--; } void i86_kb_install_partone() { i86_irq_install_handler(1, i86_kb_handler);// instali handler i86_kb_waitin(); outportb(0x60, 0xFF); // Reset kb // Initialize variables kb_newdata = 0; kb_modifier_status = 0; kb_prefix = 0; kb_lights_status = 0; kb_scancode_set = 0; } int i86_kb_install_parttwo() { int ret = 0; // Wait for BAT test results unsigned char temp; do temp = inportb(0x60); while (temp!=0xAA && temp!=0xFC); if (temp == 0xFC) ret = -1; // Set new repeat rate i86_kb_set_repeat(1, 11); // Set scancode set 2 i86_kb_set_scancodeset(2); // Set new scancode set i86_kb_waitin(); outportb(0x64, 0x20); // Get "Command unsigned char" do { temp = inportb(0x60); } while (temp==0xFA || temp==0xAA); temp &= 0xFF - (1<<6); // Set bit6 to 0: disable conversion i86_kb_waitin(); outportb(0x64, 0x60); // Function to write cmd unsigned char i86_kb_waitin(); outportb(0x60, temp); // Send it memset((void*)kb_array, 0, 16); return ret; }