diff --git a/lib/TerranVirtualDisk-src.jar b/lib/TerranVirtualDisk-src.jar index bdc865e..5508e1a 100644 Binary files a/lib/TerranVirtualDisk-src.jar and b/lib/TerranVirtualDisk-src.jar differ diff --git a/lib/TerranVirtualDisk.jar b/lib/TerranVirtualDisk.jar index a3de12f..fd3c492 100644 Binary files a/lib/TerranVirtualDisk.jar and b/lib/TerranVirtualDisk.jar differ diff --git a/terranmon.txt b/terranmon.txt index db0b5d3..cc1d76e 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -115,12 +115,12 @@ MMIO n-read: size of the block from the other device, LSB (4096-full block size is zero) m-read: size of the block from the other device, MSB (4096-full block size is zero) a-read: if the other device hasNext (doYouHaveNext), false if device not present - z-read: set if the size is actually 0 instead of 4096 + z-read: set if the size is actually 0 instead of 4096 (overrides n and m parameters) n-write: size of the block I'm sending, LSB (4096-full block size is zero) m-write: size of the block I'm sending, MSB (4096-full block size is zero) a-write: if there's more to send (hasNext) - z-write: set if the size is actually 0 instead of 4096 + z-write: set if the size is actually 0 instead of 4096 (overrides n and m parameters) 4092..4095 RW: Block transfer control for Port 1 through 4 0b 00ms abcd diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt index cfd61dc..850c911 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt @@ -121,6 +121,8 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath: val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE) blockSendBuffer.size % BLOCK_SIZE + else if (blockSendBuffer.size <= BLOCK_SIZE) + blockSendBuffer.size else BLOCK_SIZE // println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}") @@ -147,21 +149,41 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath: //println("[DiskDrive] writeout with inputdata length of ${inputData.size}") //println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}") +// println("[TestDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)") + + if (!fileOpen) throw InternalError("File is not open but the drive is in write mode") - System.arraycopy(inputData, 0, writeBuffer, writeBufferUsage, minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE)) - writeBufferUsage += inputData.size + if (writeModeLength == 0) { +// println("[TestDiskDrive] write mode was initiated with zero-byte writing; closing immediately") - if (writeBufferUsage >= writeModeLength) { - // commit to the disk - if (appendMode) - file.appendBytes(writeBuffer) - else if (writeMode) - file.writeBytes(writeBuffer) + if (writeMode) + file.writeBytes(ByteArray(0)) writeMode = false appendMode = false } + else { + System.arraycopy( + inputData, + 0, + writeBuffer, + writeBufferUsage, + minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE) + ) + writeBufferUsage += inputData.size + + if (writeBufferUsage >= writeModeLength) { + // commit to the disk + if (appendMode) + file.appendBytes(writeBuffer) + else if (writeMode) + file.writeBytes(writeBuffer) + + writeMode = false + appendMode = false + } + } } else if (fileOpenMode == 17) { if (!fileOpen) throw InternalError("Bootloader file is not open but the drive is in boot write mode") diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt index 88e62cc..498e88d 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt @@ -117,6 +117,8 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath: val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE) blockSendBuffer.size % BLOCK_SIZE + else if (blockSendBuffer.size <= BLOCK_SIZE) + blockSendBuffer.size else BLOCK_SIZE // println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}") @@ -143,12 +145,17 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath: //println("[DiskDrive] writeout with inputdata length of ${inputData.size}") //println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}") - println("[TevDiskDrive] write-payload (${inputData.size} bytes)") +// println("[TevDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)") if (!fileOpen) throw InternalError("File is not open but the drive is in write mode") - if (writeBuffer.isEmpty()) { + if (writeModeLength == 0) { +// println("[TevDiskDrive] write mode was initiated with zero-byte writing; closing immediately") + + if (writeMode) + file.overwrite(ByteArray(0)) + writeMode = false appendMode = false }