summaryrefslogtreecommitdiff
path: root/kernel/src/devices
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/devices')
-rw-r--r--kernel/src/devices/keyboard.c41
-rw-r--r--kernel/src/devices/timer.c27
2 files changed, 57 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);
}
diff --git a/kernel/src/devices/timer.c b/kernel/src/devices/timer.c
new file mode 100644
index 0000000..1291219
--- /dev/null
+++ b/kernel/src/devices/timer.c
@@ -0,0 +1,27 @@
+#include <timer.h>
+#include <libk/stdio.h>
+#include <io.h>
+
+uint32_t tick = 0;
+uint32_t seconds = 0;
+
+void timer_handler()
+{
+ tick++;
+ if (tick > TICKS_PER_SECOND) {
+ tick = 0;
+ seconds++;
+ }
+}
+
+void init_timer(uint32_t frequency)
+{
+ uint32_t divisor = 1193180 / frequency;
+ outb(0x43, 0x36);
+
+ uint8_t l = (uint8_t)(divisor & 0xFF);
+ uint8_t h = (uint8_t)((divisor>>8) & 0xFF);
+
+ outb(0x40, l);
+ outb(0x40, h);
+}