90 lines
2.5 KiB
Plaintext
90 lines
2.5 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
|
|
plex screen is $0
|
|
load_address &screen_namespace -> $18
|
|
int mode is $11
|
|
load_immediate 0 -> mode
|
|
syscall OPEN $18 mode -> screen # openout Plex screen, in namespace, in flags
|
|
|
|
nat_to_string screen -> $5
|
|
call &pln $5
|
|
|
|
nat width is $20
|
|
load_offset_32 screen 8 -> width # load width
|
|
nat_to_string width -> $5
|
|
call &pln $5
|
|
|
|
nat buffer_size is $22
|
|
load_offset_32 screen 12 -> buffer_size # load size
|
|
nat_to_string buffer_size -> $5
|
|
call &pln $5
|
|
|
|
nat screen_buffer is $21
|
|
load_immediate $1 16 # offset for screen buffer
|
|
add_nat screen $1 -> screen_buffer
|
|
|
|
nat_to_string screen_buffer -> $5
|
|
call &pln $5
|
|
|
|
# open mouse
|
|
plex mouse is $15
|
|
load_address &mouse_namespace -> $16
|
|
syscall OPEN $16 mode -> mouse # openout Plex mouse, in namespace, in flags
|
|
|
|
syscall WRITE screen screen_buffer buffer_size # redraw
|
|
|
|
draw_loop:
|
|
# load mouse click data
|
|
syscall STAT mouse
|
|
|
|
byte left_down is $9
|
|
load_offset_8 mouse 16 -> left_down # load btn1 pressed
|
|
|
|
jump_eq_nat &draw_loop left_down mode # mode is 0 which is an alias for false
|
|
|
|
nat x is $7
|
|
load_offset_32 mouse 8 -> x # load x
|
|
nat y is $8
|
|
load_offset_32 mouse 12 -> y # load y
|
|
|
|
# Compute start address: y*width + x
|
|
nat pixel_pos is $30
|
|
mul_nat y $20 -> pixel_pos # = y * width
|
|
add_nat x pixel_pos -> pixel_pos # += x
|
|
add_nat screen_buffer pixel_pos -> pixel_pos # += pixel_offset
|
|
nat fat_ptr_size is $1
|
|
load_immediate 4 -> fat_ptr_size # need to add offset for fat pointer size
|
|
add_nat pixel_pos fat_ptr_size -> pixel_pos
|
|
|
|
byte color is $3
|
|
load_absolute_32 &WHITE -> color
|
|
store_absolute_8 pixel_pos color # draw color at screen [x,y]
|
|
syscall WRITE screen screen_buffer buffer_size # redraw
|
|
|
|
jump &draw_loop
|
|
exit 0
|
|
|
|
function pln (str message is $0)
|
|
str term is $1
|
|
int msg_length is $2
|
|
str nl is $3
|
|
int nl_length is $4
|
|
int mode is $5
|
|
|
|
load_address &terminal_namespace -> term # get terminal device
|
|
load_immediate 0 -> mode
|
|
syscall OPEN term mode -> term
|
|
strlen message -> msg_length
|
|
syscall WRITE term message msg_length
|
|
load_address &new_line -> nl
|
|
strlen nl -> nl_length
|
|
syscall WRITE term nl nl_length
|
|
return
|