a way to run program with arguments

This commit is contained in:
minjaesong
2020-11-01 12:03:03 +09:00
parent af876866b5
commit c331af2cc4
8 changed files with 52 additions and 24 deletions

View File

@@ -84,6 +84,11 @@ if (!Array.prototype.filter){
return res;
};
}
if (!String.prototype.padStart) {
String.prototype.padStart = function(l, c) {
return (this.length >= l) ? this : (c.repeat(l - this.length) + this);
};
}
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) {

View File

@@ -65,4 +65,10 @@ var GL = eval(filesystem.readAll("A"));
// Boot script
filesystem.open("A", "tvdos/command.js", "R");
eval(filesystem.readAll("A"));
let cmdsrc = filesystem.readAll("A");
// app execution stub
let prg = eval("let _appStub=function(exec_args){"+cmdsrc+"};_appStub;"); // making 'exec_args' a app-level global
prg(undefined);
//let testtest = prg(42);
//println(testtest.test);

View File

@@ -1,4 +1,4 @@
const PROMPT_TEXT = ">";
let PROMPT_TEXT = ">";
let CURRENT_DRIVE = "A";
let shell_pwd = [""];
@@ -15,6 +15,11 @@ function greet() {
}
let shell = {};
shell.test = "command.js test string";
if (exec_args !== undefined) return shell;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
println("Starting TVDOS...");
@@ -47,9 +52,10 @@ while (true) {
println();
try {
println("You entered: " + cmdbuf);
}
catch (e) {
println(e);
printerrln(e);
}
finally {
if (cmdbuf.trim().length > 0)
@@ -91,4 +97,6 @@ while (true) {
}
}
}
}
}
return 0;

View File

@@ -1,22 +1,19 @@
serial.println(typeof atob);
const inputstr =
"//////////////////////////////////////////j//////////////"+
"/////////////////j////////////////////////z8/P///j///+hoaGhof+hof////////Pz//////j//6Gh//////+hof////////Pz//////j//6"+
"Gh//////+hoaGhof//8/Pz8/P///j///+hoaH///+hof//oaH///Pz//////j//////6Gh//+hof//oaH///Pz//////j///////+hof+hof//oaH///P"+
"z//////j///////+hof+hof//oaH///Pz//////j//6GhoaGh//+hof//oaH///////////j///////////////////////////////j/////////////"+
"////////////////////////////////////////"
'println("TERRAN Megatrends inc.");let p=0;let m=[[0,255,170,85,105,15,165,30,199,113,142,227,202,254,186,190],[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]];con.move(2,1),print("000 KB OK");try{for(;p<8<<20;){con.move(2,1);var x=""+(p+1>>10);print(x<10?"00"+x:x<100?"0"+x:x);for(var t=0;t<m.length;t++){for(var b=0;b<m[t].length;b++)if(sys.poke(p+b,m[t][b]),m[t][b]!=sys.peek(p+b))throw"Memory Error";for(var b=0;b<m[t].length;b++)if(sys.poke(p+b,255-m[t][b]),255-m[t][b]!=sys.peek(p+b))throw"Memory Error"}p+=m[0].length}}catch(t){"Memory Error"==t?println(" Memory Error"):println(" KB OK!")}var _BIOS={FIRST_BOOTABLE_PORT:[0,1]};Object.freeze(_BIOS);let n=0,s=0;for(;n<4&&(!com.areYouThere(n)||(com.sendMessage(n,"LOADBOOT"),s=com.getStatusCode(n),0!=s));)n+=1;n<4?eval(com.fetchResponse(n).trimNull()):printerrln("No bootable medium found.");';
serial.println(inputstr);
//FIXME bad Base64.atob impl
serial.println(base64.btoa(base64.atob(inputstr)))
var zipbin = gzip.comp(base64.atob(inputstr));
var zipped = base64.btoa(zipbin);
serial.println(zipped);
//var unzipped = base64.btoa(gzip.decomp(zipbin));
var unzipped = base64.btoa(gzip.decomp(base64.atob(zipped)));
let inputbytes = [];
serial.println(unzipped);
for (let i = 0; i < inputstr.length; i++) {
inputbytes.push(inputstr.charCodeAt(i));
}
serial.println("It is now safe to turn off");
let compstr = gzip.comp(inputbytes);
for (let i = 0; i < compstr.length; i++) {
serial.print((compstr[i] & 255).toString(16).padStart(2,'0') + " ");
}