mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-09 12:41:51 +09:00
startSend() wont send extra fill-in bytes
This commit is contained in:
@@ -55,6 +55,8 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
private var file: File? = null
|
||||
//private var readModeLength = -1 // always 4096
|
||||
private var stateCode = STATE_CODE_STANDBY
|
||||
private var writeMode = false
|
||||
private var writeModeLength = -1
|
||||
|
||||
private val messageComposeBuffer = ByteArrayOutputStream(BLOCK_SIZE) // always use this and don't alter blockSendBuffer please
|
||||
private var blockSendBuffer = ByteArray(1)
|
||||
@@ -92,14 +94,12 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
|
||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||
val i = blockSendCount * BLOCK_SIZE
|
||||
if (i + it >= blockSendBuffer.size) {
|
||||
0.toByte()
|
||||
}
|
||||
else {
|
||||
blockSendBuffer[i + it]
|
||||
}
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else BLOCK_SIZE
|
||||
|
||||
recipient.writeout(ByteArray(sendSize) {
|
||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
@@ -124,21 +124,20 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
file = null
|
||||
blockSendCount = 0
|
||||
stateCode = STATE_CODE_STANDBY
|
||||
writeMode = false
|
||||
writeModeLength = -1
|
||||
}
|
||||
else if (inputString.startsWith("DEVSTU$END_OF_SEND_BLOCK")) {
|
||||
if (stateCode < 128) {
|
||||
recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||
//startSend { it.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode])) }
|
||||
}
|
||||
else {
|
||||
startSend { it.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode])) }
|
||||
recipient?.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||
}
|
||||
}
|
||||
else if (inputString.startsWith("DEVTYP$END_OF_SEND_BLOCK"))
|
||||
//startSend { it.writeout(composePositiveAns("STOR")) }
|
||||
recipient?.writeout(composePositiveAns("STOR"))
|
||||
else if (inputString.startsWith("DEVNAM$END_OF_SEND_BLOCK"))
|
||||
//startSend { it.writeout(composePositiveAns("Testtec Virtual Disk Drive")) }
|
||||
recipient?.writeout(composePositiveAns("Testtec Virtual Disk Drive"))
|
||||
else if (inputString.startsWith("OPENR\"") || inputString.startsWith("OPENW\"") || inputString.startsWith("OPENA\"")) {
|
||||
if (file != null) {
|
||||
|
||||
@@ -80,7 +80,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
15360th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
15616th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
15872nd Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
16128th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF#""".toByteArray(Charsets.US_ASCII)
|
||||
16128th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
16384th Byte and some trailing bytes too!""".toByteArray(Charsets.US_ASCII)
|
||||
|
||||
private var fileOpen = false
|
||||
|
||||
@@ -106,14 +107,12 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
blockSendBuffer = fileContent_multiblocks
|
||||
}
|
||||
|
||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||
val i = blockSendCount * BLOCK_SIZE
|
||||
if (i + it >= blockSendBuffer.size) {
|
||||
0.toByte()
|
||||
}
|
||||
else {
|
||||
blockSendBuffer[i + it]
|
||||
}
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else BLOCK_SIZE
|
||||
|
||||
recipient.writeout(ByteArray(sendSize) {
|
||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
|
||||
Reference in New Issue
Block a user