1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/programs/ps2_driver/src/controller.hb

68 lines
1.6 KiB
Plaintext
Raw Normal View History

.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
.{bit0, bit5} := @use("bits.hb")
$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)
//TODO test functions
/*test_port1 := fn(): bool {
}*/
get_config_byte := fn(): u8 {
memory.outb(0x64, 0x20)
loop if has_input(get_info()) break
return memory.inb(0x60)
}
Info := struct {d: u8}
$get_info := fn(): u8 return .(memory.inb(0x64))
$has_input := fn(info: Info): bool return bit0(info.d)
flush_input := fn(): void {
loop if has_input(get_info()) == false break else memory.inb(0x60)
}
init := fn(): void {
disable_port1()
disable_port2()
//Disables ports to make sure that they won't interfere with the setup process.
flush_input()
enable_port2()
ports[1].exists = bit5(@inline(get_config_byte)) == false
disable_port2()
flush_input()
memory.outb(0x64, 0xAB)
loop if has_input(get_info()) break
ports[0].exists = memory.inb(0x60) == 0x0
//Test port 1.
if ports[1].exists {
memory.outb(0x64, 0xA9)
loop if has_input(get_info()) break
ports[1].exists = memory.inb(0x60) == 0x0
}
//Test port 2.
if (ports[0].exists | ports[1].exists) == false {
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
}
if ports[0].exists {
log.info("Port 1 exists.\0")
enable_port1()
ports[0].commands_queued = 1
}
if ports[1].exists {
log.info("Port 2 exists.\0")
enable_port2()
ports[1].commands_queued = 1
}
}