From f01345fb6fdf655e4f3b2787584e74a5af7c381e Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 7 Nov 2020 17:33:54 +0900 Subject: [PATCH] more chdir wip --- assets/tvdos/TVDOS.SYS | 10 ++++++++++ assets/tvdos/bin/command.js | 13 +++++++++++++ src/net/torvald/tsvm/peripheral/TestDiskDrive.kt | 2 ++ src/net/torvald/tsvm/vdc/V2kRunTest.kt | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index b4600c6..d860ce7 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -69,6 +69,16 @@ filesystem.readAll = function(driveLetter) { } return com.pullMessage(port[0]); }; +filesystem.isDirectory = function(driveLetter) { + let port = filesystem._toPorts(driveLetter); + com.sendMessage(port[0], "LISTFILES"); + let response = com.getStatusCode(port[0]); + + if (135 == response) { + throw Error("File not opened"); + } + return (response === 0); +} Object.freeze(filesystem); /////////////////////////////////////////////////////////////////////////////// diff --git a/assets/tvdos/bin/command.js b/assets/tvdos/bin/command.js index 3ad0fd3..a4abd80 100644 --- a/assets/tvdos/bin/command.js +++ b/assets/tvdos/bin/command.js @@ -138,9 +138,22 @@ shell.coreutils = { return } + // replace slashes into revslashes let pathstr = args[1].replaceAll('/','\\\\'); + // split them into an array while filtering empty elements except for the root 'head' let newPwd = [""].concat(pathstr.split("\\").filter(function(it) { return (it.length > 0); })); + // construct new pathstr from pwd arr so it will be sanitised + pathstr = newPwd.join('\\').substring(1); + if (DEBUG_PRINT) serial.println("command.js > pathstr = "+pathstr); + + // check if path is valid + let dirOpened = filesystem.open(CURRENT_DRIVE, pathstr, 'R'); + if (!dirOpened) { printerrln("CHDIR failed for '"+pathstr+"'"); return; } + + // check if path is directory + let isDir = filesystem.isDirectory(CURRENT_DRIVE); + if (!isDir) { printerrln("CHDIR failed for '"+pathstr+"'"); return; } shell_pwd = newPwd; }, diff --git a/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt b/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt index 4fe879e..5a31a16 100644 --- a/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt +++ b/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt @@ -365,6 +365,8 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc // applies a "cap" if the path attemps to access parent directory of the root private fun filterSuperRoot(path: String): String { + if (path.isEmpty()) return path + var parentCount = 0 val paths = path.split('/') val newPaths = ArrayList() diff --git a/src/net/torvald/tsvm/vdc/V2kRunTest.kt b/src/net/torvald/tsvm/vdc/V2kRunTest.kt index 1902161..d34d07b 100644 --- a/src/net/torvald/tsvm/vdc/V2kRunTest.kt +++ b/src/net/torvald/tsvm/vdc/V2kRunTest.kt @@ -29,7 +29,7 @@ class V2kRunTest(val appConfig: LwjglApplicationConfiguration) : ApplicationAdap override fun create() { super.create() - gpu = GraphicsAdapter(vm, lcdMode = false) + gpu = GraphicsAdapter(vm, theme = GraphicsAdapter.THEME_COLORCRT) vm.peripheralTable[1] = PeripheralEntry( VM.PERITYPE_GPU_AND_TERM,