End meeeee
This commit is contained in:
parent
f11122e58e
commit
3d5a8f6f10
|
@ -1,6 +1,6 @@
|
|||
# Unified PS/2 Driver
|
||||
|
||||
Te entire thing is heavily documented with comments because I'm not sure how else to make this understandable.
|
||||
Te entire thing is held together inspite
|
||||
|
||||
## !!Assumptions!!
|
||||
Anyone who works on this should work to keep this list as small as possible/remove as many of these as possible.
|
||||
|
@ -17,3 +17,6 @@ Anyone who works on this should work to keep this list as small as possible/remo
|
|||
- 0x01xx
|
||||
- 0x03xx
|
||||
- 0x04xx
|
||||
- Literally all PS/2 keyboards can be handeled the exact same way. We have the capability for detecting different keyboard types, I just don't bother with it because that would litreally take months to get working.
|
||||
|
||||
Supporting mice in the keyboard port and vice versa was a ***bad*** idea, but I do not regret it because it means we're "superior" to real world operating systems.
|
|
@ -2,8 +2,8 @@
|
|||
.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb");
|
||||
.{Port, PORT_AT_STARTUP} := @use("port.hb")
|
||||
|
||||
port1 := PORT_AT_STARTUP
|
||||
port2 := PORT_AT_STARTUP
|
||||
port1 := @as(Port, PORT_AT_STARTUP)
|
||||
port2 := @as(Port, PORT_AT_STARTUP)
|
||||
|
||||
$disable_port1 := fn(): void memory.outb(0x64, 0xAD)
|
||||
$enable_port1 := fn(): void memory.outb(0x64, 0xAE)
|
||||
|
@ -47,7 +47,7 @@ get_port := fn(info: Info): ^Port {
|
|||
}
|
||||
|
||||
send_byte := fn(port: ^Port, byte: u8): void {
|
||||
if port == port2 {
|
||||
if port == &port2 {
|
||||
memory.outb(0x64, 0xD4)
|
||||
}
|
||||
loop if can_send(get_info()) break
|
||||
|
|
|
@ -1,19 +1,51 @@
|
|||
.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb")
|
||||
.{memory, log, buffer, string} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{MouseEvent} := @use("../../../libraries/intouch/src/lib.hb").events;
|
||||
.{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb")
|
||||
devices := @use("devices.hb")
|
||||
controller := @use("controller.hb")
|
||||
mouse := @use("mouse.hb")
|
||||
format_page := memory.dangling(u8)
|
||||
|
||||
mouse_buffer := 0
|
||||
keyboard_buffer := 0
|
||||
info := controller.Info.(0)
|
||||
|
||||
process := fn(port: ^controller.Port): void {
|
||||
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
|
||||
send_command := fn(port: ^controller.Port, byte: u8): void {
|
||||
controller.send_byte(port, byte)
|
||||
loop {
|
||||
info = controller.get_info()
|
||||
if controller.has_input(info) == false {
|
||||
continue
|
||||
}
|
||||
input := controller.get_input()
|
||||
if controller.get_port(info) != port {
|
||||
if check_complete(port) == false {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process := fn(port: ^controller.Port): void {
|
||||
if port.device.value < devices.MOUSE_5_BUTTON.value {
|
||||
event := MouseEvent.(0, 0, false, false, false)
|
||||
|
||||
event.left = bit0(port.packet[0])
|
||||
event.right = bit1(port.packet[0])
|
||||
event.middle = bit2(port.packet[0])
|
||||
|
||||
event.x_change = @intcast(port.packet[1])
|
||||
event.y_change = @intcast(port.packet[2])
|
||||
|
||||
buffer.write(MouseEvent, mouse_buffer, &event)
|
||||
} else if port.device == devices.MOUSE_INIT_1 {
|
||||
port.device.value = port.packet[0]
|
||||
if port.device != devices.MOUSE_SCROLLWHEEL {
|
||||
controller.send_byte(port, 0xF4)
|
||||
return
|
||||
}
|
||||
port.device = devices.MOUSE_INIT_2
|
||||
} else if port.device == devices.MOUSE_INIT_2 {
|
||||
port.device.value = port.packet[0] | port.packet[1] << 8
|
||||
port.device.value = port.packet[0]
|
||||
} else if port.device == devices.NO_DEVICE {
|
||||
if port.packet_length == 1 {
|
||||
port.device.value = port.packet[0]
|
||||
|
@ -33,11 +65,9 @@ check_complete := fn(port: ^controller.Port): bool {
|
|||
} else if port.packet_length == 2 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if port.device == devices.MOUSE_3_BUTTON {
|
||||
} else 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 {
|
||||
} else 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")
|
||||
|
@ -47,6 +77,7 @@ check_complete := fn(port: ^controller.Port): bool {
|
|||
}
|
||||
|
||||
main := fn(): void {
|
||||
mouse_buffer = buffer.create("PS/2 Mouse\0")
|
||||
format_page = memory.alloc(u8, 1024)
|
||||
|
||||
controller.init()
|
||||
|
@ -63,14 +94,18 @@ main := fn(): void {
|
|||
|
||||
if controller.has_input(info) {
|
||||
port := controller.get_port(info)
|
||||
if port.packet_length > 0 & check_complete(port) {
|
||||
process(port)
|
||||
}
|
||||
input := controller.get_input()
|
||||
if input == 0xAA & port.can_hot_plug {
|
||||
port.device = devices.NO_DEVICE
|
||||
}
|
||||
port.packet[port.packet_length] = input
|
||||
port.packet_length += 1
|
||||
if @inline(check_complete, port) {
|
||||
if check_complete(port) {
|
||||
process(port)
|
||||
port.packet_length = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
|
@ -0,0 +1,21 @@
|
|||
Button := struct {id: u8}
|
||||
$LEFT_BUTTON := Button.(1)
|
||||
$RIGHT_BUTTON := Button.(2)
|
||||
$MIDDLE_BUTTON := Button.(4)
|
||||
$BUTTON4 := Button.(8)
|
||||
$BUTTON5 := Button.(16)
|
||||
|
||||
SampleRate := struct {value: u8}
|
||||
$SR10 := SampleRate.(10)
|
||||
$SR20 := SampleRate.(20)
|
||||
$SR40 := SampleRate.(40)
|
||||
$SR60 := SampleRate.(60)
|
||||
$SR80 := SampleRate.(80)
|
||||
$SR100 := SampleRate.(100)
|
||||
$SR200 := SampleRate.(200)
|
||||
|
||||
Resolution := struct {value: u8}
|
||||
$RES_1COUNT_PER_MM := Resolution.(0)
|
||||
$RES_2COUNT_PER_MM := Resolution.(1)
|
||||
$RES_4COUNT_PER_MM := Resolution.(2)
|
||||
$RES_8COUNT_PER_MM := Resolution.(3)
|
|
@ -15,7 +15,7 @@ Port := packed struct {
|
|||
$PORT_AT_STARTUP := Port.(
|
||||
true,
|
||||
NO_DEVICE,
|
||||
.(0, 0, 0, 0),
|
||||
.(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
0,
|
||||
true,
|
||||
)
|
Loading…
Reference in a new issue