From 5b8930202f9172466eac1a80a99757be5224ab17 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 12 May 2022 10:47:20 +0900 Subject: [PATCH] more pipe stuffs --- assets/bios/openbios.js | 9 +++-- assets/disk0/tvdos/TVDOS.SYS | 3 +- assets/disk0/tvdos/bin/command.js | 28 ++++++++++++++++ assets/disk0/tvdos/bin/less.js | 55 ++++++++++++++++++------------- 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/assets/bios/openbios.js b/assets/bios/openbios.js index cb5968a..6ed3a49 100644 --- a/assets/bios/openbios.js +++ b/assets/bios/openbios.js @@ -28,7 +28,12 @@ function bootFromPort(port) { else throw "No Bootsector" } catch (e) { - printerrln(`No bootable medium on COM ${port+1}`) + if ("No Bootsector" == e) + printerrln(`No bootable medium on COM ${port+1}`) + else + printerrln(`Boot failed with errors:\n\n${e}`) + + serial.printerr(e) } } @@ -152,7 +157,7 @@ showHowtoEnterMenu() let bootable = probeBootable() let sysRq = false let tmr = sys.nanoTime() -while (sys.nanoTime() - tmr < 5 * 1000000000.0) { +while (sys.nanoTime() - tmr < 3 * 1000000000.0) { sysRq = sys.getSysrq() if (sysRq) break sys.spin() diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index 47cc1f5..d8a34d1 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -76,8 +76,7 @@ filesystem._close = (portNo) => { filesystem._flush = (portNo) => { com.sendMessage(portNo, "FLUSH"); }; -// @return true if operation committed successfully, false if: -// - opening file with R-mode and target file does not exists +// @return disk status code (0 for successful operation) // throws if: // - java.lang.NullPointerException if path is null // - Error if operation mode is not "R", "W" nor "A" diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index 92523d7..b97e082 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -456,6 +456,34 @@ shell.execute = function(line) { } }; shell.pipes = {}; // syntax: _G.shell.pipes[name] = contents; all pipes are named pipes just like in Windows +shell.currentlyActivePipes = []; // pipe queue. Use shell.getPipe() to dequeue and shell.pushPipe() to enqueue. +shell._rndstr = '0123456789+qwfpgjluyarstdhneiozxcvbkm/QWFPGJLUYARSTDHNEIOZXCVBKM' +shell.generateRandomName = function() { + let name = '' + while (true) { + name = "anonpipe_" + for (let k = 0; k < 32; k++) { + name += shell._rndstr[(Math.random() * 64)|0] + } + if (shell.pipes[name] == undefined) break + } + return name +} +shell.getPipe = function() { + let n = shell.currentlyActivePipes.shift() + return (n != undefined) ? shell.pipes[n] : undefined +} +shell.pushAnonPipe = function(contents) { + let name = shell.generateRandomName() + shell.pushPipe(name, contents) +} +shell.pushPipe = function(name, contents) { + shell.pipes[name] = contents + shell.currentlyActivePipes.unshift(name) +} +shell.hasPipe = function() { + return shell.currentlyActivePipes[0] != undefined +} Object.freeze(shell); _G.shell = shell; diff --git a/assets/disk0/tvdos/bin/less.js b/assets/disk0/tvdos/bin/less.js index 8eacd50..202e181 100644 --- a/assets/disk0/tvdos/bin/less.js +++ b/assets/disk0/tvdos/bin/less.js @@ -1,7 +1,4 @@ -if (exec_args[1] === undefined) { - println('Missing filename ("less -?" for help)'); - return 0; -} +let filename = exec_args[1] /*let help = "\n SUMMARY OF COMMANDS\n @@ -10,27 +7,46 @@ SUMMARY OF COMMANDS\n q Q Exit \n"*/ -if (exec_args[1].startsWith("-?")) { - println("less "); - return 0; -} - -let fileOpened = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(exec_args[1]).string, "R"); -if (!fileOpened) { - printerrln(_G.shell.resolvePathInput(exec_args[1]).string+": cannot open"); - return 1; -} - let scroll = 0; let pan = -1; let termW = con.getmaxyx()[1]; let termH = con.getmaxyx()[0] - 1; let buf = ""; -let fileContent = filesystem.readAll(_G.shell.getCurrentDrive()); +let fileContent = undefined let key = -1; let panSize = termW >> 1; let scrollSize = termH >> 3; +let startAddr = -1; +let paintCur = 0; +let cy = 1; +let cx = 1; +let char = -1; + +let numbuf = 0; + +if (filename === undefined && _G.shell.hasPipe()) { + fileContent = _G.shell.getPipe() +} +else if (filename === undefined) { + println('Missing filename ("less -?" for help)'); + return 0; +} +else { + if (filename.startsWith("-?")) { + println("less "); + return 0; + } + + let fileOpened = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(filename).string, "R"); + if (fileOpened != 0) { + printerrln(_G.shell.resolvePathInput(filename).string+": cannot open"); + return 1; + } + + fileContent = filesystem.readAll(_G.shell.getCurrentDrive()); +} + // initialise some helper variables let lineToBytes = [0]; let maxPan = 0; @@ -45,13 +61,8 @@ for (let i = 0; i < fileContent.length; i++) { } } -let startAddr = -1; -let paintCur = 0; -let cy = 1; -let cx = 1; -let char = -1; -let numbuf = 0; + let resetKeyReadStatus = function() { numbuf = 0;