mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
oh my
This commit is contained in:
@@ -11,11 +11,13 @@ class VmFilesystemDelegate(val vm: VM, val portNo: Int) {
|
||||
|
||||
class DiskDriveFileInputStream(vm: VM, portNo: Int, path: String) : InputStream() {
|
||||
|
||||
private val contents = SerialHelper.sendMessageGetBytes(vm, portNo, "OPENR\"$path\"".toByteArray(VM.CHARSET))
|
||||
private val contents: ByteArray
|
||||
private var readCursor = 0
|
||||
|
||||
init {
|
||||
contents.toString() // meaningless statement to NOT lazy eval the property
|
||||
SerialHelper.sendMessage(vm, portNo, "OPENR\"$path\"".toByteArray(VM.CHARSET))
|
||||
SerialHelper.waitUntilReady(vm, portNo)
|
||||
contents = SerialHelper.sendMessageGetBytes(vm, portNo, "READ".toByteArray(VM.CHARSET))
|
||||
}
|
||||
|
||||
override fun markSupported() = true
|
||||
@@ -60,4 +62,5 @@ class DiskDriveFileInputStream(vm: VM, portNo: Int, path: String) : InputStream(
|
||||
override fun close() {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@ object SerialHelper {
|
||||
|
||||
fun sendMessageGetBytes(vm: VM, portNo: Int, message: ByteArray): ByteArray {
|
||||
sendMessage(vm, portNo, message)
|
||||
|
||||
// wait until it is ready
|
||||
while (!checkIfDeviceIsReady(vm, portNo)) { Thread.sleep(SLEEP_TIME) }
|
||||
|
||||
waitUntilReady(vm, portNo)
|
||||
return getMessage(vm, portNo)
|
||||
}
|
||||
|
||||
@@ -55,6 +52,10 @@ object SerialHelper {
|
||||
return msgBuffer.toByteArray()
|
||||
}
|
||||
|
||||
fun waitUntilReady(vm: VM, portNo: Int) {
|
||||
while (!checkIfDeviceIsReady(vm, portNo)) { Thread.sleep(SLEEP_TIME) }
|
||||
}
|
||||
|
||||
|
||||
private fun checkIfDeviceIsThere(vm: VM, portNo: Int) =
|
||||
(vm.getIO().mmio_read(4092L + portNo)!! and 1.toByte()) == 1.toByte()
|
||||
|
||||
Reference in New Issue
Block a user