1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-27 12:48:07 +11:00

Compare commits

..

No commits in common. "13f8190cbf1a8b0c2407b06e3d52bfe695da994a" and "66076af6bdbed57e969619708396ee1bcf8146de" have entirely different histories.

27 changed files with 9 additions and 1267 deletions

View File

@ -1,3 +0,0 @@
task("dirs", function()
os.execute("mkdir -p release")
end)

View File

@ -1,222 +0,0 @@
-- VELX builder
--[[----------------------------------------------------------------------------
LZSS - encoder / decoder
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
--]]----------------------------------------------------------------------------
--------------------------------------------------------------------------------
local M = {}
local string, table = string, table
--------------------------------------------------------------------------------
local POS_BITS = 12
local LEN_BITS = 16 - POS_BITS
local POS_SIZE = 1 << POS_BITS
local LEN_SIZE = 1 << LEN_BITS
local LEN_MIN = 3
--------------------------------------------------------------------------------
function M.compress(input)
local offset, output = 1, {}
local window = ''
local function search()
for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do
local str = string.sub(input, offset, offset + i - 1)
local pos = string.find(window, str, 1, true)
if pos then
return pos, str
end
end
end
while offset <= #input do
local flags, buffer = 0, {}
for i = 0, 7 do
if offset <= #input then
local pos, str = search()
if pos and #str >= LEN_MIN then
local tmp = ((pos - 1) << LEN_BITS) | (#str - LEN_MIN)
buffer[#buffer + 1] = string.pack('>I2', tmp)
else
flags = flags | (1 << i)
str = string.sub(input, offset, offset)
buffer[#buffer + 1] = str
end
window = string.sub(window .. str, -POS_SIZE)
offset = offset + #str
else
break
end
end
if #buffer > 0 then
output[#output + 1] = string.char(flags)
output[#output + 1] = table.concat(buffer)
end
end
return table.concat(output)
end
--------------------------------------------------------------------------------
function M.decompress(input)
local offset, output = 1, {}
local window = ''
while offset <= #input do
local flags = string.byte(input, offset)
offset = offset + 1
for i = 1, 8 do
local str = nil
if (flags & 1) ~= 0 then
if offset <= #input then
str = string.sub(input, offset, offset)
offset = offset + 1
end
else
if offset + 1 <= #input then
local tmp = string.unpack('>I2', input, offset)
offset = offset + 2
local pos = (tmp >> LEN_BITS) + 1
local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN
str = string.sub(window, pos, pos + len - 1)
end
end
flags = flags >> 1
if str then
output[#output + 1] = str
window = string.sub(window .. str, -POS_SIZE)
end
end
end
return table.concat(output)
end
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, table.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"}
}
local function velx_multistep(path, arcpath, args, steps)
local shell_args = ""
for k, v in pairs(args) do
if (k == "PWD") then
shell_args = "cd "..v.."; " .. shell_args
else
shell_args = shell_args .. k .. "=\"".. v .."\" "
end
end
steps.precomp()
local h = io.popen(shell_args.."luacomp "..path.." 2>/dev/null", "r")
local prog = h:read("*a")
h:close()
prog = steps.postcomp(prog)
steps.prearc()
local arc = ""
if arcpath then
h = io.popen("cd "..arcpath.."; find $".."(ls) -depth | tsar -o", "r")
arc = h:read("*a")
h:close()
steps.postarc()
end
if (not args.noz) then
steps.prez()
prog = M.compress(prog)
steps.postz()
end
local header = velx_spec({
magic = "\27VelX",
compression = (args.noz and 0) or 1,
lver = 0x53,
fver = 1,
os = 0xDA, --da, comrade
psize = #prog,
lsize=0,
ssize=0,
rsize=#arc,
arctype=(arcpath and "tsar") or ""
})
return header .. prog .. arc
end
local function velx(path, arcpath, args)
return velx_multistep(path, arcpath, args, {
precomp = function()end,
postcomp = function(prog) return prog end,
prearc = function()end,
postarc = function()end,
prez = function()end,
postz = function()end,
})
end
local function velxv2(sections)
end
EXPORT.velx = velx
EXPORT.velx_multistep = velx_multistep

View File

@ -1,92 +0,0 @@
local M = {}
local string, table = string, table
--------------------------------------------------------------------------------
local POS_BITS = 12
local LEN_BITS = 16 - POS_BITS
local POS_SIZE = 1 << POS_BITS
local LEN_SIZE = 1 << LEN_BITS
local LEN_MIN = 3
--------------------------------------------------------------------------------
function M.compress(input)
local offset, output = 1, {}
local window = ''
local function search()
for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do
local str = string.sub(input, offset, offset + i - 1)
local pos = string.find(window, str, 1, true)
if pos then
return pos, str
end
end
end
while offset <= #input do
local flags, buffer = 0, {}
for i = 0, 7 do
if offset <= #input then
local pos, str = search()
if pos and #str >= LEN_MIN then
local tmp = ((pos - 1) << LEN_BITS) | (#str - LEN_MIN)
buffer[#buffer + 1] = string.pack('>I2', tmp)
else
flags = flags | (1 << i)
str = string.sub(input, offset, offset)
buffer[#buffer + 1] = str
end
window = string.sub(window .. str, -POS_SIZE)
offset = offset + #str
else
break
end
end
if #buffer > 0 then
output[#output + 1] = string.char(flags)
output[#output + 1] = table.concat(buffer)
end
end
return table.concat(output)
end
--------------------------------------------------------------------------------
function M.decompress(input)
local offset, output = 1, {}
local window = ''
while offset <= #input do
local flags = string.byte(input, offset)
offset = offset + 1
for i = 1, 8 do
local str = nil
if (flags & 1) ~= 0 then
if offset <= #input then
str = string.sub(input, offset, offset)
offset = offset + 1
end
else
if offset + 1 <= #input then
local tmp = string.unpack('>I2', input, offset)
offset = offset + 2
local pos = (tmp >> LEN_BITS) + 1
local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN
str = string.sub(window, pos, pos + len - 1)
end
end
flags = flags >> 1
if str then
output[#output + 1] = str
window = string.sub(window .. str, -POS_SIZE)
end
end
end
return table.concat(output)
end
EXPORT.lzss = M

View File

@ -1,86 +0,0 @@
local function mkplat(plat)
local h = io.popen("luacomp src/loader.lua".." 2>/dev/null")
local loader = h:read("*a")
h:close()
local h = io.popen("ZY_PLATFORM="..plat.." luacomp src/zy-neo/neoinit.lua 2>/dev/null | lua5.3 utils/makezbios.lua")
local dat = h:read("*a")
h:close()
os.execute("mkdir -p pkg/bios")
local h = io.open("pkg/bios/"..plat..".bios", "wb")
h:write(string.format(loader, dat))
h:close()
if (os.execute("[[ $".."(stat --printf=%s pkg/bios/"..plat..".bios) > 4096 ]]")) then
io.stderr:write("WARNING: "..plat.." bios is over 4KiB!\n")
end
end
--[[function actions.managed_bios()
mkplat("managed")
end
function actions.initramfs_bios()
mkplat("initramfs")
end
function actions.prom_bios()
mkplat("prom")
end
function actions.osdi_bios()
mkplat("osdi")
end
function actions.bootstrap()
--os.execute("luacomp src/zy-neo/zinit.lua | lua5.3 utils/makezbios.lua > pkg/bios/bootstrap.bin")
local h = io.popen("luacomp src/zy-neo/zinit.lua")
local dat = h:read("*a")
h:close()
local h = io.open("pkg/bios/bootstrap.bin", "wb")
h:write(lzss.compress(dat))
h:close()
end
function actions.bios()
actions.managed_bios()
actions.initramfs_bios()
actions.prom_bios()
actions.osdi_bios()
actions.bootstrap()
end]]
local blist = {}
local function addbios(name)
blist[#blist+1] = name..".bios"
task(name..".bios", function()
status("build", name)
mkplat(name)
end)
end
addbios("managed")
addbios("initramfs")
addbios("prom")
addbios("osdi")
task("bootstrap.bin", function()
local h = io.popen("luacomp src/zy-neo/zinit.lua".." 2>/dev/null")
local dat = h:read("*a")
h:close()
local h = io.open("pkg/bios/bootstrap.bin", "wb")
h:write(EXPORT.lzss.compress(dat))
h:close()
end)
task("bios", function()
for i=1, #blist do
dep(blist[i])
end
dep("bootstrap.bin")
end)
--[[actions[#actions+1] = "managed_bios"
actions[#actions+1] = "initramfs_bios"
actions[#actions+1] = "prom_bios"
actions[#actions+1] = "osdi_bios"
actions[#actions+1] = "bootstrap"]]

View File

@ -1,35 +0,0 @@
local function make_module(mod)
os.execute("mkdir -p pkg/mods")
--print("MOD", mod)
local arc = false
if (os.execute("[[ -d mods/"..mod.."/arc ]]")) then
arc = "mods/"..mod.."/arc"
end
local h = io.open("pkg/mods/"..mod..".velx", "w")
h:write(EXPORT.velx("init.lua", arc, {
PWD = os.getenv("PWD").."/mods/"..mod
}))
h:close()
end
local mods = {}
local h = io.popen("ls mods", "r")
for line in h:lines() do
--[[actions["mod_"..line] = function()
make_module(line)
end]]
task("mod_"..line, function()
status("build", line)
make_module(line)
end)
mods[#mods+1] = "mod_"..line
end
task("allmods", function()
for i=1, #mods do
dep(mods[i])
end
end)
--actions[#actions+1] = "allmods"

View File

@ -1,33 +0,0 @@
local function make_library(mod)
os.execute("mkdir -p pkg/lib")
--print("LIB", mod)
local arc = false
if (os.execute("[[ -d lib/"..mod.."/arc ]]")) then
arc = "lib/"..mod.."/arc"
end
local h = io.open("pkg/lib/"..mod..".velx", "w")
h:write(EXPORT.velx("init.lua", arc, {
PWD = os.getenv("PWD").."/lib/"..mod
}))
h:close()
end
local lib = {}
local h = io.popen("ls lib", "r")
for line in h:lines() do
--[[actions["mod_"..line] = function()
make_module(line)
end]]
task("lib_"..line, function()
status("build", line)
make_library(line)
end)
lib[#lib+1] = "lib_"..line
end
task("alllibs", function()
for i=1, #lib do
dep(lib[i])
end
end)

View File

@ -1,3 +0,0 @@
task("makepkg", function()
os.execute("cd pkg; find bios lib mods -depth | lua ../utils/make_tsar.lua > ../release/zorya-neo-update.tsar")
end)

View File

@ -1,22 +0,0 @@
local function makeselfextract(indir, outfile)
local cwd = os.getenv("PWD")
os.execute("cd "..indir.."; find * -depth | lua "..cwd.."/utils/make_tsar.lua | lua "..cwd.."/utils/mkselfextract.lua > "..cwd.."/"..outfile)
end
task("installer", function()
os.execute("cp utils/ser.lua pkg/init.lua")
os.execute("mkdir -p pkg/installer_dat")
os.execute("cp installer_dat/bios_list.lua pkg/installer_dat")
os.execute("cp installer_dat/package_list.lua pkg/installer_dat")
os.execute("mkdir -p pkg/installer_dat/lang")
local h = io.popen("ls installer_dat/lang | grep lua", "r")
for line in h:lines() do
os.execute("luacomp installer_dat/lang/"..line.." -O pkg/installer_dat/lang/"..line.." 2>/dev/null")
end
h:close()
makeselfextract("pkg", "release/zorya-neo-installer.lua")
end)
task("utils", function()
makeselfextract("util", "release/zorya-neo-utils-installer.lua")
end)

View File

@ -1,17 +0,0 @@
task("clean", function()
os.execute("mkdir -p pkg")
os.execute("rm -rf pkg/*")
os.execute("mkdir -p release")
os.execute("rm -rf release/*")
end)
task("all", function()
dep("dirs")
dep("bios")
dep("allmods")
dep("alllibs")
dep("makepkg")
dep("installer")
dep("utils")
end)

View File

@ -1,3 +1 @@
unpack = unpack or table.unpack
os.execute("mkdir -p release") os.execute("mkdir -p release")

View File

@ -213,7 +213,3 @@ local function velx(path, arcpath, args)
postz = function()end, postz = function()end,
}) })
end end
local function velxv2(sections)
end

View File

View File

@ -1,2 +1,2 @@
#!/usr/bin/env sh #!/usr/bin/env sh
luacomp build.lua 2>/dev/null | lua5.3 - $@ luacomp build.lua 2>/dev/null | lua - $@

View File

@ -7,7 +7,6 @@
{name="oefiv2", cat="util", path="mods/util_oefiv2.velx"}, {name="oefiv2", cat="util", path="mods/util_oefiv2.velx"},
{name="oefiv1", cat="util", path="mods/util_oefiv1.velx"}, {name="oefiv1", cat="util", path="mods/util_oefiv1.velx"},
{name="openos", cat="loader", path="mods/loader_openos.velx"}, {name="openos", cat="loader", path="mods/loader_openos.velx"},
{name="monolith", cat="loader", path="mods/loader_monolith.velx"},
{name="fuchas", cat="loader", path="mods/loader_fuchas.velx"}, {name="fuchas", cat="loader", path="mods/loader_fuchas.velx"},
{name="vbios", cat="vdev", path="mods/vdev_vbios.velx"}, {name="vbios", cat="vdev", path="mods/vdev_vbios.velx"},
{name="biosdev", cat="vdev", path="mods/vdev_biosdev.velx"}, {name="biosdev", cat="vdev", path="mods/vdev_biosdev.velx"},

View File

View File

@ -1,297 +0,0 @@
--#!/usr/bin/env luajit
EXPORT = {}
local version = "0.1.0"
local lanes = require("lanes").configure({
demote_full_userdata = true
})
local argparse = require("argparse")
local nproc = 0
do
local h = io.popen("nproc", "r")
local n = h:read("*a"):match("%d+")
h:close()
if n and tonumber(n) then
nproc = tonumber(n)
end
end
_NPROC = nproc
local tags = {
["info"] = "\27[36mINFO\27[0m",
["warning"] = "\27[93mWARNING\27[0m",
["error"] = "\27[91mERROR\27[0m",
["build"] = "\27[35mBUILD\27[0m",
["ok"] = "\27[92mOK\27[0m",
["link"] = "\27[34mLINK\27[0m",
["pack"] = "\27[95mPACK\27[0m",
}
function lastmod(path)
end
local function wait_start(t)
while t.status == "pending" do lanes.sleep() end
end
local function getwh()
local f = io.popen("stty size", "r")
local w, h = f:read("*n"), f:read("*n")
f:close()
return tonumber(w), tonumber(h)
end
local function draw_bar(tag, object, max, current)
if (#object > 15) then
object = object:sub(1, 12).."..."
end
os.execute("stty raw -echo 2> /dev/null") -- i cannot comprehend what retardation lead me to have to do this
io.stdout:write("\27[6n")
io.stdout:flush()
local lc = ""
while lc ~= "\27" do
-- print(string.byte(lc) or "<none>")
lc = io.stdin:read(1)
-- print(string.byte(lc))
end
io.stdin:read(1)
local buf = ""
while lc ~= "R" do
lc = io.stdin:read(1)
buf = buf .. lc
end
os.execute("stty sane 2> /dev/null")
--print(buf)
local y, x = buf:match("(%d+);(%d+)")
x = tonumber(x)
y = tonumber(y)
--print(os.getenv("LINES"), os.getenv("COLUMNS"))
--local l = tonumber(os.getenv("LINES"))
--local c = tonumber(os.getenv("COLUMNS"))
--print(l, c)
local l, c = getwh() -- WHY
if (y == l) then
print("")
y = y - 1
end
local mx = string.format("%x", max)
local cur = string.format("%."..#mx.."x", current)
local bar = (current/max)*(c-(26+#mx*2))
if bar ~= bar then bar = 0 end
io.stdout:write("\27["..l.."H")
local pad = 6-#tag
local opad = 16-#object
--print(math.floor(bar))
local hashes = string.rep("#", math.floor(bar))
local dashes = string.rep("-", c-(26+#mx*2+#hashes))
io.stdout:write(tags[tag], string.rep(" ", pad), object, string.rep(" ", opad), cur, "/", mx, " [", hashes, dashes, "]")
io.stdout:write("\27[", x, ";", y, "H")
end
function status(tag, msg)
print(tags[tag], msg)
end
local threads = {}
local stat = status
local function run(cmd)
if not status then status = stat end
local h = io.popen(cmd.." 2>&1", "r")
local out = h:read("*a")
local rtn = h:close()
return rtn, out
end
local tasks = {}
local reflect = {}
function task(name, stuff)
tasks[#tasks+1] = {name, stuff, false}
end
reflect.task = task
reflect._NPROC = nproc
reflect.status = status
reflect.draw_bar = draw_bar
function dep(name)
if not status then setmetatable(_G, {__index=reflect}) end
for i=1, #tasks do
if (tasks[i][1] == name) then
if not tasks[i][3] then
tasks[i][3] = true
tasks[i][2]()
end
return
end
end
status("error", "Task `"..name.."' not found!")
os.exit(1)
end
reflect.dep = dep
local function sync()
local errors = {}
while #threads > 0 do
for i=1, #threads do
if (threads[j].status ~= "running") then
if not threads[j][1] then
errors[#errors+1] = threads[j][2]
end
table.remove(threads, j)
break
end
end
end
return errors
end
reflect.sync = sync
local CC_STATE = {
compiler = "clang",
flags = {},
args = {},
libs = {},
}
local run_t = lanes.gen("*", run)
local function compile(file)
local compiler_command = compiler .. " -fdiagnostics-color=always "
for i=1, #CC_STATE.flags do
compiler_command = compiler_command .. "-f"..CC_STATE.flags[i].." "
end
for i=1, #CC_STATE.args do
compiler_command = compiler_command .. CC_STATE.args[i].." "
end
compiler_command = compiler_command .. file
return run_t(compiler_command)
end
local function link(target, files)
local nfiles = {}
for i=1, #files do
nfiles[i] = files[i]:gsub("%.c$", ".o")
end
local compiler_command = compiler .. " -fdiagnostics-color=always "
for i=1, #CC_STATE.libs do
compiler_command = compiler_command .. "-l"..CC_STATE.args[i].." "
end
compiler_command = compiler_command "-o "..target.. " " .. table.concat(files, " ")
run(compiler_command)
end
function build(target, files)
status("build", target.." ("..#files.." source files)")
draw_bar("build", target, 0, #files)
for i=1, #files do
if (#threads == nproc) then
while true do
for j=1, #threads do
if (threads[j].status ~= "running") then
if not threads[j][1] then
status("error", "Error in compile, waiting for all threads to finish...")
local errors = sync()
print(threads[j][2])
for k=1, #errors do
print(errors[k])
end
os.exit(1)
else
threads[j] = compile(files[i])
wait_start(threads[j])
break
end
end
end
lanes.sleep()
end
else
threads[#threads+1] = compile(files[i])
end
draw_bar("build", target, #files, i)
end
local errors = sync()
if #errors > 0 then
for i=1, #errors do
print(errors[i])
end
os.exit(1)
end
status("link", target)
draw_bar("link", target, 1, 1)
link(target, files)
end
reflect.build = build
reflect.EXPORT = EXPORT
function find(path)
local entries = {}
local h = io.popen("find "..path, "r")
for l in h:lines() do
entries[#entries+1] = l
end
return entries
end
reflect.find = find
local files = find(".build")
for i=1, #files do
if (files[i]:match("%.lua$")) then
dofile(files[i])
end
end
task("list", function()
for i=1, #tasks do
print(tasks[i][1])
end
end)
local dep_t = lanes.gen("*", dep)
local function run_task(task)
local t = dep_t(task)
wait_start(t)
while true do
if (t.status ~= "running") then
if (t.status ~= "done") then
status("error", "Task '"..task.."' has run into an error!")
print(t[1])
end
break
end
end
lanes.sleep()
end
local parser = argparse("luabuild", "High-speed lua build system.")
parser:option("-j --threads", "Number of threads", nproc)
parser:argument("tasks", "Tasks to run"):args("*")
local args = parser:parse()
status("info", "luabuild version is "..version)
status("info", "lua verison is ".._VERSION)
if not tonumber(args.threads) then
status("error", "Number of threads must be a number!")
os.exit(1)
end
nproc = tonumber(args.threads)
status("info", "core count: "..nproc)
for i=1, #args.tasks do
status("info", "Current task: "..args.tasks[i])
local st = os.clock()
run_task(args.tasks[i])
local dur = os.clock()-st
status("ok", "Task `"..args.tasks[i].."' completed in "..string.format("%.2fs", dur))
end
status("ok", "Build completed in "..string.format("%.2fs", os.clock()))

View File

@ -1,17 +0,0 @@
local cfg = {}
local function b2a(data)
return string.format(string.format("%s-%s%s",string.rep("%.2x", 4),string.rep("%.2x%.2x-",3),string.rep("%.2x",6)),string.byte(data, 1,#data))
end
local function a2b(addr)
addr=addr:gsub("%-", "")
local baddr = ""
for i=1, #addr, 2 do
baddr = baddr .. string.char(tonumber(addr:sub(i, i+1), 16))
end
return baddr
end
do
-- Get EEPROM config data.
local eep = component.proxy(component.list("eeprom")())
local dat = eep.getData():sub(37)
end

View File

@ -1,54 +1,9 @@
local computer = computer or require("computer")
local component = component or require("component")
local menu = {} local menu = {}
local gpu = component.proxy(component.list("gpu")()) local gpu = component.proxy(component.list("gpu")())
--gpu.bind((component.list("screen")())) gpu.bind(component.list("screen")())
gpu.set(1, 1, _BIOS.." ".._ZVSTR.." BIOS/Bootloader") gpu.set(1, 1, "Zorya NEO v2.0 BIOS/Bootloader")
gpu.set(1, 2, "(c) 2020 Adorable-Catgirl") gpu.set(1, 2, "(c) 2020 Adorable-Catgirl")
gpu.set(1, 3, "Git Revsion: ".._ZGIT) gpu.set(1, 4, "Memory: "..math.floor(computer.totalMemory()/1024).."K")
gpu.set(1, 5, "Memory: "..math.floor(computer.totalMemory()/1024).."K")
--gpu.set(1, 5) --gpu.set(1, 5)
local logo = {
" ⣾⣷ ",
" ⢠⡟⢻⡄ ",
" ⢀⡾⢡⡌⢷⡀ ",
"⣠⣤⣤⠶⠞⣋⣴⣿⣿⣦⣙⠳⠶⣤⣤⣄",
"⠙⠛⠛⠶⢦⣍⠻⣿⣿⠟⣩⡴⠶⠛⠛⠋",
" ⠈⢷⡘⢃⡾⠁ ",
" ⠘⣧⣼⠃ ",
" ⢿⡿ "
}
local w, h = gpu.getViewport()
gpu.setForeground(0x770077)
for i=1, #logo do
gpu.set(w-18, 1+i, logo[i])
end
gpu.setForeground(0xFFFFFF)
gpu.set(1, h, "F1 for setup; F2 for boot options.")
local y = 0
local my = h-9
function status(msg)
msg = msg:sub(1, w-18)
y = y + 1
if y > my then
gpu.copy(2, 9, w, h-10, 0, -1)
y = my
end
gpu.set(1, y+8, msg)
end
for c, t in component.list("") do
status("Found "..t..": "..c)
end
local et = computer.uptime()+5
while et>=computer.uptime() do
computer.pullSignal(et-computer.uptime())
end

View File

@ -9,7 +9,6 @@ local function load_velx(read, seek, close, name)
end end
if (osid & 0x80 > 0) then if (osid & 0x80 > 0) then
return nil, "not an executable" return nil, "not an executable"
end
if (compression > 1) then if (compression > 1) then
return nil, "bad compression" return nil, "bad compression"
end end

View File

@ -1,175 +0,0 @@
do
local velx2 = {}
local vx_header = "c5BHlllHB"
local vx_section = "llllI4HHB"
local dtype = {
["str"] = function(s)
return s
end,
["u8"] = function(s)
return s:byte()
end,
["u16"] = function(s, e)
return string.unpack(e.."H", s)
end,
["u32"] = function(s, e)
return string.unpack(e.."I4", s)
end,
["u64"] = function(s, e)
return string.unpack(e.."L", s)
end,
["i8"] = function(s, e)
return string.unpack(e.."b", s)
end,
["i16"] = function(s, e)
return string.unpack(e.."h", s)
end,
["i32"] = function(s, e)
return string.unpack(e.."i4", s)
end,
["i64"] = function(s, e)
return string.unpack(e.."l", s)
end,
["bool"] = function(s)
return s:byte() > 0
end,
["f32"] = function(s, e)
return string.unpack(e.."f", s)
end,
["f64"] = function(s, e)
return string.unpack(e.."d", s)
end
}
function util.velx2(read, seek, close, name)
-- Read main header.
local h = read(vx_header:packsize())
local magic, ver, etest = "<c5BH"
local endian = "<"
if (magic ~= "\27VelX" or ver ~= 2) then
return nil, "not a VELXv2"
end
if (etest ~= 0xaa55) then
endian = ">"
end
local sections = {}
local magic, ver, etest, checksum, flags, main_offset, sec_count, btype = string.unpack(endian .. vx_header, h)
local csum = xxh.state(0)
for i=1, sec_count do
local section = {tags={}}
local sh = read(vx_section:packsize())
csum:update(sh)
section.csum, section.size, section.offset, section.flags, section.id, section.tagcount, section.align, section.namelength = string.pack(endian .. vx_section, sh)
local name = read(namelength)
csum:update(name)
for j=1, section.tagcount do
local th = read(2)
csum:update(th)
local tname = read(th:byte(1))
local tval = read(th:byte(2))
csum:update(tname)
csum:update(tval)
section.tags[tname] = tval
local ttype, rtname = tname:match("(.+):(.+)")
if (dtype[ttype]) then
section.tags[rtname] = dtype[ttype](tval, endian)
end
end
section.pos = seek()
local sec_csum = xxh.state(0)
local ramt = section.size
while ramt > 0 do
local spoon = 1024*1024
if (ramt < spoon) then
spoon = ramt
end
local d = read(spoon)
csum:update(d)
sec_csum:update(d)
ramt = ramt - spoon
end
local c_scsum = sec_csum:digest()
if (c_scsum ~= section.csum) then
section.invalid = true
-- some warning here
end
sections[#sections+1] = section
end
local c_csum = csum:digest()
if (c_csum ~= checksum) then
return nil, string.format("checksum mismatch %x ~= %x", c_csum, checksum)
end
return setmetatable({
read = read,
seek = seek,
close = close,
sections = sections,
flags = flags,
offset = offset,
type = btype,
}, {__index=velx2})
end
function velx2:getsection(osid, sec)
for i=1, #self.sections do
local sec = self.sections[i]
if (sec.id == osid and sec.name == name or sec.id == 0) then
self.seek(sec.pos-self.seek())
local dat = self.read(sec.size)
if (sec.tags.compression == "lzss") then
dat = lzss_decompress(dat)
end
return dat
end
end
end
function velx2:gettag(osid, sec, tag)
for i=1, #self.sections do
local sec = self.sections[i]
if (sec.id == osid and sec.name == name or sec.id == 0) then
return sec.tags[tag]
end
end
end
function velx2:getsecinfo(osid, sec)
for i=1, #self.sections do
local sec = self.sections[i]
if (sec.id == osid and sec.name == name or sec.id == 0) then
return sec
end
end
end
function velx2:getstream(osid, sec)
for i=1, #self.sections do
local sec = self.sections[i]
if (sec.id == osid and sec.name == name or sec.id == 0) then
local ptr = 0
return function(a)
self.seek((sec.pos+ptr)-self.seek())
if (ptr+a+1 > sec.size) then
a = sec.size - ptr
end
if (a < 1) then
return ""
end
return self.read(a)
end, function(a)
a = a-1 or 0
ptr = ptr + a
if (ptr < 0) then
ptr = 0
elseif (ptr > sec.size-1) then
ptr = self.size-1
end
return ptr+1
end, function() end
end
end
end
end

View File

@ -1,177 +0,0 @@
-- i can't see "v2" without thinking of ace combat zero
local prime1, prime2, prime3, prime4, prime5 = 0x9E3779B185EBCA87, 0xC2B2AE3D27D4EB4F, 0x165667B19E3779F9, 0x85EBCA77C2B2AE63, 0x27D4EB2F165667C5
local function rotl64(x, r)
return (((x) << (r)) | ((x) >> (64 - (r))))
end
local function round(acc, input)
acc = acc + (input * prime2)
acc = rotl64(acc, 31)
acc = acc * prime1
return acc
end
local function merge_round(acc, val)
val = round(0, val)
acc = acc ~ val
acc = acc * prime1 + prime4
return acc
end
local function avalanche(h64)
h64 = h64 ~ (h64 >> 33)
h64 = h64 * prime2
h64 = h64 ~ (h64 >> 29)
h64 = h64 * prime3
h64 = h64 ~ (h64 >> 32)
return h64
end
local function finalize(h64, input)
while #input & 31 > 0 do
if (#input < 8) then
if (#input < 4) then
for i=1, #input do
h64 = h64 ~ (input:byte() * prime5)
input = input:sub(2)
h64 = rotl64(h64, 11) * prime1
end
else
h64 = h64 ~ (string.unpack("<I4", input) * prime1)
input = input:sub(5)
h64 = rotl64(h64, 23) * prime2 + prime3
end
else
local k1 = round(0, string.unpack("<l", input))
input = input:sub(9)
h64 = h64 ~ k1
h64 = rotl64(h64, 27) * prime1 + prime4
end
end
return avalanche(h64)
end
local function endian_align(input, seed)
local l = #input
if (#input >= 32) then
local v1 = seed + prime1 + prime2
local v2 = seed + prime2 -- << It's time. >>
local v3 = seed
local v4 = seed - prime1
repeat
v1 = round(v1, string.unpack("<l", input))
input = input:sub(9)
v2 = round(v2, string.unpack("<l", input))
input = input:sub(9)
v3 = round(v3, string.unpack("<l", input))
input = input:sub(9)
v4 = round(v4, string.unpack("<l", input))
input = input:sub(9)
until #input < 32
h64 = rotl64(v1, 1) + rotl64(v2, 7) + rotl64(v3, 12) + rotl64(v4, 18)
h64 = merge_round(h64, v1)
h64 = merge_round(h64, v2)
h64 = merge_round(h64, v3)
h64 = merge_round(h64, v4)
else
h64 = seed + prime5
end
h64 = h64 + l
return finalize(h64, input)
end
local function xxh64(input, seed)
return endian_align(input, seed or 0)
end
local state = {}
local function create_state(seed)
local s = {
v1 = 0,
v2 = 0, -- << Too bad buddy, this twisted game needs to be reset. We'll start over from 'Zero' with this V2 and entrust the future to the next generation. >>
v3 = 0,
v4 = 0,
buffer = "",
size = 0
}
setmetatable(s, {__index=state})
s:reset(seed)
return s
end
function state:reset(seed)
seed = seed or 0
self.v1 = seed + prime1 + prime2
self.v2 = seed + prime2 -- << What have borders ever given us? >>
self.v3 = seed
self.v4 = seed - prime1
self.buffer = ""
self.size = 0
end
function state:update(input)
self.size = self.size + #input
input = self.buffer .. input
local data_len = #input - (#input & 31)
self.buffer = input:sub(data_len+1)
local data = input:sub(1, data_len)
local v1 = self.v1
local v2 = self.v2 -- << Can you see any borders from up here? >>
local v3 = self.v3
local v4 = self.v4
repeat
v1 = round(v1, string.unpack("<l", data))
data = data:sub(9)
v2 = round(v2, string.unpack("<l", data))
data = data:sub(9)
v3 = round(v3, string.unpack("<l", data))
data = data:sub(9)
v4 = round(v4, string.unpack("<l", data))
data = data:sub(9)
until #data < 32
self.v1 = v1
self.v2 = v2
self.v3 = v3
self.v4 = v4
end
function state:digest(input)
if input then
self:update(input)
end
local h64 = 0
if (self.size >= 32) then
local v1 = self.v1
local v2 = self.v2
local v3 = self.v3
local v4 = self.v4
h64 = rotl64(v1, 1) + rotl64(v2, 7) + rotl64(v3, 12) + rotl64(v4, 18)
h64 = merge_round(h64, v1)
h64 = merge_round(h64, v2)
h64 = merge_round(h64, v3)
h64 = merge_round(h64, v4)
else
h64 = self.v3 + prime5
end
h64 = h64 + self.size
return finalize(h64, self.buffer) -- << That's what V2 is for. >>
end
return {
sum = xxh64,
state = create_state
}

View File

@ -42,10 +42,6 @@ local function readfile(f,h)
return b return b
end end
local xxh = (function()
--#include "src/zy-neo/builtins/util_xxh64.lua"
end)()
--#include "src/zy-neo/builtins/util_tsar.lua" --#include "src/zy-neo/builtins/util_tsar.lua"
@[[if not svar.get("ZY_PLATFORM") then]] @[[if not svar.get("ZY_PLATFORM") then]]
--#define "ZY_PLATFORM" "managed" --#define "ZY_PLATFORM" "managed"

View File

@ -53,29 +53,11 @@ end
local velx_header = "<c5BBBBc4I3I3I3I4" local velx_header = "<c5BBBBc4I3I3I3I4"
function utils.load_velx(read, seek, close, name) function utils.load_velx(read, seek, close, name)
local spos = seek()
-- Load a VELX format library. -- Load a VELX format library.
local magic, fver, compression, lver, osid, arctype, psize, lsize, ssize, rsize = sunpack(velx_header, read(string.packsize(velx_header))) local magic, fver, compression, lver, osid, arctype, psize, lsize, ssize, rsize = sunpack(velx_header, read(string.packsize(velx_header)))
if magic ~= "\27VelX" then if magic ~= "\27VelX" then
return nil, "bad magic ("..magic..")" return nil, "bad magic ("..magic..")"
end end
if (fver == 2) then
seek(spos-seek())
local vx2 = utils.velx2(read, seek, close, name)
if (vx2.type > 0) then
return nil, "not an executable"
end
local code = vx2:getsection(0x5A, "lua")
local t = vx2:gettag(0x5A, "archive", "type")
local env = {}
if (t and t ~= "tsar") then
return nil, "bad arctype"
elseif (t) then
env._ARCHIVE = tsar.read(vx2:getstream(0x5A, "archive"))
end
setmetatable(env, {__index=_G, __newindex=function(_, i, v) _G[i] = v end})
return load(code, "="..(name or "(loaded velx)"), "t", env)
end
if osid & 0x7F ~= 0x5A then if osid & 0x7F ~= 0x5A then
return nil, string.format("wrong os (%x ~= 0x5A)", osid & 0x7F) return nil, string.format("wrong os (%x ~= 0x5A)", osid & 0x7F)
end end

View File

@ -18,8 +18,6 @@ end
local builtins = {} local builtins = {}
--#include "src/zy-neo/utils.lua" --#include "src/zy-neo/utils.lua"
local log = utils.debug_log local log = utils.debug_log
builtins.utils_tsar = function() return tsar end
builtins.util_xxh64 = function() return xxh end
sys.add_lib("zorya", (function() sys.add_lib("zorya", (function()

View File

@ -73,4 +73,4 @@ do
io.stdout:write(ent.name) io.stdout:write(ent.name)
size = size + 32 size = size + 32
end end
--io.stderr:write((size//512).." blocks.\n") io.stderr:write((size//512).." blocks.\n")

View File

@ -77,7 +77,7 @@ function lzss_compress(input)
end end
local tmp = os.tmpname() local tmp = os.tmpname()
local h = io.popen("luacomp ../utils/selfextract.lua -O"..tmp.." 2>/dev/null", "w") local h = io.popen("luacomp ../utils/selfextract.lua -O"..tmp, "w")
--h:write(mkstr(lzss_compress(f))) --h:write(mkstr(lzss_compress(f)))
h:write(mkstr(f)) h:write(mkstr(f))
h:close() h:close()

View File

@ -231,9 +231,7 @@ local bios_files = load("return "..getfile("installer_dat/bios_list.lua"))()
setBar(33) setBar(33)
local pkg_files = load("return "..getfile("installer_dat/package_list.lua"))() local pkg_files = load("return "..getfile("installer_dat/package_list.lua"))()
setBar(67) setBar(67)
local lf = load("return "..(getfile("installer_dat/lang/en_US.lua") or "{}")) local lang = load("return "..(getfile("installer_dat/lang/en_US.lua") or "{}"))()
if not lf then lf = function()return {}end end
local lang = lf()
setBar(100) setBar(100)
setStatus("Extracting files...") setStatus("Extracting files...")
@ -241,7 +239,7 @@ setBar(0)
for i=1, #pkg_files do for i=1, #pkg_files do
setStatus("Extracting "..(lang["mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name"] or "#mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name").."... ("..i.." of "..#pkg_files..")") setStatus("Extracting "..(lang["mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name"] or "#mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name").."... ("..i.." of "..#pkg_files..")")
setBar(100*(i/#pkg_files)) setBar(100*(i/#pkg_files))
writeFile(".zy2/"..pkg_files[i].path, getfile(pkg_files[i].path) or "") writeFile(".zy2/"..pkg_files[i].path, getfile(pkg_files[i].path))
end end
setStatus("Extracting EEPROM...") setStatus("Extracting EEPROM...")