/** * Converts keyboard scan codes into ascii chars * by calling scan_to_ascii and extended_scan_to_ascii. * Keeps track of shift, caps lock etc. * * @param keypress the scancode. * * @return the corresponding character. */ int process_scancode(int keypress) { int pressed = !(keypress & 0x80); keypress &= 0x7F; if (key_state & EXTENDED_KEY_PRESS) return extended_scan_to_ascii(keypress, pressed); if (keypress == 0x2A) { /* Shift key. */ if (pressed) key_state |= LSHIFT_KEY_ON; else key_state &= ~LSHIFT_KEY_ON; return -1; } else if (keypress == 0x36) { /* Shift key. */ if (pressed) key_state |= RSHIFT_KEY_ON; else key_state &= ~RSHIFT_KEY_ON; return -1; } else if (keypress == 0x1D) { /* Left control key. */ if (pressed) key_state |= LCONTROL_KEY_ON; else key_state &= ~LCONTROL_KEY_ON; return -1; } else if (keypress == 0x38) { /* Left alt key. */ if (pressed) key_state |= LALT_KEY_ON; else key_state &= ~LALT_KEY_ON; return -1; } else if (keypress == 0x3A) { /* Caps lock. */ if (pressed) { if (key_state & CAPS_LOCK_ON) key_state &= ~CAPS_LOCK_ON; else key_state |= CAPS_LOCK_ON; } return -1; } else if (keypress == 0xE0) { /* Extended key code. Set extended marker. */ key_state |= EXTENDED_KEY_PRESS; return -1; } else { /* It's just a normal key. If it's a release, we don't care about it. */ if (!pressed) return -1; else return scan_to_ascii(keypress); } /* Should never be here! */ return -1; }
extern u32 wait_input (char* buffer) { for (int i = 0; i< 80; i++) input_buffer[i] = 0; input_buffer_cursor = 0; scan_to_ascii (0,W_ENABLE); u8 input = 0x0; while (((input_buffer_cursor) == 0) || (input_buffer [(input_buffer_cursor) -1] != SC_ENTER)) ; scan_to_ascii (0,W_DISABLE); /*|| // (input_buffer[input_buffer_cursor-1] // == SC_ENTER)*/ /* wait input */ // ;// kprintf ("%c", input_buffer[input_buffer_cursor]); memcpy (buffer, input_buffer, input_buffer_cursor-1); buffer [input_buffer_cursor-1] = '\0'; return input_buffer_cursor -1; }
extern void refresh_ps2_controller () { static u8 ignore = 0; while (((INB(I8042_COMMAND)) & 1) == 0) ; u8 c = INB (0x60); if (ignore) { ignore = 0; return; } if (c == 0xE0) { ignore = 1; return; } if (get_type(c) != KEYRELEASED) return; u8 sc = get_scan_code (c); scan_to_ascii (sc, W_NULL); }