Best way to implement keyboard buffer?
Posted: Wed Nov 18, 2015 11:39 pm
I have just finished creating a proper keyboard driver for my pmode OS. However, right now I am using a rather kludgy way of putting keys into the buffer, this is the code for my keyboard interrupt handler. The handler is called from an assembly routine which calls this and then iret's:
kbd_buffer is a global variable of type char. What is a better way to implement the buffer? Then, the system call for read() from stdin would be able to remove characters from buffer and shift them around.
Code: Select all
void
kbd_handler(
void)
{
uint8_t status;
int8_t keycode;
status = port_byte_in(KBD_STATUS_PORT);
if (status & 0x01) {
keycode = port_byte_in(KBD_DATA_PORT);
if (keycode < 0) {
return;
}
kbd_buffer = keymap[keycode];
}
port_byte_out(PIC_2_COMMAND, PIC_EOI);
port_byte_out(PIC_1_COMMAND, PIC_EOI);
}