akern-gkgoat-fork/sysdata/programs/ps2_driver/src/main.hb

77 lines
2.1 KiB
Plaintext
Raw Normal View History

2024-11-17 14:30:58 -06:00
.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb")
devices := @use("devices.hb")
2024-11-17 04:17:32 -06:00
controller := @use("controller.hb")
2024-11-15 13:47:11 -06:00
format_page := memory.dangling(u8)
2024-11-10 14:24:19 -06:00
2024-11-17 10:57:06 -06:00
info := controller.Info.(0)
2024-11-17 12:11:13 -06:00
process := fn(port: ^controller.Port): void {
2024-11-17 14:30:58 -06:00
if port.device == devices.MOUSE_3_BUTTON {
} else if port.device == devices.MOUSE_INIT_1 {
port.device.value = port.packet[0] | port.packet[1] << 8
if port.device == devices.MOUSE_SCROLLWHEEL {
port.device = devices.MOUSE_INIT_2
}
} else if port.device == devices.MOUSE_INIT_2 {
port.device.value = port.packet[0] | port.packet[1] << 8
} else if port.device == devices.NO_DEVICE {
if port.packet_length == 1 {
port.device.value = port.packet[0]
} else {
port.device.value = port.packet[1] | port.packet[0] << 8
}
log.info("Identified device!\0")
log.info(string.display_int(port.device.value, format_page, 16))
}
2024-11-17 10:57:06 -06:00
}
check_complete := fn(port: ^controller.Port): bool {
2024-11-17 14:30:58 -06:00
last_value := port.packet[port.packet_length - 1]
if port.device == devices.NO_DEVICE {
if last_value == 0 | last_value == 3 | last_value == 4 {
return true
} else if port.packet_length == 2 {
return true
}
}
if port.device == devices.MOUSE_3_BUTTON {
if port.packet_length == 3 return true
}
if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON {
if port.packet_length == 4 return true
} else {
log.error("Very unexpected error. Cannot handle this!\0")
return true
}
return false
2024-11-17 10:57:06 -06:00
}
2024-11-10 14:24:19 -06:00
main := fn(): void {
2024-11-15 13:47:11 -06:00
format_page = memory.alloc(u8, 1024)
2024-11-17 04:17:32 -06:00
controller.init()
2024-11-17 10:57:06 -06:00
loop {
info = controller.get_info()
if controller.timed_out(info) {
log.error("Timeout error! Cannot handle these!\0")
}
if controller.check_parity(info) {
log.error("Parity error! Cannot handle these!\0")
}
if controller.has_input(info) {
port := controller.get_port(info)
2024-11-17 14:30:58 -06:00
input := controller.get_input()
if input == 0xAA & port.can_hot_plug {
port.device = devices.NO_DEVICE
}
port.packet[port.packet_length] = input
2024-11-17 10:57:06 -06:00
port.packet_length += 1
if @inline(check_complete, port) {
process(port)
}
}
}
2024-11-10 14:24:19 -06:00
}