qnd input impl with slow spinning

This commit is contained in:
minjaesong
2020-05-15 12:02:52 +09:00
parent 75bb177106
commit 73ae5ec252
4 changed files with 28 additions and 8 deletions

View File

@@ -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()

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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
} }