1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-11 04:58:06 +11:00
Zorya-NEO/util/OpenOS/zyvbios-new.lua
2020-04-10 10:38:52 -05:00

82 lines
2.2 KiB
Lua

local args = {...}
local fs = require("filesystem")
local comp = require("computer")
local luabios = [[
local init
do
local component_invoke = component.invoke
local 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
-- backwards compatibility, may remove later
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
do
local screen = component.list("screen")()
local gpu = component.list("gpu")()
if gpu and screen then
boot_invoke(gpu, "bind", screen)
end
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
local reason
if computer.getBootAddress() then
init, reason = tryLoadFrom(computer.getBootAddress())
end
if not init then
computer.setBootAddress()
for address in component.list("filesystem") do
init, reason = tryLoadFrom(address)
if init then
computer.setBootAddress(address)
break
end
end
end
if not init then
error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
end
computer.beep(1000, 0.2)
end
init()
]]
fs.makeDirectory("/etc/zorya-neo/vbios/"..args[1])
local f = io.open("/etc/zorya-neo/vbios/"..args[1].."/code.lua", "w")
f:write(luabios)
f:close()
local f = io.open("/etc/zorya-neo/vbios/"..args[1].."/label.txt", "w")
f:write("EEPROM (Lua BIOS)")
f:close()
local f = io.open("/etc/zorya-neo/vbios/"..args[1].."/data.bin", "w")
f:write(comp.getBootAddress())
f:close()