90 lines
2.2 KiB
Plaintext
90 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;
|
|
|
|
load_immediate screen_namespace -> screen;
|
|
load_immediate 0 -> mode;
|
|
syscall OPEN screen mode -> screen;
|
|
|
|
nat_to_string screen -> tmp_str;
|
|
call pln tmp_str -> void;
|
|
|
|
load_offset_32 screen 8 -> width;
|
|
nat_to_string width -> tmp_str;
|
|
call pln tmp_str -> void;
|
|
|
|
load_offset_32 screen 12 -> buffer_size;
|
|
nat_to_string buffer_size -> tmp_str;
|
|
call pln tmp_str -> void;
|
|
|
|
load_immediate 16 -> offset_temp;
|
|
add_nat screen offset_temp -> screen_buffer;
|
|
|
|
nat_to_string screen_buffer -> tmp_str;
|
|
call pln tmp_str -> void;
|
|
|
|
// open mouse
|
|
load_immediate mouse_namespace -> mouse;
|
|
syscall OPEN mouse mode -> mouse;
|
|
|
|
syscall WRITE screen screen_buffer buffer_size; // redraw
|
|
|
|
loop draw_loop
|
|
// load mouse click data
|
|
syscall STAT 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 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 $0)
|
|
str ts $1;
|
|
int mode $5;
|
|
int msg_length $2;
|
|
str nl $3;
|
|
int nl_length $4;
|
|
|
|
load_immediate terminal_namespace -> ts;
|
|
load_immediate 0 -> mode;
|
|
syscall OPEN ts mode -> ts;
|
|
string_length message -> msg_length;
|
|
syscall WRITE ts message msg_length ;
|
|
load_immediate new_line -> nl;
|
|
string_length nl -> nl_length;
|
|
syscall WRITE ts nl nl_length;
|
|
return;
|