improvement: kbd_key_read now populates a bit mask containing information about state
This commit is contained in:
parent
9be7091faa
commit
58da5af56c
18
kbd.c
18
kbd.c
@ -1,6 +1,7 @@
|
||||
// US Keyboard layout because 'Murrica
|
||||
#include "kbd.h"
|
||||
#include "ports.h"
|
||||
#include "pit.h"
|
||||
#include "serial.h"
|
||||
#include "types.h"
|
||||
#include "stlio.h"
|
||||
@ -49,10 +50,23 @@ unsigned char keymap[128] = {
|
||||
|
||||
// Reads one key from the keyboard
|
||||
void kbd_read_key(struct cpu_reg_state* cpu) {
|
||||
u32 scancode = serial_read_byte(KBD_PORT);
|
||||
putch(keymap[scancode]);
|
||||
u8 scancode = serial_read_byte(KBD_PORT);
|
||||
if(scancode & 0x80) {
|
||||
// Key released
|
||||
kbd_state &= KBD_RELEASE;
|
||||
}
|
||||
else {
|
||||
// Key pressed
|
||||
kbd_key = keymap[scancode & 0x7f]; // clamp to 127 as the max val(gcc is anoying)
|
||||
kbd_state = kbd_state & !KBD_RELEASE & KBD_PRESS;
|
||||
kbd_time = pit_timer_ticks;
|
||||
putch(kbd_key);
|
||||
}
|
||||
}
|
||||
|
||||
void kbd_install_keyboard(void) {
|
||||
init_irq_handler(1, kbd_read_key);
|
||||
kbd_key = '\0';
|
||||
kbd_state = 0;
|
||||
kbd_time = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user