OC-Tsuki/extras/velxboot/flashvelxboot.lua
Sam Roxanne c9c05221d9 wot
2020-06-02 01:23:58 -05:00

72 lines
1.4 KiB
Lua

local component = require("component")
local computer = require("computer")
print("Flashing velxboot...")
component.eeprom.set([[
--#include "velxboot/init.lua"
]])
component.eeprom.setData(computer.getBootAddress()..";boot.velx")
print("Creating boot.velx...")
local f = io.open("/init.lua")
local prog = f:read("*a")
f:close()
local function struct(tbl)
local pat = tbl.endian or "="
local args = {}
for i=1, #tbl do
local a, b = pairs(tbl[i])
local k, v = a(b)
args[i] = k
pat = pat .. v
end
return setmetatable({}, {__call=function(_, arg)
--checkArg(1, arg, "string", "table")
if (type(arg) == "string") then
local sval = {string.unpack(pat, arg)}
local rtn = {}
for i=1, #args do
rtn[args[i]] = sval[i]
end
return rtn, sval[#sval]
elseif (type(arg) == "table") then
local sval = {}
for i=1, #args do
sval[i] = arg[args[i]]
end
return string.pack(pat, unpack(sval))
end
end, __len=function()
return string.packsize(pat)
end})
end
local velx_spec = struct {
endian = "<",
{magic="c5"},
{fver="B"},
{compression="B"},
{lver="B"},
{os="B"},
{arctype="c4"},
{psize="I3"},
{lsize="I3"},
{ssize="I3"},
{rsize="I4"}
}
f = io.open("/boot.velx", "wb")
f:write(velx_spec({
magic="\27VelX",
fver=1,
compression=0,
lver=0x53,
os=127,
arctype="",
psize=#prog
lsize=0,
ssize=0,
rsize=0,
}))
f:write(prog)
f:close()