From 0d1e33f7e62fbfa987e4f42b38e5bde4d1de4700 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 6 Sep 2022 20:30:46 +0900 Subject: [PATCH] getting rid of old filesystem functions --- assets/JS_INIT.js | 3 ++ assets/disk0/tvdos/TVDOS.SYS | 2 ++ assets/disk0/tvdos/bin/edit.js | 8 ++--- assets/disk0/tvdos/bin/fsh.js | 6 ++-- assets/disk0/tvdos/bin/hexdump.js | 32 +++++++++++++------ assets/disk0/tvdos/bin/less.js | 6 ++-- assets/disk0/tvdos/bin/touch.js | 26 +++++++-------- assets/disk0/tvdos/i18n/korean.js | 14 ++++---- doc/implementation.tex | 4 ++- doc/tsvmman.idx | 8 ++--- doc/tsvmman.ind | 4 +-- .../net/torvald/tsvm/peripheral/GlassTty.kt | 26 +++++++++++++-- .../tsvm/peripheral/GraphicsAdapter.kt | 6 ++++ .../src/net/torvald/tsvm/peripheral/TTY.kt | 4 +++ 14 files changed, 102 insertions(+), 47 deletions(-) diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index ba93ca8..766a2c7 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -439,6 +439,9 @@ con.move = function(y, x) { con.addch = function(c) { graphics.putSymbol(c|0); }; +con.prnch = function(c) { + print("\x84"+c+"u"); +}; con.mvaddch = function(y, x, c) { con.move(y, x); con.addch(c); }; diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index bb716c9..e948768 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -570,6 +570,7 @@ Object.freeze(_TVDOS.DRV.FS.DEVFBIPF) // Legacy Serial filesystem, !!pending for removal!! +/* const filesystem = {}; filesystem._toPorts = (driveLetter) => { @@ -692,6 +693,7 @@ filesystem.remove = (driveLetter) => { return (response === 0); }; Object.freeze(filesystem); +*/ /////////////////////////////////////////////////////////////////////////////// diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index 99546a7..309ae53 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -39,9 +39,10 @@ let bulletinShown = false; let cursoringCol = 0; // load existing file if it's there -let editingExistingFile = (0 == filesystem.open(driveLetter, filePath, "R")); +let file = files.open(`${driveLetter}:/${filePath}`) +let editingExistingFile = file.exists if (editingExistingFile) { - textbuffer = filesystem.readAll(driveLetter).split("\n"); + textbuffer = file.sread().split("\n") } let windowWidth = 0; @@ -197,8 +198,7 @@ function gotoText() { // FUNCTIONING FUNCTIONS (LOL) // function writeout() { - filesystem.open(driveLetter, filePath, "W"); - filesystem.write(driveLetter, textbuffer.join('\n')); + file.swrite(textbuffer.join("\n")) } // KEYBOARDING FUNCTIONS // diff --git a/assets/disk0/tvdos/bin/fsh.js b/assets/disk0/tvdos/bin/fsh.js index c3e4d5c..45d4e07 100644 --- a/assets/disk0/tvdos/bin/fsh.js +++ b/assets/disk0/tvdos/bin/fsh.js @@ -21,9 +21,11 @@ _fsh.brandLogoTexSmall = new GL.Texture(24, 14, gzip.decomp(base64.atob( _fsh.scrlayout = ["com.fsh.clock","com.fsh.calendar","com.fsh.todo_list", "com.fsh.quick_access"]; _fsh.drawWallpaper = function() { - filesystem.open("A", "/tvdos/wall.bytes", "R") + let wp = files.open("A:/tvdos/wall.bytes") +// filesystem.open("A", "/tvdos/wall.bytes", "R") let b = sys.malloc(250880) - dma.comToRam(0, 0, b, 250880) +// dma.comToRam(0, 0, b, 250880) + wp.pread(b, 250880, 0) dma.ramToFrame(b, 0, 250880) sys.free(b) }; diff --git a/assets/disk0/tvdos/bin/hexdump.js b/assets/disk0/tvdos/bin/hexdump.js index a36b7bd..2e81064 100644 --- a/assets/disk0/tvdos/bin/hexdump.js +++ b/assets/disk0/tvdos/bin/hexdump.js @@ -3,18 +3,30 @@ if (exec_args[1] === undefined) { return 1; } -let fileOpenedStatus = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(exec_args[1]).string, "R"); -if (fileOpenedStatus != 0) { +let file = files.open(`${_G.shell.getCurrentDrive()}:/${_G.shell.resolvePathInput(exec_args[1]).string}`) +if (!file.exists) { printerrln(_G.shell.resolvePathInput(exec_args[1]).string+": cannot open"); - return fileOpenedStatus; + return 1; } -let fileContent = filesystem.readAll(_G.shell.getCurrentDrive()); -let visible = ""; +let fileContent = file.sread() -for (let k = 0; k < fileContent.length; k++) { - if (k > 0 && k % 16 == 0) visible += "\n"; - visible += `${fileContent.charCodeAt(k).toString(16).toUpperCase().padStart(2, '0')} `; +for (let k = 0; k < fileContent.length; k += 16) { + for (let i = 0; i < 16; i++) { + let charCode = fileContent.charCodeAt(k+i) + if (!isNaN(charCode)) + print(`${charCode.toString(16).toUpperCase().padStart(2, '0')} `) + else + print(` `) + } + print('| ') + for (let i = 0; i < 16; i++) { + let charCode = fileContent.charCodeAt(k+i) + if (!isNaN(charCode)) + con.prnch(charCode) + else + con.prnch(0) + } + + println() } - -println(visible); return 0; \ No newline at end of file diff --git a/assets/disk0/tvdos/bin/less.js b/assets/disk0/tvdos/bin/less.js index 0bbac84..2fc2842 100644 --- a/assets/disk0/tvdos/bin/less.js +++ b/assets/disk0/tvdos/bin/less.js @@ -38,13 +38,13 @@ else { return 0; } - let fileOpened = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(filename).string, "R"); - if (fileOpened != 0) { + let file = files.open(`${_G.shell.getCurrentDrive()}:/${_G.shell.resolvePathInput(filename).string}`) + if (!file.exists) { printerrln(_G.shell.resolvePathInput(filename).string+": cannot open"); return 1; } - fileContent = filesystem.readAll(_G.shell.getCurrentDrive()); + fileContent = file.sread() } // initialise some helper variables diff --git a/assets/disk0/tvdos/bin/touch.js b/assets/disk0/tvdos/bin/touch.js index 2f2f190..40f614a 100644 --- a/assets/disk0/tvdos/bin/touch.js +++ b/assets/disk0/tvdos/bin/touch.js @@ -11,20 +11,20 @@ if (exec_args[1] === undefined) { let path = _G.shell.resolvePathInput(exec_args[2] || exec_args[1]).string; let driveLetter = _G.shell.getCurrentDrive(); let noNewFile = (exec_args[1] == "/c" || exec_args[1] == "/C"); -let fileOpenedStatus = filesystem.open(driveLetter, path, "W"); -if (fileOpenedStatus != 0) { - printerrln("TOUCH: Can't open "+driveLetter+":\\"+path+" due to IO error"); - return fileOpenedStatus; -} - -if (!noNewFile) { - filesystem.mkFile(driveLetter); -} - -let touched = filesystem.touch(driveLetter); -if (!touched) { - printerrln("TOUCH: Can't touch "+driveLetter+":\\"+path+" due to IO error"); +let file = files.open(`${driveLetter}:/${path}`) +if (!file.exists) { + printerrln("TOUCH: Can't open "+file.fullPath+" due to IO error"); return 1; } +if (!noNewFile) { + file.mkFile() +} + +let touched = file.touch() +if (!touched) { + printerrln("TOUCH: Can't touch "+file.fullPath+" due to IO error"); + return 2; +} + return 0; \ No newline at end of file diff --git a/assets/disk0/tvdos/i18n/korean.js b/assets/disk0/tvdos/i18n/korean.js index fc4040e..b3a91c2 100644 --- a/assets/disk0/tvdos/i18n/korean.js +++ b/assets/disk0/tvdos/i18n/korean.js @@ -2,26 +2,28 @@ let status = 0 let workarea = sys.malloc(1920) // install LOCHRROM -status = filesystem.open("A", "/tvdos/i18n/hang_lo.chr", "R") -if (status != 0) { +let hangulRomL = files.open("A:/tvdos/i18n/hang_lo.chr") +if (!hangulRomL.exists) { printerrln("hang_lo.chr not found") sys.free(workarea) return status } -dma.comToRam(filesystem._toPorts("A")[0], 0, workarea, 1920) +//dma.comToRam(filesystem._toPorts("A")[0], 0, workarea, 1920) +hangulRomL.pread(workarea, 1920, 0) for (let i = 0; i < 1920; i++) sys.poke(-1300607 - i, sys.peek(workarea + i)) sys.poke(-1299460, 18) // install HICHRROM -status = filesystem.open("A", "/tvdos/i18n/hang_hi.chr", "R") -if (status != 0) { +let hangulRomH = files.open("A:/tvdos/i18n/hang_hi.chr") +if (!hangulRomH.exists) { printerrln("hang_hi.chr not found") sys.free(workarea) sys.poke(-1299460, 20) // clean up the crap return status } -dma.comToRam(filesystem._toPorts("A")[0], 0, workarea, 1920) +//dma.comToRam(filesystem._toPorts("A")[0], 0, workarea, 1920) +hangulRomH.pread(workarea, 1920, 0) for (let i = 0; i < 1920; i++) sys.poke(-1300607 - i, sys.peek(workarea + i)) sys.poke(-1299460, 19) diff --git a/doc/implementation.tex b/doc/implementation.tex index 555522f..0a39b55 100644 --- a/doc/implementation.tex +++ b/doc/implementation.tex @@ -73,8 +73,10 @@ Functions: \1\formalsynopsis{getch}{}{Returns a key code read from the keyboard.} \1\formalsynopsis{poll\_keys}{}[IntArray(8) of Keycodes]{Poll the keyboard, then returns the captured keycodes. If less than 8 keys were held down at the moment of the polling, 0 will be substituted for the spot on the array.} \1\formalsynopsis{move}{y: Int, x: Int}{Moves the text cursor to the given position. Note that the cursor position starts at 1.} -\1\formalsynopsis{addch}{char: Int}{Puts a character denoted by its code point to where the text cursor is. The cursor will not advance.} +\1\formalsynopsis{addch}{char: Int}{Puts a character denoted by its code point to where the text cursor is. The cursor will not advance. NOTE: this function accesses the graphics device directly, which may not be desirable; use \code{prnch} when you really need to \code{print} the character.} \1\formalsynopsis{mvaddch}{y: Int, x: Int, char: Int}{Combination of \code{move} and \code{addch}.} +\1\formalsynopsis{prnch}{char: Int}{Prints out a character denoted by its code point using the escape sequences. Unlike \code{addch} this function actually print out a character, which makes difference in certain situation.} + \1\formalsynopsis{getmaxyx}{}[IntArray(2)]{Returns the size of the terminal in row-column order.} \1\formalsynopsis{getyx}{}[IntArray(2)]{Returns the current position of the text cursor in row-column order.} \1\formalsynopsis{curs\_up}{}{Moves the text cursor up once.} diff --git a/doc/tsvmman.idx b/doc/tsvmman.idx index 197d384..918904d 100644 --- a/doc/tsvmman.idx +++ b/doc/tsvmman.idx @@ -2,10 +2,10 @@ \indexentry{stdio (library)|hyperpage}{9} \indexentry{console (library)|hyperpage}{9} \indexentry{con (library)|hyperpage}{9} -\indexentry{gzip (library)|hyperpage}{11} -\indexentry{gzip (library)|hyperpage}{11} -\indexentry{base64 (library)|hyperpage}{12} -\indexentry{base64 (library)|hyperpage}{12} +\indexentry{gzip (library)|hyperpage}{12} +\indexentry{gzip (library)|hyperpage}{12} +\indexentry{base64 (library)|hyperpage}{13} +\indexentry{base64 (library)|hyperpage}{13} \indexentry{sys (library)|hyperpage}{13} \indexentry{block communication|hyperpage}{16} \indexentry{com (library)|hyperpage}{16} diff --git a/doc/tsvmman.ind b/doc/tsvmman.ind index f4ca683..e88fcbe 100644 --- a/doc/tsvmman.ind +++ b/doc/tsvmman.ind @@ -1,6 +1,6 @@ \begin{theindex} - \item base64 (library), \hyperpage{12} + \item base64 (library), \hyperpage{13} \item block communication, \hyperpage{16} \item boot process, \hyperpage{29} @@ -27,7 +27,7 @@ \item gl (DOS), \hyperpage{39} \item graphics (library), \hyperpage{26} - \item gzip (library), \hyperpage{11} + \item gzip (library), \hyperpage{12} \indexspace diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/GlassTty.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/GlassTty.kt index d66c423..f532332 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/GlassTty.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/GlassTty.kt @@ -77,12 +77,13 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { ttyEscArguments.push(ttyEscArguments.pop() * 10 + (newnum.toInt() - 0x30)) } - //println("[tty] accepting char $char, state: $ttyEscState") +// println("[tty] accepting char $char (${char.toChar()}), state: $ttyEscState") when (ttyEscState) { TTY_ESC_STATE.INITIAL -> { when (char) { ESC -> ttyEscState = TTY_ESC_STATE.ESC + X84 -> ttyEscState = TTY_ESC_STATE.XCSI LF -> crlf() BS -> backspace() TAB -> insertTab() @@ -98,6 +99,20 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { else -> return reject() } } + TTY_ESC_STATE.XCSI -> { + when (char.toChar()) { + 'u' -> emitChar(0) + in '0'..'9' -> registerNewNumberArg(char, TTY_ESC_STATE.XNUM1) + else -> return reject() + } + } + TTY_ESC_STATE.XNUM1 -> { + when (char.toChar()) { + 'u' -> return accept { emitChar(ttyEscArguments.pop()) } + in '0'..'9' -> appendToExistingNumber(char) + else -> return reject() + } + } TTY_ESC_STATE.CSI -> { when (char.toChar()) { 'A' -> return accept { cursorUp() } @@ -244,6 +259,11 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { abstract fun backspace() abstract fun privateSeqH(arg: Int) abstract fun privateSeqL(arg: Int) + /** Emits arbitrary character by its char code. + * Syntax \x84 u + * Number: Any integer 0..1114111 + **/ + abstract fun emitChar(code: Int) abstract fun getPrintStream(): OutputStream abstract fun getErrorStream(): OutputStream @@ -255,9 +275,11 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { private val BS = 0x08.toByte() private val BEL = 0x07.toByte() private val ESC = 0x1B.toByte() + private val X84 = 0x84.toByte() private enum class TTY_ESC_STATE { - INITIAL, ESC, CSI, NUM1, SEP1, NUM2, SEP2, NUM3, PRIVATESEQ, PRIVATENUM + INITIAL, ESC, CSI, NUM1, SEP1, NUM2, SEP2, NUM3, PRIVATESEQ, PRIVATENUM, + XCSI, XNUM1 } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index b3e4e23..1fd3f21 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -440,6 +440,11 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi textArea[memTextOffset + textOff] = text } + override fun emitChar(code: Int) { + val (x, y) = getCursorPos() + putChar(x, y, code.toByte()) + setCursorPos(x + 1, y) + } override fun cursorUp(arg: Int) { val (x, y) = getCursorPos() setCursorPos(x, y - arg) @@ -640,6 +645,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi putChar(x - 1, y, 0x20.toByte()) } + private lateinit var PRINTSTREAM_INSTANCE: OutputStream private lateinit var ERRORSTREAM_INSTANCE: OutputStream //private lateinit var INPUTSTREAM_INSTANCE: InputStream diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TTY.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TTY.kt index 703e4a0..dbc5efd 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TTY.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TTY.kt @@ -197,6 +197,10 @@ class TTY(assetsRoot: String, val vm: VM) : GlassTty(TEXT_ROWS, TEXT_COLS), Peri vm.poke(-39, key.toByte()) } + override fun emitChar(code: Int) { + TODO("Not yet implemented") + } + /** * @return key code in 0..255 (TODO: JInput Keycode or ASCII-Code?) */