// Boot script var _TVDOS = {}; _TVDOS.DRIVES = {}; // Object where key-value pair is : [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(); return (response == 0); }; // @return the entire contents of the file in String filesystem.readAll = function() { let port = filesystem._toPorts(driveLetter); com.sendMessage(port[0], "READ"); let response = com.getStatusCode(); 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);