73 lines
1.2 KiB
Fortran
73 lines
1.2 KiB
Fortran
/**
|
|
* Constants
|
|
*/
|
|
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
|
|
*/
|
|
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(screen_namespace, 0);
|
|
pln(screen.handle as str);
|
|
pln(screen.width as str);
|
|
pln(screen.size as str);
|
|
unsafe {
|
|
pln(screen.screen_buffer.ptr as str);
|
|
}
|
|
|
|
Mouse mouse = open(mouse_namespace, 0);
|
|
screen.draw();
|
|
|
|
loop {
|
|
if (mouse.left) {
|
|
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(terminal_namespace, 0);
|
|
write(term, message, message.length);
|
|
write(term, nl, nl.length);
|
|
}
|