tmpfs wip

This commit is contained in:
minjaesong
2023-05-05 20:44:34 +09:00
parent 9adcce746b
commit b6fb9acd6a
4 changed files with 131 additions and 7 deletions

View File

@@ -22,6 +22,57 @@ class SIG {
const SIGTERM = new SIG("TERM",15);
const SIGSEGV = new SIG("SEGV",11);
class PmemFSdir {
constructor(targetpath) {
if (targetpath === undefined) {
this.data = ""
return
}
if (typeof myVar === 'string' || myVar instanceof String) {
this.target = targetpath
}
else {
throw Error("Invalid type for directory")
}
}
}
class PmemFSfile {
constructor(bytes) {
if (bytes === undefined) {
this.data = ""
return
}
// string representation (preferable)
if (typeof myVar === 'string' || myVar instanceof String) {
this.data = bytes
}
// Javascript array OR JVM byte[]
else if (Array.isArray(bytes) || bytes.toString().startsWith("[B")) {
this.data = ""
for (let i = 0; i < array.length; i++) {
this.data += String.fromCharCode(bytes[i])
}
}
else {
throw Error("Invalid type for directory")
}
}
dataAsString() {
return this.data
}
dataAsBytes() {
let bytes = new Uint8Array(this.data.length)
for (let i = 0; i < this.data.length; i++) {
bytes[i] = this.data.charCodeAt(i)
}
return bytes
}
}
function generateRandomHashStr(len) {
let cs = 'qwfpgarstdzxcvbjluyhneiokmQWFPGARSTDZXCVBJLUYHNEIOKM';
let s = '';
@@ -45,9 +96,13 @@ _TVDOS.DRIVEINFO["A"] = {
name: com.sendMessageGetBytes(_BIOS.FIRST_BOOTABLE_PORT[0], "DEVNAM\x17").init(),
type: com.sendMessageGetBytes(_BIOS.FIRST_BOOTABLE_PORT[0], "DEVTYP\x17").substring(0,4)
}
_TVDOS.TMPFS = {
".": new PmemFSdir("TMP/"),
"..": new PmemFSdir("TMP/"),
};
// probe filesystem devices
let devnameToDriver = {"PRNT":"LP","STOR":"SERIAL","COMM":"COM","HTTP":"NET"}
let devnameToDriver = {"PRNT":"LP","STOR":"SERIAL","COMM":"COM","HTTP":"NET","TMP":"PMEMFS"}
let currentDriveLetter = ["A","B","C","D"]
for (let portNo = 1; portNo < 4; portNo++) {
if (com.areYouThere(portNo)) {
@@ -656,6 +711,48 @@ _TVDOS.DRV.FS.DEVFBIPF.exists = () => true
Object.freeze(_TVDOS.DRV.FS.DEVFBIPF)
///////////////////////////////////////////////////////////////////////////////
_TVDOS.DRV.FS.DEVTMP = {}
_TVDOS.DRV.FS.DEVTMP.sread = (fd) => {
if (_TVDOS.TMPFS[fd.path] === undefined) throw Error(`No such file: ${fd.fullPath}`)
return _TVDOS.TMPFS[fd.path].dataAsString()
}
_TVDOS.DRV.FS.DEVTMP.bread = (fd) => {
if (_TVDOS.TMPFS[fd.path] === undefined) throw Error(`No such file: ${fd.fullPath}`)
return _TVDOS.TMPFS[fd.path].dataAsBytes()
}
_TVDOS.DRV.FS.DEVTMP.pread = (fd, ptr, count, offset) => {
if (_TVDOS.TMPFS[fd.path] === undefined) throw Error(`No such file: ${fd.fullPath}`)
let str = _TVDOS.TMPFS[fd.path].dataAsString()
for (let i = 0; i < count - offset; i++) {
sys.poke(ptr + i, String.charCodeAt(i + offset))
}
}
_TVDOS.DRV.FS.DEVTMP.flush = (fd) => {}
_TVDOS.DRV.FS.DEVTMP.close = (fd) => {}
_TVDOS.DRV.FS.DEVTMP.isDirectory = (fd) => (_TVDOS.TMPFS[fd.path] != undefined && _TVDOS.TMPFS[fd.path] instanceof PmemFSdir)
_TVDOS.DRV.FS.DEVTMP.listFiles = (fd) => undefined
_TVDOS.DRV.FS.DEVTMP.touch = (fd) => {}
_TVDOS.DRV.FS.DEVTMP.mkDir = (fd) => {
_TVDOS.TMPFS[fd.path] = new PmemFSdir(fd.path)
return true
}
_TVDOS.DRV.FS.DEVTMP.mkFile = (fd) => {
_TVDOS.TMPFS[fd.path] = new PmemFSfile(fd.path)
return true
}
_TVDOS.DRV.FS.DEVTMP.remove = (fd) => {
delete _TVDOS.TMPFS[fd.path]
return true
}
_TVDOS.DRV.FS.DEVTMP.exists = (fd) => (_TVDOS.TMPFS[fd.path] !== undefined)
Object.freeze(_TVDOS.DRV.FS.DEVTMP)
///////////////////////////////////////////////////////////////////////////////
_TVDOS.DRV.FS.NET = {}
@@ -839,6 +936,7 @@ files.reservedNames = ["AUX", // unused
"PMEM0","PMEM1","PMEM2","PMEM3","PMEM4","PMEM5","PMEM6","PMEM7", // /dev/mem for peripherals
"PRN", // a printer
"RND", // /dev/urandom
"TMP", // tmp file that resides in the Program Memory
"XFB", // raw framebuffer, 4096 colours, typ. 560x448. Memory layout follows the gpu's (0..250779: RG-plane, 250880..262143: gap, 262144..513023: BA-plane)
"ZERO"] // /dev/zero

View File

@@ -12,7 +12,7 @@ exports.Texture = function(w, h, bytes) {
this.texData = bytes;
if (!Array.isArray(bytes) && !bytes.toString().startsWith("[B")) {
throw "Texture data is not an instance of array";
throw Error("Texture data is not an instance of array");
}
};
exports.MonoTex = function(w, h, bits) {
@@ -21,7 +21,7 @@ exports.MonoTex = function(w, h, bits) {
this.texData = bits;
if (!Array.isArray(bits) && !bits.toString().startsWith("[B")) {
throw "Texture data is not an instance of array";
throw Error("Texture data is not an instance of array");
}
};
exports.SpriteSheet = function(tilew, tileh, tex) {
@@ -30,18 +30,18 @@ exports.SpriteSheet = function(tilew, tileh, tex) {
this.texture = tex;
if (!tex instanceof exports.Texture) {
throw "Texture is not an instance of exports.Texture";
throw Error("Texture is not an instance of exports.Texture");
}
this.getOffX = function(x) { // THIS, or: exports.SpriteSheet.prototype.getOffX
let tx = this.tileWidth * (x|0);
if (tx + this.tileWidth > this.texture.width) throw "Sprite x-offset of "+tx+" is greater than sprite width "+this.texture.width;
if (tx + this.tileWidth > this.texture.width) throw Error("Sprite x-offset of "+tx+" is greater than sprite width "+this.texture.width);
return tx;
};
this.getOffY = function(y) {
let ty = this.tileHeight * (y|0);
if (ty + this.tileHeight > this.texture.height) throw "Sprite y-offset of "+ty+" is greater than sprite height "+this.texture.height;
if (ty + this.tileHeight > this.texture.height) throw Error("Sprite y-offset of "+ty+" is greater than sprite height "+this.texture.height);
return ty;
};
};

View File

@@ -0,0 +1,27 @@
/*
Loads files into the memory and returns their respective pointers. If the file was failed to load (file not found or
out of memory), `null` will be used instead.
The path must be an absolute path including drive letter.
This program is not meant to be used by the end user, but the creators of packaged apps where the simple and easy way of
pre-loading resources (e.g. graphical assets) into the memory is desirable.
This library requires TVDOS.SYS to be loaded.
*/
exports = function mload(paths) {
return paths.map(path => {
let f = files.open(path)
let flen = f.size
try {
let p = sys.malloc(flen)
f.pread(p, flen, 0)
return p
}
catch (e) {
return null
}
})
}

View File

@@ -3,7 +3,6 @@ package net.torvald.tsvm
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.utils.GdxRuntimeException
import com.badlogic.gdx.utils.JsonValue
import kotlin.coroutines.*
import net.torvald.tsvm.peripheral.BlockTransferInterface
import net.torvald.tsvm.peripheral.GraphicsAdapter
import net.torvald.tsvm.peripheral.PeriBase