diff --git a/assets/disk0/tvdos/bin/defrag.js b/assets/disk0/tvdos/bin/defrag.js new file mode 100644 index 0000000..3589379 --- /dev/null +++ b/assets/disk0/tvdos/bin/defrag.js @@ -0,0 +1,18 @@ + +let drive = _G.shell.getCurrentDrive() +let port = _TVDOS.DRV.FS.SERIAL._toPorts(drive) + com.sendMessage(port[0], "CLOSE") +for (let i = 0; i < 20; i++) { + com.sendMessage(port[0], "READCLUST"+i) + let response = com.getStatusCode(port[0]) + if (response < 0 || response >= 128) { + throw Error(`Reading cluster #${i} failed with `+response) + } + let bytes = com.pullMessage(port[0]) + print(`#${i}\t`) + for (let k = 0; k < 16; k++) { + print(bytes.charCodeAt(k).toString(16).padStart(2, '0')) + print(' ') + } + println() +} \ No newline at end of file diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt index bcdfacd..5b90bc2 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt @@ -339,6 +339,15 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath: fileOpenMode = -1 statusCode.set(STATE_CODE_STANDBY) } + else if (inputString.startsWith("READCLUST")) { + if (fileOpen) { + statusCode.set(STATE_CODE_FILE_ALREADY_OPENED) + return + } + val clustnum = inputString.substring(9 until inputString.length).toInt() + resetBuf() + messageComposeBuffer.write(DOM.getRawCluster(clustnum)) + } else if (inputString.startsWith("READ")) { //readModeLength = inputString.substring(4 until inputString.length).toInt()