Last active
November 5, 2018 17:48
-
-
Save Sascha-T/c8fa889ff18bca63519e300923a6b708 to your computer and use it in GitHub Desktop.
OpenComputers SBoot eeprom (Crunched version made with https://oc.cil.li/index.php?/topic/511-crunch-break-the-4k-limit/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local gpu = component.proxy(component.list("gpu")()) | |
local y = 1 | |
local x = 1 | |
local screenX, screenY = gpu.getResolution() | |
local component_invoke = component.invoke | |
function boot_invoke(address, method, ...) | |
local result = table.pack(pcall(component_invoke, address, method, ...)) | |
if not result[1] then | |
return nil, result[2] | |
else | |
return table.unpack(result, 2, result.n) | |
end | |
end | |
local eeprom = component.list("eeprom")() | |
computer.getBootAddress = function() | |
return boot_invoke(eeprom, "getData") | |
end | |
computer.setBootAddress = function(address) | |
return boot_invoke(eeprom, "setData", address) | |
end | |
local function tryLoadFrom(address) | |
local handle, reason = boot_invoke(address, "open", "/init.lua") | |
if not handle then | |
return nil, reason | |
end | |
local buffer = "" | |
repeat | |
local data, reason = boot_invoke(address, "read", handle, math.huge) | |
if not data and reason then | |
return nil, reason | |
end | |
buffer = buffer .. (data or "") | |
until not data | |
boot_invoke(address, "close", handle) | |
return load(buffer, "=init") | |
end | |
bg = gpu.setBackground | |
fill = gpu.fill | |
local gray = 2236962 | |
bg(gray) | |
fill(1, 1, screenX, screenY, " ") | |
local function wait(seconds) | |
local begin = computer.uptime() | |
repeat | |
computer.pullSignal(0.05) | |
until computer.uptime() - begin >= seconds | |
end | |
function print(stringA) | |
write(stringA) | |
y = y + 1 | |
x = 1 | |
end | |
function write(stringE) | |
gpu.set(x, y, stringE) | |
x = x + string.len(stringE) | |
end | |
bg(0) | |
fill(1, 1, 19, 3, " ") | |
bg(16711680) | |
fill(1, 4, 19, 3, " ") | |
bg(16776960) | |
fill(1, 7, 19, 3, " ") | |
y = 5 | |
x = 23 | |
bg(gray) | |
print("SBios v1.0") | |
x = 1 | |
y = 11 | |
local lastY = 0 | |
local index = 0 | |
local sata = {} | |
local sataData = {} | |
for a, _ in component.list("filesystem") do | |
local fs = component.proxy(a) | |
if fs.getLabel() == "tmpfs" or (not fs.exists("/init.lua")) then | |
else | |
index = index + 1 | |
sata[index] = a | |
sataData[index] = y | |
print("[O] SATA ".. index .. " at " .. a) | |
end | |
end | |
lastY = y + 2 | |
function resetSelection() | |
bg(16711680) | |
for i, yL in ipairs(sataData) do | |
gpu.set(2, yL, "X") | |
end | |
bg(gray) | |
end | |
local attemptBoot = "" | |
function selection(indx) | |
resetSelection() | |
attemptBoot = sata[indx] | |
bg(65280) | |
gpu.set(2, sataData[indx], "O") | |
bg(gray) | |
end | |
function startSelection() | |
local max = index | |
local now = 1 | |
selection(now) | |
while true do | |
local name, addr, _, key = computer.pullSignal() | |
if name == "key_down" then | |
if key == 208 then | |
if (now + 1) > max then | |
else | |
now = now + 1 | |
end | |
end | |
if key == 200 then | |
if (now - 1) < 1 then | |
else | |
now = now - 1 | |
end | |
end | |
selection(now) | |
if key == 28 then | |
break | |
end | |
end | |
end | |
end | |
function bootProcess() | |
local oldError = error | |
while true do | |
startSelection() | |
local init, reason = tryLoadFrom(attemptBoot) | |
computer.bootAttempt = attemptBoot | |
attemptBoot = "" | |
if not init then | |
y = lastY | |
print(reason.. " | Frozen") | |
wait(3) | |
local amount = string.len(reason) + 9 | |
local overwrite = "" | |
while amount > 1 do | |
overwrite = overwrite .. " " | |
amount = amount - 1 | |
end | |
gpu.set(1, lastY-1, overwrite) | |
else | |
computer.setBootAddress(computer.bootAttempt) | |
fill(1, 1, screenX, screenY, " ") | |
init() | |
end | |
end | |
end | |
bootProcess() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local f,i,p,q,r,s,y,B,D,E,F,G,H,I,J,K,L=bg,computer,boot_invoke," ",fill,component,print,selection,bootProcess,"setBootAddress",startSelection,"pullSignal",16711680,"bootAttempt","/init.lua",resetSelection,string | |
local | |
j=s.proxy(s.list"gpu"())local | |
h=1 | |
local | |
m=1 | |
local | |
A,z=j.getResolution()local | |
C=s.invoke | |
function | |
p(u,n,...)local | |
b=table.pack(pcall(C,u,n,...))if | |
not | |
b[1]then | |
return | |
nil,b[2]else | |
return | |
table.unpack(b,2,b.n)end | |
end | |
local | |
u=s.list"eeprom"()i.getBootAddress=function()return | |
p(u,"getData")end | |
i[E]=function(n)return | |
p(u,"setData",n)end | |
local | |
function | |
n(b)local | |
o,c=p(b,"open",J)if | |
not | |
o | |
then | |
return | |
nil,c | |
end | |
local | |
d=""repeat | |
local | |
l,k=p(b,"read",o,math.huge)if | |
not | |
l | |
and | |
k | |
then | |
return | |
nil,k | |
end | |
d=d..(l | |
or"")until | |
not | |
l | |
p(b,"close",o)return | |
load(d,"=init")end | |
f=j.setBackground | |
r=j.fill | |
local | |
b=2236962 | |
f(b)r(1,1,A,z,q)local | |
function | |
o(c)local | |
d=i.uptime()repeat | |
i[G](0.05)until | |
i.uptime()-d>=c | |
end | |
function | |
y(c)write(c)h=h+1 | |
m=1 | |
end | |
function | |
write(c)j.set(m,h,c)m=m+L.len(c)end | |
f(0)r(1,1,19,3,q)f(H)r(1,4,19,3,q)f(16776960)r(1,7,19,3,q)h=5 | |
m=23 | |
f(b)y"SBios v1.0"m=1 | |
h=11 | |
local | |
c=0 | |
local | |
d=0 | |
local | |
l={}local | |
k={}for | |
e,g | |
in | |
s.list"filesystem"do | |
local | |
a=s.proxy(e)if | |
a.getLabel()=="tmpfs"or(not | |
a.exists(J))then | |
else | |
d=d+1 | |
l[d]=e | |
k[d]=h | |
y("[O] SATA "..d.." at "..e)end | |
end | |
c=h+2 | |
function | |
K()f(H)for | |
e,g | |
in | |
ipairs(k)do | |
j.set(2,g,"X")end | |
f(b)end | |
local | |
e=""function | |
B(g)K()e=l[g]f(65280)j.set(2,k[g],"O")f(b)end | |
function | |
F()local | |
g=d | |
local | |
a=1 | |
B(a)while | |
true | |
do | |
local | |
t,w,v,x=i[G]()if | |
t=="key_down"then | |
if | |
x==208 | |
then | |
if(a+1)>g | |
then | |
else | |
a=a+1 | |
end | |
end | |
if | |
x==200 | |
then | |
if(a-1)<1 | |
then | |
else | |
a=a-1 | |
end | |
end | |
B(a)if | |
x==28 | |
then | |
break | |
end | |
end | |
end | |
end | |
function | |
D()local | |
g=error | |
while | |
true | |
do | |
F()local | |
a,t=n(e)i[I]=e | |
e=""if | |
not | |
a | |
then | |
h=c | |
y(t.." | Frozen")o(3)local | |
w=L.len(t)+9 | |
local | |
v=""while | |
w>1 | |
do | |
v=v..q | |
w=w-1 | |
end | |
j.set(1,c-1,v)else | |
i[E](i[I])r(1,1,A,z,q)a()end | |
end | |
end | |
D() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment