summaryrefslogtreecommitdiff
path: root/kernel/src/devices/keyboard.c
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2022-09-01 23:45:47 +0200
committerAleksa Vuckovic <aleksav013@gmail.com>2022-09-01 23:45:47 +0200
commit11ced165e0df11cc3c889eb0cc402467361c421b (patch)
treeba6456fdae72e0deff0130612f226cd5d94aea17 /kernel/src/devices/keyboard.c
parent9a54c41ad07ec00316bb8fcdeba51c215446d454 (diff)
timer & stdbuff
Diffstat (limited to 'kernel/src/devices/keyboard.c')
-rw-r--r--kernel/src/devices/keyboard.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/kernel/src/devices/keyboard.c b/kernel/src/devices/keyboard.c
index f39f978..60f41b8 100644
--- a/kernel/src/devices/keyboard.c
+++ b/kernel/src/devices/keyboard.c
@@ -1,42 +1,61 @@
#include <types.h>
#include <keyboard.h>
-
#include <pic.h>
#include <io.h>
#include <keymap.h>
#include <libk/stdio.h>
#include <libk/math.h>
-
-#define KEYBOARD_DATA_PORT 0x60
-#define KEYBOARD_STATUS_PORT 0x64
+#include <libk/string.h>
bool is_pressed[128];
-void keyboard_handler(void)
+#include <stdbuff.h>
+#include <heap.h>
+#define BUFFER_SIZE 10000
+stdbuff* keyboard_buffer;
+
+void keyboard_handler()
{
+ if (keyboard_buffer == NULL) {
+ keyboard_buffer = init_buff(BUFFER_SIZE);
+ memset(keyboard_buffer->data, ' ', BUFFER_SIZE);
+ }
+
uint8_t status = inb(KEYBOARD_STATUS_PORT);
if (!(status & 0x1)) {
return;
}
+
uint8_t keycode = inb(KEYBOARD_DATA_PORT);
+
if (keycode < keymap_len) {
is_pressed[keycode] = true;
if (keycode == KEY_SPACE) {
- printf(" ");
-
+ write_buff(keyboard_buffer, " ", 1);
} else if (keycode == KEY_BACKSPACE) {
if (curr_x != 0)
- printf("\b \b");
+ write_buff(keyboard_buffer, "\b \b", 3);
} else if (keycode == KEY_ENTER) {
- printf("%c", keymap[keycode]);
+ char* output = kalloc(sizeof(char) + 1);
+ output[0] = keymap[keycode];
+ write_buff(keyboard_buffer, output, 1);
+ kfree(output);
} else {
+ char* output = kalloc(sizeof(char) + 1);
if (keymap[keycode] == ' ') return;
if (is_pressed[KEY_LSHIFT] || is_pressed[KEY_RSHIFT])
- printf("%c", shift_keymap[keycode]);
+ output[0] = shift_keymap[keycode];
else
- printf("%c", keymap[keycode]);
+ output[0] = keymap[keycode];
+ write_buff(keyboard_buffer, output, 1);
+ kfree(output);
}
} else {
is_pressed[keycode - 128] = false;
}
+
+ uint32_t len = (uint32_t)(keyboard_buffer->head - keyboard_buffer->tail);
+ char* print_buff = kalloc(len + 1);
+ read_buff(keyboard_buffer, print_buff, len);
+ printf("%s", print_buff);
}