device files are mounted under the drive letter of dollarsign

This commit is contained in:
minjaesong
2022-09-24 16:46:44 +09:00
parent f9eecab830
commit 0304ded991
8 changed files with 38 additions and 26 deletions

View File

@@ -1,3 +1,3 @@
let f = files.open("CON")
let f = files.open("$:/CON")
f.swrite("Hello, world! I'm just writing to a file named 'CON'\n")
f.close()

View File

@@ -1,4 +1,4 @@
let fout = files.open("FBIPF")
let fout = files.open("$:/FBIPF")
let fin = files.open(_G.shell.resolvePathInput(exec_args[1]).full)
let ipfRead = fin.bread()

View File

@@ -1,4 +1,4 @@
let f = files.open("RND")
let f = files.open("$:/RND")
let mlen = 512
let m = sys.malloc(mlen)

View File

@@ -94,15 +94,17 @@ _TVDOS.DRV.FS = {}
class TVDOSFileDescriptor {
constructor(path0, driverID) {
if (driverID === undefined) {
if (!files.reservedNames.includes(path0)) {
throw Error(`${path0} is not a valid device file`)
if (path0.startsWith("$")) {
let devName = path0.substring(3)
if (!files.reservedNames.includes(devName)) {
throw Error(`${devName} is not a valid device file`)
}
this._driveLetter = undefined
this._path = path0
this._driverID = `DEV${path0}`
this._driver = _TVDOS.DRV.FS[`DEV${path0}`] // can't just put `driverID` here
this._driverID = `DEV${devName}`
this._driver = _TVDOS.DRV.FS[`DEV${devName}`] // can't just put `driverID` here
}
else {
let p = path0.replaceAll("/", "\\")
@@ -111,7 +113,7 @@ class TVDOSFileDescriptor {
p = p.substring(0, p.length - 1)
}
this._driveLetter = p[0]
this._path = p.substring(2) // detaches A:
this._path = p.substring(2) // detaches $:
this._driverID = driverID
this._driver = _TVDOS.DRV.FS[driverID]
serial.println(`TVDOSFileDescriptor input path: ${path0}, p = ${p}, driveLetter = ${this._driveLetter}, path = ${this._path}`)
@@ -810,6 +812,12 @@ files.open = (fullPath) => {
if (fullPath[2] != '/' && fullPath[2] != '\\') throw Error("Expected full path with drive letter, got " + fullPath)
let driveLetter = fullPath[0].toUpperCase()
let driver = _TVDOS.DRIVEFS[driveLetter]
// special device files ($:\NUL, $:\CON, etc)
if ("$" == driveLetter) {
return new TVDOSFileDescriptor(fullPath.toUpperCase())
}
return new TVDOSFileDescriptor(fullPath, driver)
}

View File

@@ -26,7 +26,7 @@ if (!magicMatching) {
}
// decode input image
let ipfFile = files.open("FBIPF")
let ipfFile = files.open("$:/FBIPF")
graphics.clearText(); graphics.clearPixels(0); graphics.clearPixels2(0)
ipfFile.pwrite(infilePtr, infile.size, 0)
sys.free(infilePtr)

View File

@@ -20,9 +20,9 @@
\indexentry{boot process|hyperpage}{29}
\indexentry{coreutils (DOS)|hyperpage}{30}
\indexentry{applications (DOS)|hyperpage}{31}
\indexentry{pipe (DOS)|hyperpage}{33}
\indexentry{filesystem (DOS)|hyperpage}{35}
\indexentry{file descriptor (DOS)|hyperpage}{35}
\indexentry{device file|hyperpage}{37}
\indexentry{input (DOS)|hyperpage}{39}
\indexentry{gl (DOS)|hyperpage}{40}
\indexentry{pipe (DOS)|hyperpage}{34}
\indexentry{filesystem (DOS)|hyperpage}{36}
\indexentry{file descriptor (DOS)|hyperpage}{36}
\indexentry{device file|hyperpage}{38}
\indexentry{input (DOS)|hyperpage}{40}
\indexentry{gl (DOS)|hyperpage}{41}

View File

@@ -19,22 +19,22 @@
\indexspace
\item device file, \hyperpage{37}
\item device file, \hyperpage{38}
\indexspace
\item file descriptor (DOS), \hyperpage{35}
\item filesystem (DOS), \hyperpage{35}
\item file descriptor (DOS), \hyperpage{36}
\item filesystem (DOS), \hyperpage{36}
\indexspace
\item gl (DOS), \hyperpage{40}
\item gl (DOS), \hyperpage{41}
\item graphics (library), \hyperpage{26}
\item gzip (library), \hyperpage{12}
\indexspace
\item input (DOS), \hyperpage{39}
\item input (DOS), \hyperpage{40}
\indexspace
@@ -51,7 +51,7 @@
\indexspace
\item pipe (DOS), \hyperpage{33}
\item pipe (DOS), \hyperpage{34}
\indexspace

View File

@@ -4,7 +4,7 @@
All \thedos-related features requires the DOS to be fully loaded.
On this documentation, what would be a reverse solidus (e.g. directory separators) are typesetted using a slash; while they \emph{are} interchangeable, using the reverse solidus are recommended for path input.
\chapter{Bootstrapping}
@@ -59,10 +59,14 @@ Variables can be set or changed using \textbf{SET} commands.
This chapter will only briefly list and describe the applications.
\begin{outline}
\1\dossynopsis{basica}{Invokens a BASIC interpreter stored in the ROM. If no BASIC rom is present, nothing will be done.}
\1\dossynopsis{basica}{Invokes a BASIC interpreter stored in the ROM. If no BASIC rom is present, nothing will be done.}
\1\dossynopsis{basic}{If your system is bundled with a software-based BASIC, this command will invoke the BASIC interpreter stored in the disk.}
\1\dossynopsis{color}{Changes the background and the foreground of the active session.}
\1\dossynopsis{command}{The default text-based DOS shell. Call with \code{command /fancy} for more \ae sthetically pleasing looks.}
\1\dossynopsis{decodeipf}{file}{Decodes the IPF-formatted image to the framebuffer using the graphics processor.}
\1\dossynopsis{drives}{Shows the list of the connected and mounted disk drives.}
\1\dossynopsis{edit}{path}{The interactive full-screen text editor.}
\1\dossynopsis{encodeipf}{1/2 imagefile ipffile}{Encodes the given image file (.jpg, .png, .bmp, .tga) to the IPF format using the graphics hardware.}
\1\dossynopsis{false}{Returns errorlevel 1 upon execution.}
\1\dossynopsis{hexdump}{path}{Prints out the contents of a file in hexadecimal view. Supports pipe.}
\1\dossynopsis{less}{path}{Allows user to read the long text, even if they are wider and/or taller than the screen. Supports pipe.}
@@ -168,7 +172,7 @@ Functions:
\section{The Device Files}
\index{device file}Some devices are also virtualised through the file descriptor, and they are given a special path. (their fullPath does not contain a drive letter)
\index{device file}Some devices are also virtualised through the file descriptor, and they are given a special drive letter of \code{\$}. (e.g. \code{\$:/RND})
\begin{outline}
\1\inlinesynopsis{RND}{returns random bytes upon reading}
@@ -186,7 +190,7 @@ Functions:
\2\argsynopsis{pwrite}{writes the bytes from the given pointer.}
\2\argsynopsis{bwrite}{identical to \code{print()} except the given byte array will be casted to string.}
\2\argsynopsis{swrite}{identical to \code{print()}.}
\1\inlinesynopsis{FBIPF}{decodes IPF-formatted image to the framebuffer. Use the \emph{Graphics} library for the encoding.}
\1\inlinesynopsis{FBIPF}{decodes IPF-formatted image to the framebuffer. Use the bundled \code{encodeipf.js} for the encoding.}
\2\argsynopsis{pwrite, bwrite}{decodes the given IPF binary data. Offsets and counts for \code{pwrite} are ignored.}
\end{outline}