93 lines
2.2 KiB
Plaintext
93 lines
2.2 KiB
Plaintext
global str screen_namespace = "/dev/screen/0";
|
|
global str mouse_namespace = "/dev/mouse/0";
|
|
global str terminal_namespace = "/dev/term/0";
|
|
global str new_line = "\n";
|
|
global byte WHITE = 255;
|
|
|
|
function main ()
|
|
plex screen $0;
|
|
plex mouse $1;
|
|
str tmp_str $2;
|
|
byte color $3;
|
|
bool left_down $4;
|
|
int mode $5;
|
|
nat offset_temp $6;
|
|
nat x $7;
|
|
nat y $8;
|
|
nat width $9;
|
|
nat screen_buffer $10;
|
|
nat buffer_size $11;
|
|
nat pixel_pos $12;
|
|
nat fat_ptr_size $13;
|
|
|
|
load_address screen_namespace -> screen;
|
|
load_immediate 0 -> mode;
|
|
syscall OPEN screen mode screen;
|
|
|
|
nat_to_string screen -> tmp_str;
|
|
call pln (tmp_str);
|
|
|
|
load_offset_32 screen 8 -> width;
|
|
nat_to_string width -> tmp_str;
|
|
call pln (tmp_str);
|
|
|
|
load_offset_32 screen 12 -> buffer_size;
|
|
nat_to_string buffer_size -> tmp_str;
|
|
call pln (tmp_str);
|
|
|
|
load_immediate 16 -> offset_temp;
|
|
add_nat screen offset_temp -> screen_buffer;
|
|
|
|
nat_to_string screen_buffer -> tmp_str;
|
|
call pln (tmp_str);
|
|
|
|
// open mouse
|
|
load_address mouse_namespace -> mouse;
|
|
syscall OPEN mouse mode mouse;
|
|
|
|
syscall WRITE screen screen_buffer buffer_size; // redraw
|
|
|
|
loop draw_loop
|
|
// load mouse click data
|
|
syscall REFRESH mouse;
|
|
|
|
load_offset_8 mouse 16 -> left_down;
|
|
|
|
jump_eq_nat draw_loop left_down mode; // mode = 0 / false
|
|
|
|
load_offset_32 mouse 8 -> x;
|
|
load_offset_32 mouse 12 -> y;
|
|
|
|
// Compute start address: y *width + x
|
|
mul_nat y width -> pixel_pos;
|
|
add_nat x pixel_pos -> pixel_pos;
|
|
add_nat screen_buffer pixel_pos -> pixel_pos;
|
|
load_immediate 4 -> fat_ptr_size;
|
|
add_nat pixel_pos fat_ptr_size -> pixel_pos;
|
|
|
|
load_absolute_32 WHITE -> color;
|
|
store_absolute_8 color -> pixel_pos; // draw color at screen [x,y]
|
|
|
|
syscall WRITE screen screen_buffer buffer_size; // redraw
|
|
|
|
jump draw_loop;
|
|
exit 0;
|
|
|
|
function pln (str message $0)
|
|
plex term $1;
|
|
int msg_length $2;
|
|
str nl $3;
|
|
int nl_length $4;
|
|
int pln_mode $5;
|
|
str term_ns $6;
|
|
|
|
load_immediate 0 -> pln_mode;
|
|
load_address terminal_namespace -> term_ns;
|
|
syscall OPEN term_ns pln_mode term;
|
|
string_length message -> msg_length;
|
|
syscall WRITE term message msg_length;
|
|
load_address new_line -> nl;
|
|
string_length nl -> nl_length;
|
|
syscall WRITE term nl nl_length;
|
|
return;
|