74 lines
2.1 KiB
Plaintext
74 lines
2.1 KiB
Plaintext
global const str screen_namespace = "/dev/screen/0"
|
|
global const str mouse_namespace = "/dev/mouse/0"
|
|
global const str terminal_namespace = "/dev/term/0"
|
|
global const str new_line = "\n"
|
|
global const byte WHITE = 255
|
|
|
|
function main ()
|
|
# open screen
|
|
# use load immediate because it is a pointer to a string, not a value
|
|
|
|
nat tmp_ptr = load_address screen_namespace
|
|
int mode = load_immediate 0
|
|
plex screen = open tmp_ptr, mode
|
|
|
|
nat screen_handle = load_offset_32 screen, 4
|
|
str tmp_str = nat_to_string screen_handle
|
|
call pln tmp_str
|
|
|
|
nat width = load_offset_32 screen, 8
|
|
tmp_str = nat_to_string width
|
|
call pln tmp_str
|
|
|
|
nat buffer_size = load_offset_32 screen, 12
|
|
tmp_str = nat_to_string buffer_size
|
|
call pln tmp_str
|
|
|
|
nat offset_temp = load_immediate 16
|
|
nat screen_buffer = add_nat screen, offset_temp
|
|
|
|
tmp_str = nat_to_string screen_buffer
|
|
call pln tmp_str
|
|
|
|
# open mouse
|
|
tmp_ptr = load_address mouse_namespace
|
|
plex mouse = open tmp_ptr, mode
|
|
|
|
write screen, screen_buffer, buffer_size # redraw
|
|
|
|
draw_loop:
|
|
# load mouse click data
|
|
stat mouse
|
|
|
|
byte left_down = load_offset_8 mouse, 16 # load btn1 pressed
|
|
|
|
jump_eq_nat draw_loop, left_down, mode # mode is 0 which is an alias for false
|
|
|
|
nat x = load_offset_32 mouse, 8
|
|
nat y = load_offset_32 mouse, 12
|
|
|
|
# Compute start address: y*width + x
|
|
nat pixel_pos = mul_nat y, width # = y * width
|
|
pixel_pos = add_nat x, pixel_pos # += x
|
|
pixel_pos = add_nat screen_buffer, pixel_pos # += pixel_offset
|
|
nat fat_ptr_size = load_immediate 4 # need to add offset for fat pointer size
|
|
pixel_pos = add_nat pixel_pos, fat_ptr_size
|
|
|
|
byte color = load_absolute_32 WHITE
|
|
store_absolute_8 pixel_pos, color # draw color at screen [x,y]
|
|
write screen, screen_buffer, buffer_size # redraw
|
|
|
|
jump draw_loop
|
|
exit 0
|
|
|
|
function pln (str message)
|
|
nat term_ns = load_address terminal_namespace # get terminal device
|
|
int mode = load_immediate 0
|
|
plex term = open term_ns, mode
|
|
int msg_length = strlen message
|
|
write term, message, msg_length
|
|
str nl = load_address new_line
|
|
int nl_length = strlen nl
|
|
write term, nl, nl_length
|
|
return
|