mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-11 13:41:50 +09:00
^C status wont spill into the next round|memvwr
This commit is contained in:
87
src/net/torvald/tsvm/Memvwr.kt
Normal file
87
src/net/torvald/tsvm/Memvwr.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
|
||||
import net.torvald.tsvm.peripheral.IOSpace
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Dimension
|
||||
import java.awt.Font
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JTextArea
|
||||
import javax.swing.WindowConstants
|
||||
|
||||
class Memvwr(val vm: VM) : JFrame() {
|
||||
|
||||
val memArea = JTextArea()
|
||||
|
||||
fun composeVwrText() {
|
||||
val sb = StringBuilder()
|
||||
val io = vm.peripheralTable[0].peripheral as IOSpace
|
||||
|
||||
sb.append("== MMIO ==\n")
|
||||
|
||||
sb.append("Keyboard buffer: ")
|
||||
for (i in 0L..31L) {
|
||||
sb.append(io.peek(i)!!.toUByte().toString(16).padStart(2, '0').toUpperCase())
|
||||
sb.append(' ')
|
||||
}
|
||||
sb.append('\n')
|
||||
|
||||
sb.append("Keyboard/Mouse input latched: ")
|
||||
sb.append(io.peek(39L) != 0.toByte())
|
||||
sb.append('\n')
|
||||
sb.append("Mouse pos: ")
|
||||
sb.append((io.peek(32L)!!.toUint() or (io.peek(33L)!!.toUint() shl 8)).toShort())
|
||||
sb.append(", ")
|
||||
sb.append((io.peek(34L)!!.toUint() or (io.peek(35L)!!.toUint() shl 8)).toShort())
|
||||
sb.append(" (mouse down: ")
|
||||
sb.append(io.peek(36L) != 0.toByte())
|
||||
sb.append(")\n")
|
||||
sb.append("Keys pressed: ")
|
||||
for (i in 40L..47L) {
|
||||
sb.append(io.peek(i)!!.toUByte().toString(16).padStart(2, '0').toUpperCase())
|
||||
sb.append(' ')
|
||||
}
|
||||
sb.append('\n')
|
||||
|
||||
sb.append("TTY Keyboard read: ")
|
||||
sb.append(io.peek(38L) != 0.toByte())
|
||||
sb.append('\n')
|
||||
|
||||
sb.append("Counter latched: ")
|
||||
sb.append(io.peek(68L)!!.toString(2).padStart(8, '0'))
|
||||
sb.append('\n')
|
||||
|
||||
sb.append("\nBlock transfer status:\n")
|
||||
for (port in 0..3) {
|
||||
val status = io.peek(4084L + 2 * port)!!.toUint() or (io.peek(4085L + 2 * port)!!.toUint() shl 8)
|
||||
|
||||
sb.append("== Port ${port + 1}\n")
|
||||
sb.append(" hasNext: ${(status and 0x8000) != 0}\n")
|
||||
sb.append(" size of the block: ${if (status and 0xFFF == 0) 4096 else status and 0xFFF}\n")
|
||||
}
|
||||
|
||||
sb.append("\nBlock transfer control:\n")
|
||||
for (port in 0..3) {
|
||||
val status = io.peek(4092L + port)!!
|
||||
|
||||
sb.append("== Port ${port + 1}: ${status.toString(2).padStart(8, '0')}\n")
|
||||
}
|
||||
|
||||
memArea.text = sb.toString()
|
||||
}
|
||||
|
||||
fun update() {
|
||||
composeVwrText()
|
||||
}
|
||||
|
||||
init {
|
||||
memArea.font = Font("Monospaced", Font.PLAIN, 12)
|
||||
memArea.highlighter = null
|
||||
|
||||
this.layout = BorderLayout()
|
||||
this.isVisible = true
|
||||
this.add(javax.swing.JScrollPane(memArea), BorderLayout.CENTER)
|
||||
this.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
|
||||
this.size = Dimension(800, 960)
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class VM(
|
||||
64
|
||||
)
|
||||
|
||||
println("[VM] Creating new VM with ID of $id, memesize $memsize")
|
||||
println("[VM] Creating new VM with ID of $id, memsize $memsize")
|
||||
|
||||
startTime = System.nanoTime()
|
||||
}
|
||||
@@ -146,9 +146,13 @@ class VM(
|
||||
internal fun poke(addr: Long, value: Byte) {
|
||||
val (memspace, offset) = translateAddr(addr)
|
||||
if (memspace == null)
|
||||
Firmware.errorIllegalAccess(addr)
|
||||
else if (memspace is UnsafePtr)
|
||||
memspace.set(offset, value)
|
||||
throw Firmware.ErrorIllegalAccess(addr)
|
||||
else if (memspace is UnsafePtr) {
|
||||
if (addr >= memspace.size)
|
||||
throw Firmware.ErrorIllegalAccess(addr)
|
||||
else
|
||||
memspace.set(offset, value)
|
||||
}
|
||||
else
|
||||
(memspace as PeriBase).poke(offset, value)
|
||||
}
|
||||
@@ -157,8 +161,12 @@ class VM(
|
||||
val (memspace, offset) = translateAddr(addr)
|
||||
return if (memspace == null)
|
||||
null
|
||||
else if (memspace is UnsafePtr)
|
||||
memspace.get(offset)
|
||||
else if (memspace is UnsafePtr) {
|
||||
if (addr >= memspace.size)
|
||||
throw Firmware.ErrorIllegalAccess(addr)
|
||||
else
|
||||
memspace.get(offset)
|
||||
}
|
||||
else
|
||||
(memspace as PeriBase).peek(offset)
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
||||
|
||||
lateinit var coroutineJob: Job
|
||||
|
||||
lateinit var memvwr: Memvwr
|
||||
|
||||
override fun create() {
|
||||
super.create()
|
||||
|
||||
gpu = GraphicsAdapter(vm, lcdMode = true)
|
||||
gpu = GraphicsAdapter(vm, lcdMode = false)
|
||||
|
||||
vm.peripheralTable[1] = PeripheralEntry(
|
||||
VM.PERITYPE_TERM,
|
||||
@@ -50,6 +52,8 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
||||
vm.getErrorStream = { gpu.getErrorStream() }
|
||||
vm.getInputStream = { gpu.getInputStream() }
|
||||
|
||||
memvwr = Memvwr(vm)
|
||||
|
||||
// TEST PRG
|
||||
//val fr = FileReader("./assets/tvdos/command.js")
|
||||
//val fr = FileReader("./assets/jscon.js")
|
||||
@@ -81,6 +85,8 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
||||
override fun render() {
|
||||
Gdx.graphics.setTitle("${AppLoader.appTitle} $EMDASH F: ${Gdx.graphics.framesPerSecond}")
|
||||
|
||||
memvwr.update()
|
||||
|
||||
super.render()
|
||||
|
||||
val dt = Gdx.graphics.rawDeltaTime
|
||||
|
||||
@@ -7,14 +7,15 @@ import org.luaj.vm2.LuaValue
|
||||
import org.luaj.vm2.lib.OneArgFunction
|
||||
import org.luaj.vm2.lib.TwoArgFunction
|
||||
import org.luaj.vm2.lib.ZeroArgFunction
|
||||
import java.lang.RuntimeException
|
||||
|
||||
internal class Firmware(val vm: VM) : TwoArgFunction() {
|
||||
|
||||
class ErrorIllegalAccess(val addr: Long) : RuntimeException() {
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun errorIllegalAccess(addr: Long) {
|
||||
|
||||
}
|
||||
|
||||
internal fun translateAddr(vm : VM, addr: LuaValue): Pair<Any?, Long> {
|
||||
val addr = addr.checklong()
|
||||
return when (addr) {
|
||||
|
||||
@@ -94,7 +94,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
||||
4088L -> (blockTransferPorts[2].yourBlockSize().toByte())
|
||||
4089L -> (blockTransferPorts[2].doYouHaveNext().toInt().shl(7) or blockTransferPorts[2].yourBlockSize().ushr(8).and(15)).toByte()
|
||||
4090L -> (blockTransferPorts[3].yourBlockSize().toByte())
|
||||
4091L -> (blockTransferPorts[4].doYouHaveNext().toInt().shl(7) or blockTransferPorts[3].yourBlockSize().ushr(8).and(15)).toByte()
|
||||
4091L -> (blockTransferPorts[3].doYouHaveNext().toInt().shl(7) or blockTransferPorts[3].yourBlockSize().ushr(8).and(15)).toByte()
|
||||
|
||||
in 4092..4095 -> composeBlockTransferStatus(adi - 4092).toByte()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user