super dupper system update (it runs)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
local BOOT_DRIVE_PATH="/$"
|
||||
local term = term
|
||||
local os = os
|
||||
-- Function to write text to the terminal with special character handling
|
||||
@@ -100,6 +101,7 @@ local ok, err = xpcall(function()
|
||||
}
|
||||
|
||||
-- Move all non-Lua standard library globals into the apis table
|
||||
local debug = debug
|
||||
for i,v in pairs(_G) do
|
||||
if not lua[i] or lua[i]==nil then
|
||||
apis[i]=v
|
||||
@@ -107,6 +109,11 @@ local ok, err = xpcall(function()
|
||||
end
|
||||
end
|
||||
|
||||
function sleep(time)
|
||||
local stoptime = apis.os.clock() + (time)
|
||||
while stoptime > apis.os.clock() do end
|
||||
end
|
||||
|
||||
-- Set up terminal default colors
|
||||
apis.term.setPaletteColor(0x1, 0x000000) -- #000000
|
||||
apis.term.setPaletteColor(0x2, 0xFFFFFF) -- #FFFFFF
|
||||
@@ -135,9 +142,9 @@ local ok, err = xpcall(function()
|
||||
end
|
||||
|
||||
-- Load kernel first if it fails, we can't continue so we display an error
|
||||
local Kernel = load(getFile("/$/boot/kernel.lua"),"@Kernel")
|
||||
local initFs = load(getFile("/$/boot/cct/initdisks","@Init_disks"))(apis)
|
||||
local fs = load(getFile("/$/boot/initfs"),"@InitFs")()
|
||||
local Kernel = load(getFile(BOOT_DRIVE_PATH.."/boot/kernel.lua"),"@Kernel")
|
||||
local initFs = load(getFile(BOOT_DRIVE_PATH.."/boot/cct/initdisks","@Init_disks"))(apis)
|
||||
local fs = load(getFile(BOOT_DRIVE_PATH.."/boot/initfs"),"@InitFs")()
|
||||
if not Kernel then
|
||||
displaySuperBadError("Could not load kernel.")
|
||||
end
|
||||
@@ -163,7 +170,7 @@ local ok, err = xpcall(function()
|
||||
-- Set up computer api
|
||||
local computer = {
|
||||
time = function() return apis.os.epoch("utc") end,
|
||||
clock = apis.os.clock,
|
||||
clock = function() return apis.os.clock()/1000 end,
|
||||
shutdown = apis.os.shutdown,
|
||||
reboot = apis.os.reboot,
|
||||
getMachineEvent = function()
|
||||
@@ -255,13 +262,13 @@ local ok, err = xpcall(function()
|
||||
end
|
||||
end, "", 1000)
|
||||
local ret = {coroutine.resume(co, ...)}
|
||||
if ret[1]=="timeout" then
|
||||
return nil, "Coroutine timed out"
|
||||
if ret[1] and ret[2]=="timeout" then
|
||||
return "timeout"
|
||||
elseif ret[1]==false then
|
||||
return false, ret[2]
|
||||
return "error", ret[2]
|
||||
else
|
||||
debug.sethook(co)
|
||||
return true, table.unpack(ret)
|
||||
return "success", table.unpack(ret, 2)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -291,12 +298,13 @@ local ok, err = xpcall(function()
|
||||
exit=true
|
||||
end
|
||||
end
|
||||
if status == false or coroutine.status(kernelCoro)=="dead" then
|
||||
if status == "error" or coroutine.status(kernelCoro)=="dead" then
|
||||
displaySuperBadError("Kernel error: "..tostring(err))
|
||||
coroutine.yield("key")
|
||||
end
|
||||
end
|
||||
end, debug.traceback)
|
||||
|
||||
if not ok then
|
||||
displaySuperBadError("Fatal error during boot: "..err)
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
sleep(1)
|
||||
local BOOT_DRIVE_PATH="/$"
|
||||
-- UnBIOS by JackMacWindows
|
||||
-- This will undo most of the changes/additions made in the BIOS, but some things may remain wrapped if `debug` is unavailable
|
||||
-- To use, just place a `bios.lua` in the root of the drive, and run this program
|
||||
@@ -58,7 +60,7 @@ function _G.term.native()
|
||||
term.setCursorPos(1, 1)
|
||||
term.setCursorBlink(true)
|
||||
term.clear()
|
||||
local file = fs.open("/$/boot/cct/boot.lua", "r")
|
||||
local file = fs.open(BOOT_DRIVE_PATH.."/boot/cct/boot.lua", "r")
|
||||
if file == nil then
|
||||
term.setCursorBlink(false)
|
||||
term.setTextColor(16384)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local apis = ({...})[1]
|
||||
local BOOT_DRIVE_PATH="/$"
|
||||
local fs = apis.fs
|
||||
local native = apis.peripheral
|
||||
local peripheral = {}
|
||||
@@ -62,33 +63,6 @@ local function createDisk(id, basePath, readonly, periph)
|
||||
return fs.getCapacity(basePath)
|
||||
end
|
||||
|
||||
function disk:readAllText(path)
|
||||
local p = fs.combine(basePath, path)
|
||||
if not fs.exists(p) then return nil, "file not found" end
|
||||
local h = fs.open(p, "r")
|
||||
local t = h.readAll()
|
||||
h.close()
|
||||
return t
|
||||
end
|
||||
|
||||
function disk:writeAllText(path, text)
|
||||
local p = fs.combine(basePath, path)
|
||||
local h = fs.open(p, "w")
|
||||
if not h then return nil, "cannot write" end
|
||||
h.write(text)
|
||||
h.close()
|
||||
return true
|
||||
end
|
||||
|
||||
function disk:appendAllText(path, text)
|
||||
local p = fs.combine(basePath, path)
|
||||
local h = fs.open(p, "a")
|
||||
if not h then return nil, "cannot append" end
|
||||
h.write(text)
|
||||
h.close()
|
||||
return true
|
||||
end
|
||||
|
||||
function disk:list(path)
|
||||
local p = fs.combine(basePath, path)
|
||||
if not fs.exists(p) or not fs.isDir(p) then return nil, "not directory" end
|
||||
@@ -105,6 +79,17 @@ local function createDisk(id, basePath, readonly, periph)
|
||||
return fs.exists(p) and fs.isDir(p)
|
||||
end
|
||||
|
||||
function disk:type(path)
|
||||
local p = fs.combine(basePath, path)
|
||||
if not fs.exists(p) then
|
||||
return nil
|
||||
elseif fs.isDir(p) then
|
||||
return "directory"
|
||||
else
|
||||
return "file"
|
||||
end
|
||||
end
|
||||
|
||||
function disk:makeDirectory(path)
|
||||
local p = fs.combine(basePath, path)
|
||||
fs.makeDir(p)
|
||||
@@ -125,9 +110,14 @@ local function createDisk(id, basePath, readonly, periph)
|
||||
return periph.getLabel()
|
||||
end
|
||||
|
||||
function disk:size(path)
|
||||
function disk:attributes(path)
|
||||
local p = fs.combine(basePath, path)
|
||||
return fs.getSize(p)
|
||||
return fs.attributes(p)
|
||||
end
|
||||
|
||||
function disk:open(path, mode)
|
||||
local p = fs.combine(basePath, path)
|
||||
return fs.open(p, mode)
|
||||
end
|
||||
|
||||
return disk
|
||||
@@ -136,7 +126,7 @@ end
|
||||
---------------------------------------------------------
|
||||
-- INTERNAL DISK "$" (mapped to "/")
|
||||
---------------------------------------------------------
|
||||
internal["$"] = createDisk("$", "/$", false, {
|
||||
internal["$"] = createDisk("$", BOOT_DRIVE_PATH, false, {
|
||||
setLabel=function(label)
|
||||
local h = fs.open("/.label", "w")
|
||||
h.write(label)
|
||||
|
||||
Reference in New Issue
Block a user