forked from Hyperion/HyperionOS
1 line
4.9 KiB
Lua
1 line
4.9 KiB
Lua
local a="/$"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;local n,m=xpcall(function()local o={}local p={coroutine=true,debug=true,_HOST=true,_VERSION=true,assert=true,collectgarbage=true,error=true,gcinfo=true,getfenv=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,setfenv=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;function sleep(r)local s=o.os.clock()+r;while s>o.os.clock()do end end;o.term.setPaletteColor(0x1,0x000000)o.term.setPaletteColor(0x2,0xFFFFFF)o.term.setPaletteColor(0x4,0xFF0000)o.term.setPaletteColor(0x8,0x00FF00)o.term.setPaletteColor(0x10,0x0000FF)o.term.setPaletteColor(0x20,0x00FFFF)o.term.setPaletteColor(0x40,0xFF00FF)o.term.setPaletteColor(0x80,0xFFFF00)o.term.setPaletteColor(0x100,0xFF6D00)o.term.setPaletteColor(0x200,0x6DFF55)o.term.setPaletteColor(0x400,0x24FFFF)o.term.setPaletteColor(0x800,0x924900)o.term.setPaletteColor(0x1000,0x6D6D55)o.term.setPaletteColor(0x2000,0xDBDBAA)o.term.setPaletteColor(0x4000,0x6D00FF)o.term.setPaletteColor(0x8000,0xB6FF00)local function t(u)local v=o.fs.open(u,"r")if not v then l("Could not open file: "..u)end;local w=v.readAll()v.close()return w end;local x=load(t(a.."/boot/kernel.lua"),"@Kernel")local y=load(t(a.."/boot/cct/initdisks","@Init_disks"))(o)local z=load(t(a.."/boot/initfs"),"@InitFs")()if not x then l("Could not load kernel.")end;if not y then l("Could not load initdisks.")end;if not z then l("Could not load initfs.")end;local A={}local B={}B[o.keys.enter]="\n"B[o.keys.backspace]="\b"B[o.keys.tab]="\t"local function C(D,...)table.insert(A,{D,...})end;local E={time=function()return o.os.epoch("utc")end,clock=function()return o.os.clock()/1000 end,shutdown=o.os.shutdown,reboot=o.os.reboot,getMachineEvent=function()if#A>0 then return table.unpack(table.remove(A,1))else return nil end end,getEEPROM=function()return t("/startup.lua")end,setEEPROM=function(F,c)local g=o.fs.open("/startup.lua","w")g.write(c)g.close()end}local G={[0x1]=0,[0x2]=1,[0x4]=2,[0x8]=3,[0x10]=4,[0x20]=5,[0x40]=6,[0x80]=7,[0x100]=8,[0x200]=9,[0x400]=10,[0x800]=11,[0x1000]=12,[0x2000]=13,[0x4000]=14,[0x8000]=15}local H={[0]=0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000}o.term.setBackgroundColor(0x1)o.term.setTextColor(0x1000)o.term.clear()o.term.setCursorPos(1,1)local I=coroutine.create(function()local n,m=xpcall(x,debug.traceback,o,y,"cct","/sbin/init",{print=function(F,c)b(c.."\n")end,printInline=function(F,c)b(c)end,clear=function()o.term.clear()o.term.setCursorPos(1,1)end,setCursorPos=function(F,d,e)o.term.setCursorPos(d,e)end,getCursorPos=function()return o.term.getCursorPos()end,getSize=function()return o.term.getSize()end,setBackgroundColor=function(F,J)o.term.setBackgroundColor(H[J])end,setTextColor=function(F,J)o.term.setTextColor(H[J])end,getBackgroundColor=function()return G[o.term.getBackgroundColor()]end,getTextColor=function()return G[o.term.getTextColor()]end},E,z,"$")if not n then l(m)end end)function coroutine.resumeWithTimeout(K,L,...)local M=E.time()debug.sethook(K,function()if E.time()>M+L then return coroutine.yield("timeout")end end,"",1000)local N={coroutine.resume(K,...)}if N[1]and N[2]=="timeout"then return"timeout"elseif N[1]==false then return"error",N[2]else debug.sethook(K)return"success",table.unpack(N,2)end end;b("Loaded in "..tostring(o.os.clock()).." seconds.\n")while true do local O,m=coroutine.resumeWithTimeout(I,50)o.os.queueEvent("NoSleep")local P=false;while not P do local D={coroutine.yield()}if D[1]=="char"then C("keyTyped",1,D[2])elseif D[1]=="key"then C("keyPressed",1,D[2])if B[D[2]]then C("keyTyped",1,B[D[2]])end elseif D[1]=="key_up"then C("keyReleased",1,D[2])elseif D[1]=="disk"then C("componentAdded","disk")elseif D[1]=="disk_eject"then C("componentRemoved","disk")elseif D[1]=="NoSleep"then P=true end end;if O=="error"or coroutine.status(I)=="dead"then l("Kernel error: "..tostring(m))coroutine.yield("key")end end end,debug.traceback)if not n then l("Fatal error during boot: "..m)end;while true do coroutine.yield()end |