Litrally almost functional PS/2 driver. #19
|
@ -1,31 +1,56 @@
|
|||
.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{bit0, bit5} := @use("bits.hb")
|
||||
.{bit0, bit5, bit6, bit7} := @use("bits.hb");
|
||||
.{Port, port_at_startup} := @use("port.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 {
|
||||
test_port1 := fn(): bool {
|
||||
memory.outb(0x64, 0xAB)
|
||||
loop if has_input(get_info()) break
|
||||
input := get_input()
|
||||
return input == 0x0
|
||||
}
|
||||
|
||||
}*/
|
||||
test_port2 := fn(): bool {
|
||||
memory.outb(0x64, 0xA9)
|
||||
loop if has_input(get_info()) break
|
||||
input := get_input()
|
||||
return input == 0x0
|
||||
}
|
||||
|
||||
get_config_byte := fn(): u8 {
|
||||
memory.outb(0x64, 0x20)
|
||||
memory.outb(0x64, 0x20)
|
||||
loop if has_input(get_info()) break
|
||||
return memory.inb(0x60)
|
||||
return get_input()
|
||||
}
|
||||
|
||||
Info := struct {d: u8}
|
||||
|
||||
$get_info := fn(): u8 return .(memory.inb(0x64))
|
||||
$has_input := fn(info: Info): bool return bit0(info.d)
|
||||
$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)
|
||||
|
||||
flush_input := fn(): void {
|
||||
loop if has_input(get_info()) == false break else memory.inb(0x60)
|
||||
loop if has_input(get_info()) == false break else get_info()
|
||||
}
|
||||
|
||||
port1 := port_at_startup
|
||||
port2 := port_at_startup
|
||||
|
||||
init := fn(): void {
|
||||
disable_port1()
|
||||
disable_port2()
|
||||
|
@ -34,35 +59,29 @@ init := fn(): void {
|
|||
flush_input()
|
||||
|
||||
enable_port2()
|
||||
ports[1].exists = bit5(@inline(get_config_byte)) == false
|
||||
port2.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.
|
||||
port1.exists = test_port1()
|
||||
|
||||
if ports[1].exists {
|
||||
memory.outb(0x64, 0xA9)
|
||||
loop if has_input(get_info()) break
|
||||
ports[1].exists = memory.inb(0x60) == 0x0
|
||||
if port2.exists {
|
||||
port2.exists = test_port2()
|
||||
}
|
||||
//Test port 2.
|
||||
|
||||
if (ports[0].exists | ports[1].exists) == false {
|
||||
if (port1.exists | port2.exists) == false {
|
||||
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
|
||||
}
|
||||
|
||||
if ports[0].exists {
|
||||
if port1.exists {
|
||||
log.info("Port 1 exists.\0")
|
||||
enable_port1()
|
||||
ports[0].commands_queued = 1
|
||||
port1.commands.length = 1
|
||||
}
|
||||
if ports[1].exists {
|
||||
if port2.exists {
|
||||
log.info("Port 2 exists.\0")
|
||||
enable_port2()
|
||||
ports[1].commands_queued = 1
|
||||
port2.commands.length = 1
|
||||
}
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb")
|
||||
controller := @use("controller.hb")
|
||||
format_page := memory.dangling(u8)
|
||||
|
||||
main := fn(): void {
|
||||
format_page = memory.alloc(u8, 1024)
|
||||
|
||||
controller.init()
|
||||
}
|
|
@ -105,7 +105,7 @@ main := fn(): void {
|
|||
|
||||
loop {
|
||||
port_info := memory.inb(0x64)
|
||||
//Enables port 1.
|
||||
|
||||
if (port_info & 0x40) > 0 {
|
||||
log.error("Timeout error! Cannot handle these!\0")
|
||||
}
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
.{DeviceID} := @use("devices.hb")
|
||||
.{DeviceID, NoDevice} := @use("devices.hb")
|
||||
|
||||
Port := struct {
|
||||
exists: bool
|
||||
device: DeviceID
|
||||
commands_queued: u8
|
||||
command_queue: [u8; 8]
|
||||
command_index: u8
|
||||
awaiting_acks: u8
|
||||
state: State
|
||||
expecting: bool
|
||||
}
|
||||
State := struct {s: u8}
|
||||
$Reboot := State.(0)
|
||||
|
||||
CommandQueue := packed struct {queue: [u8; 8], length: u8, current_index: u8}
|
||||
|
||||
Port := packed struct {
|
||||
exists: bool,
|
||||
device: DeviceID,
|
||||
commands: CommandQueue,
|
||||
state: State,
|
||||
}
|
||||
|
||||
$port_at_startup := Port.(
|
||||
true,
|
||||
NoDevice,
|
||||
.(.(0xFF, 0, 0, 0, 0, 0, 0, 0), 1, 0),
|
||||
Reboot,
|
||||
)
|
Loading…
Reference in a new issue