From ab0827b96cd8e0f7f4ed8c15e5cff6038846dc26 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 4 Nov 2020 16:10:33 +0900 Subject: [PATCH] command.js to run batch file --- assets/AUTOEXEC.BAT | 3 ++- assets/JS_INIT.js | 3 +++ assets/tvdos/TVDOS.SYS | 2 +- assets/tvdos/{ => bin}/command.js | 27 +++++++++++++------ assets/tvdos/{ => bin}/flsh.js | 0 assets/tvdos/{ => bin}/fsh.js | 0 .../tsvm/peripheral/GraphicsAdapter.kt | 1 + 7 files changed, 26 insertions(+), 10 deletions(-) rename assets/tvdos/{ => bin}/command.js (90%) rename assets/tvdos/{ => bin}/flsh.js (100%) rename assets/tvdos/{ => bin}/fsh.js (100%) diff --git a/assets/AUTOEXEC.BAT b/assets/AUTOEXEC.BAT index e3c62f0..4ddca96 100644 --- a/assets/AUTOEXEC.BAT +++ b/assets/AUTOEXEC.BAT @@ -1,2 +1,3 @@ echo "Hello, world!" -fsh \ No newline at end of file +fsh +command \ No newline at end of file diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 101544c..fde6590 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -377,6 +377,9 @@ con.clear = function() { con.curs_set = function(arg) { print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h")); }; +con.reset_graphics = function() { + println(String.fromCharCode(27,91,109)); +}; Object.freeze(con); // system management function var system = {}; diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index d1cdd57..befee40 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -80,6 +80,6 @@ var execApp = function(cmdsrc, args) { /////////////////////////////////////////////////////////////////////////////// // Boot script -filesystem.open("A", "tvdos/command.js", "R"); +filesystem.open("A", "tvdos/bin/command.js", "R"); let cmdsrc = filesystem.readAll("A"); execApp(cmdsrc, ["", "/c", "\\AUTOEXEC.BAT"]); diff --git a/assets/tvdos/command.js b/assets/tvdos/bin/command.js similarity index 90% rename from assets/tvdos/command.js rename to assets/tvdos/bin/command.js index 7988981..422a411 100644 --- a/assets/tvdos/command.js +++ b/assets/tvdos/bin/command.js @@ -1,6 +1,6 @@ let PROMPT_TEXT = ">"; let CURRENT_DRIVE = "A"; - +let executableExtensions = [".com",".bat",".js", ""]; Object.freeze(executableExtensions); let shell_pwd = []; const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION; @@ -109,6 +109,9 @@ shell.coreutils = { args.forEach(function(it,i) { if (i > 0) print(it+" ") }); } println(); + }, + rem: function(args) { + return 0; } }; Object.freeze(shell.coreutils); @@ -117,6 +120,9 @@ shell.execute = function(line) { let tokens = shell.parse(line); let cmd = tokens[0]; + // handle Ctrl-C + if (con.hitterminate()) return 1; + if (shell.coreutils[cmd.toLowerCase()] !== undefined) { let retval = shell.coreutils[cmd.toLowerCase()](tokens); return retval|0; // return value of undefined will cast into 0 @@ -129,11 +135,14 @@ shell.execute = function(line) { searchDir.forEach(function(it) { serial.println("Searchdir: "+it); }); + searchLoop: for (let i = 0; i < searchDir.length; i++) { - let path = (searchDir[i] + cmd).substring(1); // without substring, this will always prepend revslash - if (filesystem.open(CURRENT_DRIVE, path, "R")) { - fileExists = true; - break; + for (let j = 0; j < executableExtensions.length; j++) { + let path = (searchDir[i] + cmd + executableExtensions[j]).substring(1); // without substring, this will always prepend revslash + if (filesystem.open(CURRENT_DRIVE, path, "R")) { + fileExists = true; + break searchLoop; + } } } @@ -151,7 +160,9 @@ shell.execute = function(line) { if ("BAT" == extension) { // parse and run as batch file let lines = prg.split('\n').filter(function(it) { return it.length > 0; }); - lines.forEach(function(it) { println("Batch: " + it) }); // TODO + lines.forEach(function(line) { + shell.execute(line); + }); } else { return execApp(prg, tokens)|0; // return value of undefined will cast into 0 @@ -165,7 +176,7 @@ Object.freeze(shell); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -if (exec_args !== undefined) { +if (exec_args[1] !== undefined) { // command /c // ^[0] ^[1] ^[2] if (exec_args[1].toLowerCase() == "/c") { @@ -178,8 +189,8 @@ if (exec_args !== undefined) { } } else { + con.reset_graphics(); println("Starting TVDOS..."); - greet(); let cmdHistory = []; // zeroth element is the oldest diff --git a/assets/tvdos/flsh.js b/assets/tvdos/bin/flsh.js similarity index 100% rename from assets/tvdos/flsh.js rename to assets/tvdos/bin/flsh.js diff --git a/assets/tvdos/fsh.js b/assets/tvdos/bin/fsh.js similarity index 100% rename from assets/tvdos/fsh.js rename to assets/tvdos/bin/fsh.js diff --git a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index 8296ed9..48624da 100644 --- a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -371,6 +371,7 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole else if (arg == 0) { ttyFore = TTY_FORE_DEFAULT ttyBack = TTY_BACK_DEFAULT + blinkCursor = true } }