2024-11-16 14:51:55 -06:00
|
|
|
.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
|
2024-11-17 04:17:32 -06:00
|
|
|
.{bit0, bit5, bit6, bit7} := @use("bits.hb");
|
|
|
|
.{Port, port_at_startup} := @use("port.hb")
|
2024-11-16 15:56:00 -06:00
|
|
|
|
|
|
|
$disable_port1 := fn(): void memory.outb(0x64, 0xAD)
|
|
|
|
$enable_port1 := fn(): void memory.outb(0x64, 0xAE)
|
|
|
|
$disable_port2 := fn(): void memory.outb(0x64, 0xA7)
|
|
|
|
$enable_port2 := fn(): void memory.outb(0x64, 0xA8)
|
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
test_port1 := fn(): bool {
|
|
|
|
memory.outb(0x64, 0xAB)
|
|
|
|
loop if has_input(get_info()) break
|
|
|
|
input := get_input()
|
|
|
|
return input == 0x0
|
|
|
|
}
|
2024-11-16 15:56:00 -06:00
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
test_port2 := fn(): bool {
|
|
|
|
memory.outb(0x64, 0xA9)
|
|
|
|
loop if has_input(get_info()) break
|
|
|
|
input := get_input()
|
|
|
|
return input == 0x0
|
|
|
|
}
|
2024-11-16 15:56:00 -06:00
|
|
|
|
|
|
|
get_config_byte := fn(): u8 {
|
2024-11-17 04:17:32 -06:00
|
|
|
memory.outb(0x64, 0x20)
|
2024-11-16 15:56:00 -06:00
|
|
|
loop if has_input(get_info()) break
|
2024-11-17 04:17:32 -06:00
|
|
|
return get_input()
|
2024-11-16 15:56:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Info := struct {d: u8}
|
|
|
|
|
|
|
|
$get_info := fn(): u8 return .(memory.inb(0x64))
|
|
|
|
$has_input := fn(info: Info): bool return bit0(info.d)
|
2024-11-17 04:17:32 -06:00
|
|
|
$timed_out := fn(info: Info): bool return bit6(info.d)
|
|
|
|
$check_parity := fn(info: Info): bool return bit7(info.d)
|
|
|
|
get_port := fn(info: Info): ^Port {
|
|
|
|
if bit5(info.d) {
|
|
|
|
return &port2
|
|
|
|
} else {
|
|
|
|
return &port1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$get_input := fn(): u8 return memory.inb(0x60)
|
|
|
|
$write_out := fn(data: u8): void memory.outb(0x60, data)
|
2024-11-16 15:56:00 -06:00
|
|
|
|
|
|
|
flush_input := fn(): void {
|
2024-11-17 04:17:32 -06:00
|
|
|
loop if has_input(get_info()) == false break else get_info()
|
2024-11-16 15:56:00 -06:00
|
|
|
}
|
2024-11-16 14:51:55 -06:00
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
port1 := port_at_startup
|
|
|
|
port2 := port_at_startup
|
|
|
|
|
2024-11-16 14:51:55 -06:00
|
|
|
init := fn(): void {
|
2024-11-16 15:56:00 -06:00
|
|
|
disable_port1()
|
|
|
|
disable_port2()
|
2024-11-16 14:51:55 -06:00
|
|
|
//Disables ports to make sure that they won't interfere with the setup process.
|
|
|
|
|
2024-11-16 15:56:00 -06:00
|
|
|
flush_input()
|
2024-11-16 14:51:55 -06:00
|
|
|
|
2024-11-16 15:56:00 -06:00
|
|
|
enable_port2()
|
2024-11-17 04:17:32 -06:00
|
|
|
port2.exists = bit5(@inline(get_config_byte)) == false
|
2024-11-16 15:56:00 -06:00
|
|
|
disable_port2()
|
2024-11-16 14:51:55 -06:00
|
|
|
|
2024-11-16 15:56:00 -06:00
|
|
|
flush_input()
|
2024-11-16 14:51:55 -06:00
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
port1.exists = test_port1()
|
2024-11-16 14:51:55 -06:00
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
if port2.exists {
|
|
|
|
port2.exists = test_port2()
|
2024-11-16 14:51:55 -06:00
|
|
|
}
|
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
if (port1.exists | port2.exists) == false {
|
2024-11-16 14:51:55 -06:00
|
|
|
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
|
|
|
|
}
|
|
|
|
|
2024-11-17 04:17:32 -06:00
|
|
|
if port1.exists {
|
2024-11-16 14:51:55 -06:00
|
|
|
log.info("Port 1 exists.\0")
|
2024-11-16 15:56:00 -06:00
|
|
|
enable_port1()
|
2024-11-17 04:17:32 -06:00
|
|
|
port1.commands.length = 1
|
2024-11-16 14:51:55 -06:00
|
|
|
}
|
2024-11-17 04:17:32 -06:00
|
|
|
if port2.exists {
|
2024-11-16 14:51:55 -06:00
|
|
|
log.info("Port 2 exists.\0")
|
2024-11-16 15:56:00 -06:00
|
|
|
enable_port2()
|
2024-11-17 04:17:32 -06:00
|
|
|
port2.commands.length = 1
|
2024-11-16 14:51:55 -06:00
|
|
|
}
|
|
|
|
}
|