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; 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 // Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19 // Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) { if (!Array.prototype.map) {

View File

@@ -65,4 +65,10 @@ var GL = eval(filesystem.readAll("A"));
// Boot script // Boot script
filesystem.open("A", "tvdos/command.js", "R"); 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 CURRENT_DRIVE = "A";
let shell_pwd = [""]; 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..."); println("Starting TVDOS...");
@@ -47,9 +52,10 @@ while (true) {
println(); println();
try { try {
println("You entered: " + cmdbuf); println("You entered: " + cmdbuf);
} }
catch (e) { catch (e) {
println(e); printerrln(e);
} }
finally { finally {
if (cmdbuf.trim().length > 0) if (cmdbuf.trim().length > 0)
@@ -91,4 +97,6 @@ while (true) {
} }
} }
} }
} }
return 0;

View File

@@ -1,22 +1,19 @@
serial.println(typeof atob); serial.println(typeof atob);
const inputstr = const inputstr =
"//////////////////////////////////////////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.");';
"/////////////////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/////////////"+
"////////////////////////////////////////"
serial.println(inputstr); 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)); let inputbytes = [];
var unzipped = base64.btoa(gzip.decomp(base64.atob(zipped)));
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') + " ");
}

View File

@@ -2,7 +2,7 @@ package net.torvald.tsvm
import com.badlogic.gdx.utils.Base64Coder import com.badlogic.gdx.utils.Base64Coder
class Base64Delegate { object Base64Delegate {
fun atob(inputstr: String): ByteArray { fun atob(inputstr: String): ByteArray {
return Base64Coder.decode(inputstr) return Base64Coder.decode(inputstr)

View File

@@ -6,7 +6,7 @@ import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream import java.util.zip.GZIPOutputStream
class CompressorDelegate { object CompressorDelegate {
/*fun comp(ba: ByteArray): ByteArray { /*fun comp(ba: ByteArray): ByteArray {
val bin = ByteArrayInputStream(ba) val bin = ByteArrayInputStream(ba)
@@ -38,4 +38,5 @@ class CompressorDelegate {
return ret return ret
} }
val GZIP_HEADER = byteArrayOf(31,-117,8) // .gz in DEFLATE
} }

View File

@@ -6,9 +6,11 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.torvald.tsvm.CompressorDelegate.GZIP_HEADER
import net.torvald.tsvm.peripheral.GraphicsAdapter import net.torvald.tsvm.peripheral.GraphicsAdapter
import java.io.File import java.io.File
import java.io.FileReader
fun ByteArray.startsWith(other: ByteArray) = this.sliceArray(other.indices).contentEquals(other)
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() { class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
@@ -53,9 +55,18 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
memvwr = Memvwr(vm) memvwr = Memvwr(vm)
// load test bios // load test bios
val bios = File("./assets/bios1.bin").readBytes()
// check if bios is compressed in gzip
val biosStr = if (bios.startsWith(GZIP_HEADER))
CompressorDelegate.decomp(bios).toString(VM.CHARSET)
else
bios.toString(VM.CHARSET)
vmRunner = VMRunnerFactory(vm, "js") vmRunner = VMRunnerFactory(vm, "js")
coroutineJob = GlobalScope.launch { coroutineJob = GlobalScope.launch {
vmRunner.executeCommand(File("./assets/bios1.js").readText(VM.CHARSET)) //vmRunner.executeCommand(File("./assets/zippytest.js").readText(VM.CHARSET))
vmRunner.executeCommand(biosStr)
} }
} }

View File

@@ -77,8 +77,8 @@ object VMRunnerFactory {
bind.put("sys", VMJSR223Delegate(vm)) // TODO use delegator class to access peripheral (do not expose VM itself) bind.put("sys", VMJSR223Delegate(vm)) // TODO use delegator class to access peripheral (do not expose VM itself)
bind.put("graphics", GraphicsJSR223Delegate(vm)) bind.put("graphics", GraphicsJSR223Delegate(vm))
bind.put("serial", VMSerialDebugger(vm)) bind.put("serial", VMSerialDebugger(vm))
bind.put("gzip", CompressorDelegate()) bind.put("gzip", CompressorDelegate)
bind.put("base64", Base64Delegate()) bind.put("base64", Base64Delegate)
bind.put("com", SerialHelperDelegate(vm)) bind.put("com", SerialHelperDelegate(vm))
val fr = FileReader("./assets/JS_INIT.js") val fr = FileReader("./assets/JS_INIT.js")