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
|
// US Keyboard layout because 'Murrica
|
||||||
#include "kbd.h"
|
#include "kbd.h"
|
||||||
#include "ports.h"
|
#include "ports.h"
|
||||||
|
#include "pit.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "stlio.h"
|
#include "stlio.h"
|
||||||
@ -49,10 +50,23 @@ unsigned char keymap[128] = {
|
|||||||
|
|
||||||
// Reads one key from the keyboard
|
// Reads one key from the keyboard
|
||||||
void kbd_read_key(struct cpu_reg_state* cpu) {
|
void kbd_read_key(struct cpu_reg_state* cpu) {
|
||||||
u32 scancode = serial_read_byte(KBD_PORT);
|
u8 scancode = serial_read_byte(KBD_PORT);
|
||||||
putch(keymap[scancode]);
|
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) {
|
void kbd_install_keyboard(void) {
|
||||||
init_irq_handler(1, kbd_read_key);
|
init_irq_handler(1, kbd_read_key);
|
||||||
|
kbd_key = '\0';
|
||||||
|
kbd_state = 0;
|
||||||
|
kbd_time = 0;
|
||||||
}
|
}
|
||||||
|
8
kbd.h
8
kbd.h
@ -5,6 +5,14 @@
|
|||||||
|
|
||||||
#define KBD_PORT 0x60
|
#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_install_keyboard(void);
|
||||||
|
|
||||||
void kbd_read_key(struct cpu_reg_state* cpu);
|
void kbd_read_key(struct cpu_reg_state* cpu);
|
||||||
|
Loading…
Reference in New Issue
Block a user