vm idle indicator

This commit is contained in:
minjaesong
2024-09-06 00:53:09 +09:00
parent 4ab69d0767
commit 8bbc752d87
6 changed files with 56 additions and 15 deletions

View File

@@ -36,15 +36,15 @@ const COL_HL_EXT = {
}
const EXEC_FUNS = {
"wav": (f) => _G.shell.execute(`playwav ${f} -i`),
"adpcm": (f) => _G.shell.execute(`playwav ${f} -i`),
"mp3": (f) => _G.shell.execute(`playmp3 ${f} -i`),
"mp2": (f) => _G.shell.execute(`playmp2 ${f} -i`),
"mov": (f) => _G.shell.execute(`playmov ${f} -i`),
"pcm": (f) => _G.shell.execute(`playpcm ${f} -i`),
"ipf1": (f) => _G.shell.execute(`decodeipf ${f} -i`),
"ipf2": (f) => _G.shell.execute(`decodeipf ${f} -i`),
"bas": (f) => _G.shell.execute(`basic ${f}`)
"wav": (f) => _G.shell.execute(`playwav "${f}" -i`),
"adpcm": (f) => _G.shell.execute(`playwav "${f}" -i`),
"mp3": (f) => _G.shell.execute(`playmp3 "${f}" -i`),
"mp2": (f) => _G.shell.execute(`playmp2 "${f}" -i`),
"mov": (f) => _G.shell.execute(`playmov "${f}" -i`),
"pcm": (f) => _G.shell.execute(`playpcm "${f}" -i`),
"ipf1": (f) => _G.shell.execute(`decodeipf "${f}" -i`),
"ipf2": (f) => _G.shell.execute(`decodeipf "${f}" -i`),
"bas": (f) => _G.shell.execute(`basic "${f}"`)
}
let windowMode = 0 // 0 == left, 1 == right

View File

@@ -10,6 +10,7 @@ import java.io.InputStream
import java.io.OutputStream
import java.nio.charset.Charset
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.math.ceil
@@ -77,6 +78,8 @@ class VM(
val isRunning: Boolean
get() = !disposed &&startTime >= 0
val isIdle = AtomicBoolean(true)
init {
println("[VM] Creating new VM with ID of $id, memsize $memsize")

View File

@@ -229,16 +229,22 @@ class VMJSR223Delegate(private val vm: VM) {
}
fun spin() {
vm.isIdle.set(true)
Thread.sleep(4L)
vm.isIdle.set(false)
}
fun sleep(time: Long) {
vm.isIdle.set(true)
Thread.sleep(time)
Thread.sleep(4L)
}
fun waitForMemChg(addr: Int, andMask: Int, xorMask: Int) {
while ((peek(addr) xor xorMask) and andMask == 0) {
vm.isIdle.set(true)
Thread.sleep(1L)
vm.isIdle.set(false)
}
}
fun waitForMemChg(addr: Int, andMask: Int) = waitForMemChg(addr, andMask, 0)

View File

@@ -19,10 +19,13 @@ import net.torvald.terrarum.DefaultGL32Shaders
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
import net.torvald.tsvm.*
import net.torvald.tsvm.peripheral.GraphicsAdapter.Companion.DRAW_SHADER_FRAG
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.*
import kotlin.experimental.and
import kotlin.math.floor
import kotlin.math.min
data class AdapterConfig(
val theme: String,
@@ -39,7 +42,7 @@ data class AdapterConfig(
val paletteShader: String = DRAW_SHADER_FRAG,
val drawScale: Float = 1f,
val scaleFiltered: Boolean = false,
val baudRate: Double = 10_240_000.0,//57600.0,
val baudRate: Double = 16_384_000.0,//57600.0,
val bitsPerChar: Int = 10 // start bit + 8 data bits + stop bit
)
@@ -934,6 +937,20 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
override fun write(p0: Int) {
writeOut(p0.toByte())
}
override fun write(b: ByteArray) {
this.write(b, 0, b.size)
}
override fun write(b: ByteArray, off: Int, len: Int) {
vm.isIdle.set(true)
Objects.checkFromIndexSize(off, len, b.size)
for (i in 0 until len) {
writeOut(b[off + i])
}
vm.isIdle.set(false)
}
}
return PRINTSTREAM_INSTANCE
@@ -951,15 +968,22 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
private val SGI_RESET = byteArrayOf(0x1B, 0x5B, 0x6D)
override fun write(p0: Int) {
vm.isIdle.set(true)
SGI_RED.forEach { writeOut(it) }
writeOut(p0.toByte())
SGI_RESET.forEach { writeOut(it) }
vm.isIdle.set(false)
}
override fun write(p0: ByteArray) {
override fun write(b: ByteArray, off: Int, len: Int) {
Objects.checkFromIndexSize(off, len, b.size)
vm.isIdle.set(true)
SGI_RED.forEach { writeOut(it) }
p0.forEach { writeOut(it) }
for (i in 0 until len) {
writeOut(b[off + i])
}
SGI_RESET.forEach { writeOut(it) }
vm.isIdle.set(false)
}
}
@@ -2242,7 +2266,8 @@ void main() {
)
}
val LAYERORDERS4 = listOf( // [drawn first, second, third, fourth], zero-indexed
val LAYERORDERS4 = listOf(
// [drawn first, second, third, fourth], zero-indexed
"1234",
"1243",
"1324",
@@ -2269,7 +2294,8 @@ void main() {
"4321",
).map { s -> (0..3).map { s[it].toInt() - 49 } }
val LAYERORDERS2 = listOf( // [drawn first, second], zero-indexed
val LAYERORDERS2 = listOf(
// [drawn first, second], zero-indexed
"12",
"12",
"12",

View File

@@ -166,7 +166,12 @@ class IOSpace(val vm: VM) : PeriBase("io"), InputProcessor {
37L -> keyboardBuffer.appendHead(byte)
38L -> {
keyboardInputRequested = (byte.isNonZero())
if (keyboardInputRequested) keyboardBuffer.clear()
if (keyboardInputRequested) {
keyboardBuffer.clear()
vm.isIdle.set(true)
}
else
vm.isIdle.set(false)
}
39L -> rawInputFunctionLatched = (byte.isNonZero())

View File

@@ -201,6 +201,7 @@ class ProfilesMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : Em
batch.setColourBy { theVM?.isRunning == true }
FONT.draw(batch, STR_PLAY, 398f, 382f)
batch.setColourBy(Color.RED, Color.LIME) { (theVM?.peek(-90)?.and(-128) ?: 0.toByte()).toInt() != 0 }
batch.setColourBy(Color.YELLOW, batch.color) { theVM?.isIdle?.get() == true }
FONT.draw(batch, STR_POWER, 419f, 382f)
}
}