undar-lang/test/window.ul

70 lines
1.1 KiB
Fortran

/**
* Constants
*/
const str nl = "\n";
const nat WHITE = 255;
/**
* Devices
*/
plex Terminal {
nat handle;
}
plex Screen {
nat handle;
nat width;
nat height;
byte[] buffer;
draw() {
write(this, this.buffer, this.buffer_size);
}
}
plex Mouse {
nat handle;
nat x;
nat y;
bool left;
bool right;
bool middle;
bool btn4;
nat size;
}
/**
* Main function
*/
function main() {
Screen screen = open("/dev/screen/0", 0);
pln(screen.handle.str);
pln(screen.width.str);
pln(screen.size.str);
unsafe {
pln(screen.screen_buffer.ptr.str);
}
Mouse mouse = open("/dev/mouse/0", 0);
screen.draw();
loop {
if (mouse.btn1) {
unsafe {
screen.buffer[mouse.y * width + mouse.x +
screen.buffer.ptr + 4] = WHITE;
screen.draw();
}
}
}
}
/**
* Print with a newline
*/
function pln(str message) {
Terminal term = open("/dev/term/0", 0);
write(term, message, message.length);
write(term, nl, nl.length);
}