some experimental syntax
This commit is contained in:
parent
a1197e8b43
commit
99e2f2c0c3
|
|
@ -1,8 +1,11 @@
|
|||
/**
|
||||
* Constants
|
||||
*/
|
||||
const str nl = "\n";
|
||||
const nat WHITE = 255;
|
||||
const str screen_namespace = "/dev/screen/0"
|
||||
const str mouse_namespace = "/dev/mouse/0"
|
||||
const str terminal_namespace = "/dev/term/0"
|
||||
const str new_line = "\n"
|
||||
const byte WHITE = 255
|
||||
|
||||
/**
|
||||
* Devices
|
||||
|
|
@ -37,15 +40,15 @@ plex Mouse {
|
|||
* Main function
|
||||
*/
|
||||
function main() {
|
||||
Screen screen = open("/dev/screen/0", 0);
|
||||
pln(screen.handle.str);
|
||||
pln(screen.width.str);
|
||||
pln(screen.size.str);
|
||||
Screen screen = open(screen_namespace, 0);
|
||||
pln(screen.handle as str);
|
||||
pln(screen.width as str);
|
||||
pln(screen.size as str);
|
||||
unsafe {
|
||||
pln(screen.screen_buffer.ptr.str);
|
||||
pln(screen.screen_buffer.ptr as str);
|
||||
}
|
||||
|
||||
Mouse mouse = open("/dev/mouse/0", 0);
|
||||
Mouse mouse = open(mouse_namespace, 0);
|
||||
screen.draw();
|
||||
|
||||
loop {
|
||||
|
|
@ -63,7 +66,7 @@ function main() {
|
|||
* Print with a newline
|
||||
*/
|
||||
function pln(str message) {
|
||||
Terminal term = open("/dev/term/0", 0);
|
||||
Terminal term = open(terminal_namespace, 0);
|
||||
write(term, message, message.length);
|
||||
write(term, nl, nl.length);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,35 +8,43 @@ 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
|
||||
plex mouse is $1
|
||||
str tmp_str is $2
|
||||
byte color is $3
|
||||
byte left_down is $4
|
||||
int mode is $5
|
||||
nat offset_temp is $6
|
||||
nat x is $7
|
||||
nat y is $8
|
||||
nat width is $9
|
||||
nat screen_buffer is $10
|
||||
nat buffer_size is $11
|
||||
nat pixel_pos is $12
|
||||
|
||||
load_address &screen_namespace -> tmp_str
|
||||
load_immediate 0 -> mode
|
||||
syscall OPEN $18 mode -> screen # openout Plex screen, in namespace, in flags
|
||||
syscall OPEN tmp_str mode -> screen # openout Plex screen, in namespace, in flags
|
||||
|
||||
nat_to_string screen -> $5
|
||||
call &pln $5
|
||||
nat_to_string screen -> tmp_str
|
||||
call &pln tmp_str
|
||||
|
||||
nat width is $20
|
||||
load_offset_32 screen 8 -> width # load width
|
||||
nat_to_string width -> $5
|
||||
call &pln $5
|
||||
nat_to_string width -> tmp_str
|
||||
call &pln tmp_str
|
||||
|
||||
nat buffer_size is $22
|
||||
load_offset_32 screen 12 -> buffer_size # load size
|
||||
nat_to_string buffer_size -> $5
|
||||
call &pln $5
|
||||
nat_to_string buffer_size -> tmp_str
|
||||
call &pln tmp_str
|
||||
|
||||
nat screen_buffer is $21
|
||||
load_immediate $1 16 # offset for screen buffer
|
||||
add_nat screen $1 -> screen_buffer
|
||||
load_immediate 16 -> offset_temp # offset for screen buffer
|
||||
add_nat screen offset_temp -> screen_buffer
|
||||
|
||||
nat_to_string screen_buffer -> $5
|
||||
call &pln $5
|
||||
nat_to_string screen_buffer -> tmp_str
|
||||
call &pln tmp_str
|
||||
|
||||
# open mouse
|
||||
plex mouse is $15
|
||||
load_address &mouse_namespace -> $16
|
||||
syscall OPEN $16 mode -> mouse # openout Plex mouse, in namespace, in flags
|
||||
load_address &mouse_namespace -> tmp_str
|
||||
syscall OPEN tmp_str mode -> mouse # openout Plex mouse, in namespace, in flags
|
||||
|
||||
syscall WRITE screen screen_buffer buffer_size # redraw
|
||||
|
||||
|
|
@ -44,26 +52,20 @@ function main ()
|
|||
# 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
|
||||
mul_nat y width -> 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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
const str screen_namespace = "/dev/screen/0";
|
||||
const str mouse_namespace = "/dev/mouse/0";
|
||||
const str terminal_namespace = "/dev/term/0";
|
||||
const str new_line = "\n";
|
||||
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 = &screen_namespace;
|
||||
int mode = 0;
|
||||
plex screen = open(tmp_ptr, mode);
|
||||
|
||||
nat screen_handle = screen.handle;
|
||||
str tmp_str = screen_handle as str;
|
||||
pln(tmp_str);
|
||||
|
||||
nat width = screen.width;
|
||||
tmp_str = width as str;
|
||||
pln(tmp_str);
|
||||
|
||||
nat buffer_size = screen.size;
|
||||
tmp_str = buffer_size as str;
|
||||
pln(tmp_str);
|
||||
|
||||
nat screen_buffer = screen.buffer.ptr;
|
||||
tmp_str = screen_buffer as str;
|
||||
pln(tmp_str);
|
||||
|
||||
// open mouse
|
||||
tmp_ptr = &mouse_namespace;
|
||||
plex mouse = open(tmp_ptr, mode);
|
||||
|
||||
write(screen, screen_buffer, buffer_size); // redraw
|
||||
|
||||
loop {
|
||||
// load mouse click data
|
||||
stat(mouse);
|
||||
|
||||
byte left_down = mouse.left;
|
||||
|
||||
if (left_down == 0) continue;
|
||||
|
||||
nat x = mouse.x;
|
||||
nat y = mouse.y;
|
||||
|
||||
// Compute start address: y*width + x
|
||||
nat pixel_pos = y * width; // = y * width
|
||||
pixel_pos = x + pixel_pos; // += x
|
||||
pixel_pos = screen_buffer + pixel_pos; // += pixel_offset
|
||||
nat fat_ptr_size = 4; // need to add offset for fat pointer size
|
||||
pixel_pos = pixel_pos + fat_ptr_size;
|
||||
|
||||
byte color = WHITE;
|
||||
store_absolute_8(pixel_pos, color); // draw color at screen [x,y]
|
||||
write(screen, screen_buffer, buffer_size); // redraw
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
function pln (str message) {
|
||||
nat term_ns = &terminal_namespace; // get terminal device
|
||||
int mode = 0;
|
||||
plex term = open(term_ns, mode);
|
||||
int msg_length = message.length;
|
||||
write(term, message, msg_length);
|
||||
str nl = &new_line;
|
||||
int nl_length = nl.length;
|
||||
write(term, nl, nl_length);
|
||||
return
|
||||
}
|
||||
Loading…
Reference in New Issue