Files
tsvm/assets/tvdos/TVDOS.SYS
minjaesong d8f7bb3973 stuffs
2020-10-30 11:45:22 +09:00

56 lines
1.9 KiB
Plaintext

// Boot script
var _TVDOS = {};
_TVDOS.VERSION = "1.0";
_TVDOS.DRIVES = {}; // Object where key-value pair is <drive-letter> : [serial-port, drive-number]
// actually figure out the drive letter association
// Drive A is always the device we're currently on
_TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT;
Object.freeze(_TVDOS);
///////////////////////////////////////////////////////////////////////////////
var filesystem = {};
filesystem._toPorts = function(driveLetter) {
let port = _TVDOS.DRIVES[driveLetter.toUpperCase()];
if (port === undefined) {
throw Error("Drive letter '" + driveLetter.toUpperCase() + "' does not exist");
}
return port
};
filesystem._close = function(portNo) {
com.sendMessage(portNo, "CLOSE");
};
filesystem._flush = function(portNo) {
com.sendMessage(portNo, "FLUSH");
};
// @return true if operation committed successfully, false otherwise; throws error
// if unknown mode or invalid drive letter was given
filesystem.open = function(driveLetter, path, operationMode) {
let port = filesystem._toPorts(driveLetter);
filesystem._flush(port[0]); filesystem._close(port[0]);
let mode = operationMode.toUpperCase();
if (mode != "R" && mode != "W" && mode != "A") {
throw Error("Unknown file opening mode: " + mode);
}
com.sendMessage(port[0], "OPEN"+mode+'"'+path+'",'+port[1]);
let response = com.getStatusCode(port[0]);
return (response == 0);
};
// @return the entire contents of the file in String
filesystem.readAll = function(driveLetter) {
let port = filesystem._toPorts(driveLetter);
com.sendMessage(port[0], "READ");
let response = com.getStatusCode(port[0]);
if (response < 0 || response >= 128) {
let status = com.getDeviceStatus(port[0]);
throw Error("Reading a file failed with "+status.code+": "+status.message);
}
return com.pullMessage(port[0]);
};
Object.freeze(filesystem);