summaryrefslogtreecommitdiff
path: root/kernel/src/devices/keyboard.c
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2022-08-06 20:03:12 +0200
committerAleksa Vuckovic <aleksav013@gmail.com>2022-08-06 20:03:12 +0200
commit36de2495d62c1652236ac1ffcba46b0b12ddabeb (patch)
tree4c34581841f3bb8f063f0f4769a302aed2d86548 /kernel/src/devices/keyboard.c
parentbd7d4366b6643b5c6cd04f40dd32f5d9c9575fd6 (diff)
keymap
Diffstat (limited to 'kernel/src/devices/keyboard.c')
-rw-r--r--kernel/src/devices/keyboard.c75
1 files changed, 73 insertions, 2 deletions
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 <stdint.h>
+#include <stdbool.h>
+
#include <pic.h>
#include <io.h>
#include <graphics.h>
#include <debug.h>
+#include <keymap.h>
#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;
+ }
}