From 42fbd98acf3feb38577b9434e8cd6fc143b51cc8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 25 Mar 2023 13:04:39 +0900 Subject: [PATCH] TEVD debugger proof-of-concept --- .../src/net/torvald/reflection/Reflection.kt | 17 ++++++++++ .../src/net/torvald/tsvm/AudioMenu.kt | 13 +------- .../src/net/torvald/tsvm/TevdMenu.kt | 33 +++++++++++++++++-- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 tsvm_core/src/net/torvald/reflection/Reflection.kt diff --git a/tsvm_core/src/net/torvald/reflection/Reflection.kt b/tsvm_core/src/net/torvald/reflection/Reflection.kt new file mode 100644 index 0000000..919c811 --- /dev/null +++ b/tsvm_core/src/net/torvald/reflection/Reflection.kt @@ -0,0 +1,17 @@ +package net.torvald.reflection + +/** + * Created by minjaesong on 2023-03-25. + */ +fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name + return this.javaClass.getDeclaredField(name).let { + it.isAccessible = true + it.get(this) + } +} +fun Any.forceInvoke(name: String, params: Array): Any? { // yes I'm deliberately using negative words for the function name + return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let { + it.isAccessible = true + it.invoke(this, *params) + } +} \ No newline at end of file diff --git a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt index e78d117..eb598f0 100644 --- a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt +++ b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt @@ -3,6 +3,7 @@ package net.torvald.tsvm import com.badlogic.gdx.Audio import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.reflection.extortField import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint import net.torvald.tsvm.EmulatorGuiToolkit.Theme.COL_ACTIVE3 import net.torvald.tsvm.EmulatorGuiToolkit.Theme.COL_HIGHLIGHT2 @@ -182,17 +183,5 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe override fun dispose() { } - private fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name - return this.javaClass.getDeclaredField(name).let { - it.isAccessible = true - it.get(this) - } - } - private fun Any.forceInvoke(name: String, params: Array): Any? { // yes I'm deliberately using negative words for the function name - return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let { - it.isAccessible = true - it.invoke(this, *params) - } - } } \ No newline at end of file diff --git a/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt b/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt index e605a3d..1772100 100644 --- a/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt +++ b/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt @@ -2,7 +2,11 @@ package net.torvald.tsvm import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.reflection.extortField +import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.EntryID +import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.PartialDOM import net.torvald.tsvm.VMEmuExecutableWrapper.Companion.FONT +import net.torvald.tsvm.peripheral.TevdDiskDrive /** * Created by minjaesong on 2023-03-25. @@ -20,10 +24,33 @@ class TevdMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMen override fun render(batch: SpriteBatch) { - batch.inUse { - batch.color = Color.CORAL - FONT.draw(batch, "Tevd!", 12f, 12f) + val dev = parent.currentlyPersistentVM?.vm?.getIO()?.blockTransferPorts?.getOrNull(cardIndex ?: -1)?.recipient + + if (dev?.javaClass?.simpleName == "TevdDiskDrive") { + val dev = dev as TevdDiskDrive + val DOM = dev.extortField("DOM") as PartialDOM + val DOMfileCache = DOM.extortField("fileCache") as HashMap + + batch.inUse { + batch.color = Color.WHITE + FONT.draw(batch, "Disk UUID: ${dev.diskUUIDstr}", 12f, 12f) + FONT.draw(batch, "F I L E C A C H E", 12f, 12f+FONT.H) + var row = 2 + DOMfileCache.forEach { (id, entry) -> + val str = "ID $id" + FONT.draw(batch, str, 12f, 12f + FONT.H * row) + + row += 1 + } + } } + else { + batch.inUse { + batch.color = Color.WHITE + FONT.draw(batch, "Device is not TevdDiskDrive", 12f, 12f) + } + } + }