mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 15:04:03 +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() {
|
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
|
private var readCursor = 0
|
||||||
|
|
||||||
init {
|
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
|
override fun markSupported() = true
|
||||||
@@ -61,3 +63,4 @@ class DiskDriveFileInputStream(vm: VM, portNo: Int, path: String) : InputStream(
|
|||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ object SerialHelper {
|
|||||||
|
|
||||||
fun sendMessageGetBytes(vm: VM, portNo: Int, message: ByteArray): ByteArray {
|
fun sendMessageGetBytes(vm: VM, portNo: Int, message: ByteArray): ByteArray {
|
||||||
sendMessage(vm, portNo, message)
|
sendMessage(vm, portNo, message)
|
||||||
|
waitUntilReady(vm, portNo)
|
||||||
// wait until it is ready
|
|
||||||
while (!checkIfDeviceIsReady(vm, portNo)) { Thread.sleep(SLEEP_TIME) }
|
|
||||||
|
|
||||||
return getMessage(vm, portNo)
|
return getMessage(vm, portNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +52,10 @@ object SerialHelper {
|
|||||||
return msgBuffer.toByteArray()
|
return msgBuffer.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun waitUntilReady(vm: VM, portNo: Int) {
|
||||||
|
while (!checkIfDeviceIsReady(vm, portNo)) { Thread.sleep(SLEEP_TIME) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun checkIfDeviceIsThere(vm: VM, portNo: Int) =
|
private fun checkIfDeviceIsThere(vm: VM, portNo: Int) =
|
||||||
(vm.getIO().mmio_read(4092L + portNo)!! and 1.toByte()) == 1.toByte()
|
(vm.getIO().mmio_read(4092L + portNo)!! and 1.toByte()) == 1.toByte()
|
||||||
|
|||||||
Reference in New Issue
Block a user