basic interpreter wip

This commit is contained in:
minjaesong
2020-05-20 05:37:36 +09:00
parent a1e053c53e
commit 904c080731
10 changed files with 205 additions and 46 deletions

40
assets/JS_INIT.js Normal file
View File

@@ -0,0 +1,40 @@
// standard print functions
function print(s) {
vm.print(s);
}
function println(s) {
if (typeof s == "undefined")
vm.print("\n");
else
vm.println(s);
}
function read() {
return vm.read();
}
// ncurses-like terminal control
var con = new Object();
con.getch = function() {
return vm.readKey();
};
con.move = function(y, x) {
print(String.fromCharCode(27,91)+y+";"+x+"H");
};
con.addch = function(c) {
graphics.putSymbol(c);
};
con.mvaddch = function(y, x, c) {
move(y, x); addch(c);
};
con.getmaxyx = function() {
return graphics.getTermDimension();
};
con.getyx = function() {
return graphics.getCursorYX();
};
Object.freeze(con);
// system management function
var sys = new Object();
sys.maxmem = function() {
return vm.peek(-65) | (vm.peek(-66) << 8) | (vm.peek(-67) << 16) | (vm.peek(-68) << 24);
};
Object.freeze(sys);