forked from AbleOS/ableos
Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
Able | 6b673bc7e6 |
|
@ -3,7 +3,7 @@ stn := @use("../../../../libraries/stn/src/lib.hb");
|
|||
.{Vec2} := stn.math
|
||||
|
||||
render := @use("../../../../libraries/render/src/lib.hb");
|
||||
.{Surface} := render;
|
||||
.{Surface, Color} := render;
|
||||
.{Font} := render.text
|
||||
|
||||
Label := struct {
|
||||
|
@ -12,6 +12,8 @@ Label := struct {
|
|||
surface: Surface,
|
||||
text: ^u8,
|
||||
text_length: uint,
|
||||
bg: Color,
|
||||
fg: Color,
|
||||
}
|
||||
|
||||
set_label_text := fn(label: Label, text: ^u8): void {
|
||||
|
@ -24,8 +26,8 @@ set_label_text := fn(label: Label, text: ^u8): void {
|
|||
|
||||
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
||||
if label.is_dirty {
|
||||
render.clear(label.surface, render.black)
|
||||
render.put_text(label.surface, font, .(0, 0), render.white, label.text)
|
||||
render.clear(label.surface, label.bg)
|
||||
render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
|
||||
}
|
||||
render.put_surface(surface, label.surface, pos, false)
|
||||
}
|
||||
|
@ -33,6 +35,12 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V
|
|||
new_label := fn(text: ^u8): Label {
|
||||
text_surface := render.new_surface(1024, 20)
|
||||
text_length := string.length(text)
|
||||
label := Label.(3, true, text_surface, text, text_length)
|
||||
label := Label.(3, true, text_surface, text, text_length, render.black, render.white)
|
||||
return label
|
||||
}
|
||||
|
||||
$set_color := fn(label: Label, bg: Color, fg: Color): void {
|
||||
label.bg = bg
|
||||
label.fg = fg
|
||||
label.is_dirty = true
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
# Unified PS/2 Driver
|
||||
|
||||
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.
|
||||
- Bit 5 of the response form 0x64 indicates which port the data is coming from. (Not true on all systems)
|
||||
- A parity or timeout error never occurs.
|
||||
- PS/2 controller exists.
|
||||
- Both PS/2 ports being broken doesn't need handling.
|
||||
- One PS/2 port being broken doesn't need special attention.
|
||||
- PS/2 controller doesn't need to perform a self-check.
|
||||
- These DeviceIDs never exist:
|
||||
- 0xFFFD
|
||||
- 0xFFFE
|
||||
- 0xFFFF
|
||||
- 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.
|
||||
- The device doesn't send any data while we're waiting for an `ACK`.
|
||||
|
||||
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.
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "ps2_driver"
|
||||
authors = ["Peony"]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
|
@ -1,26 +0,0 @@
|
|||
//Do not question.
|
||||
|
||||
$bit0 := fn(value: u8): bool {
|
||||
return (value & 0x1) > 0
|
||||
}
|
||||
$bit1 := fn(value: u8): bool {
|
||||
return (value & 0x2) > 0
|
||||
}
|
||||
$bit2 := fn(value: u8): bool {
|
||||
return (value & 0x4) > 0
|
||||
}
|
||||
$bit3 := fn(value: u8): bool {
|
||||
return (value & 0x8) > 0
|
||||
}
|
||||
$bit4 := fn(value: u8): bool {
|
||||
return (value & 0x10) > 0
|
||||
}
|
||||
$bit5 := fn(value: u8): bool {
|
||||
return (value & 0x20) > 0
|
||||
}
|
||||
$bit6 := fn(value: u8): bool {
|
||||
return (value & 0x40) > 0
|
||||
}
|
||||
$bit7 := fn(value: u8): bool {
|
||||
return (value & 0x80) > 0
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb");
|
||||
.{Port, PORT_AT_STARTUP} := @use("port.hb")
|
||||
|
||||
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)
|
||||
$disable_port2 := fn(): void memory.outb(0x64, 0xA7)
|
||||
$enable_port2 := fn(): void memory.outb(0x64, 0xA8)
|
||||
|
||||
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)
|
||||
loop if has_input(get_info()) break
|
||||
return get_input()
|
||||
}
|
||||
|
||||
Info := struct {d: u8}
|
||||
|
||||
$get_info := fn(): Info return .(memory.inb(0x64))
|
||||
//inline when can
|
||||
has_input := fn(info: Info): bool return bit0(info.d)
|
||||
can_send := fn(info: Info): bool return bit1(info.d) == false
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
send_byte := fn(port: ^Port, byte: u8): void {
|
||||
if port == &port2 {
|
||||
memory.outb(0x64, 0xD4)
|
||||
}
|
||||
loop if can_send(get_info()) break
|
||||
memory.outb(0x60, byte)
|
||||
}
|
||||
|
||||
$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 get_info()
|
||||
}
|
||||
|
||||
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()
|
||||
port2.exists = bit5(@inline(get_config_byte)) == false
|
||||
disable_port2()
|
||||
|
||||
flush_input()
|
||||
|
||||
port1.exists = test_port1()
|
||||
|
||||
if port2.exists {
|
||||
port2.exists = test_port2()
|
||||
}
|
||||
|
||||
if (port1.exists | port2.exists) == false {
|
||||
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
|
||||
}
|
||||
|
||||
if port1.exists {
|
||||
log.info("Port 1 exists.\0")
|
||||
enable_port1()
|
||||
}
|
||||
if port2.exists {
|
||||
log.info("Port 2 exists.\0")
|
||||
enable_port2()
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
DeviceID := struct {value: u16}
|
||||
|
||||
$MOUSE_3_BUTTON := DeviceID.(0x0)
|
||||
$MOUSE_SCROLLWHEEL := DeviceID.(0x3)
|
||||
$MOUSE_5_BUTTON := DeviceID.(0x4)
|
||||
$KEYBOARD_SPACESAVER := DeviceID.(0x84AB)
|
||||
$KEYBOARD_122_KEY := DeviceID.(0x86AB)
|
||||
$KEYBOARD_JAPANESE_G := DeviceID.(0x90AB)
|
||||
$KEYBOARD_JAPANESE_P := DeviceID.(0x91AB)
|
||||
$KEYBOARD_JAPANESE_A := DeviceID.(0x92AB)
|
||||
$KEYBOARD_NCD_SUN := DeviceID.(0xA1AC)
|
||||
|
||||
$MOUSE_INIT_1 := DeviceID.(0xFFFD)
|
||||
$MOUSE_INIT_2 := DeviceID.(0xFFFE)
|
||||
$NO_DEVICE := DeviceID.(0xFFFF)
|
|
@ -1,144 +0,0 @@
|
|||
.{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)
|
||||
|
||||
send_command := fn(port: ^controller.Port, byte: u8): void {
|
||||
tries := 3
|
||||
loop if tries == 0 break else {
|
||||
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 {
|
||||
port.packet[port.packet_length] = input
|
||||
port.packet_length += 1
|
||||
}
|
||||
continue
|
||||
}
|
||||
if input == 0xFA {
|
||||
return
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
tries -= 1
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
} else if port.device == devices.NO_DEVICE {
|
||||
if port.packet_length == 1 {
|
||||
port.device.value = port.packet[0]
|
||||
} else {
|
||||
port.device.value = port.packet[1] | port.packet[0] << 8
|
||||
send_command(port, 0xF4)
|
||||
}
|
||||
log.info("Identified device!\0")
|
||||
log.info(string.display_int(port.device.value, format_page, 16))
|
||||
} else {
|
||||
log.info("KEY PRESSED\0")
|
||||
}
|
||||
}
|
||||
|
||||
check_complete := fn(port: ^controller.Port): bool {
|
||||
last_value := port.packet[port.packet_length - 1]
|
||||
if port.device == devices.NO_DEVICE {
|
||||
if last_value == 0 | last_value == 3 | last_value == 4 {
|
||||
return true
|
||||
} else if port.packet_length == 2 {
|
||||
return true
|
||||
}
|
||||
} else if port.device == devices.MOUSE_3_BUTTON {
|
||||
if port.packet_length == 3 return true
|
||||
} else if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON {
|
||||
if port.packet_length == 4 return true
|
||||
} else {
|
||||
if port.packet[0] == 0xE1 {
|
||||
if port.packet_length == 6 {
|
||||
return true
|
||||
}
|
||||
} else if port.packet[0] != 0xE0 {
|
||||
return true
|
||||
} else if port.packet_length == 2 & port.packet[1] != 0x2A & port.packet[1] != 0xB7 {
|
||||
return true
|
||||
} else if port.packet_length == 4 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
main := fn(): void {
|
||||
mouse_buffer = buffer.create("PS/2 Mouse\0")
|
||||
format_page = memory.alloc(u8, 1024)
|
||||
|
||||
controller.init()
|
||||
|
||||
if controller.port1.exists {
|
||||
controller.send_byte(&controller.port1, 0xF4)
|
||||
}
|
||||
if controller.port2.exists {
|
||||
controller.send_byte(&controller.port2, 0xF4)
|
||||
}
|
||||
|
||||
loop {
|
||||
info = controller.get_info()
|
||||
|
||||
if controller.timed_out(info) {
|
||||
log.error("Timeout error! Cannot handle these!\0")
|
||||
}
|
||||
if controller.check_parity(info) {
|
||||
log.error("Parity error! Cannot handle these!\0")
|
||||
}
|
||||
|
||||
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
|
||||
controller.send_byte(port, 0xF4)
|
||||
}*/
|
||||
port.packet[port.packet_length] = input
|
||||
port.packet_length += 1
|
||||
if check_complete(port) {
|
||||
process(port)
|
||||
port.packet_length = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
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)
|
|
@ -1,21 +0,0 @@
|
|||
.{DeviceID, NO_DEVICE} := @use("devices.hb")
|
||||
|
||||
State := struct {s: u8}
|
||||
$Recive := State.(0)
|
||||
$Reboot := State.(1)
|
||||
|
||||
Port := packed struct {
|
||||
exists: bool,
|
||||
device: DeviceID,
|
||||
packet: [u8; 8],
|
||||
packet_length: u8,
|
||||
can_hot_plug: bool,
|
||||
}
|
||||
|
||||
$PORT_AT_STARTUP := Port.(
|
||||
true,
|
||||
NO_DEVICE,
|
||||
.(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
0,
|
||||
true,
|
||||
)
|
|
@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb")
|
|||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label
|
||||
.{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label
|
||||
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{Vec2} := stn.math
|
||||
|
@ -29,6 +29,7 @@ main := fn(): int {
|
|||
mouse_y := 100
|
||||
|
||||
text_label := new_label("Hi\0")
|
||||
set_color(text_label, sunset.server.DECO_COLOUR, render.black)
|
||||
|
||||
loop {
|
||||
mouse_event := intouch.recieve_mouse_event()
|
||||
|
@ -38,7 +39,7 @@ main := fn(): int {
|
|||
change_x = change_x >> 8
|
||||
|
||||
mouse_x += change_x
|
||||
if mouse_x < 0 {
|
||||
if mouse_x <= 0 {
|
||||
mouse_x = 0
|
||||
}
|
||||
if mouse_x >= screen.width - 20 {
|
||||
|
@ -49,13 +50,13 @@ main := fn(): int {
|
|||
change_y = change_y << 8
|
||||
change_y = change_y >> 8
|
||||
|
||||
mouse_y -= change_y
|
||||
if mouse_y < 0 {
|
||||
mouse_y = 0
|
||||
mouse_y = 1
|
||||
}
|
||||
if mouse_y >= screen.height - 20 {
|
||||
mouse_y = @intcast(screen.height - 21)
|
||||
}
|
||||
mouse_y -= change_y
|
||||
|
||||
if mouse_event.left {
|
||||
set_label_text(text_label, "LEFT CLICK\0")
|
||||
|
|
|
@ -28,17 +28,20 @@ resolution = "1024x768x24"
|
|||
# [boot.limine.ableos.modules.horizon]
|
||||
# path = "boot:///horizon.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
# path = "boot:///ps2_mouse_driver.hbf"
|
||||
[boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
path = "boot:///ps2_mouse_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.ps2_driver]
|
||||
path = "boot:///ps2_driver.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client]
|
||||
path = "boot:///sunset_client.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_client]
|
||||
# path = "boot:///sunset_client.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client_2]
|
||||
path = "boot:///sunset_client_2.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_server]
|
||||
# path = "boot:///sunset_server.hbf"
|
||||
[boot.limine.ableos.modules.sunset_server]
|
||||
path = "boot:///sunset_server.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.processes]
|
||||
# path = "boot:///processes.hbf"
|
||||
|
|
Loading…
Reference in a new issue