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

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

View File

@@ -6,7 +6,7 @@ import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
class CompressorDelegate {
object CompressorDelegate {
/*fun comp(ba: ByteArray): ByteArray {
val bin = ByteArrayInputStream(ba)
@@ -38,4 +38,5 @@ class CompressorDelegate {
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.g2d.SpriteBatch
import kotlinx.coroutines.*
import net.torvald.tsvm.CompressorDelegate.GZIP_HEADER
import net.torvald.tsvm.peripheral.GraphicsAdapter
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() {
@@ -53,9 +55,18 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
memvwr = Memvwr(vm)
// 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")
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("graphics", GraphicsJSR223Delegate(vm))
bind.put("serial", VMSerialDebugger(vm))
bind.put("gzip", CompressorDelegate())
bind.put("base64", Base64Delegate())
bind.put("gzip", CompressorDelegate)
bind.put("base64", Base64Delegate)
bind.put("com", SerialHelperDelegate(vm))
val fr = FileReader("./assets/JS_INIT.js")