more input reading|js console app

This commit is contained in:
minjaesong
2020-05-19 11:14:27 +09:00
parent 9321dbceb1
commit 619257ecf2
10 changed files with 240 additions and 41 deletions

44
assets/jscon.js Normal file
View File

@@ -0,0 +1,44 @@
function readConsoleInput() {
var cmdbuf = "";
var key = -1;
while (key != 10 && key != 13) {
key = vm.readKey();
// printable chars
if (key >= 32 && key <= 126) {
var s = String.fromCharCode(key);
cmdbuf += s;
print(s);
}
// backspace
else if (key == 8 && cmdbuf.length > 0) {
cmdbuf = cmdbuf.substring(0, cmdbuf.length - 1);
print(String.fromCharCode(key));
}
// up down key
else if (key >= 19 && key <= 20) {
return key;
}
// left right key
else if (key >= 19 && key <= 20) {
//
}
}
return cmdbuf;
}
println("JS Console");
while (true) {
print("JS> ");
var cmdbuf = readConsoleInput();
if (typeof cmdbuf == "string") {
println();
try {
println(eval(cmdbuf));
}
catch (e) {
println(e);
}
}
}

View File

@@ -22,16 +22,9 @@ println("Starting TVDOS...");
greet();
/*while (true) {
while (true) {
print(get_prompt_text());
var s = read();
println();
println("String read: " + s + "@");
}*/
println(vm.peek(-4093)); // expecting an odd number
vm.poke(-4093, 6);
for (i = 0; i < 4096; i++) {
print(String.fromCharCode(vm.peek(-4097 - i)));
}
println();
}