mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-12 22:16:05 +09:00
some random shits
This commit is contained in:
@@ -65,6 +65,20 @@ class GraphicsJSR223Delegate(val vm: VM) {
|
||||
return intArrayOf(-1, -1)
|
||||
}
|
||||
|
||||
fun setBackground(r: Int, g: Int, b: Int) {
|
||||
getFirstGPU()?.let {
|
||||
it.poke(250880, r.toByte())
|
||||
it.poke(250881, g.toByte())
|
||||
it.poke(250882, b.toByte())
|
||||
}
|
||||
}
|
||||
|
||||
fun clearText() {
|
||||
getFirstGPU()?.let {
|
||||
it.eraseInDisp(2)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prints a char as-is; won't interpret them as an escape sequence
|
||||
*/
|
||||
|
||||
@@ -58,16 +58,23 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
||||
val bios = fr1.readText()
|
||||
fr1.close()
|
||||
|
||||
|
||||
val fr2 = FileReader("./assets/tvdos/gl.js")
|
||||
val tvgl = fr2.readText()
|
||||
fr2.close()
|
||||
|
||||
|
||||
//val fr = FileReader("./assets/tvdos/command.js")
|
||||
val fr = FileReader("./assets/tbas/basic.js")
|
||||
val fr = FileReader("./assets/tvdos/fsh.js")
|
||||
//val fr = FileReader("./assets/tbas/basic.js")
|
||||
//val fr = FileReader("./assets/jscon.js")
|
||||
val prg = fr.readText()
|
||||
fr.close()
|
||||
|
||||
vmRunner = VMRunnerFactory(vm, "js")
|
||||
coroutineJob = GlobalScope.launch {
|
||||
vmRunner.executeCommand(sanitiseJS(bios))
|
||||
vmRunner.executeCommand(sanitiseJS(prg))
|
||||
vmRunner.evalGlobal(bios + "\n" + tvgl)
|
||||
vmRunner.executeCommand(prg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import kotlin.test.assertNotNull
|
||||
abstract class VMRunner(val extension: String) {
|
||||
|
||||
abstract suspend fun executeCommand(command: String)
|
||||
abstract suspend fun evalGlobal(command: String)
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +37,10 @@ object VMRunnerFactory {
|
||||
override suspend fun executeCommand(command: String) {
|
||||
vmLua.lua.load(command).call()
|
||||
}
|
||||
|
||||
override suspend fun evalGlobal(command: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
"vt2" -> {
|
||||
@@ -47,6 +52,10 @@ object VMRunnerFactory {
|
||||
override suspend fun executeCommand(command: String) {
|
||||
engine.eval(command)
|
||||
}
|
||||
|
||||
override suspend fun evalGlobal(command: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -76,7 +85,11 @@ object VMRunnerFactory {
|
||||
}
|
||||
|
||||
override suspend fun executeCommand(command: String) {
|
||||
engine.eval("\"use strict\";{$command}", context)
|
||||
engine.eval("\"use strict\";" + sanitiseJS(toSingleLine(command)), context)
|
||||
}
|
||||
|
||||
override suspend fun evalGlobal(command: String) {
|
||||
engine.eval("\"use strict\";" + toSingleLine(command), context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +97,8 @@ object VMRunnerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')
|
||||
fun sanitiseJS(code: String) = "eval('${toSingleLine(code).replace("\\", "\\\\")}')"
|
||||
private fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')
|
||||
private fun sanitiseJS(code: String) = "eval('${toSingleLine(code).replace("\\", "\\\\")}')"
|
||||
|
||||
}
|
||||
|
||||
@@ -276,6 +276,16 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole
|
||||
|
||||
override fun eraseInDisp(arg: Int) {
|
||||
when (arg) {
|
||||
2 -> {
|
||||
val foreBits = ttyFore or ttyFore.shl(8) or ttyFore.shl(16) or ttyFore.shl(24)
|
||||
val backBits = ttyBack or ttyBack.shl(8) or ttyBack.shl(16) or ttyBack.shl(24)
|
||||
for (i in 0 until TEXT_COLS * TEXT_ROWS step 4) {
|
||||
spriteAndTextArea.setInt(memTextForeOffset + i, foreBits)
|
||||
spriteAndTextArea.setInt(memTextBackOffset + i, backBits)
|
||||
spriteAndTextArea.setInt(memTextOffset + i, -1)
|
||||
}
|
||||
spriteAndTextArea.setShort(memTextCursorPosOffset, 0)
|
||||
}
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +224,8 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
|
||||
val wordsUpper = stmtUpper.split(reTokenizer)
|
||||
|
||||
if (stmtUpper.startsWith("SCENE_")) { // indexed scene
|
||||
if (currentScene != 0L) throw IllegalStateException("Line $lnum: Scenes cannot be nested")
|
||||
|
||||
val scenenumStr = stmt.substring(6)
|
||||
try {
|
||||
val scenenum = scenenumStr.toLong()
|
||||
@@ -235,6 +237,8 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
|
||||
}
|
||||
}
|
||||
else if (stmtUpper.startsWith("SCENE ")) { // named scene
|
||||
if (currentScene != 0L) throw IllegalStateException("Line $lnum: Scenes cannot be nested")
|
||||
|
||||
val sceneName = wordsUpper[1]
|
||||
if (sceneName.isNullOrBlank()) {
|
||||
throw IllegalArgumentException("Line $lnum: Illegal scene name on $stmt")
|
||||
@@ -246,9 +250,7 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
|
||||
currentScene = registerNewVariable(sceneName) // scenes use same addr space as vars, to make things easier on the backend
|
||||
}
|
||||
else if (wordsUpper[0] == "END" && wordsUpper[1] == "SCENE") { // END SCENE
|
||||
if (currentScene == 0L) {
|
||||
throw IllegalArgumentException("Line $lnum: END SCENE is called without matching SCENE definition")
|
||||
}
|
||||
if (currentScene == 0L) throw IllegalArgumentException("Line $lnum: END SCENE is called without matching SCENE definition")
|
||||
|
||||
scenes[currentScene] = sceneStatements.toTypedArray()
|
||||
|
||||
@@ -532,7 +534,7 @@ object Command {
|
||||
instance.sleepLatch = true
|
||||
|
||||
val timeTook = (System.nanoTime() - instance.performanceCounterTmr).toDouble()
|
||||
instance.statsFrameTime = timeTook / 1000000000.0
|
||||
instance.statsFrameTime = timeTook * 0.000001
|
||||
instance.performanceCounterTmr = System.nanoTime()
|
||||
}
|
||||
instSet[CMP shr 3] = { instance, args -> // CMP rA rB rC
|
||||
|
||||
Reference in New Issue
Block a user