fixed boot crash

This commit is contained in:
Astronand committed 2026-03-21 01:10:47 -04:00
1 parent 462c74686a
commit 22b5021e9d
3 files changed
+150 -3

No files matched your search

+148 -1
View File
@@ -249,7 +249,154 @@ local ok, err = xpcall(function()
return value return value
end end
local allscreens = {apis.peripheral.find("monitor")} local peripheral={}
local native = apis.peripheral
local sides = {"top", "bottom", "left", "right", "front", "back"}
function peripheral.getNames()
local results = {}
for n = 1, #sides do
local side = sides[n]
if native.isPresent(side) then
table.insert(results, side)
if native.hasType(side, "peripheral_hub") then
local remote = native.call(side, "getNamesRemote")
for _, name in ipairs(remote) do
table.insert(results, name)
end
end
end
end
return results
end
function peripheral.isPresent(name)
if native.isPresent(name) then
return true
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return true
end
end
return false
end
function peripheral.getType(peripheral)
if type(peripheral) == "string" then
if native.isPresent(peripheral) then
return native.getType(peripheral)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
return native.call(side, "getTypeRemote", peripheral)
end
end
return nil
else
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return table.unpack(mt.types)
end
end
function peripheral.hasType(peripheral, peripheral_type)
if type(peripheral) == "string" then
if native.isPresent(peripheral) then
return native.hasType(peripheral, peripheral_type)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
return native.call(side, "hasTypeRemote", peripheral, peripheral_type)
end
end
return nil
else
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return mt.types[peripheral_type] ~= nil
end
end
function peripheral.getMethods(name)
if native.isPresent(name) then
return native.getMethods(name)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return native.call(side, "getMethodsRemote", name)
end
end
return nil
end
function peripheral.getName(peripheral)
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.name) ~= "string" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return mt.name
end
function peripheral.call(name, method, ...)
if native.isPresent(name) then
return native.call(name, method, ...)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return native.call(side, "callRemote", name, method, ...)
end
end
return nil
end
function peripheral.wrap(name)
local methods = peripheral.getMethods(name)
if not methods then
return nil
end
local types = { peripheral.getType(name) }
for i = 1, #types do types[types[i]] = true end
local result = setmetatable({}, {
__name = "peripheral",
name = name,
type = types[1],
types = types,
})
for _, method in ipairs(methods) do
result[method] = function(...)
return peripheral.call(name, method, ...)
end
end
return result
end
function peripheral.find(ty, filter)
local results = {}
for _, name in ipairs(peripheral.getNames()) do
if peripheral.hasType(name, ty) then
local wrapped = peripheral.wrap(name)
if filter == nil or filter(name, wrapped) then
table.insert(results, wrapped)
end
end
end
return table.unpack(results)
end
local allscreens = {peripheral.find("monitor")}
for i=1, #allscreens do for i=1, #allscreens do
allscreens[i].setTextScale(.5) allscreens[i].setTextScale(.5)
allscreens[i].clear() allscreens[i].clear()
+1 -1
View File
@@ -247,7 +247,7 @@ def main():
return return
prod = "prod" in args.target prod = "prod" in args.target
minify = "mini" in args.target or "micro" in args.target or "prod" in args.target minify = "mini" in args.target or "micro" in args.target
micro = "micro" in args.target micro = "micro" in args.target
include_test = "test" in args.target include_test = "test" in args.target
+1 -1
View File
@@ -1 +1 @@
local a=({...})[1]or"/$"local term=term;local os=os;local function b(c)local d,e=term.getCursorPos()local f,g=term.getSize()for h=1,#c do local i=c:sub(h,h)if i=="\n"then e=e+1;d=1 elseif i=="\t"then local j=4;local k=j-(d-1)%j;term.write(string.rep(" ",k))d=d+k elseif i=="\b"then if d>1 then d=d-1;term.setCursorPos(d,e)term.write(" ")term.setCursorPos(d,e)end else if d<=f and e<=g then term.setCursorPos(d,e)term.write(i)d=d+1 end end;if d>f then d=1;e=e+1 end;if e-1>=g then term.scroll(1)e=g;term.setCursorPos(d,e)end end;term.setCursorPos(d,e)end;local function l(m)term.setBackgroundColor(0x1)term.setTextColor(0x4)term.clear()term.setCursorPos(1,1)term.write("A critical error occurred while loading the system:")term.setCursorPos(1,3)b(m)while true do end end;term.setCursorBlink(false)local n,m=xpcall(function()local o={BOOT_DRIVE_PATH=a}local p={coroutine=true,debug=true,_VERSION=true,assert=true,collectgarbage=true,error=true,gcinfo=true,getmetatable=true,ipairs=true,__inext=true,load=true,math=true,next=true,pairs=true,pcall=true,rawequal=true,rawget=true,rawlen=true,rawset=true,select=true,setmetatable=true,string=true,table=true,tonumber=true,tostring=true,type=true,xpcall=true,_G=true}local debug=debug;for h,q in pairs(_G)do if not p[h]or p[h]==nil then o[h]=q;_G[h]=nil end end;local r={[o.keys.enter]="\n",[o.keys.tab]="\t",[o.keys.backspace]="\b",[o.keys.up]="\17",[o.keys.down]="\18",[o.keys.left]="\19",[o.keys.right]="\20"}function sleep(s)local t=o.os.clock()+s;while t>o.os.clock()do end end;o.term.setPaletteColor(0x1,0xFFFFFF)o.term.setPaletteColor(0x2,0xFF0000)o.term.setPaletteColor(0x4,0x00FF00)o.term.setPaletteColor(0x8,0x0000FF)o.term.setPaletteColor(0x10,0x00FFFF)o.term.setPaletteColor(0x20,0xFF00FF)o.term.setPaletteColor(0x40,0xFFFF00)o.term.setPaletteColor(0x80,0xFF6D00)o.term.setPaletteColor(0x100,0x6DFF55)o.term.setPaletteColor(0x200,0x24FFFF)o.term.setPaletteColor(0x400,0x924900)o.term.setPaletteColor(0x800,0x6D6D55)o.term.setPaletteColor(0x1000,0xDBDBAA)o.term.setPaletteColor(0x2000,0x6D00FF)o.term.setPaletteColor(0x4000,0xB6FF00)o.term.setPaletteColor(0x8000,0x000000)local function u(v)local w=o.fs.open(v,"r")if not w then l("Could not open file: "..v)end;local x=w.readAll()w.close()return x end;local y=load(u(a.."/boot/kernel.lua"),"@Kernel")local z=load(u(a.."/boot/cct/initdisks"),"@Init_disks")(o)local A=load(u(a.."/boot/initfs"),"@InitFs")()if not y then l("Could not load kernel.")end;if not z then l("Could not load initdisks.")end;if not A then l("Could not load initfs.")end;if not o.fs.exists("/nvram.dat")then local w=o.fs.open("/nvram.dat","w")w.write("Hello, World!")w.close()end;local B;if o.fs.exists("/startup.lua")then B="/startup.lua"elseif o.fs.exists("/eeprom")then B="/eeprom"end;local C={}local function D(E,...)table.insert(C,{E,...})end;local F={[0x000000]=0x0001,[0xFFFFFF]=0x0002,[0xFF0000]=0x0004,[0x00FF00]=0x0008,[0x0000FF]=0x0010,[0x00FFFF]=0x0020,[0xFF00FF]=0x0040,[0xFFFF00]=0x0080,[0xFF6D00]=0x0100,[0x6DFF55]=0x0200,[0x24FFFF]=0x0400,[0x924900]=0x0800,[0x6D6D55]=0x1000,[0xDBDBAA]=0x2000,[0x6D00FF]=0x4000,[0xB6FF00]=0x8000}local G,H=0x6D6D55,0x000000;local I,J,K,L={},{},{},0;local function M(N,O)local P=nil;local Q=math.huge;for R,S in pairs(N)do if R==O then return R end;local T=math.abs(R-O)if T<Q then Q=T;P=R end end;return P end;local function U(V)L=L+1;if L%1024==0 then J={}I={}end;if L%8192==0 then K={}end;if K[V]~=nil then return K[V]end;if J[V]~=nil then I[V]=I[V]+1;if I[V]>=16 then K[V]=J[V]J[V]=nil;I[V]=nil;return K[V]end;return J[V]end;local W=M(F,V)if not W then return nil end;local X=F[W]J[V]=X;I[V]=1;return X end;local Y={o.peripheral.find("monitor")}for h=1,#Y do Y[h].setTextScale(.5)Y[h].clear()Y[h].setCursorPos(1,1)Y[h].write("Initializing...")end;local Z={getEpochMs=function()return o.os.epoch("utc")end,getUptime=function()return o.os.clock()*1000 end,date=function()return o.os.date("!%Y-%m-%dT%H:%M:%SZ",o.os.epoch("utc")/1000)end,getMachineEvent=function()if#C>0 then return table.unpack(table.remove(C,1))else return nil end end,getEEPROM=function()return u(B)end,setEEPROM=function(S,c)local g=o.fs.open(B,"w")g.write(c)g.close()end,initfs=A,disks=z,screenCtl={print=function(S,c)b(c.."\n")end,printInline=function(S,c)b(c)end,clear=function()o.term.clear()o.term.setCursorPos(1,1)end,setCursorPos=function(S,d,e)o.term.setCursorPos(d,e)end,getCursorPos=function()return o.term.getCursorPos()end,getSize=function()return o.term.getSize()end,setBackgroundColor=function(S,_)o.term.setBackgroundColor(U(_))end,setTextColor=function(S,_)o.term.setTextColor(U(_))end,getBackgroundColor=function()return H end,getTextColor=function()return G end,enable=function()end,disable=function()end},architecture="cct",getNvram=function()return u("/nvram.dat")end,setNvram=function(S,c)local g=o.fs.open("/nvram.dat","w")g.write(c)g.close()end,firmware=o,reboot=false,beep=function()end}o.term.setBackgroundColor(0x8000)o.term.setTextColor(0x1000)o.term.clear()o.term.setCursorPoLine truncated local a=({...})[1]or"/$"local term=term;local os=os;local function b(c)local d,e=term.getCursorPos()local f,g=term.getSize()for h=1,#c do local i=c:sub(h,h)if i=="\n"then e=e+1;d=1 elseif i=="\t"then local j=4;local k=j-(d-1)%j;term.write(string.rep(" ",k))d=d+k elseif i=="\b"then if d>1 then d=d-1;term.setCursorPos(d,e)term.write(" ")term.setCursorPos(d,e)end else if d<=f and e<=g then term.setCursorPos(d,e)term.write(i)d=d+1 end end;if d>f then d=1;e=e+1 end;if e-1>=g then term.scroll(1)e=g;term.setCursorPos(d,e)end end;term.setCursorPos(d,e)end;local function l(m)term.setBackgroundColor(0x1)term.setTextColor(0x4)term.clear()term.setCursorPos(1,1)term.write("A critical error occurred while loading the system:")term.setCursorPos(1,3)b(m)while true do end end;term.setCursorBlink(false)local n,m=xpcall(function()local o={BOOT_DRIVE_PATH=a}local p={coroutine=true,debug=true,_VERSION=true,assert=true,collectgarbage=true,error=true,gcinfo=true,getmetatable=true,ipairs=true,__inext=true,load=true,math=true,next=true,pairs=true,pcall=true,rawequal=true,rawget=true,rawlen=true,rawset=true,select=true,setmetatable=true,string=true,table=true,tonumber=true,tostring=true,type=true,xpcall=true,_G=true}local debug=debug;for h,q in pairs(_G)do if not p[h]or p[h]==nil then o[h]=q;_G[h]=nil end end;local r={[o.keys.enter]="\n",[o.keys.tab]="\t",[o.keys.backspace]="\b",[o.keys.up]="\17",[o.keys.down]="\18",[o.keys.left]="\19",[o.keys.right]="\20"}function sleep(s)local t=o.os.clock()+s;while t>o.os.clock()do end end;o.term.setPaletteColor(0x1,0xFFFFFF)o.term.setPaletteColor(0x2,0xFF0000)o.term.setPaletteColor(0x4,0x00FF00)o.term.setPaletteColor(0x8,0x0000FF)o.term.setPaletteColor(0x10,0x00FFFF)o.term.setPaletteColor(0x20,0xFF00FF)o.term.setPaletteColor(0x40,0xFFFF00)o.term.setPaletteColor(0x80,0xFF6D00)o.term.setPaletteColor(0x100,0x6DFF55)o.term.setPaletteColor(0x200,0x24FFFF)o.term.setPaletteColor(0x400,0x924900)o.term.setPaletteColor(0x800,0x6D6D55)o.term.setPaletteColor(0x1000,0xDBDBAA)o.term.setPaletteColor(0x2000,0x6D00FF)o.term.setPaletteColor(0x4000,0xB6FF00)o.term.setPaletteColor(0x8000,0x000000)local function u(v)local w=o.fs.open(v,"r")if not w then l("Could not open file: "..v)end;local x=w.readAll()w.close()return x end;local y=load(u(a.."/boot/kernel.lua"),"@Kernel")local z=load(u(a.."/boot/cct/initdisks"),"@Init_disks")(o)local A=load(u(a.."/boot/initfs"),"@InitFs")()if not y then l("Could not load kernel.")end;if not z then l("Could not load initdisks.")end;if not A then l("Could not load initfs.")end;if not o.fs.exists("/nvram.dat")then local w=o.fs.open("/nvram.dat","w")w.write("Hello, World!")w.close()end;local B;if o.fs.exists("/startup.lua")then B="/startup.lua"elseif o.fs.exists("/eeprom")then B="/eeprom"end;local C={}local function D(E,...)table.insert(C,{E,...})end;local F={[0x000000]=0x0001,[0xFFFFFF]=0x0002,[0xFF0000]=0x0004,[0x00FF00]=0x0008,[0x0000FF]=0x0010,[0x00FFFF]=0x0020,[0xFF00FF]=0x0040,[0xFFFF00]=0x0080,[0xFF6D00]=0x0100,[0x6DFF55]=0x0200,[0x24FFFF]=0x0400,[0x924900]=0x0800,[0x6D6D55]=0x1000,[0xDBDBAA]=0x2000,[0x6D00FF]=0x4000,[0xB6FF00]=0x8000}local G,H=0x6D6D55,0x000000;local I,J,K,L={},{},{},0;local function M(N,O)local P=nil;local Q=math.huge;for R,S in pairs(N)do if R==O then return R end;local T=math.abs(R-O)if T<Q then Q=T;P=R end end;return P end;local function U(V)L=L+1;if L%1024==0 then J={}I={}end;if L%8192==0 then K={}end;if K[V]~=nil then return K[V]end;if J[V]~=nil then I[V]=I[V]+1;if I[V]>=16 then K[V]=J[V]J[V]=nil;I[V]=nil;return K[V]end;return J[V]end;local W=M(F,V)if not W then return nil end;local X=F[W]J[V]=X;I[V]=1;return X end;local Y={}local Z=o.peripheral;local _={"top","bottom","left","right","front","back"}function Y.getNames()local a0={}for a1=1,#_ do local a2=_[a1]if Z.isPresent(a2)then table.insert(a0,a2)if Z.hasType(a2,"peripheral_hub")then local a3=Z.call(a2,"getNamesRemote")for S,a4 in ipairs(a3)do table.insert(a0,a4)end end end end;return a0 end;function Y.isPresent(a4)if Z.isPresent(a4)then return true end;for a1=1,#_ do local a2=_[a1]if Z.hasType(a2,"peripheral_hub")and Z.call(a2,"isPresentRemote",a4)then return true end end;return false end;function Y.getType(Y)if type(Y)=="string"then if Z.isPresent(Y)then return Z.getType(Y)end;for a1=1,#_ do local a2=_[a1]if Z.hasType(a2,"peripheral_hub")and Z.call(a2,"isPresentRemote",Y)then return Z.call(a2,"getTypeRemote",Y)end end;return nil else local a5=getmetatable(Y)if not a5 or a5.__name~="peripheral"or type(a5.types)~="table"then error("bad argument #1 (table is not a peripheral)",2)end;return table.unpack(a5.types)end end;function Y.hasType(Y,a6)if type(Y)=="string"then if Z.isPresent(Y)then return Z.hasType(Y,a6)end;for a1=1,#_ do local a2=_[a1]if Z.hasType(a2,"peripheral_hub")and Z.call(a2,"isPresentRemote",Y)then return Z.call(a2,"hasTypeRemote",Y,a6)end end;return nil else local a5=getmetatable(Y)if not a5 or a5.__name~="peripheral"or type(a5.types)~="table"then error("bad argument #1 (table is not aLine truncated