Add: read keyboard input (getch)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user