ableos/sysdata/programs/ps2_keyboard_driver/src/main.hb

40 lines
759 B
Plaintext
Raw Normal View History

2024-11-11 01:23:14 -06:00
stn := @use("../../../libraries/stn/src/lib.hb");
.{memory, log, buffer} := stn
intouch := @use("../../../libraries/intouch/src/lib.hb");
.{KeyEvent} := intouch
2024-09-15 11:01:29 -05:00
send_byte := fn(byte: u8): u8 {
memory.outb(96, byte)
return memory.inb(96)
}
main := fn(): int {
2024-11-11 01:23:14 -06:00
buf := buffer.create("PS/2 Keyboard\0")
2024-11-03 16:31:53 -06:00
_ = send_byte(238)
2024-09-16 14:45:19 -05:00
log.info("PS/2 Driver Loaded\0")
2024-11-11 01:23:14 -06:00
2024-09-16 14:45:19 -05:00
if send_byte(238) == 238 {
log.info("PS/2 Keyboard Echoed\0")
}
2024-11-11 01:23:14 -06:00
2024-09-16 14:45:19 -05:00
if send_byte(244) == 250 {
log.info("Enabled scanning\0")
}
2024-11-11 01:23:14 -06:00
2024-09-16 14:45:19 -05:00
prev_input := 250
loop {
2024-11-11 01:23:14 -06:00
loop if (memory.inb(0x64) & 0x20) == 0x20 break
2024-09-16 14:45:19 -05:00
input := memory.inb(96)
2024-11-11 01:23:14 -06:00
2024-09-16 14:45:19 -05:00
if input == prev_input {
continue
}
prev_input = input
2024-11-11 01:23:14 -06:00
kevent := KeyEvent.(false, true, input)
buffer.write(KeyEvent, &kevent, buf)
2024-09-16 14:45:19 -05:00
}
2024-09-15 11:01:29 -05:00
return 0
}