disk drive: fixed baaaaad writeout implementation -- what the fuck was i thinking?

This commit is contained in:
minjaesong
2021-04-22 14:18:03 +09:00
parent 4ed44be569
commit 2767386820
2 changed files with 15 additions and 12 deletions

View File

@@ -378,13 +378,13 @@ shell.execute = function(line) {
if (_G.shellProgramTitles === undefined) _G.shellProgramTitles = []; if (_G.shellProgramTitles === undefined) _G.shellProgramTitles = [];
_G.shellProgramTitles.push(cmd.toUpperCase()) _G.shellProgramTitles.push(cmd.toUpperCase())
sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]); sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]);
serial.println(_G.shellProgramTitles); //serial.println(_G.shellProgramTitles);
let ret = execApp(programCode, tokens)|0; // return value of undefined will cast into 0 let ret = execApp(programCode, tokens)|0; // return value of undefined will cast into 0
_G.shellProgramTitles.pop(); _G.shellProgramTitles.pop();
sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]); sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]);
serial.println(_G.shellProgramTitles); //serial.println(_G.shellProgramTitles);
return ret; return ret;
} }

View File

@@ -118,6 +118,9 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
return sendSize return sendSize
} }
private lateinit var writeBuffer: ByteArray
private var writeBufferUsage = 0
/** Computer's attempt to startSend() will result in calling this very function. /** Computer's attempt to startSend() will result in calling this very function.
* In such cases, `inputData` will be the message the computer sends. * In such cases, `inputData` will be the message the computer sends.
* *
@@ -125,20 +128,18 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
*/ */
override fun writeoutImpl(inputData: ByteArray) { override fun writeoutImpl(inputData: ByteArray) {
if (writeMode) { if (writeMode) {
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
//println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}")
if (!fileOpen) throw InternalError("File is not open but the drive is in write mode") if (!fileOpen) throw InternalError("File is not open but the drive is in write mode")
inputData.forEach { System.arraycopy(inputData, 0, writeBuffer, writeBufferUsage, minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE))
if (writeModeLength > 0) { writeBufferUsage += inputData.size
//writeBuffer.write(it.toInt())
//writeModeLength -= 1
file.writeBytes(inputData.sliceArray(0 until writeModeLength))
writeModeLength = 0
}
}
if (writeModeLength <= 0) { if (writeBufferUsage >= writeModeLength) {
writeMode = false writeMode = false
//writeBuffer.reset() // commit to the disk
file.writeBytes(writeBuffer)
} }
} }
else { else {
@@ -375,6 +376,8 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
} }
writeMode = true writeMode = true
writeModeLength = inputString.substring(5, inputString.length).toInt() writeModeLength = inputString.substring(5, inputString.length).toInt()
writeBuffer = ByteArray(writeModeLength)
writeBufferUsage = 0
statusCode = STATE_CODE_STANDBY statusCode = STATE_CODE_STANDBY
} }
else else