From 11976b752f13412faf5dbbbfbb383ae057fe7d5e Mon Sep 17 00:00:00 2001 From: peony Date: Sat, 16 Nov 2024 22:56:00 +0100 Subject: [PATCH] PS/2 driver going well (it still doesn't work) --- sysdata/programs/ps2_driver/src/controller.hb | 59 ++++++++++++------- sysdata/programs/ps2_driver/src/devices.hb | 12 ++++ sysdata/programs/ps2_driver/src/port.hb | 2 + 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 sysdata/programs/ps2_driver/src/devices.hb diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 00a83f613..a6826da43 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -1,35 +1,52 @@ .{memory, log} := @use("../../../libraries/stn/src/lib.hb"); -.{bit5} := @use("bits.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 { - memory.outb(0x64, 0xAD) - memory.outb(0x64, 0xA7) + disable_port1() + disable_port2() //Disables ports to make sure that they won't interfere with the setup process. - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. + flush_input() - memory.outb(0x64, 0xA8) - //Enables port 2. - memory.outb(0x64, 0x20) - //Gimme configuration byte. - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = bit5(memory.inb(0x60)) == false - if ports[1].exists { - memory.outb(0x64, 0xA7) - } + enable_port2() + ports[1].exists = bit5(@inline(get_config_byte)) == false + disable_port2() - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. + flush_input() memory.outb(0x64, 0xAB) - loop if (memory.inb(0x64) & 1) == 1 break + 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 (memory.inb(0x64) & 1) == 1 break + loop if has_input(get_info()) break ports[1].exists = memory.inb(0x60) == 0x0 } //Test port 2. @@ -40,14 +57,12 @@ init := fn(): void { if ports[0].exists { log.info("Port 1 exists.\0") - memory.outb(0x64, 0xAE) - //Enables port 1. + enable_port1() ports[0].commands_queued = 1 } if ports[1].exists { log.info("Port 2 exists.\0") - memory.outb(0x64, 0xA8) - //Enables port 2. + enable_port2() ports[1].commands_queued = 1 } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/devices.hb b/sysdata/programs/ps2_driver/src/devices.hb new file mode 100644 index 000000000..db92593af --- /dev/null +++ b/sysdata/programs/ps2_driver/src/devices.hb @@ -0,0 +1,12 @@ +DeviceID := struct {value: u16} + +$Mouse3Button := DeviceID.(0x0) +$MouseScrollwheel := DeviceID.(0x3) +$Mouse5Button := DeviceID.(0x4) +$Spacesaver := DeviceID.(0x84AB) +$Keyboard122Key := DeviceID.(0x86AB) +$KeyboardJapaneseG := DeviceID.(0x90AB) +$KeyboardJapanesep := DeviceID.(0x91AB) +$KeyboardJapaneseA := DeviceID.(0x92AB) +$KeyboardNCDSun := DeviceID.(0xA1AC) +$NoDevice := DeviceID.(0xFFFF) \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 65918402f..1bcc674eb 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -1,3 +1,5 @@ +.{DeviceID} := @use("devices.hb") + Port := struct { exists: bool device: DeviceID