From 36de2495d62c1652236ac1ffcba46b0b12ddabeb Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Sat, 6 Aug 2022 20:03:12 +0200 Subject: keymap --- kernel/src/devices/keyboard.c | 75 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'kernel/src/devices/keyboard.c') diff --git a/kernel/src/devices/keyboard.c b/kernel/src/devices/keyboard.c index 105c3a8..bf4948d 100644 --- a/kernel/src/devices/keyboard.c +++ b/kernel/src/devices/keyboard.c @@ -1,13 +1,62 @@ #include +#include + #include #include #include #include +#include #define KEYBOARD_DATA_PORT 0x60 #define KEYBOARD_STATUS_PORT 0x64 -uint8_t i = 0; +static uint32_t x; +static uint32_t y; +bool is_pressed[128]; + +uint32_t strlen(const char *s); + +uint32_t stoi(const char *s) +{ + static uint32_t num; + uint32_t s_len = strlen(s); + + for (int i = s_len - 1; i >= 0; i--) { + num += s[i] - '0'; + } + + return num; +} + +void itos(uint32_t num, char** s) +{ + uint32_t i; + for (i = 0; num; num/=10, i++) { + *s[i] = num%10 - '0'; + } + *s[i] = '\0'; +} + +void print_char(char c) +{ + if (x * 8 >= fb.width) { + x = 0; + y++; + } + if (y * 16 >= fb.height) { + x = 0; + y = 0; + } + fb_draw_character(fb, c, x * 8, y * 16, WHITE, BLACK); + x++; +} + +void print_string(char* s) +{ + for (uint32_t i = 0; i < strlen(s); i++) { + print_char(s[i]); + } +} void keyboard_handler(void) { @@ -16,5 +65,27 @@ void keyboard_handler(void) return; } uint8_t keycode = inb(KEYBOARD_DATA_PORT); - fb_draw_character(fb, keycode, 0, 0, RED, BLACK); + if (keycode < keymap_len) { + is_pressed[keycode] = true; + if (keycode == KEY_SPACE) { + print_char(' '); + + } else if (keycode == KEY_BACKSPACE) { + if (!x) return; + x--; + print_char(' '); + x--; + } else if (keycode == KEY_ENTER) { + x = 0; + y++; + } else { + if (keymap[keycode] == ' ') return; + if (is_pressed[KEY_LSHIFT] || is_pressed[KEY_RSHIFT]) + print_char(shift_keymap[keycode]); + else + print_char(keymap[keycode]); + } + } else { + is_pressed[keycode - 128] = false; + } } -- cgit v1.2.3