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.errorStream = gpu.getErrorStream()
|
||||
//inputStream = gpu.getInputStream()
|
||||
vm.inputStream = gpu.getInputStream()
|
||||
|
||||
// TEST PRG
|
||||
vmRunner = VMRunnerFactory(vm, "js")
|
||||
@@ -267,10 +267,7 @@ println("");
|
||||
print("C:\\\\>");
|
||||
|
||||
while (true) {
|
||||
var mx = vm.peek(-33) + vm.peek(-34) * 256;
|
||||
var my = vm.peek(-35) + vm.peek(-36) * 256;
|
||||
println("mx: "+mx+", my: "+my);
|
||||
graphics.plotPixel(mx, my, (mx + my) % 255);
|
||||
print(String.fromCharCode(vm.readKey()));
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class VMJSR223Delegate(val vm: VM) {
|
||||
vm.printStream.write((s + '\n').toByteArray())
|
||||
}
|
||||
|
||||
fun readKey() = vm.inputStream.read()
|
||||
}
|
||||
|
||||
class VMSerialDebugger(val vm: VM) {
|
||||
|
||||
@@ -413,7 +413,27 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false) : GlassTty(Compa
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
@@ -67,8 +67,10 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
||||
}
|
||||
|
||||
override fun keyTyped(p0: Char): Boolean {
|
||||
keyboardBuffer.appendTail(p0.toByte())
|
||||
println("[IO] Key typed: $p0")
|
||||
try {
|
||||
keyboardBuffer.appendTail(p0.toByte())
|
||||
}
|
||||
catch (e: StackOverflowError) { /* if stack overflow, simply stop reading more keys */ }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user