mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
temporarily using threads instead of who-knows-what-the-fucks-have-changed new coroutine
This commit is contained in:
@@ -41,7 +41,7 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
|
|
||||||
var gpu: GraphicsAdapter? = null
|
var gpu: GraphicsAdapter? = null
|
||||||
lateinit var vmRunner: VMRunner
|
lateinit var vmRunner: VMRunner
|
||||||
lateinit var coroutineJob: Job
|
lateinit var coroutineJob: Thread
|
||||||
lateinit var fullscreenQuad: Mesh
|
lateinit var fullscreenQuad: Mesh
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
@@ -110,16 +110,17 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
|
|
||||||
|
|
||||||
vmRunner = VMRunnerFactory("./assets", vm, "js")
|
vmRunner = VMRunnerFactory("./assets", vm, "js")
|
||||||
coroutineJob = GlobalScope.launch {
|
coroutineJob = Thread({
|
||||||
vmRunner.executeCommand(vm.roms[0]!!.readAll())
|
vmRunner.executeCommand(vm.roms[0]!!.readAll())
|
||||||
}
|
}, "VmRunner:${vm.id}")
|
||||||
|
coroutineJob.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var rebootRequested = false
|
private var rebootRequested = false
|
||||||
|
|
||||||
private fun reboot() {
|
private fun reboot() {
|
||||||
vmRunner.close()
|
vmRunner.close()
|
||||||
coroutineJob.cancel("reboot requested")
|
coroutineJob.interrupt()
|
||||||
|
|
||||||
vm.init()
|
vm.init()
|
||||||
init()
|
init()
|
||||||
@@ -208,7 +209,7 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
super.dispose()
|
super.dispose()
|
||||||
batch.dispose()
|
batch.dispose()
|
||||||
fullscreenQuad.dispose()
|
fullscreenQuad.dispose()
|
||||||
coroutineJob.cancel()
|
coroutineJob.interrupt()
|
||||||
vm.dispose()
|
vm.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.torvald.tsvm
|
package net.torvald.tsvm
|
||||||
|
|
||||||
import kotlin.coroutines.Job
|
|
||||||
import net.torvald.UnsafeHelper
|
import net.torvald.UnsafeHelper
|
||||||
import net.torvald.UnsafePtr
|
import net.torvald.UnsafePtr
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toHex
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toHex
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
package net.torvald.tsvm
|
package net.torvald.tsvm
|
||||||
|
|
||||||
import kotlin.coroutines.GlobalScope
|
|
||||||
import kotlin.coroutines.Job
|
|
||||||
import kotlin.coroutines.launch
|
|
||||||
import net.torvald.UnsafeHelper
|
import net.torvald.UnsafeHelper
|
||||||
import net.torvald.UnsafePtr
|
import net.torvald.UnsafePtr
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
||||||
import net.torvald.tsvm.peripheral.*
|
import net.torvald.tsvm.peripheral.*
|
||||||
import java.nio.charset.Charset
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm"
|
* Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm"
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import java.io.FileReader
|
|||||||
import javax.script.ScriptEngineManager
|
import javax.script.ScriptEngineManager
|
||||||
|
|
||||||
abstract class VMRunner(val extension: String) {
|
abstract class VMRunner(val extension: String) {
|
||||||
abstract suspend fun evalGlobal(command: String) // Ring 0
|
abstract fun evalGlobal(command: String) // Ring 0
|
||||||
abstract suspend fun executeCommand(command: String) // Ring 1
|
abstract fun executeCommand(command: String) // Ring 1
|
||||||
abstract fun eval(command: String) // Ring 2 (for child processes spawned using Parallel API)
|
abstract fun eval(command: String) // Ring 2 (for child processes spawned using Parallel API)
|
||||||
abstract fun close()
|
abstract fun close()
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ object VMRunnerFactory {
|
|||||||
val engine =
|
val engine =
|
||||||
Videotron2K(vm.findPeribyType(VM.PERITYPE_GPU_AND_TERM)!!.peripheral!! as GraphicsAdapter)
|
Videotron2K(vm.findPeribyType(VM.PERITYPE_GPU_AND_TERM)!!.peripheral!! as GraphicsAdapter)
|
||||||
|
|
||||||
override suspend fun executeCommand(command: String) {
|
override fun executeCommand(command: String) {
|
||||||
engine.eval(command)
|
engine.eval(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ object VMRunnerFactory {
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun evalGlobal(command: String) {
|
override fun evalGlobal(command: String) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ object VMRunnerFactory {
|
|||||||
context.eval("js", sanitiseJS(prg))
|
context.eval("js", sanitiseJS(prg))
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun executeCommand(command: String) {
|
override fun executeCommand(command: String) {
|
||||||
try {
|
try {
|
||||||
bind.putMember("parallel", ringOneParallel)
|
bind.putMember("parallel", ringOneParallel)
|
||||||
context.eval("js", encapsulateJS(sanitiseJS(command)))
|
context.eval("js", encapsulateJS(sanitiseJS(command)))
|
||||||
@@ -106,7 +106,7 @@ object VMRunnerFactory {
|
|||||||
throw e
|
throw e
|
||||||
} }
|
} }
|
||||||
|
|
||||||
override suspend fun evalGlobal(command: String) {
|
override fun evalGlobal(command: String) {
|
||||||
bind.putMember("parallel", ringOneParallel)
|
bind.putMember("parallel", ringOneParallel)
|
||||||
context.eval("js", "\"use strict\";" + sanitiseJS(command))
|
context.eval("js", "\"use strict\";" + sanitiseJS(command))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ object VMSetupBroker {
|
|||||||
* @param vmRunners Hashmap on the host of VMs that holds the instances of the VMRunners for the given VM. Key: Int(VM's identifier), value: [net.torvald.tsvm.VMRunner]
|
* @param vmRunners Hashmap on the host of VMs that holds the instances of the VMRunners for the given VM. Key: Int(VM's identifier), value: [net.torvald.tsvm.VMRunner]
|
||||||
* @param coroutineJobs Hashmap on the host of VMs that holds the coroutine-job object for the currently running VM-instance. Key: Int(VM's identifier), value: [kotlin.coroutines.Job]
|
* @param coroutineJobs Hashmap on the host of VMs that holds the coroutine-job object for the currently running VM-instance. Key: Int(VM's identifier), value: [kotlin.coroutines.Job]
|
||||||
*/
|
*/
|
||||||
fun initVMenv(vm: VM, profileJson: JsonValue, profileName: String, gpu: GraphicsAdapter, vmRunners: HashMap<VmId, VMRunner>, coroutineJobs: HashMap<VmId, Job>, whatToDoOnVmException: (Throwable) -> Unit) {
|
fun initVMenv(vm: VM, profileJson: JsonValue, profileName: String, gpu: GraphicsAdapter, vmRunners: HashMap<VmId, VMRunner>, coroutineJobs: HashMap<VmId, Thread>, whatToDoOnVmException: (Throwable) -> Unit) {
|
||||||
vm.init()
|
vm.init()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -40,13 +40,16 @@ object VMSetupBroker {
|
|||||||
vm.poke(-90L, 0)
|
vm.poke(-90L, 0)
|
||||||
|
|
||||||
vmRunners[vm.id] = VMRunnerFactory(vm.assetsDir, vm, "js")
|
vmRunners[vm.id] = VMRunnerFactory(vm.assetsDir, vm, "js")
|
||||||
coroutineJobs[vm.id] = GlobalScope.launch {
|
Thread({
|
||||||
try {
|
try {
|
||||||
vmRunners[vm.id]?.executeCommand(vm.roms[0].readAll())
|
vmRunners[vm.id]?.executeCommand(vm.roms[0].readAll())
|
||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
whatToDoOnVmException(e)
|
whatToDoOnVmException(e)
|
||||||
}
|
}
|
||||||
|
}, "VmRunner:${vm.id}").let {
|
||||||
|
coroutineJobs[vm.id] = it
|
||||||
|
it.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +60,7 @@ object VMSetupBroker {
|
|||||||
* @param vmRunners Hashmap on the host of VMs that holds the instances of the VMRunners for the given VM. Key: Int(VM's identifier), value: [net.torvald.tsvm.VMRunner]
|
* @param vmRunners Hashmap on the host of VMs that holds the instances of the VMRunners for the given VM. Key: Int(VM's identifier), value: [net.torvald.tsvm.VMRunner]
|
||||||
* @param coroutineJobs Hashmap on the host of VMs that holds the coroutine-job object for the currently running VM-instance. Key: Int(VM's identifier), value: [kotlin.coroutines.Job]
|
* @param coroutineJobs Hashmap on the host of VMs that holds the coroutine-job object for the currently running VM-instance. Key: Int(VM's identifier), value: [kotlin.coroutines.Job]
|
||||||
*/
|
*/
|
||||||
fun killVMenv(vm: VM, vmRunners: HashMap<VmId, VMRunner>, coroutineJobs: HashMap<VmId, Job>) {
|
fun killVMenv(vm: VM, vmRunners: HashMap<VmId, VMRunner>, coroutineJobs: HashMap<VmId, Thread>) {
|
||||||
|
|
||||||
vm.park()
|
vm.park()
|
||||||
vm.poke(-90L, -128)
|
vm.poke(-90L, -128)
|
||||||
@@ -69,7 +72,7 @@ object VMSetupBroker {
|
|||||||
catch (_: Throwable) {}
|
catch (_: Throwable) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
coroutineJobs[vm.id]?.cancel("VM kill command received")
|
coroutineJobs[vm.id]?.interrupt()
|
||||||
vmRunners[vm.id]?.close()
|
vmRunners[vm.id]?.close()
|
||||||
|
|
||||||
vm.getPrintStream = { TODO() }
|
vm.getPrintStream = { TODO() }
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
|
|||||||
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 com.badlogic.gdx.graphics.glutils.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import kotlin.coroutines.GlobalScope
|
|
||||||
import kotlin.coroutines.Job
|
|
||||||
import kotlin.coroutines.launch
|
|
||||||
import net.torvald.terrarum.DefaultGL32Shaders
|
import net.torvald.terrarum.DefaultGL32Shaders
|
||||||
import net.torvald.tsvm.*
|
import net.torvald.tsvm.*
|
||||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||||
@@ -24,7 +21,7 @@ class V2kRunTest : ApplicationAdapter() {
|
|||||||
|
|
||||||
lateinit var vmRunner: VMRunner
|
lateinit var vmRunner: VMRunner
|
||||||
|
|
||||||
lateinit var coroutineJob: Job
|
lateinit var coroutineJob: Thread
|
||||||
lateinit var vdc: Videotron2K
|
lateinit var vdc: Videotron2K
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
@@ -53,9 +50,9 @@ class V2kRunTest : ApplicationAdapter() {
|
|||||||
vdc = Videotron2K(gpu)
|
vdc = Videotron2K(gpu)
|
||||||
|
|
||||||
vmRunner = VMRunnerFactory("./assets", vm, "js")
|
vmRunner = VMRunnerFactory("./assets", vm, "js")
|
||||||
coroutineJob = GlobalScope.launch {
|
coroutineJob = Thread({
|
||||||
vdc.eval(Videotron2K.screenfiller)
|
vdc.eval(Videotron2K.screenfiller)
|
||||||
}
|
}, "VmRunner:${vm.id}")
|
||||||
|
|
||||||
|
|
||||||
Gdx.input.inputProcessor = vm.getIO()
|
Gdx.input.inputProcessor = vm.getIO()
|
||||||
@@ -96,7 +93,7 @@ class V2kRunTest : ApplicationAdapter() {
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
super.dispose()
|
super.dispose()
|
||||||
batch.dispose()
|
batch.dispose()
|
||||||
coroutineJob.cancel()
|
coroutineJob.interrupt()
|
||||||
vm.dispose()
|
vm.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import com.badlogic.gdx.graphics.*
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.utils.JsonValue
|
import com.badlogic.gdx.utils.JsonValue
|
||||||
import com.badlogic.gdx.utils.JsonWriter
|
import com.badlogic.gdx.utils.JsonWriter
|
||||||
import kotlin.coroutines.Job
|
|
||||||
import kotlin.coroutines.cancel
|
|
||||||
import net.torvald.terrarum.DefaultGL32Shaders
|
import net.torvald.terrarum.DefaultGL32Shaders
|
||||||
import net.torvald.terrarum.FlippingSpriteBatch
|
import net.torvald.terrarum.FlippingSpriteBatch
|
||||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||||
@@ -85,7 +83,7 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
|
|||||||
lateinit var camera: OrthographicCamera
|
lateinit var camera: OrthographicCamera
|
||||||
|
|
||||||
var vmRunners = HashMap<VmId, VMRunner>() // <VM's identifier, VMRunner>
|
var vmRunners = HashMap<VmId, VMRunner>() // <VM's identifier, VMRunner>
|
||||||
var coroutineJobs = HashMap<VmId, Job>() // <VM's identifier, Job>
|
var coroutineJobs = HashMap<VmId, Thread>() // <VM's identifier, Job>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val APPDATADIR = TsvmEmulator.defaultDir
|
val APPDATADIR = TsvmEmulator.defaultDir
|
||||||
@@ -277,7 +275,7 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
|
|||||||
val vm = currentlyLoadedProfiles[profileName]!!
|
val vm = currentlyLoadedProfiles[profileName]!!
|
||||||
|
|
||||||
vmRunners[vm.id]!!.close()
|
vmRunners[vm.id]!!.close()
|
||||||
coroutineJobs[vm.id]!!.cancel("reboot requested")
|
coroutineJobs[vm.id]!!.interrupt()
|
||||||
|
|
||||||
vm.init()
|
vm.init()
|
||||||
initVMenv(vm, profileName)
|
initVMenv(vm, profileName)
|
||||||
@@ -406,7 +404,7 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
|
|||||||
batch.dispose()
|
batch.dispose()
|
||||||
fbatch.dispose()
|
fbatch.dispose()
|
||||||
fullscreenQuad.dispose()
|
fullscreenQuad.dispose()
|
||||||
coroutineJobs.values.forEach { it.cancel() }
|
coroutineJobs.values.forEach { it.interrupt() }
|
||||||
vms.forEach { it?.vm?.dispose() }
|
vms.forEach { it?.vm?.dispose() }
|
||||||
|
|
||||||
writeProfilesToFile(Gdx.files.absolute("$APPDATADIR/profiles.json"))
|
writeProfilesToFile(Gdx.files.absolute("$APPDATADIR/profiles.json"))
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
|
|
||||||
var gpu: GraphicsAdapter? = null
|
var gpu: GraphicsAdapter? = null
|
||||||
lateinit var vmRunner: VMRunner
|
lateinit var vmRunner: VMRunner
|
||||||
lateinit var coroutineJob: Job
|
lateinit var coroutineJob: Thread
|
||||||
lateinit var memvwr: Memvwr
|
lateinit var memvwr: Memvwr
|
||||||
lateinit var fullscreenQuad: Mesh
|
lateinit var fullscreenQuad: Mesh
|
||||||
|
|
||||||
@@ -115,16 +115,16 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
|
|
||||||
|
|
||||||
vmRunner = VMRunnerFactory(vm.assetsDir, vm, "js")
|
vmRunner = VMRunnerFactory(vm.assetsDir, vm, "js")
|
||||||
coroutineJob = GlobalScope.launch {
|
coroutineJob = Thread({
|
||||||
vmRunner.executeCommand(vm.roms[0]!!.readAll())
|
vmRunner.executeCommand(vm.roms[0]!!.readAll())
|
||||||
}
|
}, "VmRunner:${vm.id}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private var rebootRequested = false
|
private var rebootRequested = false
|
||||||
|
|
||||||
private fun reboot() {
|
private fun reboot() {
|
||||||
vmRunner.close()
|
vmRunner.close()
|
||||||
coroutineJob.cancel("reboot requested")
|
coroutineJob.interrupt()
|
||||||
|
|
||||||
vm.init()
|
vm.init()
|
||||||
init()
|
init()
|
||||||
@@ -217,7 +217,7 @@ class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHe
|
|||||||
super.dispose()
|
super.dispose()
|
||||||
batch.dispose()
|
batch.dispose()
|
||||||
fullscreenQuad.dispose()
|
fullscreenQuad.dispose()
|
||||||
coroutineJob.cancel()
|
coroutineJob.interrupt()
|
||||||
vm.dispose()
|
vm.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user