diff options
author | Marvin Borner | 2019-10-24 22:29:37 +0200 |
---|---|---|
committer | Marvin Borner | 2019-10-24 22:29:37 +0200 |
commit | 707ea2cd052d92ddbdf3ad0f5b0108def8674d31 (patch) | |
tree | c4a192cfa05f2864a750844f2c0fdf68f8b15454 | |
parent | 389554a245cd8660d63e2cf81e6d9ac78bfea04a (diff) |
Added basic VESA keyboard support
-rw-r--r-- | src/kernel/graphics/vesa.c | 45 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.h | 6 | ||||
-rw-r--r-- | src/kernel/input/ps2/keyboard.c | 4 | ||||
-rw-r--r-- | src/kernel/kernel.c | 2 |
4 files changed, 55 insertions, 2 deletions
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index c5a1a1b..3cce570 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -191,6 +191,23 @@ void vesa_set_pixel(uint16_t x, uint16_t y, uint32_t color) { fb[pos + 2] = (color >> 16) & 255; } +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, int color) { + int i, j; + char blue = color & 255; + char green = (color >> 8) & 255; + char red = (color >> 16) & 255; + int pos1 = x1 * vbe_bpp + y1 * vbe_pitch; + char *draw = &fb[pos1]; + for (i = 0; i <= y2 - y1; i++) { + for (j = 0; j <= x2 - x1; j++) { + draw[vbe_bpp * j] = blue; + draw[vbe_bpp * j + 1] = green; + draw[vbe_bpp * j + 2] = red; + } + draw += vbe_pitch; + } +} + void vesa_draw_char(char ch, int x, int y) { int mask[8] = {1, 2, 4, 8, 16, 32, 64, 128}; unsigned char *glyph = font[ch - 32]; @@ -204,6 +221,34 @@ void vesa_draw_char(char ch, int x, int y) { } } +void vesa_keyboard_char(char ch) { + vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 10, terminal_y + 16, 0x0); + + if (ch == 0x08) { + if (terminal_x != 0) terminal_x -= 10; + } else if (ch == 0x09) { + terminal_x += 8 * 10; + } else if (ch == '\r') { + terminal_x = 0; + } else if (ch == '\n') { + terminal_y += 15; + terminal_x = 0; + // terminal_scroll(); + } else if (ch >= ' ') { + vesa_draw_char(ch, terminal_x, terminal_y); + terminal_x += 10; + } + + // Add new line on overflow + if (terminal_x >= vbe_width) { + terminal_x = 0; + terminal_y += 15; + } + + // terminal_scroll(); + vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + 10, terminal_y + 16, terminal_color); +} + void vesa_draw_string(char *data) { vesa_clear(); int i = 0; diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index 039a549..0a8bd60 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -135,6 +135,12 @@ void vbe_set_mode(unsigned short mode); void set_optimal_resolution(); /** + * Draw a char from keyboard + * @param ch + */ +void vesa_keyboard_char(char ch); + +/** * Draw a string in VESA mode * @param ch */ diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c index 262178d..e2fd18f 100644 --- a/src/kernel/input/ps2/keyboard.c +++ b/src/kernel/input/ps2/keyboard.c @@ -1,6 +1,6 @@ #include "../../interrupts/interrupts.h" #include "../../io/io.h" -#include "../../graphics/graphics.h" +#include "../../graphics/vesa.h" char keymap[128] = { 0 /*E*/, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', @@ -38,7 +38,7 @@ void keyboard_handler(struct regs *r) { scan_code = receive_b(0x60); if (!(scan_code & 0x80)) { - terminal_put_keyboard_char(keymap[scan_code]); + vesa_keyboard_char(keymap[scan_code]); } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 6d03b7a..e064f4f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -4,10 +4,12 @@ #include "io/io.h" #include "timer/timer.h" #include "paging/paging.h" +#include "input/input.h" void init() { timer_install(); gdt_install(); + keyboard_install(); initialise_paging(); idt_install(); isrs_install(); |