mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 15:04:03 +09:00
working multiblock transfer (kinda)
This commit is contained in:
@@ -272,6 +272,15 @@ if ('function' !== typeof Array.prototype.reduceRight) {
|
|||||||
|
|
||||||
load = undefined
|
load = undefined
|
||||||
loadWithNewGlobal = undefined
|
loadWithNewGlobal = undefined
|
||||||
|
//
|
||||||
|
function javaArrayToJs(jarr) {
|
||||||
|
if (!jarr.toString.startsWith("[")) return jarr;
|
||||||
|
var arr = [];
|
||||||
|
for (var k = 0; k < jarr.length; k++) {
|
||||||
|
arr.push(jarr[k]);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
// standard print functions
|
// standard print functions
|
||||||
function print(s) {
|
function print(s) {
|
||||||
sys.print(s);
|
sys.print(s);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
var ba = com.sendMessageGetBytes(0, [0x44,0x45,0x56,0x4e,0x41,0x4d,0x17]);
|
var ba = com.sendMessageGetBytes(0, [0x44,0x45,0x56,0x4e,0x41,0x4d,0x17]);
|
||||||
serial.println(ba);
|
serial.println(ba);
|
||||||
for (let k = 0; k < 4096; k++) {
|
for (let k = 0; k < ba.length; k++) {
|
||||||
serial.print(String.fromCharCode(ba[k]));
|
serial.print(String.fromCharCode(ba[k]));
|
||||||
}
|
}
|
||||||
serial.print("\n");
|
serial.print("\n");
|
||||||
|
|
||||||
ba = com.pullMessage(0)
|
ba = com.pullMessage(0)
|
||||||
for (let k = 0; k < 4096; k++) {
|
for (let k = 0; k < ba.length; k++) {
|
||||||
serial.print(String.fromCharCode(ba[k]));
|
serial.print(String.fromCharCode(ba[k]));
|
||||||
}
|
}
|
||||||
serial.print("\n");
|
serial.print("\n");
|
||||||
|
|||||||
@@ -61,15 +61,11 @@ object SerialHelper {
|
|||||||
waitUntilReady(vm, portNo)
|
waitUntilReady(vm, portNo)
|
||||||
|
|
||||||
val transStat = getBlockTransferStatus(vm, portNo)
|
val transStat = getBlockTransferStatus(vm, portNo)
|
||||||
val incomingMsg = ByteArray(transStat.first)
|
|
||||||
|
|
||||||
UnsafeHelper.memcpyRaw(
|
for (k in 0 until minOf(BLOCK_SIZE, transStat.first)) {
|
||||||
null, vm.getIO().blockTransferRx[portNo].ptr,
|
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
||||||
incomingMsg, UnsafeHelper.getArrayOffset(incomingMsg),
|
}
|
||||||
transStat.first.toLong()
|
|
||||||
)
|
|
||||||
|
|
||||||
msgBuffer.write(incomingMsg)
|
|
||||||
} while (transStat.second)
|
} while (transStat.second)
|
||||||
|
|
||||||
getReady(vm, portNo)
|
getReady(vm, portNo)
|
||||||
@@ -122,8 +118,9 @@ object SerialHelper {
|
|||||||
private fun getBlockTransferStatus(vm: VM, portNo: Int): Pair<Int, Boolean> {
|
private fun getBlockTransferStatus(vm: VM, portNo: Int): Pair<Int, Boolean> {
|
||||||
val bits = vm.getIO().mmio_read(4084L + (portNo * 2))!!.toUint() or
|
val bits = vm.getIO().mmio_read(4084L + (portNo * 2))!!.toUint() or
|
||||||
(vm.getIO().mmio_read(4085L + (portNo * 2))!!.toUint() shl 8)
|
(vm.getIO().mmio_read(4085L + (portNo * 2))!!.toUint() shl 8)
|
||||||
val rawcnt = bits.and(BLOCK_SIZE - 1)
|
val rawcnt = bits.and(4095)
|
||||||
return (if (rawcnt == 0) BLOCK_SIZE else rawcnt) to (bits < 0)
|
//FIXME return (if (rawcnt == 0) BLOCK_SIZE else rawcnt) to (bits < 0)
|
||||||
|
return (if (rawcnt == 0) BLOCK_SIZE else rawcnt) to (vm.getIO().blockTransferPorts[portNo].doYouHaveNext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.torvald.tsvm
|
package net.torvald.tsvm
|
||||||
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory
|
import jdk.nashorn.api.scripting.NashornScriptEngineFactory
|
||||||
|
import jdk.nashorn.api.scripting.ScriptUtils
|
||||||
|
import jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java
|
||||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||||
import net.torvald.tsvm.vdc.Videotron2K
|
import net.torvald.tsvm.vdc.Videotron2K
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
UnsafeHelper.allocate(4096),
|
UnsafeHelper.allocate(4096),
|
||||||
UnsafeHelper.allocate(4096)
|
UnsafeHelper.allocate(4096)
|
||||||
)
|
)
|
||||||
private val blockTransferPorts = Array(4) { BlockTransferPort(vm, it) }
|
/*private*/ val blockTransferPorts = Array(4) { BlockTransferPort(vm, it) }
|
||||||
|
|
||||||
private val keyEventBuffers = ByteArray(8)
|
private val keyEventBuffers = ByteArray(8)
|
||||||
|
|
||||||
@@ -56,11 +56,11 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
blockTransferPorts[portno].ready = bits.and(0b0000_0010) != 0.toByte()
|
blockTransferPorts[portno].ready = bits.and(0b0000_0010) != 0.toByte()
|
||||||
if (bits.and(0b0000_0100) != 0.toByte()) {
|
if (bits.and(0b0000_0100) != 0.toByte()) {
|
||||||
if (blockTransferPorts[portno].getMode()) {
|
if (blockTransferPorts[portno].getMode()) {
|
||||||
println("[IOSpace] startSend()")
|
//println("[IOSpace] startSend()")
|
||||||
blockTransferPorts[portno].startSend()
|
blockTransferPorts[portno].startSend()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println("[IOSpace] startRead()")
|
//println("[IOSpace] startRead()")
|
||||||
blockTransferPorts[portno].startRead()
|
blockTransferPorts[portno].startRead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
|
|
||||||
|
|
||||||
return (blockSendCount * BLOCK_SIZE <= blockSendBuffer.size)
|
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Computer's attempt to startRead() will result in calling this very function.
|
/** Computer's attempt to startRead() will result in calling this very function.
|
||||||
@@ -93,7 +93,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
}
|
}
|
||||||
|
|
||||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||||
val i = (blockSendCount + 1) * BLOCK_SIZE
|
val i = blockSendCount * BLOCK_SIZE
|
||||||
if (i + it >= blockSendBuffer.size) {
|
if (i + it >= blockSendBuffer.size) {
|
||||||
0.toByte()
|
0.toByte()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
|
|
||||||
private var fileOpen = false
|
private var fileOpen = false
|
||||||
|
|
||||||
private var readModeLength = -1
|
|
||||||
|
|
||||||
private var blockSendBuffer = ByteArray(1)
|
private var blockSendBuffer = ByteArray(1)
|
||||||
private var blockSendCount = 0
|
private var blockSendCount = 0
|
||||||
|
|
||||||
@@ -102,8 +100,6 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun startSend() {
|
override fun startSend() {
|
||||||
println("[TestFunctionGenerator] startSend()")
|
|
||||||
|
|
||||||
recipient?.let { recipient ->
|
recipient?.let { recipient ->
|
||||||
if (blockSendCount == 0) {
|
if (blockSendCount == 0) {
|
||||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||||
@@ -111,7 +107,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
}
|
}
|
||||||
|
|
||||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||||
val i = (blockSendCount + 1) * BLOCK_SIZE
|
val i = blockSendCount * BLOCK_SIZE
|
||||||
if (i + it >= blockSendBuffer.size) {
|
if (i + it >= blockSendBuffer.size) {
|
||||||
0.toByte()
|
0.toByte()
|
||||||
}
|
}
|
||||||
@@ -121,37 +117,37 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
})
|
})
|
||||||
|
|
||||||
blockSendCount += 1
|
blockSendCount += 1
|
||||||
}
|
|
||||||
|
|
||||||
println("[TestFunctionGenerator] startSend() end")
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean = false
|
override fun hasNext(): Boolean {
|
||||||
|
|
||||||
|
|
||||||
|
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
||||||
|
}
|
||||||
override fun writeout(inputData: ByteArray) {
|
override fun writeout(inputData: ByteArray) {
|
||||||
val inputString = inputData.toString(VM.CHARSET)
|
val inputString = inputData.toString(VM.CHARSET)
|
||||||
|
|
||||||
println("InputString: $inputString")
|
|
||||||
|
|
||||||
if (inputString.startsWith("DEVRST\u0017")) {
|
if (inputString.startsWith("DEVRST\u0017")) {
|
||||||
readModeLength = -1
|
|
||||||
fileOpen = false
|
fileOpen = false
|
||||||
|
blockSendCount = 0
|
||||||
}
|
}
|
||||||
else if (inputString.startsWith("DEVTYP\u0017"))
|
else if (inputString.startsWith("DEVTYP\u0017"))
|
||||||
startSend { it.writeout(composeSerialAns("STOR")) }
|
recipient?.writeout(composeSerialAns("STOR"))
|
||||||
else if (inputString.startsWith("DEVNAM\u0017")) {
|
else if (inputString.startsWith("DEVNAM\u0017"))
|
||||||
println("Device name?")
|
recipient?.writeout(composeSerialAns("Testtec Virtual Disk Drive"))
|
||||||
startSend { it.writeout(composeSerialAns("Testtec Virtual Disk Drive")) }
|
|
||||||
}
|
|
||||||
else if (inputString.startsWith("OPENR\""))
|
else if (inputString.startsWith("OPENR\""))
|
||||||
fileOpen = true
|
fileOpen = true
|
||||||
else if (inputString.startsWith("CLOSE"))
|
else if (inputString.startsWith("CLOSE"))
|
||||||
fileOpen = false
|
fileOpen = false
|
||||||
else if (inputString.startsWith("READ"))
|
//else if (inputString.startsWith("READ"))
|
||||||
readModeLength = inputString.substring(4 until inputString.length).toInt()
|
// readModeLength = inputString.substring(4 until inputString.length).toInt()
|
||||||
else if (inputString.startsWith("LIST"))
|
else if (inputString.startsWith("LIST"))
|
||||||
startSend { it.writeout("\"LOREM.TXT\" TXT\nTotal 1 files on the disk".toByteArray()) }
|
recipient?.writeout("\"LOREM.TXT\" TXT\nTotal 1 files on the disk".toByteArray())
|
||||||
|
|
||||||
|
|
||||||
|
blockSendCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setMode(sendmode: Boolean) {
|
override fun setMode(sendmode: Boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user