mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
qnd input impl with slow spinning
This commit is contained in:
@@ -46,7 +46,7 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
|||||||
|
|
||||||
vm.printStream = gpu.getPrintStream()
|
vm.printStream = gpu.getPrintStream()
|
||||||
vm.errorStream = gpu.getErrorStream()
|
vm.errorStream = gpu.getErrorStream()
|
||||||
//inputStream = gpu.getInputStream()
|
vm.inputStream = gpu.getInputStream()
|
||||||
|
|
||||||
// TEST PRG
|
// TEST PRG
|
||||||
vmRunner = VMRunnerFactory(vm, "js")
|
vmRunner = VMRunnerFactory(vm, "js")
|
||||||
@@ -267,10 +267,7 @@ println("");
|
|||||||
print("C:\\\\>");
|
print("C:\\\\>");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var mx = vm.peek(-33) + vm.peek(-34) * 256;
|
print(String.fromCharCode(vm.readKey()));
|
||||||
var my = vm.peek(-35) + vm.peek(-36) * 256;
|
|
||||||
println("mx: "+mx+", my: "+my);
|
|
||||||
graphics.plotPixel(mx, my, (mx + my) % 255);
|
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class VMJSR223Delegate(val vm: VM) {
|
|||||||
vm.printStream.write((s + '\n').toByteArray())
|
vm.printStream.write((s + '\n').toByteArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun readKey() = vm.inputStream.read()
|
||||||
}
|
}
|
||||||
|
|
||||||
class VMSerialDebugger(val vm: VM) {
|
class VMSerialDebugger(val vm: VM) {
|
||||||
|
|||||||
@@ -413,7 +413,27 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false) : GlassTty(Compa
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getInputStream(): InputStream {
|
override fun getInputStream(): InputStream {
|
||||||
TODO("Not yet implemented")
|
try {
|
||||||
|
return INPUTSTREAM_INSTANCE
|
||||||
|
}
|
||||||
|
catch (e: UninitializedPropertyAccessException) {
|
||||||
|
INPUTSTREAM_INSTANCE = object : InputStream() {
|
||||||
|
|
||||||
|
override fun read(): Int {
|
||||||
|
var key: Byte
|
||||||
|
do {
|
||||||
|
Thread.sleep(4L) // if spinning rate is too fast, this function fail.
|
||||||
|
// Possible cause: Input event handling of GDX is done on separate thread
|
||||||
|
key = vm.getIO().mmio_read(37L)!!
|
||||||
|
} while (key == (-1).toByte())
|
||||||
|
|
||||||
|
println("[stdin] key = $key")
|
||||||
|
return key.toInt().and(255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return INPUTSTREAM_INSTANCE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -67,8 +67,10 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyTyped(p0: Char): Boolean {
|
override fun keyTyped(p0: Char): Boolean {
|
||||||
keyboardBuffer.appendTail(p0.toByte())
|
try {
|
||||||
println("[IO] Key typed: $p0")
|
keyboardBuffer.appendTail(p0.toByte())
|
||||||
|
}
|
||||||
|
catch (e: StackOverflowError) { /* if stack overflow, simply stop reading more keys */ }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user