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() contexts.clear()
} }
/**
* Makes the VM stop suddenly without disposing of.
*/
fun park() {
killAllContexts()
startTime = -1
}
fun init() { fun init() {
killAllContexts() killAllContexts()
usermem.fillWith(0)
startTime = System.currentTimeMillis()
mallocMap.clear() mallocMap.clear()
mallocSizes.clear() mallocSizes.clear()
allocatedBlockCount = 0 allocatedBlockCount = 0
startTime = System.currentTimeMillis()
} }
@@ -115,6 +123,7 @@ class VM(
disposed = true disposed = true
} }
/** /**
* To check if the VM has started, check if startTime >= 0 * 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.files.FileHandle
import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.GdxRuntimeException
import com.badlogic.gdx.utils.JsonReader import com.badlogic.gdx.utils.JsonReader
import com.badlogic.gdx.utils.JsonValue import com.badlogic.gdx.utils.JsonValue
import com.badlogic.gdx.utils.JsonWriter 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) { internal fun initVMenv(vm: VM) {
vm.init() vm.init()
vm.peripheralTable.getOrNull(1)?.peripheral?.dispose() try {
vm.peripheralTable.getOrNull(1)?.peripheral?.dispose()
}
catch (_: GdxRuntimeException) {}
val gpu = ReferenceGraphicsAdapter2("./assets", vm) val gpu = ReferenceGraphicsAdapter2("./assets", vm)
vm.peripheralTable[1] = PeripheralEntry(gpu)//, GraphicsAdapter.VRAM_SIZE, 16, 0) 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) { internal fun killVMenv(vm: VM) {
vm.dispose() vm.park()
vm.peripheralTable.fill(PeripheralEntry())
for (i in 1 until vm.peripheralTable.size) {
vm.peripheralTable[i].peripheral?.dispose()
}
vm.getPrintStream = { TODO() } vm.getPrintStream = { TODO() }
vm.getErrorStream = { TODO() } vm.getErrorStream = { TODO() }
vm.getInputStream = { TODO() } vm.getInputStream = { TODO() }
vmRunners[vm.id]?.close() vmRunners[vm.id]?.close()
coroutineJobs[vm.id]?.cancel() coroutineJobs[vm.id]?.cancel("VM kill command received")
// re-create the IOSpace (peripheral index 0)
vm.peripheralTable[0] = PeripheralEntry(IOSpace(vm))
} }
private fun setCameraPosition(newX: Float, newY: Float) { private fun setCameraPosition(newX: Float, newY: Float) {