stopping and restarting the vm

This commit is contained in:
minjaesong
2022-12-14 21:02:14 +09:00
parent 45dd5be3f2
commit 77f0c77723
2 changed files with 24 additions and 10 deletions

View File

@@ -79,14 +79,22 @@ class VM(
contexts.clear()
}
/**
* Makes the VM stop suddenly without disposing of.
*/
fun park() {
killAllContexts()
startTime = -1
}
fun init() {
killAllContexts()
startTime = System.currentTimeMillis()
usermem.fillWith(0)
mallocMap.clear()
mallocSizes.clear()
allocatedBlockCount = 0
startTime = System.currentTimeMillis()
}
@@ -115,6 +123,7 @@ class VM(
disposed = true
}
/**
* To check if the VM has started, check if startTime >= 0
*/

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.GdxRuntimeException
import com.badlogic.gdx.utils.JsonReader
import com.badlogic.gdx.utils.JsonValue
import com.badlogic.gdx.utils.JsonWriter
@@ -192,7 +193,10 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
internal fun initVMenv(vm: VM) {
vm.init()
vm.peripheralTable.getOrNull(1)?.peripheral?.dispose()
try {
vm.peripheralTable.getOrNull(1)?.peripheral?.dispose()
}
catch (_: GdxRuntimeException) {}
val gpu = ReferenceGraphicsAdapter2("./assets", vm)
vm.peripheralTable[1] = PeripheralEntry(gpu)//, GraphicsAdapter.VRAM_SIZE, 16, 0)
@@ -206,17 +210,18 @@ class VMEmuExecutable(val windowWidth: Int, val windowHeight: Int, var panelsX:
}
internal fun killVMenv(vm: VM) {
vm.dispose()
vm.peripheralTable.fill(PeripheralEntry())
vm.park()
for (i in 1 until vm.peripheralTable.size) {
vm.peripheralTable[i].peripheral?.dispose()
}
vm.getPrintStream = { TODO() }
vm.getErrorStream = { TODO() }
vm.getInputStream = { TODO() }
vmRunners[vm.id]?.close()
coroutineJobs[vm.id]?.cancel()
// re-create the IOSpace (peripheral index 0)
vm.peripheralTable[0] = PeripheralEntry(IOSpace(vm))
coroutineJobs[vm.id]?.cancel("VM kill command received")
}
private fun setCameraPosition(newX: Float, newY: Float) {