diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 36272c2..b43f5e9 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/os.iso b/os.iso index 390cb51..6d4fd1d 100644 Binary files a/os.iso and b/os.iso differ diff --git a/src/kernel/kb.c b/src/kernel/kb.c index 3152868..437d0d8 100644 --- a/src/kernel/kb.c +++ b/src/kernel/kb.c @@ -2,6 +2,8 @@ #include "../libc/stdio.h" #include "system.h" +#define KEYBOARD_BUFFER_SIZE 256 + unsigned char kbdus[128] = { 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */ @@ -42,6 +44,10 @@ unsigned char kbdus[128] = 0, /* All other keys are undefined */ }; +static char keyboard_buffer[KEYBOARD_BUFFER_SIZE]; +static unsigned int keyboard_buffer_start = 0; +static unsigned int keyboard_buffer_end = 0; + void keyboard_handler() { unsigned char scancode; @@ -53,7 +59,12 @@ void keyboard_handler() } else { - putc(kbdus[scancode]); + char c = kbdus[scancode]; + if (c) + { + keyboard_buffer[keyboard_buffer_end] = c; + keyboard_buffer_end = (keyboard_buffer_end+1) % KEYBOARD_BUFFER_SIZE; + } } } @@ -61,3 +72,12 @@ void keyboard_install() { irq_install_handler(1, keyboard_handler); } + +char keyboard_getchar() +{ + while (keyboard_buffer_start == keyboard_buffer_end); + + char c = keyboard_buffer[keyboard_buffer_start]; + keyboard_buffer_start = (keyboard_buffer_start+1) % KEYBOARD_BUFFER_SIZE; + return c; +} diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index 5edeba0..110be8b 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -4,6 +4,8 @@ #include "idt.h" #include "system.h" +#define BUFFER_SIZE 256 + int kmain(int retvalue) { @@ -29,8 +31,13 @@ int kmain(int retvalue) // TODO: Fix scrolling bug (framebuffer driver) // TODO: Fix keyboard driver bug (some keys mapped weirdly) + add suport for SHIFT and backspace (deleting character) // TODO: Grub modules to load programs - //timer_install(); keyboard_install(); + + char input_buffer[BUFFER_SIZE]; + colorputs("Enter something: ", 9); + get_input(input_buffer, BUFFER_SIZE); + printf("\nYou entered: %s\n", input_buffer); + return retvalue; } diff --git a/src/kernel/system.h b/src/kernel/system.h index fc459fc..0b436e3 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -20,5 +20,6 @@ void irq_uninstall_handler(int irq); void timer_install(); void delay(int ticks); void keyboard_install(); +char keyboard_getchar(); #endif diff --git a/src/libc/stdio.c b/src/libc/stdio.c index f4d8994..4468acb 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -2,6 +2,7 @@ #include "stdio.h" #include "string.h" #include "stdint.h" +#include "../kernel/system.h" char* fb = (char *) 0x000B8000; const unsigned VGA_WIDTH = 80; @@ -335,3 +336,23 @@ int* printf_number(int* argp, int length, bool sign, int radix) return argp; } + +int getch() +{ + return keyboard_getchar(); +} + +void get_input(char *buffer, int size) { + int index = 0; + char c; + + while (index < size-1) + { + c = getch(); + if (c == '\n') break; + + buffer[index++] = c; + putc(c); + } + buffer[index] = '\0'; +} \ No newline at end of file diff --git a/src/libc/stdio.h b/src/libc/stdio.h index c89d3fc..7337340 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -37,5 +37,7 @@ void colorputc(char c, unsigned int color); void printf(const char* fmt, ...); int* printf_number(int* argp, int length, bool sign, int radix); +int getch(); +void get_input(char *buffer, int size); #endif