mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
duh duh duh duh
This commit is contained in:
@@ -61,6 +61,7 @@ object SerialHelper {
|
||||
waitUntilReady(vm, portNo)
|
||||
|
||||
val transStat = getBlockTransferStatus(vm, portNo)
|
||||
println("[SerialHelper.pullMessage()] received length: ${transStat.first}")
|
||||
|
||||
for (k in 0 until minOf(BLOCK_SIZE, transStat.first)) {
|
||||
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
||||
|
||||
@@ -22,16 +22,14 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
||||
|
||||
/** Writes a thing to the recipient.
|
||||
* A method exposed to outside of the box */
|
||||
abstract fun startSend()
|
||||
abstract fun startSendImpl(recipient: BlockTransferInterface)
|
||||
/** The actual implementation */
|
||||
protected fun startSend(sendfun: ((BlockTransferInterface) -> Unit)? = null) {
|
||||
fun startSend() {
|
||||
//if (areYouReady()) {
|
||||
busy = true
|
||||
ready = false
|
||||
|
||||
recipient?.let { recipient ->
|
||||
sendfun?.invoke(recipient)
|
||||
}
|
||||
recipient?.let { startSendImpl(it) }
|
||||
|
||||
busy = false
|
||||
ready = true
|
||||
@@ -48,13 +46,13 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
||||
}
|
||||
|
||||
/** A method called by the sender so it can ACTUALLY write its thing onto me. */
|
||||
abstract fun writeout(inputData: ByteArray)
|
||||
abstract fun writeoutImpl(inputData: ByteArray)
|
||||
/** The actual implementation; must be called by a sender class */
|
||||
protected fun writeout(inputData: ByteArray, writeoutfun: (() -> Unit)? = null) {
|
||||
fun writeout(inputData: ByteArray) {
|
||||
busy = true
|
||||
ready = false
|
||||
blockSize = minOf(inputData.size, BLOCK_SIZE)
|
||||
writeoutfun?.invoke()
|
||||
writeoutImpl(inputData)
|
||||
busy = false
|
||||
ready = true
|
||||
}
|
||||
|
||||
@@ -10,32 +10,22 @@ class BlockTransferPort(val vm: VM, val portno: Int) : BlockTransferInterface(tr
|
||||
|
||||
internal var hasNext = false
|
||||
|
||||
override fun startSend() {
|
||||
startSend { recipient ->
|
||||
val ba = ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] }
|
||||
recipient.writeout(ba)
|
||||
}
|
||||
|
||||
this.ready = true
|
||||
this.busy = false
|
||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||
recipient.writeout(ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] })
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = hasNext
|
||||
|
||||
override fun writeout(inputData: ByteArray) {
|
||||
writeout(inputData) {
|
||||
//val copySize = minOf(BLOCK_SIZE, inputData.size).toLong()
|
||||
//val arrayOffset = UnsafeHelper.getArrayOffset(inputData)
|
||||
//UnsafeHelper.memcpyRaw(inputData, arrayOffset, null, vm.getIO().blockTransferRx[portno].ptr, copySize)
|
||||
override fun writeoutImpl(inputData: ByteArray) {
|
||||
//val copySize = minOf(BLOCK_SIZE, inputData.size).toLong()
|
||||
//val arrayOffset = UnsafeHelper.getArrayOffset(inputData)
|
||||
//UnsafeHelper.memcpyRaw(inputData, arrayOffset, null, vm.getIO().blockTransferRx[portno].ptr, copySize)
|
||||
|
||||
// not exposing raw memory to block probable security hole
|
||||
for (k in 0 until BLOCK_SIZE) {
|
||||
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0 else inputData[k]
|
||||
}
|
||||
// not exposing raw memory to block probable security hole
|
||||
println("[BlockTranferPort] writeout size: ${inputData.size}")
|
||||
for (k in 0 until BLOCK_SIZE) {
|
||||
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0x5F else inputData[k]
|
||||
}
|
||||
|
||||
this.ready = true
|
||||
this.busy = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -88,22 +88,20 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
*
|
||||
* Disk drive must send prepared message (or file transfer packet) to the computer.
|
||||
*/
|
||||
override fun startSend() {
|
||||
recipient?.let { recipient ->
|
||||
if (blockSendCount == 0) {
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
|
||||
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
|
||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||
if (blockSendCount == 0) {
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/** Computer's attempt to startSend() will result in calling this very function.
|
||||
@@ -111,11 +109,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
*
|
||||
* Disk drive must create desired side effects in accordance with the input message.
|
||||
*/
|
||||
override fun writeout(inputData: ByteArray) {
|
||||
ready = false
|
||||
busy = true
|
||||
|
||||
|
||||
override fun writeoutImpl(inputData: ByteArray) {
|
||||
val inputString = inputData.toString()
|
||||
|
||||
if (inputString.startsWith("DEVRST$END_OF_SEND_BLOCK")) {
|
||||
@@ -190,10 +184,6 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ready = true
|
||||
busy = false
|
||||
}
|
||||
|
||||
val diskID: UUID = UUID(0, 0)
|
||||
|
||||
@@ -100,24 +100,21 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
return sb.toByteArray()
|
||||
}
|
||||
|
||||
override fun startSend() {
|
||||
recipient?.let { recipient ->
|
||||
if (blockSendCount == 0) {
|
||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
blockSendBuffer = fileContent_multiblocks
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||
if (blockSendCount == 0) {
|
||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
blockSendBuffer = fileContent_multiblocks
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
@@ -125,7 +122,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
|
||||
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
||||
}
|
||||
override fun writeout(inputData: ByteArray) {
|
||||
override fun writeoutImpl(inputData: ByteArray) {
|
||||
val inputString = inputData.toString(VM.CHARSET)
|
||||
|
||||
if (inputString.startsWith("DEVRST\u0017")) {
|
||||
|
||||
Reference in New Issue
Block a user