mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
test disk drive wip
This commit is contained in:
@@ -17,7 +17,10 @@ All peripherals using serial connection must follow these standards
|
||||
|
||||
<COMMAND-STRING> 0x17
|
||||
<COMMAND-STRING> 0x1E <ARGUMENTS-STRINGS SEPARATED BY 0x1F> 0x17
|
||||
<ANSWER-STRINGS SEPARATED BY 0x1F> 0x17
|
||||
In case of positive acknowledge:
|
||||
0x06 <ANSWER-STRINGS SEPARATED BY 0x1F> 0x17
|
||||
In case of negative acknowledge (e.g. error messages):
|
||||
0x15 <ANSWER-STRINGS SEPARATED BY 0x1F> 0x17
|
||||
|
||||
All ENQUIRY commands are RECOMMENDED to be no larger than 4096 bytes
|
||||
STRINGs only consists with printable ASCII subset
|
||||
|
||||
@@ -18,7 +18,8 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
||||
open fun areYouReady(): Boolean = recipient?.ready ?: false
|
||||
open fun areYouBusy(): Boolean = recipient?.busy ?: false
|
||||
|
||||
/** A method exposed to outside of the box */
|
||||
/** Writes a thing to the recipient.
|
||||
* A method exposed to outside of the box */
|
||||
abstract fun startSend()
|
||||
/** The actual implementation */
|
||||
protected fun startSend(sendfun: ((BlockTransferInterface) -> Unit)? = null) {
|
||||
@@ -35,11 +36,13 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
||||
}
|
||||
}
|
||||
|
||||
/** Ask the recipient to start send its thing to me so that I can 'read'
|
||||
*/
|
||||
open fun startRead() {
|
||||
recipient?.startSend(null)
|
||||
}
|
||||
|
||||
/** A method exposed to outside of the box */
|
||||
/** A method called by the sender so it can ACTUALLY write its thing onto me. */
|
||||
abstract fun writeout(inputData: ByteArray)
|
||||
/** The actual implementation; must be called by a sender class */
|
||||
protected fun writeout(inputData: ByteArray, writeoutfun: (() -> Unit)? = null) {
|
||||
|
||||
@@ -38,7 +38,8 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
||||
private val keyEventBuffers = ByteArray(8)
|
||||
|
||||
init {
|
||||
blockTransferPorts[0].attachDevice(TestFunctionGenerator())
|
||||
//blockTransferPorts[0].attachDevice(TestFunctionGenerator())
|
||||
blockTransferPorts[0].attachDevice(TestDiskDrive(0))
|
||||
}
|
||||
|
||||
private fun composeBlockTransferStatus(portno: Int): Int {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package net.torvald.tsvm.peripheral
|
||||
|
||||
import java.util.*
|
||||
|
||||
class SerialDiskDrive : BlockTransferInterface(false, true) {
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun startSend() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun writeout(inputData: ByteArray) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
val diskID: UUID = UUID(0, 0)
|
||||
|
||||
|
||||
}
|
||||
100
src/net/torvald/tsvm/peripheral/TestDiskDrive.kt
Normal file
100
src/net/torvald/tsvm/peripheral/TestDiskDrive.kt
Normal file
@@ -0,0 +1,100 @@
|
||||
package net.torvald.tsvm.peripheral
|
||||
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, true) {
|
||||
|
||||
private var fileOpen = false
|
||||
private var readModeLength = -1
|
||||
|
||||
private val rootPath = File("test_assets/test_drive_$driveNum")
|
||||
|
||||
init {
|
||||
if (!rootPath.exists()) {
|
||||
rootPath.mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
fun composePositiveAns(vararg msg: String): ByteArray {
|
||||
val sb = ArrayList<Byte>()
|
||||
sb.add(0x06)
|
||||
sb.addAll(msg[0].toByteArray().toTypedArray())
|
||||
for (k in 1 until msg.lastIndex) {
|
||||
sb.add(0x1F)
|
||||
sb.addAll(msg[k].toByteArray().toTypedArray())
|
||||
}
|
||||
sb.add(0x17)
|
||||
return sb.toByteArray()
|
||||
}
|
||||
|
||||
fun composeNegativeAns(vararg msg: String): ByteArray {
|
||||
val sb = ArrayList<Byte>()
|
||||
sb.add(0x15)
|
||||
sb.addAll(msg[0].toByteArray().toTypedArray())
|
||||
for (k in 1 until msg.lastIndex) {
|
||||
sb.add(0x1F)
|
||||
sb.addAll(msg[k].toByteArray().toTypedArray())
|
||||
}
|
||||
sb.add(0x17)
|
||||
return sb.toByteArray()
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
if (!fileOpen) return false
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/** Computer's attempt to startRead() will result in calling this very function.
|
||||
*
|
||||
* Disk drive must send prepared message (or file transfer packet) to the computer.
|
||||
*/
|
||||
override fun startSend() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
/** Computer's attempt to startSend() will result in calling this very function.
|
||||
* In such cases, `inputData` will be the message the computer sends.
|
||||
*
|
||||
* Disk drive must create desired side effects in accordance with the input message.
|
||||
*/
|
||||
override fun writeout(inputData: ByteArray) {
|
||||
val inputString = inputData.toString()
|
||||
|
||||
if (inputString.startsWith("DEVRST\u0017")) {
|
||||
readModeLength = -1
|
||||
fileOpen = false
|
||||
}
|
||||
else if (inputString.startsWith("DEVTYP\u0017"))
|
||||
startSend { it.writeout(composePositiveAns("STOR")) }
|
||||
else if (inputString.startsWith("DEVNAM\u0017"))
|
||||
startSend { it.writeout(composePositiveAns("Testtec Virtual Disk Drive")) }
|
||||
else if (inputString.startsWith("OPENR\"")) {
|
||||
|
||||
|
||||
|
||||
fileOpen = true
|
||||
}
|
||||
else if (inputString.startsWith("CLOSE")) {
|
||||
|
||||
|
||||
|
||||
fileOpen = false
|
||||
}
|
||||
else if (inputString.startsWith("READ")) {
|
||||
|
||||
|
||||
|
||||
readModeLength = inputString.substring(4 until inputString.length).toInt()
|
||||
}
|
||||
else if (inputString.startsWith("LIST")) {
|
||||
startSend { it.writeout("\"LOREM.TXT\" TXT\nTotal 1 files on the disk".toByteArray()) }
|
||||
}
|
||||
}
|
||||
|
||||
val diskID: UUID = UUID(0, 0)
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.torvald.tsvm.peripheral
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class TestFunctionGenerator : BlockTransferInterface(true, false) {
|
||||
|
||||
val filecontent_lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ipsum magna, ultrices eu leo eu, consequat eleifend arcu. Nam tempor nunc aliquam mi cursus mollis. Aenean dictum iaculis dolor eget porttitor. Fusce vulputate dui id mauris ultricies, non aliquet nulla pulvinar. Integer consectetur nulla at cursus cursus. Nullam enim nisl, elementum a fermentum sed, suscipit id sapien. Duis eget enim lacinia, aliquam sapien ac, commodo risus. Morbi at enim sem. Aenean sollicitudin purus et sem porttitor, convallis ultricies nulla posuere. Suspendisse euismod sagittis vestibulum. Mauris lorem nisl, placerat et finibus non, cursus non ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Suspendisse finibus non dui vel tempor. Nam rhoncus ligula et massa sagittis fringilla. Cras convallis pellentesque nulla in rutrum.
|
||||
@@ -20,6 +22,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
|
||||
fun composeSerialAns(vararg msg: String): ByteArray {
|
||||
val sb = ArrayList<Byte>()
|
||||
sb.add(0x06) // always positive ans
|
||||
sb.addAll(msg[0].toByteArray().toTypedArray())
|
||||
for (k in 1 until msg.lastIndex) {
|
||||
sb.add(0x1F)
|
||||
|
||||
Reference in New Issue
Block a user