improvement: kbd_key_read now populates a bit mask containing information about state

This commit is contained in:
shockrah 2019-12-01 02:31:08 -08:00
parent 9be7091faa
commit 58da5af56c
2 changed files with 24 additions and 2 deletions

18
kbd.c
View File

@ -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;
}

8
kbd.h
View File

@ -5,6 +5,14 @@
#define KBD_PORT 0x60
#define KBD_PRESS 0b00000001
#define KBD_RELEASE 0b00000010
#define KBD_SHIFT 0b00000100
char kbd_key;
u8 kbd_state;
u8 kbd_time;
void kbd_install_keyboard(void);
void kbd_read_key(struct cpu_reg_state* cpu);