From 16135ae536a513f2219a57c91de8a79b2b1906da Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 3 Nov 2024 18:37:39 -0600 Subject: [PATCH] mouse render --- sysdata/programs/ps2_mouse_driver/src/main.hb | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/sysdata/programs/ps2_mouse_driver/src/main.hb b/sysdata/programs/ps2_mouse_driver/src/main.hb index 0b70519f1..98b360a2b 100644 --- a/sysdata/programs/ps2_mouse_driver/src/main.hb +++ b/sysdata/programs/ps2_mouse_driver/src/main.hb @@ -1,6 +1,8 @@ .{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb") Vec2 := math.Vec2 +render := @use("../../../libraries/render/src/lib.hb") + i9 := packed struct {sign: bool, value: u8} Button := struct {id: u8} LeftButton := Button.(1) @@ -82,20 +84,31 @@ set_resolution := fn(resolution: Resolution): void { @inline(send_command_byte, resolution.value) } +set_up_mouse := fn(): void { + @inline(reset_mouse) + @inline(set_resolution, res_8count_per_mm) + @inline(enable_streaming) +} + button_states := @as(u8, 0) main := fn(): int { format_page := memory.alloc(u8, 1024) + screen := render.init(true) + + // Clear the screen to black. + render.clear(screen, render.black) + send_byte(0x64, 0xA8) log.info("Aux mouse device enabled.\0") - reset_mouse() - set_defaults() - enable_streaming() + set_up_mouse() - x := @as(i16, 0) - y := @as(i16, 0) + set_resolution(res_8count_per_mm) + + x := @as(u8, 0) + y := @as(u8, 0) loop { loop if (memory.inb(0x64) & 0x20) == 0x20 break @@ -104,9 +117,7 @@ main := fn(): int { if status == 0xAA { loop if memory.inb(0x60) == 0 break log.info("Mouse plugged in!\0") - reset_mouse() - set_defaults() - enable_streaming() + set_up_mouse() continue } @@ -132,12 +143,20 @@ main := fn(): int { dx.value = memory.inb(0x60) dx.sign = (status & 0x10) > 0 - dy.value = memory.inb(0x60) ^ 0xFF + dy.value = -memory.inb(0x60) dy.sign = (status & 0x20) == 0 if dy.value != 0 & dx.value != 0 { mouse_moved(.(dx, dy)) + x += dx.value + y += dy.value } + + render.clear(screen, render.black) + + render.put_rect(screen, .(x, y), .(10, 10), render.white) + // Sync the screen + render.sync(screen) } return 0