half assed keyboard driver yippegit add .git add .git add .git add .git add .git add .git add .git add .git add .git add .git add .git add .!
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
|
||||
global loader ; entry symbol for ELF
|
||||
extern kmain
|
||||
extern gdt_init
|
||||
|
||||
MAGIC_NUMBER equ 0x1BADB002 ; magic number constant
|
||||
FLAGS equ 0x3
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <kernel/x86/idt.h>
|
||||
#include <kernel/x86/pic.h>
|
||||
#include <kernel/x86/io.h>
|
||||
#include <kernel/x86/keyb.h>
|
||||
|
||||
__attribute__((aligned(0x10)))
|
||||
static idt_entry_t idt[256];
|
||||
@ -27,9 +28,13 @@ void exception_handler(unsigned int i)
|
||||
|
||||
if (i == PIC_KEYB) {
|
||||
#ifdef __TESTING__
|
||||
kinfo("Sending EOI instruction to KEYB");
|
||||
//kinfo("Sending EOI instruction to KEYB");
|
||||
#endif
|
||||
printf("Scancode: %x\n", inb(0x60)); // read from kb
|
||||
unsigned char in = inb(0x60);
|
||||
char to_print = decode_key_enum(decode_scancode(in));
|
||||
if (to_print != '\0')
|
||||
printf("%c", to_print);
|
||||
|
||||
/**
|
||||
* TODO: this is a cute temporary fix but lets do a real keyboard driver please?
|
||||
*/
|
||||
|
125
kernel/arch/io/keyb.c
Normal file
125
kernel/arch/io/keyb.c
Normal file
@ -0,0 +1,125 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <kernel/x86/keyb.h>
|
||||
|
||||
bool is_shift_down = false;
|
||||
|
||||
|
||||
kb_key_press_t decode_scancode(uint8_t scancode)
|
||||
{return (kb_key_press_t) scancode;}
|
||||
|
||||
// TODO: check the shift scan code as a boolean, if yes ... blah blah
|
||||
|
||||
char decode_key_enum(kb_key_press_t keycode)
|
||||
{
|
||||
switch(keycode) {
|
||||
case KEY_Q:
|
||||
return (is_shift_down) ? 'Q' : 'q';
|
||||
case KEY_W:
|
||||
return (is_shift_down) ? 'W' : 'w';
|
||||
case KEY_E:
|
||||
return (is_shift_down) ? 'E' : 'e';
|
||||
case KEY_R:
|
||||
return (is_shift_down) ? 'R' : 'r';
|
||||
case KEY_T:
|
||||
return (is_shift_down) ? 'T' : 't';
|
||||
case KEY_Y:
|
||||
return (is_shift_down) ? 'Y' : 'y';
|
||||
case KEY_U:
|
||||
return (is_shift_down) ? 'U' : 'u';
|
||||
case KEY_I:
|
||||
return (is_shift_down) ? 'I' : 'i';
|
||||
case KEY_O:
|
||||
return (is_shift_down) ? 'O' : 'o';
|
||||
case KEY_P:
|
||||
return (is_shift_down) ? 'P' : 'p';
|
||||
case KEY_A:
|
||||
return (is_shift_down) ? 'A' : 'a';
|
||||
case KEY_S:
|
||||
return (is_shift_down) ? 'S' : 's';
|
||||
case KEY_D:
|
||||
return (is_shift_down) ? 'D' : 'd';
|
||||
case KEY_F:
|
||||
return (is_shift_down) ? 'F' : 'f';
|
||||
case KEY_G:
|
||||
return (is_shift_down) ? 'G' : 'g';
|
||||
case KEY_H:
|
||||
return (is_shift_down) ? 'H' : 'h';
|
||||
case KEY_J:
|
||||
return (is_shift_down) ? 'J' : 'j';
|
||||
case KEY_K:
|
||||
return (is_shift_down) ? 'K' : 'k';
|
||||
case KEY_L:
|
||||
return (is_shift_down) ? 'L' : 'l';
|
||||
case KEY_Z:
|
||||
return (is_shift_down) ? 'Z' : 'z';
|
||||
case KEY_X:
|
||||
return (is_shift_down) ? 'X' : 'x';
|
||||
case KEY_C:
|
||||
return (is_shift_down) ? 'C' : 'c';
|
||||
case KEY_V:
|
||||
return (is_shift_down) ? 'V' : 'v';
|
||||
case KEY_B:
|
||||
return (is_shift_down) ? 'B' : 'b';
|
||||
case KEY_N:
|
||||
return (is_shift_down) ? 'N' : 'n';
|
||||
case KEY_M:
|
||||
return (is_shift_down) ? 'M' : 'm';
|
||||
case KEY_1:
|
||||
return (is_shift_down) ? '!' : '1';
|
||||
case KEY_2:
|
||||
return (is_shift_down) ? '@' : '2';
|
||||
case KEY_3:
|
||||
return (is_shift_down) ? '#' : '3';
|
||||
case KEY_4:
|
||||
return (is_shift_down) ? '$' : '4';
|
||||
case KEY_5:
|
||||
return (is_shift_down) ? '%' : '5';
|
||||
case KEY_6:
|
||||
return (is_shift_down) ? '^' : '6';
|
||||
case KEY_7:
|
||||
return (is_shift_down) ? '&' : '7';
|
||||
case KEY_8:
|
||||
return (is_shift_down) ? '*' : '8';
|
||||
case KEY_9:
|
||||
return (is_shift_down) ? '(' : '9';
|
||||
case KEY_0:
|
||||
return (is_shift_down) ? ')' : '0';
|
||||
case KEY_MINUS:
|
||||
return (is_shift_down) ? '_' : '-';
|
||||
case KEY_EQUALS:
|
||||
return (is_shift_down) ? '=' : '+';
|
||||
case KEY_LEFT_BRACKET:
|
||||
return (is_shift_down) ? '{' : '[';
|
||||
case KEY_RIGHT_BRACKET:
|
||||
return (is_shift_down) ? '}' : ']';
|
||||
case KEY_BACKSLASH:
|
||||
return (is_shift_down) ? '|' : '\\';
|
||||
case KEY_SEMICOLON:
|
||||
return (is_shift_down) ? ':' : ';';
|
||||
case KEY_SINGLE_QUOTE:
|
||||
return (is_shift_down) ? '\"' : '\'';
|
||||
case KEY_COMMA:
|
||||
return (is_shift_down) ? '<' : ',';
|
||||
case KEY_PERIOD:
|
||||
return (is_shift_down) ? '>' : '.';
|
||||
case KEY_FORWARDSLASH:
|
||||
return (is_shift_down) ? '?' : '/';
|
||||
case KEY_BACK_TICK:
|
||||
return (is_shift_down) ? '~' : '`';
|
||||
case KEY_ENTER:
|
||||
return '\n';
|
||||
case KEY_SPACE:
|
||||
return ' ';
|
||||
case KEY_LEFT_SHIFT:
|
||||
case KEY_RIGHT_SHIFT:
|
||||
is_shift_down = true;
|
||||
return '\0';
|
||||
case KEY_LEFT_SHIFT_R:
|
||||
case KEY_RIGHT_SHIFT_R:
|
||||
is_shift_down = false;
|
||||
return '\0'; // TODO: should i send a character on a no op key?
|
||||
default:
|
||||
return '\0';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user