getting rid of old filesystem functions

This commit is contained in:
minjaesong
2022-09-06 20:30:46 +09:00
parent 8232053695
commit 0d1e33f7e6
14 changed files with 102 additions and 47 deletions

View File

@@ -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);
};

View File

@@ -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);
*/
///////////////////////////////////////////////////////////////////////////////

View File

@@ -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 //

View File

@@ -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)
};

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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)

View File

@@ -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.}

View File

@@ -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}

View File

@@ -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

View File

@@ -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 <number> 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
}

View File

@@ -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

View File

@@ -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?)
*/