2 lines
5.2 KiB
Lua
2 lines
5.2 KiB
Lua
local a={...}local b=a[1]local c=components:getFirst("gpu")local d=nil;local e,f=0,0;local g,h=128,25;if c then d=c:newBuffer(g,h)for i,j in components:list()do if i=="screen"then c:assignBuffer(d,j)end end end;local function k(l)e,f=d:pasteText(e,f,"SCROLL_SPILL_CLEAR",l)f=f+1;e=0;if f>=h then f=h-1;d:newline()end end;local function m(n)c:freeAllBuffers()d=c:newBuffer(g,h)for i,j in components:list()do if i=="screen"then c:assignBuffer(d,j)end end;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)k(n)while true do end end;local o,n=xpcall(function()local p={}local q={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 r,j in pairs(_G)do if not q[r]or q[r]==nil then p[r]=j;_G[r]=nil end end;local function s(t)local u=t:read()local v={u or""}local w=1;local x=false;local function y()return table.concat(v)end;local function z(A)v={A}end;local function B()t.write(y())end;local t={}function t:read(C)assert(not x,"file is closed")local A=y()local D=#A;if not C then local E=A:sub(w)w=D+1;return E end;local E=A:sub(w,w+C-1)w=w+#E;return E end;function t:write(F)assert(not x,"file is closed")local A=y()local G=A:sub(1,w-1)local H=A:sub(w+#F)z(G..F..H)w=w+#F;return true end;function t:seek(I,J)assert(not x,"file is closed")local A=y()local D=#A;I=I or"cur"J=J or 0;if I=="set"then w=J+1 elseif I=="cur"then w=w+J elseif I=="end"then w=D+J+1 else error("invalid whence")end;if w<1 then w=1 end;if w>D+1 then w=D+1 end;return w-1 end;function t:close()assert(not x,"file is closed")B()x=true end;function t:flush()assert(not x,"file is closed")B()end;return t end;local function K(L)local t=b:open(L,"r")if not t then m("Could not open file: "..L)end;local y=t:read()return y end;local M=load(K("/boot/kernel.lua"),"@Kernel")local N=load(K("/boot/ac/initdisks"),"@Init_disks")(p)local O=load(K("/boot/initfs"),"@InitFs")()if not M then m("Could not load kernel.")end;if not N then m("Could not load initdisks.")end;if not O then m("Could not load initfs.")end;local P=p.components:getFirst("computer")local Q=p.components:getFirst("uefi")local R={time=function()return p.os.epoch("utc")end,clock=function()return p.os.clock()*1000 end,shutdown=p.os.shutdown,reboot=p.os.reboot,getMachineEvent=function()return P:getMachineEvent()end,getEEPROM=function()return Q.data end,setEEPROM=function(S,l)Q.data=l end}local T={[0x1]=1,[0x2]=2,[0x4]=3,[0x8]=4,[0x10]=5,[0x20]=6,[0x40]=7,[0x80]=8,[0x100]=9,[0x200]=10,[0x400]=11,[0x800]=12,[0x1000]=13,[0x2000]=14,[0x4000]=15,[0x8000]=16}local U={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000}p.term.setBackgroundColor(0x8000)p.term.setTextColor(0x1000)p.term.clear()p.term.setCursorPos(1,1)local V=coroutine.create(function()local o,n=xpcall(M,debug.traceback,p,N,"cct","/sbin/init",{print=function(S,l)k(l.."\n")end,printInline=function(S,l)k(l)end,clear=function()p.term.clear()p.term.setCursorPos(1,1)end,setCursorPos=function(S,W,X)p.term.setCursorPos(W,X)end,getCursorPos=function()return p.term.getCursorPos()end,getSize=function()return p.term.getSize()end,setBackgroundColor=function(S,Y)p.term.setBackgroundColor(U[Y])end,setTextColor=function(S,Y)p.term.setTextColor(U[Y])end,getBackgroundColor=function()return T[p.term.getBackgroundColor()]end,getTextColor=function()return T[p.term.getTextColor()]end},R,O,"$")if not o then m(n)end end)function coroutine.resumeWithTimeout(Z,_,...)local a0=R.time()debug.sethook(Z,function()if R.time()>a0+_ then return coroutine.yield("timeout")end end,"",1000)local a1={coroutine.resume(Z,...)}if a1[1]and a1[2]=="timeout"then return"timeout"elseif a1[1]==false then return"error",a1[2]else debug.sethook(Z)return"success",table.unpack(a1,2)end end;k("Loaded in "..tostring(p.os.clock()).." seconds.\n")while true do local a2,n=coroutine.resumeWithTimeout(V,50)p.os.queueEvent("NoSleep")local a3=false;while not a3 do local a4={coroutine.yield()}if a4[1]=="key"then queueEvent("keyPressed",1,a4[2])if acekeys[a4[2]]then queueEvent("keyTyped",1,acekeys[a4[2]])end elseif a4[1]=="char"then queueEvent("keyTyped",1,a4[2])elseif a4[1]=="key_up"then queueEvent("keyReleased",1,a4[2])elseif a4[1]=="disk"then queueEvent("componentAdded","disk")elseif a4[1]=="disk_eject"then queueEvent("componentRemoved","disk")elseif a4[1]=="modem_message"then queueEvent("modem_message",table.unpack(a4,2))elseif a4[1]=="rednet_message"then queueEvent("rednet_message",table.unpack(a4,2))elseif a4[1]=="http_success"then queueEvent("http_success",table.unpack(a4,2))elseif a4[1]=="http_failure"then queueEvent("http_failure",table.unpack(a4,2))elseif a4[1]=="NoSleep"then a3=true end end;if a2=="error"or coroutine.status(V)=="dead"then m("Kernel error: "..tostring(n))coroutine.yield("key")end end end,debug.traceback)if not o then m("Fatal error during boot: "..n)end;while true do coroutine.yield()end
|