mouse render

This commit is contained in:
Able 2024-11-03 18:37:39 -06:00
parent 941eed0ac9
commit 16135ae536

View file

@ -1,6 +1,8 @@
.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb") .{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb")
Vec2 := math.Vec2 Vec2 := math.Vec2
render := @use("../../../libraries/render/src/lib.hb")
i9 := packed struct {sign: bool, value: u8} i9 := packed struct {sign: bool, value: u8}
Button := struct {id: u8} Button := struct {id: u8}
LeftButton := Button.(1) LeftButton := Button.(1)
@ -82,20 +84,31 @@ set_resolution := fn(resolution: Resolution): void {
@inline(send_command_byte, resolution.value) @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) button_states := @as(u8, 0)
main := fn(): int { main := fn(): int {
format_page := memory.alloc(u8, 1024) format_page := memory.alloc(u8, 1024)
screen := render.init(true)
// Clear the screen to black.
render.clear(screen, render.black)
send_byte(0x64, 0xA8) send_byte(0x64, 0xA8)
log.info("Aux mouse device enabled.\0") log.info("Aux mouse device enabled.\0")
reset_mouse() set_up_mouse()
set_defaults()
enable_streaming()
x := @as(i16, 0) set_resolution(res_8count_per_mm)
y := @as(i16, 0)
x := @as(u8, 0)
y := @as(u8, 0)
loop { loop {
loop if (memory.inb(0x64) & 0x20) == 0x20 break loop if (memory.inb(0x64) & 0x20) == 0x20 break
@ -104,9 +117,7 @@ main := fn(): int {
if status == 0xAA { if status == 0xAA {
loop if memory.inb(0x60) == 0 break loop if memory.inb(0x60) == 0 break
log.info("Mouse plugged in!\0") log.info("Mouse plugged in!\0")
reset_mouse() set_up_mouse()
set_defaults()
enable_streaming()
continue continue
} }
@ -132,12 +143,20 @@ main := fn(): int {
dx.value = memory.inb(0x60) dx.value = memory.inb(0x60)
dx.sign = (status & 0x10) > 0 dx.sign = (status & 0x10) > 0
dy.value = memory.inb(0x60) ^ 0xFF dy.value = -memory.inb(0x60)
dy.sign = (status & 0x20) == 0 dy.sign = (status & 0x20) == 0
if dy.value != 0 & dx.value != 0 { if dy.value != 0 & dx.value != 0 {
mouse_moved(.(dx, dy)) 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 return 0