Compare commits
43 Commits
Author | SHA1 | Date |
---|---|---|
lunaboards-dev | bc9617228f | |
i develop things | 52c9da6fe3 | |
i develop things | d96ffb10da | |
i develop things | 001234bcd5 | |
i develop things | b1f64f97a1 | |
sam | 831d96de84 | |
sam | 13f8190cbf | |
sam | 99adfbb54a | |
Adorable-Catgirl | 66076af6bd | |
Ocawesome101 | 813bf47319 | |
Sam Roxanne | 7b4fab427d | |
Sam Roxanne | ed447d98fa | |
Ocawesome101 | 722606b419 | |
Sam Roxanne | 1ffba24166 | |
Sam Roxanne | 3c18756141 | |
Sam Roxanne | ea6e5da1c3 | |
Sam Roxanne | 39ff04c2b6 | |
Sam Roxanne | 93158455e4 | |
sam | d09c52f6c2 | |
Jane Roxanne | 06d43e99ad | |
Jane Roxanne | 530796bf5f | |
sam | d4b07eebc1 | |
Jane Roxanne | 3b484d8c5c | |
Jane Roxanne | 4318a82965 | |
Jane Roxanne | 0e7f55624a | |
Adorable-Catgirl | 760bec1eb7 | |
Adorable-Catgirl | 782c99df08 | |
JakobCh | 376ccc11a3 | |
JakobCh | d496ba127e | |
sam | 2ff54eceb9 | |
sam | a900ff3b54 | |
Jane Roxanne | 0e52343432 | |
Jane Roxanne | f5d18e6dbe | |
Jane Roxanne | 44b8229580 | |
Jane Roxanne | f1f5958684 | |
Jane Roxanne | e56b0c28c5 | |
Jane Roxanne | 9a1a073d46 | |
Jane Roxanne | b5d155a9cf | |
Jane Roxanne | 116a35786e | |
Jane Roxanne | 25779bd202 | |
Jane Roxanne | f4b58de582 | |
Jane Roxanne | 73ce20f41b | |
Jane Roxanne | 77e542785e |
|
@ -0,0 +1,3 @@
|
|||
task("dirs", function()
|
||||
os.execute("mkdir -p release")
|
||||
end)
|
|
@ -0,0 +1,222 @@
|
|||
-- 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
|
|
@ -0,0 +1,92 @@
|
|||
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
|
|
@ -0,0 +1,86 @@
|
|||
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"]]
|
|
@ -0,0 +1,35 @@
|
|||
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"
|
|
@ -0,0 +1,33 @@
|
|||
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)
|
|
@ -0,0 +1,3 @@
|
|||
task("makepkg", function()
|
||||
os.execute("cd pkg; find bios lib mods -depth | lua ../utils/make_tsar.lua > ../release/zorya-neo-update.tsar")
|
||||
end)
|
|
@ -0,0 +1,22 @@
|
|||
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)
|
|
@ -0,0 +1,17 @@
|
|||
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)
|
|
@ -0,0 +1,3 @@
|
|||
unpack = unpack or table.unpack
|
||||
|
||||
os.execute("mkdir -p release")
|
|
@ -0,0 +1,219 @@
|
|||
-- 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, 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, "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
|
|
@ -0,0 +1,92 @@
|
|||
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 lzss = M
|
|
@ -0,0 +1,55 @@
|
|||
local function mkplat(plat)
|
||||
local h = io.popen("luacomp src/loader.lua")
|
||||
local loader = h:read("*a")
|
||||
h:close()
|
||||
local h = io.popen("ZY_PLATFORM="..plat.." luacomp src/zy-neo/neoinit.lua | 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
|
||||
|
||||
actions[#actions+1] = "managed_bios"
|
||||
actions[#actions+1] = "initramfs_bios"
|
||||
actions[#actions+1] = "prom_bios"
|
||||
actions[#actions+1] = "osdi_bios"
|
||||
actions[#actions+1] = "bootstrap"
|
|
@ -0,0 +1,31 @@
|
|||
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(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
|
||||
mods[#mods+1] = "mod_"..line
|
||||
end
|
||||
|
||||
function actions.allmods()
|
||||
for i=1, #mods do
|
||||
actions[mods[i]]()
|
||||
end
|
||||
end
|
||||
|
||||
actions[#actions+1] = "allmods"
|
|
@ -0,0 +1,27 @@
|
|||
function make_library(mod)
|
||||
os.execute("mkdir -p pkg/lib")
|
||||
print("LIB", mod)
|
||||
local h = io.open("pkg/lib/"..mod..".velx", "w")
|
||||
h:write(velx("init.lua", false, {
|
||||
PWD = os.getenv("PWD").."/lib/"..mod
|
||||
}))
|
||||
h:close()
|
||||
end
|
||||
|
||||
local libs = {}
|
||||
|
||||
local h = io.popen("ls lib", "r")
|
||||
for line in h:lines() do
|
||||
actions["lib_"..line] = function()
|
||||
make_library(line)
|
||||
end
|
||||
libs[#libs+1] = "lib_"..line
|
||||
end
|
||||
|
||||
function actions.alllibs()
|
||||
for i=1, #libs do
|
||||
actions[libs[i]]()
|
||||
end
|
||||
end
|
||||
|
||||
actions[#actions+1] = "alllibs"
|
|
@ -0,0 +1,5 @@
|
|||
function actions.makepkg()
|
||||
os.execute("cd pkg; find bios lib mods -depth | lua ../utils/make_tsar.lua > ../release/zorya-neo-update.tsar")
|
||||
end
|
||||
|
||||
actions[#actions+1] = "makepkg"
|
|
@ -0,0 +1,4 @@
|
|||
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
|
|
@ -0,0 +1,15 @@
|
|||
function actions.installer()
|
||||
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)
|
||||
end
|
||||
h:close()
|
||||
makeselfextract("pkg", "release/zorya-neo-installer.lua")
|
||||
end
|
||||
|
||||
actions[#actions+1] = "installer"
|
|
@ -0,0 +1,5 @@
|
|||
function actions.utils()
|
||||
makeselfextract("util", "release/zorya-neo-utils-installer.lua")
|
||||
end
|
||||
|
||||
actions[#actions+1] = "utils"
|
|
@ -0,0 +1,11 @@
|
|||
function actions.clean()
|
||||
print("Cleaning up...")
|
||||
--os.execute("rm -rf .docs")
|
||||
--os.execute("rm -rf .ktmp")
|
||||
os.execute("mkdir -p pkg")
|
||||
os.execute("rm -rf pkg/*")
|
||||
|
||||
os.execute("mkdir -p release")
|
||||
os.execute("rm -rf release/*")
|
||||
|
||||
end
|
|
@ -2,4 +2,6 @@ pkg/**
|
|||
debug.lua
|
||||
luapreproc.lua
|
||||
zorya-neo-installer.lua
|
||||
bsrc/**
|
||||
zorya-neo-utils-installer.lua
|
||||
bsrc/**
|
||||
release/**
|
31
Makefile
31
Makefile
|
@ -1,31 +0,0 @@
|
|||
LC = luacomp
|
||||
|
||||
VER_MAJ = 2
|
||||
VER_MIN = 0
|
||||
VER_PAT = 0
|
||||
|
||||
VER_STR = $(VER_MAJ).$(VER_MIN).$(VER_PAT)
|
||||
VER_NAME = New and Improved
|
||||
|
||||
MODS = $(wildcard mods/*)
|
||||
|
||||
release: dirs zyneo modules
|
||||
find bin -depth | cpio -o > release.cpio
|
||||
gzip -9k release.cpio # Maybe one day.
|
||||
|
||||
zyneo: bios
|
||||
VER_STR=$(VER_STR) ZYNEO_PLATFORM=$(PLATFORM) $(LC) src/zy-neo/init.lua -O bin/zyneo.lua
|
||||
|
||||
bios:
|
||||
VER_STR=$(VER_STR) ZYNEO_PLATFORM=$(PLATFORM) $(LC) bsrc/bios/init.lua -O bin/zyneo_bios.lua -mluamin
|
||||
if [[ $(shell stat --printf=%s) > 4096 ]]; then \
|
||||
echo "Warning! BIOS is over 4KiB!" > &2; \
|
||||
fi
|
||||
|
||||
modules: $(MODS)
|
||||
|
||||
mods/%:
|
||||
$(LC) src/lkern/$</init.lua -O bin/mods/$<
|
||||
|
||||
dirs:
|
||||
mkdir -p bin/mods
|
28
README.md
28
README.md
|
@ -4,16 +4,30 @@
|
|||
Zorya NEO is the successor to the Zorya 1.x series of BIOS+Bootloaders for OpenComputers. It's design is now much more modular and extendable.
|
||||
|
||||
## How do I begin?
|
||||
wait till it's stable and i release a zorya-neo-installer cpio
|
||||
Grab the latest release. Install the BIOS before the utilities. The install is self-extracting. Don't download the tsar.
|
||||
|
||||
## How do I configure it?
|
||||
Edit /.zy2/cfg.lua
|
||||
Edit /.zy2/cfg.lua or use the OpenOS config generator.
|
||||
|
||||
## What modules/libraries are included by default?
|
||||
* Microtel (`krequire "net_minitel"`)
|
||||
* Zorya LAN Boot 2.0 (`krequire "util_zlan"`)
|
||||
* Classic Zorya Menu (`loadmod "menu_classic"`)
|
||||
* Threading library (`krequire "thd"`)
|
||||
* Virtual Devices library (`loadmod "util_vdev"`)
|
||||
* Multithreading (`krequire("thd")`)
|
||||
* TSAR archive reader (`krequire("util_tsar")`)
|
||||
* CPIO archive reader (`krequire("util_cpio")`)
|
||||
* URF archive reader (`krequire("util_urf")`)
|
||||
* Romfs archive reader (`krequire("util_romfs")`)
|
||||
* Minitel networking (`krequire("net_minitel")`)
|
||||
* vComponent (`krequire("util_vcomponent")`)
|
||||
* OEFIv1 (`loadmod("util_oefiv1")`)
|
||||
* OEFIv2 (`loadmod("util_oefiv2")`)
|
||||
* OpenOS loader (`loadmod("loader_openos")`)
|
||||
* Fuchas loader (`loadmod("loader_fuchas")`)
|
||||
* vBIOS (`loadmod("vdev_vbios")`)
|
||||
* Search paths configuration (`loadmod("util_searchpaths")`)
|
||||
* BIOS info component (`loadmod("vdev_biosdev")`)
|
||||
* VFS (`loadmod("vfs")`)
|
||||
* Zorya classic menu (`loadmod("menu_classic")`)
|
||||
|
||||
## What's the difference between modules and libraries?
|
||||
There's not really a hard difference. But libraries shouldn't load modules. Modules can load libraries, though.
|
||||
|
||||
<hr>
|
|
@ -0,0 +1,36 @@
|
|||
local actions = {}
|
||||
|
||||
@[[local h = io.popen("ls .buildactions", "r")
|
||||
for line in h:lines() do]]
|
||||
--#include @[{".buildactions/"..line}]
|
||||
@[[end]]
|
||||
|
||||
--[[function actions.debug()
|
||||
actions.kernel(true)
|
||||
actions.crescent()
|
||||
actions.velxboot()
|
||||
actions.clean()
|
||||
end]]
|
||||
|
||||
function actions.all()
|
||||
for i=1, #actions do
|
||||
actions[actions[i]]()
|
||||
end
|
||||
end
|
||||
|
||||
function actions.list()
|
||||
for k, v in pairs(actions) do
|
||||
if type(k) == "string" then
|
||||
io.stdout:write(k, " ")
|
||||
end
|
||||
end
|
||||
print("")
|
||||
end
|
||||
|
||||
if not arg[1] then
|
||||
arg[1] = "all"
|
||||
end
|
||||
|
||||
actions[arg[1]]()
|
||||
|
||||
print("Build complete.")
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env sh
|
||||
luacomp build.lua 2>/dev/null | lua5.3 - $@
|
|
@ -0,0 +1,2 @@
|
|||
# Development tips
|
||||
Loading libraries is done with `krequire`. Be careful of this. Also, you have to load modules through the `zorya` library. Also, uncaught thread errors will crash the system. Be mindful of that.
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
{type="managed", path="bios/managed.bios"},
|
||||
--{type="osdi", path="bios/osdi.bios"},
|
||||
{type="initramfs", path="bios/initramfs.bios"},
|
||||
{type="osdi", path="bios/osdi.bios"},
|
||||
{type="prom", path="bios/prom.bios"}
|
||||
--{type="romfs", path="bios/romfs.bios"},
|
||||
--{type="proxfs", path="bios/proxfs.bios"}
|
||||
}
|
|
@ -1,34 +1,43 @@
|
|||
{
|
||||
["bios_managed_name"] = "Standard Zorya BIOS",
|
||||
["bios_managed_desc"] = "Zorya BIOS boots off of a managed drive.",
|
||||
["bios_osdi_name"] = "OSDI Zorya BIOS",
|
||||
["bios_osdi_desc"] = "Zorya BIOS boots off of an OSDI BOOTCODE partition.",
|
||||
["bios_romfs_name"] = "ROMFS Zorya BIOS",
|
||||
["bios_romfs_desc"] = "Zorya BIOS boots off of a ROMFS formatted EEPROM card.",
|
||||
["bios_proxfs_name"] = "ProximaFS Zorya BIOS",
|
||||
["bios_proxfs_desc"] = "placeholder",
|
||||
["mod_util_zlan_name"] = "Zorya LAN",
|
||||
["mod_util_zlan_desc"] = "Provides the ability to use the Zorya LAN Boot (zlan) protocol.",
|
||||
["mod_loader_openos_name"] = "OpenOS",
|
||||
["mod_loader_openos_desc"] = "Provides a utility to allow for BIOS threads to work while using OpenOS.",
|
||||
["mod_loader_tsuki_name"] = "Tsuki",
|
||||
["mod_loader_tsuki_desc"] = "Allows for easier loading of the Tsuki kernel.",
|
||||
["mod_util_romfs_name"] = "ROMFS",
|
||||
["mod_util_romfs_desc"] = "Allows loading romfs files",
|
||||
["mod_util_cpio_name"] = "cpio",
|
||||
["mod_util_cpio_desc"] = "Allows the reading of CPIO archives",
|
||||
["mod_util_frequest_name"] = "frequest",
|
||||
["mod_util_frequest_desc"] = "Allows fetching of files over frequest.",
|
||||
["mod_net_minitel_name"] = "Minitel",
|
||||
["mod_net_minitel_desc"] = "Allows use of Minitel in Zorya.",
|
||||
["mod_util_vdev_name"] = "vdev",
|
||||
["mod_util_vdev_desc"] = "Allows for the creation of virtual devices.",
|
||||
["mod_rtmod_vdevrt_name"] = "vdev",
|
||||
["mod_rtmod_vdevrt_desc"] = "rtmod version of vdev",
|
||||
["cat_bios"] = "BIOS",
|
||||
["cat_util"] = "Utilities",
|
||||
["cat_loader"] = "Loaders",
|
||||
["cat_rtmod"] = "Runtime modifiers",
|
||||
["cat_net"] = "Networking",
|
||||
["cat_vdev"] = "Virtual Devices"
|
||||
-- BIOSes
|
||||
@[[function add_bios(bios, name, desc)]]
|
||||
["bios_@[{bios}]_name"] = @[{string.format("%q", name)}],
|
||||
["bios_@[{bios}]_desc"] = @[{string.format("%q", desc)}],
|
||||
@[[end]]
|
||||
@[[add_bios("managed", "Low Memory Managed FS Loader", "Loads an image.tsar from a managed filesystem for low memeory systems.")
|
||||
add_bios("initramfs", "Initramfs Managed System Loader", "Loads an image.tsar from a managed filesystem straight into memory.")
|
||||
add_bios("prom", "OSSM PROM Loader", "Loads an image.tsar from an OSSM PROM.")
|
||||
add_bios("osdi", "OSDI Loader", "Loads an image.tsar from an OSDI partition.")]]
|
||||
|
||||
-- Packages.
|
||||
@[[function add_pkg(pkg, name, desc)]]
|
||||
["mod_@[{pkg}]_name"] = @[{string.format("%q", name)}],
|
||||
["mod_@[{pkg}]_desc"] = @[{string.format("%q", desc)}],
|
||||
@[[end]]
|
||||
|
||||
@[[add_pkg("fs_arcfs", "Archive FS", "Use an archive as a filesystem.")
|
||||
add_pkg("fs_foxfs", "FoxFS", "Load from FoxFS volumes.")
|
||||
add_pkg("net_minitel", "Microtel", "Minitel for Zorya NEO!")
|
||||
add_pkg("util_cpio", "CPIO archive loader", "Load CPIOs.")
|
||||
add_pkg("util_osdi", "OSDI library", "Read and write OSDI partition tables.")
|
||||
add_pkg("util_romfs", "RomFS archive loader", "Load RomFS archives.")
|
||||
add_pkg("util_urf", "URF Archive loader", "Load the most awful archive format ever")
|
||||
add_pkg("util_zlan", "zlan 2.0 library", "Load things from zlan.")
|
||||
add_pkg("util_vcomponent", "vComponent", "Virtual components.")
|
||||
add_pkg("fs_fat", "FAT12/16 FS", "FAT12/16 filesystem loader.")
|
||||
add_pkg("core_io", "io library", "PUC Lua compatible io library.")
|
||||
add_pkg("loader_fuchas", "Fuchas kernel loader", "Load Fuchas.")
|
||||
add_pkg("loader_openos", "OpenOS loader", "Load OpenOS and compatible OSes.")
|
||||
add_pkg("loader_tsuki", "Tsuki kernel loader", "Load the Tsuki kernel.")
|
||||
add_pkg("menu_bios", "BIOS Menu", "A menu that looks like a real BIOS.")
|
||||
add_pkg("menu_classic", "Zorya 1.x Menu", "The classic Zorya 1.x menu that looks like discount GRUB.")
|
||||
add_pkg("util_blkdev", "Block device util", "Block devices in Zorya.")
|
||||
add_pkg("util_luaconsole", "Lua Recovery Console", "A Lua recovery console for Zorya.")
|
||||
add_pkg("util_oefiv1", "OEFIv1 library", "OEFIv1 library and loader.")
|
||||
add_pkg("util_oefiv2", "OEFIv2 and 2.1 library", "Library for loading OEFIv2.x executables.")
|
||||
add_pkg("util_searchpaths", "Easy searchpaths", "Easier searchpaths for Zorya.")
|
||||
add_pkg("util_velx", "VELX loader", "VELX executable loaders.")
|
||||
add_pkg("vdev_vbios", "vBIOS library", "Virtual BIOSes in Zorya!")
|
||||
add_pkg("core_vfs", "VFS for Zorya", "Virtual Filesystems")
|
||||
]]
|
||||
}
|
|
@ -1,20 +1,27 @@
|
|||
{
|
||||
{name="zlan", cat="util", path="lib/util_zlan.zy2l"},
|
||||
{name="cpio", cat="util", path="lib/util_cpio.zy2l"},
|
||||
{name="urf", cat="util", path="lib/util_urf.zy2l"},
|
||||
{name="vcomponent", cat="util", path="lib/util_vcomponent.zy2l"},
|
||||
{name="oefiv2", cat="util", path="mods/util_oefiv2.zy2m"},
|
||||
{name="oefiv1", cat="util", path="mods/util_oefiv1.zy2m"},
|
||||
{name="openos", cat="loader", path="mods/loader_openos.zy2m"},
|
||||
{name="fuchas", cat="loader", path="mods/loader_fuchas.zy2m"},
|
||||
{name="zlan", cat="util", path="lib/util_zlan.velx"},
|
||||
{name="cpio", cat="util", path="lib/util_cpio.velx"},
|
||||
{name="velx", cat="util", path="mods/util_velx.velx"},
|
||||
{name="urf", cat="util", path="lib/util_urf.velx"},
|
||||
{name="vcomponent", cat="util", path="lib/util_vcomponent.velx"},
|
||||
{name="oefiv2", cat="util", path="mods/util_oefiv2.velx"},
|
||||
{name="oefiv1", cat="util", path="mods/util_oefiv1.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="vbios", cat="vdev", path="mods/vdev_vbios.velx"},
|
||||
{name="biosdev", cat="vdev", path="mods/vdev_biosdev.velx"},
|
||||
{name="searchpaths", cat="util", path="mods/util_searchpaths.velx"},
|
||||
{name="vfs", cat="core", path="mods/vfs.velx"},
|
||||
--{name="tsuki", cat="loader", path="mods/loader_tsuki.zy2m"},
|
||||
--{name="romfs", cat="util", path="mods/util_romfs.zy2m"},
|
||||
{name="cpio", cat="util", path="lib/util_cpio.zy2l"},
|
||||
{name="cpio", cat="util", path="lib/util_cpio.velx"},
|
||||
--{name="frequest", cat="util", path="mods/util_frequest.zy2m"},
|
||||
--{name="loadfile", cat="loader", path="mods/loader_loadfile.zy2m"},
|
||||
{name="minitel", cat="net", path="lib/net_minitel.zy2l"},
|
||||
{name="minitel", cat="net", path="lib/net_minitel.velx"},
|
||||
--{name="vdev", cat="util", path="mods/util_vdev.zy2m"},
|
||||
{name="menu", cat="menu", path="mods/menu_classic.zy2m"},
|
||||
{name="classic", cat="menu", path="mods/menu_classic.velx"},
|
||||
{name="luaconsole", cat="util", path="mods/util_luaconsole.velx"},
|
||||
--{name="vdevrt", cat="rtmod", path="mods/rtmod_vdevrt.zy2m"},
|
||||
--{name="tsukinet", cat="net", path="mods/net_tsukinet"},
|
||||
--{name="biosemu", cat="loader", path="mods/loader_biosemu.zy2m", warning="warn_mod_biosemu"},
|
||||
|
|
|
@ -50,6 +50,7 @@ function thd.run()
|
|||
for i=1, #threads do
|
||||
if (threads[i][4] <= computer.uptime() or #last_sig > 0) then
|
||||
if (c_status(threads[i][2]) ~= "running") then
|
||||
local dt = computer.uptime()
|
||||
local er, dl = c_resume(threads[i][2], unpack(last_sig))
|
||||
if (not er) then error(threads[i][1]..": "..dl) end
|
||||
if (dl == "k") then
|
||||
|
@ -57,7 +58,8 @@ function thd.run()
|
|||
end
|
||||
dl = computer.uptime() + (dl or math.huge)
|
||||
threads[i][4] = dl
|
||||
sigs[#sigs+1] = {ps(0)}
|
||||
threads[i].delta = computer.uptime() - dt
|
||||
--sigs[#sigs+1] = {ps(0)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,4 +10,4 @@ function krequire(pkg)
|
|||
if (r) then krlib[pkg] = r() return krlib[pkg] end
|
||||
end
|
||||
end
|
||||
local krequire = krequire
|
||||
local krequire = krequire
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
local arcfs = {}
|
||||
|
||||
function arcfs.make(arc)
|
||||
local proxy = {}
|
||||
local function ni()return nil, "not implemented"end
|
||||
local hands = {}
|
||||
proxy.remove = ni
|
||||
proxy.makeDirectory = ni
|
||||
function proxy.exists(path)
|
||||
return arc:exists(path)
|
||||
end
|
||||
function proxy.spaceUsed()
|
||||
return 0
|
||||
end
|
||||
function proxy.open(path, mode)
|
||||
if mode ~= "r" and mode ~= "rb" then
|
||||
return nil, "read-only filesystem"
|
||||
end
|
||||
end
|
||||
function proxy.isReadOnly()
|
||||
return true
|
||||
end
|
||||
proxy.write = ni
|
||||
function proxy.spaceTotal()
|
||||
return 0
|
||||
end
|
||||
function proxy.isDirectory(dir)
|
||||
if arc.isdir then return arc:isdir(dir) end
|
||||
return #arc:list(dir) > 0
|
||||
end
|
||||
function proxy.list(path)
|
||||
return arc:list(path)
|
||||
end
|
||||
function proxy.lastModified(path)
|
||||
return 0
|
||||
end
|
||||
function proxy.getLabel()
|
||||
return "ARCFS_VOLUME"
|
||||
end
|
||||
function proxy.close(hand)
|
||||
|
||||
end
|
||||
function proxy.size(path)
|
||||
return
|
||||
end
|
||||
function proxy.read(hand, count)
|
||||
|
||||
end
|
||||
function proxy.seek(hand, whence, amt)
|
||||
|
||||
end
|
||||
function proxy.setLabel()
|
||||
return "ARCFS_VOLUME"
|
||||
end
|
||||
end
|
|
@ -49,9 +49,10 @@ local function checkCache(packetID)
|
|||
end
|
||||
|
||||
--local realComputerPullSignal = computer.pullSignal
|
||||
thd.add(function()
|
||||
local ps = computer.pullSignal
|
||||
thd.add("minitel_handler", function()
|
||||
while true do
|
||||
local eventTab = {computer.pullSignal(0)}
|
||||
local eventTab = {ps(0)}
|
||||
for k,v in pairs(net.hook) do
|
||||
pcall(v,table.unpack(eventTab))
|
||||
end
|
||||
|
|
|
@ -70,13 +70,49 @@ function arc:fetch(path)
|
|||
return nil, "file not found"
|
||||
end
|
||||
|
||||
function arc:exists(path)
|
||||
for i=1, #self.tbl do
|
||||
if (self.tbl[i].name == path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function arc:close()
|
||||
self.fs.close(self.handle)
|
||||
self.tbl = {}
|
||||
end
|
||||
|
||||
function arc:list_dir(path)
|
||||
--soon:tm:
|
||||
if path:sub(#path) ~= "/" then path = path .. "/" end
|
||||
local ent = {}
|
||||
for i=1, #self.tbl do
|
||||
if (self.tbl[i].name:sub(1, #path) == path and not self.tbl[i].name:find("/", #path+1, false)) then
|
||||
ent[#ent+1] = self.tbl[i].name
|
||||
end
|
||||
end
|
||||
return ent
|
||||
end
|
||||
|
||||
function arc:stream()
|
||||
for i=1, #self.tbl do
|
||||
if (self.tbl[i].name == path and self.tbl[i].mode & 32768 > 0) then
|
||||
local pos = 1
|
||||
local function read(amt)
|
||||
self.seek(self.tbl[i].pos-self.seek(0)+pos-1)
|
||||
pos = pos + amt
|
||||
return self.read(amt)
|
||||
end
|
||||
local function seek(amt)
|
||||
pos = pos + amt
|
||||
return pos
|
||||
end
|
||||
local function close()end
|
||||
return read, seek, close
|
||||
end
|
||||
end
|
||||
return nil, "file not found"
|
||||
end
|
||||
|
||||
return cpio
|
|
@ -0,0 +1,67 @@
|
|||
local romfs = {}
|
||||
local arc = {}
|
||||
|
||||
local function readint(r, n)
|
||||
local str = assert(r(n), "Unexpected EOF!")
|
||||
return string.unpack("<i"..n, str)
|
||||
end
|
||||
|
||||
function romfs.read(read, seek, close)
|
||||
local sig = read(7)
|
||||
assert(sig, "Read error!")
|
||||
if sig ~= "romfs\1\0" then error(string.format("Invalid romfs (%.14x != %.14x)", string.unpack("i7", sig), string.unpack("i7", "romfs\1\0"))) end
|
||||
local tbl = {}
|
||||
local lname
|
||||
while lname ~= "TRAILER!!!" do
|
||||
local nz = read(1):byte()
|
||||
local name = read(nz)
|
||||
local fsize = readint(read, 2)
|
||||
local exec = read(1)
|
||||
tbl[#tbl+1] = {name = name, size = fsize, exec = exec == "x", pos = seek(0)}
|
||||
utils.debug_log(nz, name, fsize, exec)
|
||||
seek(fsize)
|
||||
lname = name
|
||||
end
|
||||
tbl[#tbl] = nil
|
||||
return setmetatable({tbl=tbl, read=read,seek=seek, close=close}, {__index=arc})
|
||||
end
|
||||
|
||||
function arc:fetch(path)
|
||||
for i=1, #self.tbl do
|
||||
if self.tbl[i].name == path then
|
||||
self.seek(self.tbl[i].pos-self.seek(0))
|
||||
return self.read(self.tbl[i].size)
|
||||
end
|
||||
end
|
||||
return nil, "file not found"
|
||||
end
|
||||
|
||||
function arc:exists(path)
|
||||
for i=1, #self.tbl do
|
||||
if (self.tbl[i].name == path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function arc:close()
|
||||
self.close()
|
||||
self.tbl = nil
|
||||
self.read = nil
|
||||
self.seek= nil
|
||||
self.close = nil
|
||||
end
|
||||
|
||||
function arc:list_dir(path)
|
||||
if path:sub(#path) ~= "/" then path = path .. "/" end
|
||||
local ent = {}
|
||||
for i=1, #self.tbl do
|
||||
if (self.tbl[i].name:sub(1, #path) == path and not self.tbl[i].name:find("/", #path+1, false)) then
|
||||
ent[#ent+1] = self.tbl[i].name
|
||||
end
|
||||
end
|
||||
return ent
|
||||
end
|
||||
|
||||
return romfs
|
|
@ -268,6 +268,11 @@ function arc:fetch(path)
|
|||
return self.fs.read(self.h, obj.size)
|
||||
end
|
||||
|
||||
function arc:exists(path)
|
||||
local obj = path_to_obj(path)
|
||||
return obj.type ~= "eoh"
|
||||
end
|
||||
|
||||
function arc:close()
|
||||
self.cache = nil
|
||||
self.fs.close(self.h)
|
||||
|
@ -296,4 +301,24 @@ function arc:list_dir(path)
|
|||
return objects
|
||||
end
|
||||
|
||||
function arc:stream(path)
|
||||
local obj = path_to_obj(self, path)
|
||||
|
||||
local fpos = self.epos+obj.offset
|
||||
|
||||
local pos = 1
|
||||
local function read(amt)
|
||||
self.seek(self.tbl[i].pos-self.seek(0)+pos-1)
|
||||
pos = pos + amt
|
||||
return self.read(amt)
|
||||
end
|
||||
local function seek(amt)
|
||||
pos = pos + amt
|
||||
return pos
|
||||
end
|
||||
local function close()end
|
||||
return read, seek, close
|
||||
return nil, "file not found"
|
||||
end
|
||||
|
||||
return urf
|
|
@ -206,4 +206,10 @@ function vcomponent.install(env)
|
|||
end
|
||||
end
|
||||
|
||||
function vcomponent.global()
|
||||
for k, v in pairs(_component) do
|
||||
component[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
return vcomponent
|
|
@ -0,0 +1,297 @@
|
|||
--#!/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()))
|
|
@ -0,0 +1 @@
|
|||
--#include "msdosfs.lua"
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
# io module (Incomplete)
|
||||
The IO module provides a PUC Lua-compatible I/O library.
|
||||
|
||||
## Additions from PUC Lua
|
||||
* `io.mkdir(path)` - Makes a directory
|
||||
* `io.isreadonly(path)` - Returns if path is read only
|
||||
* `io.exists(path)` - Returns if path exists
|
|
@ -0,0 +1,45 @@
|
|||
local vfs = krequire("zorya").loadmod("vfs")
|
||||
local io = {}
|
||||
local hand = {}
|
||||
|
||||
local hands = {}
|
||||
|
||||
function io.open(path, mode)
|
||||
local proxy, path = vfs.resolve(path)
|
||||
if not proxy then return nil, "file not found" end
|
||||
end
|
||||
|
||||
function io.remove(path)
|
||||
local proxy, path = vfs.resolve(path)
|
||||
if not proxy then return false end
|
||||
return proxy.remove(path)
|
||||
end
|
||||
|
||||
function io.mkdir(path)
|
||||
local proxy, path = vfs.resolve(path)
|
||||
if not proxy then return false end
|
||||
return proxy.makeDirectory(path)
|
||||
end
|
||||
|
||||
function io.move(path, newpath)
|
||||
local proxy1, path1 = vfs.resolve(path)
|
||||
local proxy2, path2 = vfs.resolve(path)
|
||||
if not proxy1 or not proxy2 then return false end
|
||||
if proxy1 == proxy2 then
|
||||
proxy1.rename(path1, path2)
|
||||
end
|
||||
end
|
||||
|
||||
function io.isreadonly(path)
|
||||
local proxy = vfs.resolve(path)
|
||||
if not proxy then return false end
|
||||
return proxy.isReadOnly()
|
||||
end
|
||||
|
||||
function io.exists(path)
|
||||
local proxy, path = vfs.resolve(path)
|
||||
if not proxy then return false end
|
||||
return proxy.exists(path)
|
||||
end
|
||||
|
||||
return io
|
|
@ -0,0 +1,35 @@
|
|||
-- cynosure loader --
|
||||
local zy = krequire("zorya")
|
||||
local utils = krequire("utils")
|
||||
local thd = krequire("thd")
|
||||
local vdev = krequire("util_vcomponent")
|
||||
local function proxytable(t)
|
||||
return setmetatable({}, {__index=function(self, i)
|
||||
if (type(t[i]) == "table") then
|
||||
self[i] = proxytable(t[i])
|
||||
return rawget(self, i)
|
||||
else
|
||||
return t[i]
|
||||
end
|
||||
end})
|
||||
end
|
||||
local monolith_count = 0
|
||||
return function(addr)
|
||||
local fs = component.proxy(addr)
|
||||
thd.add("cynosure$"..monolith_count, function()
|
||||
local env = utils.make_env()
|
||||
function env.computer.getBootAddress()
|
||||
return addr
|
||||
end
|
||||
function env.computer.setBootAddress()end
|
||||
local old_dl = utils.debug_log
|
||||
load(utils.readfile(fs.address, fs.open("/boot/cynosure.lua")), "=/boot/cynosure.lua", "t", env)()
|
||||
computer.pushSignal("cynosure_dead")
|
||||
end)
|
||||
while true do
|
||||
if computer.pullSignal() == "cynosure_dead" then
|
||||
utils.debug_log("Got signal.")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,9 +18,11 @@ function fuchas:boot()
|
|||
while true do if computer.pullSignal() == "fuchas_dead" then break end end
|
||||
end
|
||||
|
||||
return function(addr, args)
|
||||
return function(addr)
|
||||
--oefi.getExtensions().ZyNeo_ExecOEFIApp(addr, ".efi/fuchas.efi2", ...)
|
||||
--We don't do that here.
|
||||
local fuch = {}
|
||||
fuch.args = {}
|
||||
fuch.env = oefi.getExtensions().ZyNeo_GetOEFIEnv(addr)
|
||||
fuch.env.computer.supportsOEFI = function()
|
||||
return true
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# Fuchas laoder
|
||||
This module provides a loader for the Fuchas operating system.
|
||||
|
||||
# Example usage
|
||||
```lua
|
||||
local fuch = loadmod("loader_fuchas")(address)
|
||||
fuch:karg("key", "value")
|
||||
fuch:boot()
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
-- monolith loader --
|
||||
local zy = krequire("zorya")
|
||||
local utils = krequire("utils")
|
||||
local thd = krequire("thd")
|
||||
local vdev = krequire("util_vcomponent")
|
||||
local function proxytable(t)
|
||||
return setmetatable({}, {__index=function(self, i)
|
||||
if (type(t[i]) == "table") then
|
||||
self[i] = proxytable(t[i])
|
||||
return rawget(self, i)
|
||||
else
|
||||
return t[i]
|
||||
end
|
||||
end})
|
||||
end
|
||||
local monolith_count = 0
|
||||
return function(addr)
|
||||
local fs = component.proxy(addr)
|
||||
thd.add("monolith$"..monolith_count, function()
|
||||
local env = utils.make_env()
|
||||
function env.computer.getBootAddress()
|
||||
return addr
|
||||
end
|
||||
function env.computer.setBootAddress()end
|
||||
local old_dl = utils.debug_log
|
||||
load(utils.readfile(fs.address, fs.open("/boot/kernel/loader")), "=/boot/kernel/loader", "t", env)()
|
||||
computer.pushSignal("monolith_dead")
|
||||
end)
|
||||
while true do
|
||||
if computer.pullSignal() == "monolith_dead" then
|
||||
utils.debug_log("Got signal.")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
-- lmao
|
|
@ -1,17 +1,48 @@
|
|||
local zy = krequire("zorya")
|
||||
--zy.loadmod("vdev_biosdev")
|
||||
local utils = krequire("utils")
|
||||
local thd = krequire("thd")
|
||||
--local vdev = krequire("zorya").loadmod("util_vdev")
|
||||
local vdev = krequire("util_vcomponent")
|
||||
local function proxytable(t)
|
||||
return setmetatable({}, {__index=function(self, i)
|
||||
if (type(t[i]) == "table") then
|
||||
self[i] = proxytable(t[i])
|
||||
return rawget(self, i)
|
||||
else
|
||||
return t[i]
|
||||
end
|
||||
end})
|
||||
end
|
||||
local openos_count = 0
|
||||
return function(addr)
|
||||
local fs = component.proxy(addr)
|
||||
local kr = krequire
|
||||
krequire = nil
|
||||
--vdev.overwrite(_G)
|
||||
function computer.getBootAddress()
|
||||
--[[function computer.getBootAddress()
|
||||
return addr
|
||||
end
|
||||
function computer.setBootAddress()end
|
||||
local env = utils.deepcopy(_G)
|
||||
env._ENV = env
|
||||
env._G = env
|
||||
env.krequire = nil]]
|
||||
--vdev.install(env)
|
||||
--log(env, env.computer, env.computer.getBootAddress, env.computer.getBootAddress())
|
||||
load(utils.readfile(fs.address, fs.open("init.lua")), "=init.lua", "t")()
|
||||
krequire = kr
|
||||
-- local env = proxytable(_G)
|
||||
thd.add("openos$"..openos_count, function()
|
||||
local env = utils.make_env()
|
||||
function env.computer.getBootAddress()
|
||||
return addr
|
||||
end
|
||||
function env.computer.setBootAddress()end
|
||||
local old_dl = utils.debug_log
|
||||
load(utils.readfile(fs.address, fs.open("init.lua")), "=init.lua", "t", env)()
|
||||
computer.pushSignal("openos_dead")
|
||||
end)
|
||||
while true do
|
||||
if computer.pullSignal() == "openos_dead" then
|
||||
utils.debug_log("Got signal.")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
local zy = require("zorya")
|
||||
local formats = {
|
||||
["msdos\0\0\0"] = "fs_fat",
|
||||
["FoX FSys"] = "fs_foxfs",
|
||||
["linux\0\0\0"] = "fs_ext2"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
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
|
|
@ -1,9 +1,54 @@
|
|||
local computer = computer or require("computer")
|
||||
local component = component or require("component")
|
||||
|
||||
local menu = {}
|
||||
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
gpu.bind(component.list("screen")())
|
||||
--gpu.bind((component.list("screen")()))
|
||||
|
||||
gpu.set(1, 1, "Zorya NEO v2.0 BIOS/Bootloader")
|
||||
gpu.set(1, 1, _BIOS.." ".._ZVSTR.." BIOS/Bootloader")
|
||||
gpu.set(1, 2, "(c) 2020 Adorable-Catgirl")
|
||||
gpu.set(1, 4, "Memory: "..math.floor(computer.totalMemory()/1024).."K")
|
||||
--gpu.set(1, 5)
|
||||
gpu.set(1, 3, "Git Revsion: ".._ZGIT)
|
||||
gpu.set(1, 5, "Memory: "..math.floor(computer.totalMemory()/1024).."K")
|
||||
--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
|
|
@ -29,31 +29,14 @@ function menu.add(text, func)
|
|||
end
|
||||
|
||||
function menu.draw()
|
||||
|
||||
local w, h = gpu.getViewport()
|
||||
local cls = function()gpu.fill(1,1,w,h," ")end
|
||||
gpu.setBackground(bg)
|
||||
gpu.setForeground(fg)
|
||||
cls()
|
||||
--Draw some things
|
||||
local namestr = _BIOS .. " " .. string.format("%.1f.%d %s", _ZVER, _ZPAT, _ZGIT)
|
||||
gpu.set((w/2)-(#namestr/2), 1, namestr)
|
||||
gpu.set(1, 2, border_chars[1])
|
||||
gpu.set(2, 2, border_chars[2]:rep(w-2))
|
||||
gpu.set(w, 2, border_chars[3])
|
||||
for i=1, h-6 do
|
||||
gpu.set(1, i+2, border_chars[4])
|
||||
gpu.set(w, i+2, border_chars[4])
|
||||
end
|
||||
gpu.set(1, h-3, border_chars[5])
|
||||
gpu.set(2, h-3, border_chars[2]:rep(w-2))
|
||||
gpu.set(w, h-3, border_chars[6])
|
||||
gpu.set(1, h-1, "Use ↑ and ↓ keys to select which entry is highlighted.")
|
||||
gpu.set(1, h, "Use ENTER to boot the selected entry.")
|
||||
local stime = computer.uptime()
|
||||
local autosel = true
|
||||
local ypos = 1
|
||||
local sel = 1
|
||||
local function redraw()
|
||||
local w, h = gpu.getViewport()
|
||||
gpu.setBackground(bg)
|
||||
gpu.setForeground(fg)
|
||||
gpu.fill(1, h-2, w, 1, " ")
|
||||
|
@ -82,7 +65,30 @@ function menu.draw()
|
|||
gpu.set(2, i+2, short)
|
||||
end
|
||||
end
|
||||
redraw()
|
||||
local function full_redraw()
|
||||
local w, h = gpu.getViewport()
|
||||
local cls = function()gpu.fill(1,1,w,h," ")end
|
||||
gpu.setBackground(bg)
|
||||
gpu.setForeground(fg)
|
||||
cls()
|
||||
--Draw some things
|
||||
local namestr = _BIOS .. " " .. string.format("%.1f.%d %s", _ZVER, _ZPAT, _ZGIT)
|
||||
gpu.set((w/2)-(#namestr/2), 1, namestr)
|
||||
gpu.set(1, 2, border_chars[1])
|
||||
gpu.set(2, 2, border_chars[2]:rep(w-2))
|
||||
gpu.set(w, 2, border_chars[3])
|
||||
for i=1, h-6 do
|
||||
gpu.set(1, i+2, border_chars[4])
|
||||
gpu.set(w, i+2, border_chars[4])
|
||||
end
|
||||
gpu.set(1, h-3, border_chars[5])
|
||||
gpu.set(2, h-3, border_chars[2]:rep(w-2))
|
||||
gpu.set(w, h-3, border_chars[6])
|
||||
gpu.set(1, h-1, "Use ↑ and ↓ keys to select which entry is highlighted.")
|
||||
gpu.set(1, h, "Use ENTER to boot the selected entry.")
|
||||
redraw()
|
||||
end
|
||||
full_redraw()
|
||||
sel = 1
|
||||
while true do
|
||||
local sig, _, key, code = computer.pullSignal(0.01)
|
||||
|
@ -108,10 +114,12 @@ function menu.draw()
|
|||
gpu.setBackground(0)
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
entries[sel][2]()
|
||||
full_redraw()
|
||||
end
|
||||
end
|
||||
if (((computer.uptime()-stime) >= timeout) and autosel) then
|
||||
entries[sel][2]()
|
||||
full_redraw()
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
local net = {}
|
||||
|
||||
net.port = 4096
|
||||
net.modems = {}
|
||||
|
||||
local sockets = {}
|
||||
local sock = {}
|
||||
|
||||
--#include "minitel-3.lua"
|
||||
--#include "minitel-4.lua"
|
||||
--#include "minitel-5.lua"
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
local c_sock = {}
|
||||
local h_sock = {}
|
||||
|
||||
function c_sock:read(a)
|
||||
local dat = self.data:sub(1, a-1)
|
||||
self.data = self.data:sub(a)
|
||||
return dat
|
||||
end
|
||||
|
||||
function c_sock:recieve(a)
|
||||
|
||||
end
|
||||
|
||||
function c_sock:write(d)
|
||||
|
||||
end
|
||||
|
||||
function c_sock:send(d)
|
||||
|
||||
end
|
||||
|
||||
function c_sock:close()
|
||||
|
||||
end
|
||||
|
||||
function c_sock:timeout(t)
|
||||
if t then self.to = t endsi
|
||||
return self.to
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
do
|
||||
local cproxy = component.proxy
|
||||
local hdd = {}
|
||||
function hdd.open(addr)
|
||||
return {pos=1, dev=cproxy(addr)}
|
||||
end
|
||||
|
||||
function hdd.size(blk)
|
||||
return blk.dev.getCapacity()
|
||||
end
|
||||
|
||||
function hdd.seek(blk, amt)
|
||||
blk.pos = blk.pos + amt
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < hdd.size(blk)) then
|
||||
blk.pos = hdd.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
function hdd.setpos(blk, pos)
|
||||
blk.pos = pos
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < hdd.size(blk)) then
|
||||
blk.pos = hdd.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
local function hd_read(dev, pos, amt)
|
||||
local start_sec = ((pos-1) // 512)+1
|
||||
local start_byte = ((pos-1) % 512)+1
|
||||
local end_sec = ((pos+amt-1) // 512)+1
|
||||
local buf = ""
|
||||
for i=0, end_sec-start_sec do
|
||||
buf = buf .. dev.readSector(start_sec+i)
|
||||
end
|
||||
return buf:sub(start_byte, start_byte+amt-1)
|
||||
end
|
||||
|
||||
function hdd.read(blk, amt)
|
||||
blk.pos = hdd.seek(blk, amt)
|
||||
return hd_read(blk.dev, blk.pos, amt)
|
||||
end
|
||||
|
||||
function hdd.write(blk, data)
|
||||
local pos = blk.pos
|
||||
local amt = #data
|
||||
local start_sec = ((pos-1) // 512)+1
|
||||
local start_byte = ((pos-1) % 512)+1
|
||||
local end_sec = ((pos+amt-1) // 512)+1
|
||||
local end_byte = ((pos+amt-1) % 512)+1
|
||||
local s_sec = blk.dev.readSector(start_sec)
|
||||
local e_sec = blk.dev.readSector(end_sec)
|
||||
local dat = s_sec:sub(1, start_byte-1)..data..e_sec:sub(end_byte)
|
||||
for i=0, end_sec-start_sec do
|
||||
blk.dev.writeSector(start_sec+i, dat:sub((i*512)+1, (i+1)*512))
|
||||
end
|
||||
end
|
||||
|
||||
blkdev.register("hdd", hdd)
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
local blkdev = {}
|
||||
|
||||
do
|
||||
local protos = {}
|
||||
local blk = {}
|
||||
|
||||
function blkdev.proxy(name, ...)
|
||||
return setmetatable({udat=protos[name].open(...),type=name}, {__index=function(t, i)
|
||||
if (blk[i]) then
|
||||
return blk[i]
|
||||
elseif (protos[t.name].hasmethod(t.udat, i)) then
|
||||
return function(b, ...)
|
||||
return protos[b.type](b.udat, i, ...)
|
||||
end
|
||||
end
|
||||
end})
|
||||
end
|
||||
|
||||
function blkdev.register(name, proto)
|
||||
protos[name] = proto
|
||||
end
|
||||
|
||||
function blk:read(amt)
|
||||
return protos[self.type].read(self.udat, amt)
|
||||
end
|
||||
|
||||
function blk:write(data)
|
||||
return protos[self.type].write(self.udat, data)
|
||||
end
|
||||
|
||||
function blk:blktype()
|
||||
return self.type
|
||||
end
|
||||
|
||||
function blk:seek(whence, amt)
|
||||
whence = whence or 0
|
||||
if (type(whence) == "number") then
|
||||
amt = whence
|
||||
whence = "cur"
|
||||
end
|
||||
if (whence == "cur") then
|
||||
return protos[self.type].seek(self.udat, amt)
|
||||
elseif (whence == "set") then
|
||||
return protos[self.type].setpos(self.udat, amt)
|
||||
elseif (whence == "end") then
|
||||
return protos[self.type].setpos(self.udat, protos[self.type].size(self.udat)+amt)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--#include "hdd.lua"
|
||||
--#include "prom.lua"
|
||||
--#include "osdi.lua"
|
||||
---#include "mtpart.lua"
|
||||
---#include "mbr.lua"
|
||||
|
||||
return blkdev
|
|
@ -0,0 +1,79 @@
|
|||
do
|
||||
local osdi = {}
|
||||
|
||||
local sig = string.pack("<I4I4c8I3c13", 1, 0, "OSDIpart", 0, "")
|
||||
|
||||
function osdi.open(blkdev, partnumber)
|
||||
blkdev:seek(1-blkdev:seek(0))
|
||||
local verinfo = blkdev:read(32)
|
||||
if (verinfo ~= sig) then
|
||||
return nil, "bad block"
|
||||
end
|
||||
blkdev:seek((partnumber-1)*32)
|
||||
local start, size, ptype, flags, name = string.unpack("<I4I4c8I3c13", blkdev:read(32))
|
||||
return {start=start, size=size, ptype=ptype, flags=flags, name=name, dev=blkdev, pos=1, part=partnumber}
|
||||
end
|
||||
|
||||
function osdi.size(blk)
|
||||
return blk.size*512
|
||||
end
|
||||
|
||||
function osdi.seek(blk, amt)
|
||||
blk.pos = blk.pos + amt
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < osdi.size(blk)) then
|
||||
blk.pos = osdi.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
function osdi.setpos(blk, pos)
|
||||
blk.pos = pos
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < osdi.size(blk)) then
|
||||
blk.pos = osdi.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
function osdi.read(blk, amt)
|
||||
blk.dev:seek(((blk.start*512)+(blk.pos-1))-blk.dev:seek(0))
|
||||
osdi.seek(blk, amt)
|
||||
return blk.dev:read(amt)
|
||||
end
|
||||
|
||||
function osdi.write(blk, data)
|
||||
blk.dev:seek(((blk.start*512)+(blk.pos-1))-blk.dev:seek(0))
|
||||
osdi.seek(blk, #data)
|
||||
blk.dev:write(data)
|
||||
end
|
||||
|
||||
local custom = {}
|
||||
function custom:type()
|
||||
return self.type
|
||||
end
|
||||
|
||||
function custom:name()
|
||||
return self.name
|
||||
end
|
||||
|
||||
function custom:flags()
|
||||
return self.flags
|
||||
end
|
||||
|
||||
function custom:partnumber()
|
||||
return self.part
|
||||
end
|
||||
|
||||
function osdi.custom(blk, fun, ...)
|
||||
return custom[fun](blk, ...)
|
||||
end
|
||||
|
||||
function osdi.hasmethod(blk, fun)
|
||||
return custom[fun] ~= nil
|
||||
end
|
||||
|
||||
blkdev.register("osdi", osdi)
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
do
|
||||
local cproxy = component.proxy
|
||||
local prom = {}
|
||||
function prom.open(addr)
|
||||
return {pos=1, dev=cproxy(addr)}
|
||||
end
|
||||
|
||||
function prom.size(blk)
|
||||
return blk.dev.numBlocks()*blk.dev.blockSize()
|
||||
end
|
||||
|
||||
function prom.seek(blk, amt)
|
||||
blk.pos = blk.pos + amt
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < prom.size(blk)) then
|
||||
blk.pos = prom.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
function prom.setpos(blk, pos)
|
||||
blk.pos = pos
|
||||
if (blk.pos < 1) then
|
||||
blk.pos = 1
|
||||
elseif (blk.pos < prom.size(blk)) then
|
||||
blk.pos = prom.size(blk)
|
||||
end
|
||||
return blk.pos
|
||||
end
|
||||
|
||||
local function hd_read(dev, pos, amt)
|
||||
local start_sec = ((pos-1) // 512)+1
|
||||
local start_byte = ((pos-1) % 512)+1
|
||||
local end_sec = ((pos+amt-1) // 512)+1
|
||||
local buf = ""
|
||||
for i=0, end_sec-start_sec do
|
||||
buf = buf .. dev.blockRead(start_sec+i)
|
||||
end
|
||||
return buf:sub(start_byte, start_byte+amt-1)
|
||||
end
|
||||
|
||||
function prom.read(blk, amt)
|
||||
blk.pos = prom.seek(blk, amt)
|
||||
return hd_read(blk.dev, blk.pos, amt)
|
||||
end
|
||||
|
||||
function prom.write(blk, data)
|
||||
local pos = blk.pos
|
||||
local amt = #data
|
||||
local start_sec = ((pos-1) // 512)+1
|
||||
local start_byte = ((pos-1) % 512)+1
|
||||
local end_sec = ((pos+amt-1) // 512)+1
|
||||
local end_byte = ((pos+amt-1) % 512)+1
|
||||
local s_sec = blk.dev.blockRead(start_sec)
|
||||
local e_sec = blk.dev.blockRead(end_sec)
|
||||
local dat = s_sec:sub(1, start_byte-1)..data..e_sec:sub(end_byte)
|
||||
for i=0, end_sec-start_sec do
|
||||
blk.dev.blockWrite(start_sec+i, dat:sub((i*512)+1, (i+1)*512))
|
||||
end
|
||||
end
|
||||
|
||||
blkdev.register("prom", prom)
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
local vdev = krequire("util_vcomponent")
|
||||
local utils = krequire("utils")
|
||||
local component = component
|
||||
return function(fs, file)
|
||||
local px = component.proxy(fs)
|
||||
local fh = px.open(file, "w")
|
||||
utils.debug_log("test")
|
||||
vdev.register("vdev-ZY_LOG2FILE", "sandbox", {
|
||||
log = function(...)
|
||||
px.write(fh, table.concat({...}, " ").."\n")
|
||||
end
|
||||
})
|
||||
return true
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
local arg = ...
|
||||
if (arg == "") then
|
||||
arg = "init.lua"
|
||||
end
|
||||
load_exec(arg)()
|
|
@ -0,0 +1,105 @@
|
|||
local inet = component.list("internet")()
|
||||
if not inet then
|
||||
tty.setcolor(0x4)
|
||||
print("internet card not found.")
|
||||
return 1
|
||||
end
|
||||
|
||||
inet = component.proxy(inet)
|
||||
|
||||
print("connecting...")
|
||||
local hand, res = inet.request("https://git.shadowkat.net/sam/OC-PsychOS2/raw/branch/master/psychos.tsar")
|
||||
if not hand then
|
||||
tty.setcolor(0x4)
|
||||
print(res)
|
||||
return 1
|
||||
end
|
||||
local fs = component.proxy(computer.tmpAddress())
|
||||
_DRIVE = computer.tmpAddress()
|
||||
|
||||
local magic = 0x5f7d
|
||||
local magic_rev = 0x7d5f
|
||||
local header_fmt = "I2I2I2I2I2I6I6"
|
||||
local en = string.unpack("=I2", string.char(0x7d, 0x5f)) == magic -- true = LE, false = BE
|
||||
local function get_end(e)
|
||||
return (e and "<") or ">"
|
||||
end
|
||||
local function read_header(dat)
|
||||
local e = get_end(en)
|
||||
local m = string.unpack(e.."I2", dat)
|
||||
if m ~= magic and m ~= magic_rev then return nil, string.format("bad magic (%.4x)", m) end
|
||||
if m ~= magic then
|
||||
e = get_end(not en)
|
||||
end
|
||||
local ent = {}
|
||||
ent.magic, ent.namesize, ent.mode, ent.uid, ent.gid, ent.filesize, ent.mtime = string.unpack(e..header_fmt, dat)
|
||||
return ent
|
||||
end
|
||||
|
||||
local spin = {"|", "/", "-", "\\"}
|
||||
|
||||
local spinv = 0
|
||||
|
||||
local function getspin()
|
||||
local c = spin[spinv + 1]
|
||||
spinv = (spinv + 1) & 3
|
||||
return c
|
||||
end
|
||||
|
||||
tty.write("downloading psychos.tsar... "..getspin())
|
||||
local x, y = tty.getcursor()
|
||||
tty.setcursor(x-1, y)
|
||||
local buf = ""
|
||||
local lc = ""
|
||||
|
||||
while true do
|
||||
tty.setcursor(x-1, y)
|
||||
tty.write(getspin())
|
||||
lc, res = hand.read()
|
||||
if not lc and res then
|
||||
tty.setcolor(0x4)
|
||||
print(res)
|
||||
return 1
|
||||
end
|
||||
buf = buf .. (lc or "")
|
||||
if not lc then
|
||||
break
|
||||
elseif (lc == "") then
|
||||
computer.pullSignal(0)
|
||||
end
|
||||
end
|
||||
hand.close()
|
||||
|
||||
print("")
|
||||
print(#buf)
|
||||
print("unpacking... "..getspin())
|
||||
x, y = tty.getcursor()
|
||||
tty.setcursor(x-1, y)
|
||||
local pos = 1
|
||||
local function read(a)
|
||||
local dat = buf:sub(pos, pos+a-1)
|
||||
pos = pos + a
|
||||
return dat
|
||||
end
|
||||
local function seek(a)
|
||||
pos = pos + a
|
||||
return pos
|
||||
end
|
||||
while true do
|
||||
tty.setcursor(x-1, y)
|
||||
tty.write(getspin())
|
||||
local header = read_header(read(string.packsize(header_fmt)))
|
||||
local fn = read(header.namesize)
|
||||
seek(header.namesize & 1)
|
||||
if (fn == "TRAILER!!!") then break end
|
||||
if (header.mode & 32768 > 0) then
|
||||
local path = fn:match("^(.+)/.+%..+$")
|
||||
if path then fs.makeDirectory(path) end
|
||||
local h = fs.open(fn, "w")
|
||||
fs.write(h, read(header.filesize))
|
||||
fs.close(h)
|
||||
seek(header.filesize & 1)
|
||||
end
|
||||
end
|
||||
tty.setcolor(0x6)
|
||||
print("run $boot to start the recovery enviroment")
|
|
@ -0,0 +1,11 @@
|
|||
print("$boot [file] - Loads a Lua or a BIOS or Zorya VELX file. Defaults to init.lua.")
|
||||
print("$download-recovery-env - Downloads a tsar with PsychOS on it and boots into it.")
|
||||
print("$help - Prints this")
|
||||
print("$kill [thread name] - Kills a thread")
|
||||
print("$ls - Lists files if a root is set, lists filesystems otherwise.")
|
||||
print("$lsfs - Lists filesystems.")
|
||||
print("$lsthd - Lists threads.")
|
||||
print("$reboot - Reboots the computer.")
|
||||
print("$root [uuid part] - Sets the root (_DRIVE variable). Will autocomplete.")
|
||||
print("$shutdown - Shuts down the computer.")
|
||||
print("$start [file] - Starts a Lua file or Zorya VELX in the background.")
|
|
@ -0,0 +1,9 @@
|
|||
local thd = krequire("thd")
|
||||
local threads = thd.get_threads()
|
||||
local n = ...
|
||||
for i=1, #threads do
|
||||
if (threads[i][1] == n) then
|
||||
thd.kill(i)
|
||||
print("killed "..n)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
local arg = ...
|
||||
if not _DRIVE then
|
||||
for d in component.list("filesystem") do
|
||||
print(d)
|
||||
end
|
||||
else
|
||||
local t = component.invoke(_DRIVE, "list", arg)
|
||||
for i=1, #t do
|
||||
print(t[i])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
for d in component.list("filesystem") do
|
||||
print(d)
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
local threads = krequire("thd").get_threads()
|
||||
for i=1, #threads do
|
||||
print(threads[i][1])
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
computer.shutdown(true)
|
|
@ -0,0 +1,6 @@
|
|||
local fs = ...
|
||||
for f in component.list("filesystem") do
|
||||
if (f:sub(1, #fs) == fs) then
|
||||
_DRIVE = f
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
computer.shutdown()
|
|
@ -0,0 +1,7 @@
|
|||
local thd = krequire("thd")
|
||||
local utils = krequire("utils")
|
||||
local arg = ...
|
||||
local name = arg:match("/(.+%..+)^") or arg
|
||||
thd.add(name, function()
|
||||
load_exec(arg)()
|
||||
end)
|
|
@ -0,0 +1,117 @@
|
|||
local utils = krequire("utils")
|
||||
--#include "tty.lua"
|
||||
--#include "velx.lua"
|
||||
--#include "load.lua"
|
||||
|
||||
function _runcmd(cmd)
|
||||
local rcmd = cmd:sub(1, (cmd:find(" ") or (#cmd+1))-1)
|
||||
local script = _ARCHIVE:fetch("bin/"..rcmd..".lua")
|
||||
load(script, "=bin/"..rcmd..".lua", "t", _G)(cmd:sub(#rcmd+1):gsub("^%s+", ""))
|
||||
end
|
||||
|
||||
return function(autorun)
|
||||
local keys = {
|
||||
lcontrol = 0x1D,
|
||||
back = 0x0E, -- backspace
|
||||
delete = 0xD3,
|
||||
down = 0xD0,
|
||||
enter = 0x1C,
|
||||
home = 0xC7,
|
||||
left = 0xCB,
|
||||
lshift = 0x2A,
|
||||
pageDown = 0xD1,
|
||||
rcontrol = 0x9D,
|
||||
right = 0xCD,
|
||||
rmenu = 0xB8, -- right Alt
|
||||
rshift = 0x36,
|
||||
space = 0x39,
|
||||
tab = 0x0F,
|
||||
up = 0xC8,
|
||||
["end"] = 0xCF,
|
||||
tab = 0x0F,
|
||||
numpadenter = 0x9C,
|
||||
}
|
||||
tty.clear()
|
||||
tty.utf()
|
||||
tty.setcursor(1, 1)
|
||||
tty.update()
|
||||
tty.setcolor(0xF)
|
||||
tty.print("Zorya NEO Lua Terminal")
|
||||
tty.print("Zorya NEO ".._ZVSTR.." ".._ZGIT)
|
||||
local buffer = ""
|
||||
function print(...)
|
||||
tty.print(...)
|
||||
end
|
||||
function exit()
|
||||
exit = nil
|
||||
print = nil
|
||||
end
|
||||
if (autorun) then
|
||||
local c = load(autorun)
|
||||
if c then
|
||||
pcall(c)
|
||||
end
|
||||
end
|
||||
tty.print("")
|
||||
tty.setcolor(2)
|
||||
tty.write("boot> ")
|
||||
tty.setcolor(0xF0)
|
||||
tty.write(" ")
|
||||
tty.setcolor(0xF)
|
||||
while exit do
|
||||
local sig = {computer.pullSignal()}
|
||||
if (sig[1] == "key_down") then
|
||||
if (sig[3] > 31 and sig[3] ~= 127) then
|
||||
local x, y = tty.getcursor()
|
||||
tty.setcursor(x-1, y)
|
||||
tty.setcolor(0xF)
|
||||
tty.write(utf8.char(sig[3]))
|
||||
tty.setcolor(0xF0)
|
||||
tty.write(" ")
|
||||
buffer = buffer .. utf8.char(sig[3])
|
||||
elseif (sig[4] == keys.back) then
|
||||
if (#buffer > 0) then
|
||||
local x, y = tty.getcursor()
|
||||
tty.setcursor(x-2, y)
|
||||
tty.setcolor(0xF0)
|
||||
tty.write(" ")
|
||||
tty.setcolor(0xF)
|
||||
tty.write(" ")
|
||||
tty.setcursor(x-1, y)
|
||||
buffer = buffer:sub(1, #buffer-1)
|
||||
end
|
||||
elseif (sig[4] == keys.enter) then
|
||||
if (buffer:sub(1,1) == "=") then
|
||||
buffer = "return "..buffer:sub(2)
|
||||
elseif (buffer:sub(1,1) == "$") then
|
||||
buffer = "return _runcmd(\""..buffer:sub(2).."\")"
|
||||
end
|
||||
local s, e = load(buffer)
|
||||
local x, y = tty.getcursor()
|
||||
tty.setcursor(x-1, y)
|
||||
tty.setcolor(0xF)
|
||||
tty.write(" ")
|
||||
tty.print(" ")
|
||||
buffer = ""
|
||||
if not s then
|
||||
tty.setcolor(0x4)
|
||||
tty.print(e)
|
||||
tty.setcolor(0xf)
|
||||
else
|
||||
tty.setcolor(0xf)
|
||||
xpcall(function()
|
||||
tty.print(s())
|
||||
end, function(e)
|
||||
tty.setcolor(0x4)
|
||||
tty.print(debug.traceback(e):gsub("\t", " "):gsub("\r", "\n"))
|
||||
end)
|
||||
end
|
||||
tty.setcolor(2)
|
||||
tty.write(((_DRIVE and _DRIVE:sub(1, 4)) or "boot").."> ")
|
||||
tty.setcolor(0xF0)
|
||||
tty.write(" ")
|
||||
tty.setcolor(0xF)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
function load_exec(path)
|
||||
if not _DRIVE then
|
||||
tty.setcolor(0x4)
|
||||
print("need to set root")
|
||||
end
|
||||
local env = utils.make_env()
|
||||
function env.computer.getBootAddress()
|
||||
return _DRIVE
|
||||
end
|
||||
function env.computer.setBootAddress()end
|
||||
local ext = path:match("%.(.+)$")
|
||||
if (ext == "lua") then
|
||||
return load(krequire("utils").readfile(_DRIVE, component.invoke(_DRIVE, "open", path)), "="..path, "t", env)
|
||||
elseif (ext == "velx") then
|
||||
local fs = component.proxy(_DRIVE)
|
||||
local h = fs.open(path)
|
||||
local v, e = load_velx(function(a)
|
||||
local c = ""
|
||||
local d
|
||||
while a > 0 do
|
||||
d = fs.read(h, a)
|
||||
a = a - #d
|
||||
c = c .. d
|
||||
end
|
||||
return c
|
||||
end, function(a)
|
||||
return fs.seek(h, "cur", a)
|
||||
end, function()
|
||||
fs.close(h)
|
||||
end, path)
|
||||
if not v then
|
||||
tty.setcolor(0x4)
|
||||
print(e)
|
||||
end
|
||||
return v
|
||||
else
|
||||
tty.setcolor(0x4)
|
||||
print("invalid executable format "..ext)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,183 @@
|
|||
-- Super basic TTY driver. Supports unicode if enabled with tty.utf.
|
||||
tty = {}
|
||||
do
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
if not gpu.getScreen() then
|
||||
local saddr = component.list("screen")()
|
||||
gpu.bind(saddr)
|
||||
end
|
||||
local gfg = -1
|
||||
local gbg = -1
|
||||
|
||||
local ttyc = 12
|
||||
local ttyx, ttyy = 1, 1
|
||||
|
||||
local w, h = gpu.maxResolution()
|
||||
|
||||
local depth = gpu.maxDepth()
|
||||
|
||||
gpu.setResolution(w, h)
|
||||
gpu.setDepth(depth)
|
||||
|
||||
if (depth == 4) then --pregen color
|
||||
for i=0, 15 do
|
||||
local hi = i >> 3
|
||||
local r = (i >> 2) & 1
|
||||
local g = (i >> 1) & 1
|
||||
local b = i & 1
|
||||
local fr = (r * 0x7F) | (hi << 7)
|
||||
local fg = (g * 0x7F) | (hi << 7)
|
||||
local fb = (b * 0x7F) | (hi << 7)
|
||||
gpu.setPaletteColor(i, (fr << 16) | (fg << 8) | fb)
|
||||
end
|
||||
end
|
||||
|
||||
function colors(i)
|
||||
if (i < 0) then i = 0 elseif (i > 15) then i = 15 end
|
||||
if (depth == 1) then
|
||||
return ((i > 0) and 0xFFFFFF) or 0
|
||||
elseif (depth == 4) then
|
||||
return i, true
|
||||
else -- e x p a n d
|
||||
local hi = i >> 3
|
||||
local r = (i >> 2) & 1
|
||||
local g = (i >> 1) & 1
|
||||
local b = i & 1
|
||||
local fr = (r * 0x7F) | (hi << 7)
|
||||
local fg = (g * 0x7F) | (hi << 7)
|
||||
local fb = (b * 0x7F) | (hi << 7)
|
||||
return (fr << 16) | (fg << 8) | fb
|
||||
end
|
||||
end
|
||||
|
||||
local buffer = string.char(0xF, 32):rep(w*h)
|
||||
|
||||
local cwidth = 1
|
||||
|
||||
local function get_segments(spos, max)
|
||||
spos = spos or 1
|
||||
if spos < 1 then spos = 1 end
|
||||
max = max or #buffer//(1+cwidth)
|
||||
local cur_color = -1
|
||||
local segments = {}
|
||||
local _buffer = ""
|
||||
local cpos = spos-1 --((spos-1)*(1+cwidth))
|
||||
local start_pos = cpos
|
||||
for i=((spos-1)*(1+cwidth))+1, max*(1+cwidth), 1+cwidth do
|
||||
local c, code = string.unpack("BI"..cwidth, buffer:sub(i, i+cwidth)) -- buffer:sub(i,i), buffer:sub(i+1, i+cwidth)
|
||||
if (c ~= cur_color or cpos%w == 0) then
|
||||
if (buffer ~= "") then
|
||||
segments[#segments+1] = {(start_pos//w)+1, (start_pos%w)+1, cur_color, _buffer}
|
||||
end
|
||||
cur_color = c
|
||||
start_pos = cpos
|
||||
_buffer = ""
|
||||
end
|
||||
cpos = cpos + 1
|
||||
_buffer = _buffer .. utf8.char(code)
|
||||
end
|
||||
if (buffer ~= "") then
|
||||
segments[#segments+1] = {((start_pos)//w)+1, ((start_pos)%w)+1, cur_color, _buffer}
|
||||
end
|
||||
return segments
|
||||
end
|
||||
|
||||
local function draw_segments(segs)
|
||||
for i=1, #segs do
|
||||
local fg, bg = segs[i][3] & 0xF, segs[i][3] >> 4
|
||||
if (fg ~= gfg) then
|
||||
gpu.setForeground(colors(fg))
|
||||
end
|
||||
if (bg ~= gbg) then
|
||||
gpu.setBackground(colors(bg))
|
||||
end
|
||||
gpu.set(segs[i][2], segs[i][1], segs[i][4])
|
||||
end
|
||||
end
|
||||
|
||||
function tty.setcolor(c)
|
||||
ttyc = c
|
||||
end
|
||||
|
||||
function tty.utf() -- Cannot be undone cleanly!
|
||||
if cwidth == 3 then return end
|
||||
local newbuf = ""
|
||||
for i=1, #buffer, 2 do
|
||||
local a, b = string.unpack("BB", buffer:sub(i, i+1))
|
||||
newbuf = newbuf .. string.pack("BI3", a, b)
|
||||
end
|
||||
buffer = newbuf
|
||||
cwidth = 3
|
||||
end
|
||||
|
||||
function tty.moveup()
|
||||
gpu.copy(1, 2, w, h-1, 0, -1)
|
||||
buffer = buffer:sub((w*(1+cwidth))+1)..(string.rep(string.pack("BI"..cwidth, 0xF, 32), w))
|
||||
gpu.fill(1, h, w, 1, " ")
|
||||
end
|
||||
|
||||
function tty.clear()
|
||||
x = 1
|
||||
y = 1
|
||||
buffer = string.rep("\x0F"..string.pack("I"..cwidth, 32), w*h)
|
||||
end
|
||||
|
||||
function tty.setcursor(x, y)
|
||||
ttyx = x or 1
|
||||
ttyy = y or 1
|
||||
end
|
||||
|
||||
function tty.getcursor()
|
||||
return ttyx, ttyy
|
||||
end
|
||||
|
||||
function tty.write(s)
|
||||
-- Convert to color/codepoint
|
||||
local charmask = string.unpack("I"..cwidth, string.rep("\xFF", cwidth))
|
||||
local _buffer = ""
|
||||
for i=1, utf8.len(s) do
|
||||
_buffer = _buffer .. string.pack("BI"..cwidth, ttyc, utf8.codepoint(s, i) & charmask)
|
||||
end
|
||||
local bpos = (((ttyx-1)+((ttyy-1)*w))*(1+cwidth))+1
|
||||
local b1, b2 = buffer:sub(1, bpos-1), buffer:sub(bpos+#_buffer)
|
||||
buffer = b1 .. _buffer .. b2
|
||||
local mod = 0
|
||||
if (#buffer > w*h*(1+cwidth)) then
|
||||
-- Scroll smoothly
|
||||
buffer = buffer .. string.rep("\x0F"..string.pack("I"..cwidth, 32), w-((#buffer/(1+cwidth)) % w))
|
||||
buffer = buffer:sub(#buffer-(w*h*(1+cwidth))+1)
|
||||
tty.update()
|
||||
mod = -w
|
||||
else
|
||||
-- Update what changed here.
|
||||
draw_segments(get_segments((ttyx-1)+((ttyy-1)*w)+1, ((ttyx-1)+((ttyy-1)*w))+utf8.len(s)))
|
||||
end
|
||||
local pz = (((ttyx-1)+((ttyy-1)*w)) + utf8.len(s)) + mod
|
||||
ttyx = (pz % w)+1
|
||||
ttyy = (pz // w)+1
|
||||
end
|
||||
|
||||
function tty.print(...)
|
||||
local args = {...}
|
||||
for i=1, #args do
|
||||
args[i] = tostring(args[i])
|
||||
end
|
||||
local str = table.concat(args, " ").."\n" -- ugly hack
|
||||
for m in str:gmatch("(.-)\n") do
|
||||
tty.write(m)
|
||||
local x, y = tty.getcursor()
|
||||
if (x ~= 1) then
|
||||
ttyy = y + 1
|
||||
ttyx = 1
|
||||
if (ttyy > h) then
|
||||
tty.moveup()
|
||||
ttyy = h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function tty.update()
|
||||
draw_segments(get_segments())
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
function load_velx(read, seek, close, name)
|
||||
-- Load a VELX format library.
|
||||
local magic, fver, compression, lver, osid, arctype, psize, lsize, ssize, rsize = string.unpack(velx_header, read(string.packsize(velx_header)))
|
||||
if (magic ~= "\27VelX") then
|
||||
return nil, "bad magic ("..magic..")"
|
||||
end
|
||||
if (osid & 0x7F ~= 0x5A or osid & 0x7F ~= 0x7F) then
|
||||
return nil, string.format("wrong os (%x)", osid & 0x7F)
|
||||
end
|
||||
if (compression > 1) then
|
||||
return nil, "bad compression"
|
||||
end
|
||||
if ((arctype ~= "\0\0\0\0" and (arctype ~= "tsar" and osid & 0x7F == 0x5A))) then
|
||||
return nil, "bad arctype ("..arctype..")"
|
||||
end
|
||||
if (fver ~= 1) then
|
||||
return nil, "wrong version"
|
||||
end
|
||||
local prog = read(psize)
|
||||
if (compression == 1) then
|
||||
prog = lzss_decompress(prog)
|
||||
end
|
||||
seek(lsize+ssize)
|
||||
local env = {}
|
||||
if (arctype == "tsar") then
|
||||
env._ARCHIVE = tsar.read(read, seek, close)
|
||||
end
|
||||
setmetatable(env, {__index=_G, __newindex=function(_, i, v) _G[i] = v end})
|
||||
return load(prog, "="..(name or "(loaded velx)"), "t", env)
|
||||
end
|
|
@ -8,8 +8,7 @@ local oefi = {}
|
|||
|
||||
local function load_oefi(drive, path, uuid)
|
||||
local oefi_env = {}
|
||||
local env = {}
|
||||
utils.deepcopy(_G, env)
|
||||
local env = utils.make_env()
|
||||
env.krequire = nil
|
||||
env._BIOS = nil
|
||||
env._ZVER = nil
|
||||
|
|
|
@ -21,8 +21,7 @@ local function load_oefi_env(file, envx)
|
|||
arc = cpio.read(envx.fs, file)
|
||||
end
|
||||
local oefi_env = {}
|
||||
local env = {}
|
||||
utils.deepcopy(_G, env)
|
||||
local env = utils.make_env()
|
||||
env.krequire = nil
|
||||
env._BIOS = nil
|
||||
env._ZVER = nil
|
||||
|
@ -116,8 +115,7 @@ end
|
|||
|
||||
function ext.ZyNeo_GetOEFIEnv(drive, arc)
|
||||
local oefi_env = {}
|
||||
local env = {}
|
||||
utils.deepcopy(_G, env)
|
||||
local env = utils.make_env()
|
||||
env.krequire = nil
|
||||
env._BIOS = nil
|
||||
env._ZVER = nil
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
local zy = krequire("zorya")
|
||||
local sys = krequire("sys")
|
||||
local utils = krequire("utils")
|
||||
|
||||
local computer, component = computer, component
|
||||
|
||||
local sp = {}
|
||||
|
||||
function sp.add_mod_path(drive, path)
|
||||
local px = component.proxy(drive)
|
||||
zy.add_mod_search(function(mod)
|
||||
if (px.exists(path.."/"..mod..".zy2m")) then
|
||||
local h = px.open(path.."/"..mod..".zy2m", "r")
|
||||
return utils.load_lua(utils.readfile(drive, h))()
|
||||
elseif (px.exists(path.."/"..mod.."/init.zy2m")) then
|
||||
local h = px.open(path.."/"..mod.."/init.zy2m", "r")
|
||||
return utils.load_lua(utils.readfile(drive, h))()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function sp.add_lib_path(drive, path)
|
||||
local px = component.proxy(drive)
|
||||
sys.add_search(function(mod)
|
||||
if (px.exists(path.."/"..mod..".zy2l")) then
|
||||
local h = px.open(path.."/"..mod..".zy2l", "r")
|
||||
return utils.load_lua(utils.readfile(drive, h))
|
||||
elseif (px.exists(path.."/"..mod.."/init.zy2l")) then
|
||||
local h = px.open(path.."/"..mod.."/init.zy2l", "r")
|
||||
return utils.load_lua(utils.readfile(drive, h))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return sp
|
|
@ -0,0 +1,25 @@
|
|||
--#include "velx.lua"
|
||||
|
||||
local velx = {}
|
||||
|
||||
function velx.loadstream(read, seek, close, name)
|
||||
return load_velx(read, seek, close, name)
|
||||
end
|
||||
|
||||
function velx.loadfile(addr, file)
|
||||
local fs = component.proxy(addr)
|
||||
local h = fs.open(file, "rb")
|
||||
local function read(a)
|
||||
return fs.read(h, a)
|
||||
end
|
||||
local function seek(a)
|
||||
return fs.seek(h, "cur", a)
|
||||
end
|
||||
local function close()
|
||||
return fs.close(h)
|
||||
end
|
||||
|
||||
return velx.loadstream(read, seek, close, file)
|
||||
end
|
||||
|
||||
return velx
|
|
@ -0,0 +1,39 @@
|
|||
local function load_velx(read, seek, close, name)
|
||||
-- Load a VELX format library.
|
||||
local magic, fver, compression, lver, osid, arctype, psize, lsize, ssize, rsize = string.unpack(velx_header, read(string.packsize(velx_header)))
|
||||
if (magic ~= "\27VelX") then
|
||||
return nil, "bad magic ("..magic..")"
|
||||
end
|
||||
if (osid & 0x7F ~= 0x5A or osid & 0x7F ~= 0x7F) then
|
||||
return nil, string.format("wrong os (%x)", osid & 0x7F)
|
||||
end
|
||||
if (osid & 0x80 > 0) then
|
||||
return nil, "not an executable"
|
||||
end
|
||||
if (compression > 1) then
|
||||
return nil, "bad compression"
|
||||
end
|
||||
if (fver ~= 1) then
|
||||
return nil, "wrong version"
|
||||
end
|
||||
local prog = read(psize)
|
||||
if (compression == 1) then
|
||||
prog = lzss_decompress(prog)
|
||||
end
|
||||
seek(lsize+ssize)
|
||||
local env = {}
|
||||
--[[
|
||||
if (arctype == "tsar") then
|
||||
env._ARCHIVE = tsar.read(read, seek, close)
|
||||
end]]
|
||||
if (arctype ~= "\0\0\0\0") then
|
||||
local arc = krequire("util_"..arctype)
|
||||
if arc then
|
||||
env._ARCHIVE = arc.read(read, seek, close)
|
||||
end
|
||||
elseif (arctype ~= "\0\0\0\0") then
|
||||
return nil, "bad arctype ("..arctype..")"
|
||||
end
|
||||
setmetatable(env, {__index=_G, __newindex=function(_, i, v) _G[i] = v end})
|
||||
return load(prog, "="..(name or "(loaded velx)"), "t", env)
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
local zy = krequire("zorya")
|
||||
local vdev = krequire("util_vcomponent")
|
||||
vdev.register("ZORYA_BIOS", "zybios", {
|
||||
vdev.register("ZORYA_BIOS", "zybios",
|
||||
{
|
||||
get_threads_info = function()
|
||||
local threads = {}
|
||||
|
@ -8,13 +8,14 @@ vdev.register("ZORYA_BIOS", "zybios", {
|
|||
local info = zy.lkthdi(i)
|
||||
threads[i] = {
|
||||
name = info[1],
|
||||
deadline = info[6]
|
||||
deadline = info[4],
|
||||
delta = info.delta
|
||||
}
|
||||
end
|
||||
return threads
|
||||
end,
|
||||
get_version = function()
|
||||
return string.format("%f.%d", _ZVER, _ZPAT)
|
||||
return string.format("%1.1f.%d", _ZVER, _ZPAT)
|
||||
end,
|
||||
get_git_revision = function()
|
||||
return _ZGIT
|
||||
|
@ -25,6 +26,6 @@ vdev.register("ZORYA_BIOS", "zybios", {
|
|||
get_version = "get_version():string -- Returns the Zorya NEO version.",
|
||||
get_git_revision = "get_git_revision():string -- Returns the git revision of the build."
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return true
|
|
@ -0,0 +1,83 @@
|
|||
local CRC32 = {
|
||||
0,79764919,159529838,222504665,319059676,
|
||||
398814059,445009330,507990021,638119352,
|
||||
583659535,797628118,726387553,890018660,
|
||||
835552979,1015980042,944750013,1276238704,
|
||||
1221641927,1167319070,1095957929,1595256236,
|
||||
1540665371,1452775106,1381403509,1780037320,
|
||||
1859660671,1671105958,1733955601,2031960084,
|
||||
2111593891,1889500026,1952343757,2552477408,
|
||||
2632100695,2443283854,2506133561,2334638140,
|
||||
2414271883,2191915858,2254759653,3190512472,
|
||||
3135915759,3081330742,3009969537,2905550212,
|
||||
2850959411,2762807018,2691435357,3560074640,
|
||||
3505614887,3719321342,3648080713,3342211916,
|
||||
3287746299,3467911202,3396681109,4063920168,
|
||||
4143685023,4223187782,4286162673,3779000052,
|
||||
3858754371,3904687514,3967668269,881225847,
|
||||
809987520,1023691545,969234094,662832811,
|
||||
591600412,771767749,717299826,311336399,
|
||||
374308984,453813921,533576470,25881363,
|
||||
88864420,134795389,214552010,2023205639,
|
||||
2086057648,1897238633,1976864222,1804852699,
|
||||
1867694188,1645340341,1724971778,1587496639,
|
||||
1516133128,1461550545,1406951526,1302016099,
|
||||
1230646740,1142491917,1087903418,2896545431,
|
||||
2825181984,2770861561,2716262478,3215044683,
|
||||
3143675388,3055782693,3001194130,2326604591,
|
||||
2389456536,2200899649,2280525302,2578013683,
|
||||
2640855108,2418763421,2498394922,3769900519,
|
||||
3832873040,3912640137,3992402750,4088425275,
|
||||
4151408268,4197601365,4277358050,3334271071,
|
||||
3263032808,3476998961,3422541446,3585640067,
|
||||
3514407732,3694837229,3640369242,1762451694,
|
||||
1842216281,1619975040,1682949687,2047383090,
|
||||
2127137669,1938468188,2001449195,1325665622,
|
||||
1271206113,1183200824,1111960463,1543535498,
|
||||
1489069629,1434599652,1363369299,622672798,
|
||||
568075817,748617968,677256519,907627842,
|
||||
853037301,1067152940,995781531,51762726,
|
||||
131386257,177728840,240578815,269590778,
|
||||
349224269,429104020,491947555,4046411278,
|
||||
4126034873,4172115296,4234965207,3794477266,
|
||||
3874110821,3953728444,4016571915,3609705398,
|
||||
3555108353,3735388376,3664026991,3290680682,
|
||||
3236090077,3449943556,3378572211,3174993278,
|
||||
3120533705,3032266256,2961025959,2923101090,
|
||||
2868635157,2813903052,2742672763,2604032198,
|
||||
2683796849,2461293480,2524268063,2284983834,
|
||||
2364738477,2175806836,2238787779,1569362073,
|
||||
1498123566,1409854455,1355396672,1317987909,
|
||||
1246755826,1192025387,1137557660,2072149281,
|
||||
2135122070,1912620623,1992383480,1753615357,
|
||||
1816598090,1627664531,1707420964,295390185,
|
||||
358241886,404320391,483945776,43990325,
|
||||
106832002,186451547,266083308,932423249,
|
||||
861060070,1041341759,986742920,613929101,
|
||||
542559546,756411363,701822548,3316196985,
|
||||
3244833742,3425377559,3370778784,3601682597,
|
||||
3530312978,3744426955,3689838204,3819031489,
|
||||
3881883254,3928223919,4007849240,4037393693,
|
||||
4100235434,4180117107,4259748804,2310601993,
|
||||
2373574846,2151335527,2231098320,2596047829,
|
||||
2659030626,2470359227,2550115596,2947551409,
|
||||
2876312838,2788305887,2733848168,3165939309,
|
||||
3094707162,3040238851,2985771188,
|
||||
}
|
||||
|
||||
local function crc32(str)
|
||||
local count = string.len(tostring(str))
|
||||
local crc = max
|
||||
|
||||
local i = 1
|
||||
while count > 0 do
|
||||
local byte = string.byte(str, i)
|
||||
|
||||
crc = (crc << 8) ~ CRC32[((crc >> 24) ~ byte) + 1]
|
||||
|
||||
i = i + 1
|
||||
count = count - 1
|
||||
end
|
||||
|
||||
return crc
|
||||
end
|
|
@ -0,0 +1,84 @@
|
|||
local vdev = krequire("util_vcomponent")
|
||||
local utils = krequire("utils")
|
||||
local thd = krequire("thd")
|
||||
local comp = component
|
||||
local eeprom = {}
|
||||
local lua_code = [[
|
||||
--#include "luabios.lua"
|
||||
]]
|
||||
--#include "crc32.lua"
|
||||
local function generate_vbios(f_, path)
|
||||
local fs = comp.proxy(f_)
|
||||
if not fs.exists(path) then
|
||||
fs.makeDirectory(path)
|
||||
end
|
||||
if not fs.exists(path.."/code.lua") then
|
||||
local h = fs.open(path.."/code.lua", "wb")
|
||||
fs.write(h, lua_code)
|
||||
fs.close(h)
|
||||
end
|
||||
if not fs.exists(path.."/data.bin") then
|
||||
local h = fs.open(path.."/data.bin", "wb")
|
||||
fs.write(h, "")
|
||||
fs.close(h)
|
||||
end
|
||||
if not fs.exists(path.."/label.txt") then
|
||||
local h = fs.open(path.."/label.txt", "wb")
|
||||
fs.write(h, "Lua BIOS")
|
||||
fs.close(h)
|
||||
end
|
||||
local tbl = {
|
||||
get = function()
|
||||
local h = fs.open(path.."/code.lua", "rb")
|
||||
return utils.readfile(f_, h)
|
||||
end,
|
||||
getData = function()
|
||||
local h = fs.open(path.."/data.bin", "rb")
|
||||
return utils.readfile(f_, h)
|
||||
end,
|
||||
getLabel = function()
|
||||
local h = fs.open(path.."/label.txt", "rb")
|
||||
return utils.readfile(f_, h)
|
||||
end,
|
||||
set = function(data)
|
||||
local h = fs.open(path.."/code.lua", "wb")
|
||||
fs.write(h, data)
|
||||
fs.close(h)
|
||||
end,
|
||||
setData = function(data)
|
||||
local h = fs.open(path.."/data.bin", "wb")
|
||||
fs.write(h, data)
|
||||
fs.close(h)
|
||||
end,
|
||||
setLabel = function(label)
|
||||
local h = fs.open(path.."/label.txt", "wb")
|
||||
fs.write(h, label:sub(1, 16))
|
||||
fs.close(h)
|
||||
end,
|
||||
getDataSize = function()
|
||||
|
||||
return fs.spaceTotal()
|
||||
end,
|
||||
getSize = function()
|
||||
|
||||
return fs.spaceTotal()
|
||||
end,
|
||||
getChecksum = function()
|
||||
|
||||
return crc32(tbl.get())
|
||||
end,
|
||||
makeReadonly = function()
|
||||
|
||||
return
|
||||
end
|
||||
}
|
||||
vdev.register("vdev-ZY_VBIOS", "eeprom", tbl)
|
||||
local nice = function()
|
||||
|
||||
--#include "machine.lua"
|
||||
|
||||
end
|
||||
return nice, tbl
|
||||
end
|
||||
|
||||
return generate_vbios
|
|
@ -0,0 +1,64 @@
|
|||
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()
|
|
@ -0,0 +1,71 @@
|
|||
-- This our custom machine.lua
|
||||
local utils = krequire("utils")
|
||||
local computer = computer
|
||||
xpcall(function()
|
||||
utils.debug_log("Copying env...")
|
||||
local env = utils.make_env()
|
||||
utils.debug_log("Coppied env.")
|
||||
env.krequire = nil
|
||||
env._BIOS = nil
|
||||
env._ZVSTR = nil
|
||||
env._ZVER = nil
|
||||
env._ZPAT = nil
|
||||
env._ZGIT = nil
|
||||
vdev.install(env)
|
||||
local _oldlist = env.component.list
|
||||
local thdid = string.format("%.4x", math.random(0, 2^16-1))
|
||||
function env.component.list(...)
|
||||
local ol = _oldlist(...)
|
||||
local tcall = function()
|
||||
local a, t = ol()
|
||||
if (a ~= "vdev-ZY_VBIOS" and t == "eeprom") then
|
||||
a, t = ol()
|
||||
end
|
||||
return a, t
|
||||
end
|
||||
for k, v in pairs(ol) do
|
||||
if (k ~= "vdev-ZY_VBIOS" and v == "eeprom") then
|
||||
ol[k] = nil
|
||||
end
|
||||
end
|
||||
return setmetatable({}, {__index=ol, __call=tcall})
|
||||
end
|
||||
function env.load(code, name, mode, e, ...)
|
||||
local e = e or env
|
||||
return load(code, name, mode, e, ...)
|
||||
end
|
||||
local ded = false
|
||||
function env.computer.returnToBios()
|
||||
local thds = thd.get_threads()
|
||||
local vbname = "vbios$"..tbl.getLabel().."#"..thdid
|
||||
for i=1, #thds do
|
||||
if (thds[i][1] == vbname) then
|
||||
thds[i][6] = true
|
||||
end
|
||||
end
|
||||
ded = true
|
||||
utils.debug_log("Returning to BIOS...")
|
||||
end
|
||||
utils.debug_log("Loading vBIOS...")
|
||||
thd.add("vbios$"..tbl.getLabel().."#"..thdid, function()
|
||||
xpcall(function()
|
||||
utils.debug_log("Starting BIOS.")
|
||||
assert(load(tbl.get(), "=vbios", "t", env))()
|
||||
end, function(err)
|
||||
utils.debug_log("ERROR", "vBIOS error!")
|
||||
utils.debug_log(err, debug.traceback())
|
||||
end)
|
||||
utils.debug_log("Sending signal.")
|
||||
computer.pushSignal("vbios_dead")
|
||||
end)
|
||||
while true do
|
||||
if computer.pullSignal() == "vbios_dead" then
|
||||
utils.debug_log("Got signal.")
|
||||
break
|
||||
end
|
||||
end
|
||||
utils.debug_log("Dead.")
|
||||
end, function(err)
|
||||
utils.debug_log("ERROR", "vBIOS error!")
|
||||
utils.debug_log(err, debug.traceback())
|
||||
end)
|
|
@ -0,0 +1,76 @@
|
|||
local component, computer = component, computer
|
||||
local vfs = {}
|
||||
|
||||
local mounts = {}
|
||||
|
||||
local function path_split(path)
|
||||
local parts = {}
|
||||
for m in path:gmatch("/(.+)") do
|
||||
if (m ~= "") then
|
||||
parts[#parts+1] = m
|
||||
end
|
||||
end
|
||||
return parts
|
||||
end
|
||||
|
||||
local function t_compare(t1, t2)
|
||||
if (#t2 > #t1) then return false end
|
||||
for i=1, #t2 do
|
||||
if t1[i] ~= t2[i] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function vfs.init()
|
||||
local tmp = component.proxy(computer.tmpAddress())
|
||||
mounts[1] = {
|
||||
path = "/",
|
||||
parts = {"/"},
|
||||
proxy = tmp
|
||||
}
|
||||
for fs in component.list("filesystem") do
|
||||
if (fs ~= tmp.address) then
|
||||
local name = fs:sub(1, 6)
|
||||
tmp.makeDirectory(name)
|
||||
vfs.mount("/"..name, component.proxy(fs))
|
||||
end
|
||||
end
|
||||
tmp.makeDirectory("tmp")
|
||||
end
|
||||
|
||||
function vfs.mount(mountpoint, proxy)
|
||||
local parts = path_split(mountpoint)
|
||||
mounts[#mounts+1] = {path=mountpoint, parts=parts, proxy=proxy}
|
||||
end
|
||||
|
||||
function vfs.resolve(path)
|
||||
local path_parts = path_split(path)
|
||||
local real_parts = {}
|
||||
for i=1, #path_parts do
|
||||
if (path_parts[i] == "..") then
|
||||
real_parts[#real_parts] = nil
|
||||
elseif (path_parts[i] ~= ".") then
|
||||
real_parts[#real_parts+1] = path_parts[i]
|
||||
end
|
||||
end
|
||||
path = "/"..table.concat(real_parts, "/")
|
||||
local search_mounts = {}
|
||||
for i=1, #mounts do
|
||||
if (path:sub(1, #mounts[i].path) == mounts[i].path) then
|
||||
search_mounts[#search_mounts+1] = mounts[i]
|
||||
end
|
||||
end
|
||||
table.sort(search_mounts, function(a, b)
|
||||
return #a.parts > #b.parts
|
||||
end)
|
||||
for i=1, #search_mounts do
|
||||
if (t_compare(real_parts, search_mounts[i].parts)) then
|
||||
return search_mounts[i].proxy, path:sub(#search_mounts[i].path+1)
|
||||
end
|
||||
end
|
||||
return nil, "not found"
|
||||
end
|
||||
|
||||
return vfs
|
16
release.lua
16
release.lua
|
@ -5,11 +5,13 @@ function status(s)
|
|||
end
|
||||
status("Cleaning last build...")
|
||||
os.execute("rm -rf pkg")
|
||||
os.execute("rm -rf release")
|
||||
|
||||
status("Making directories...")
|
||||
os.execute("mkdir -p pkg/mods")
|
||||
os.execute("mkdir -p pkg/lib")
|
||||
os.execute("mkdir -p pkg/bios")
|
||||
os.execute("mkdir -p release")
|
||||
|
||||
status("Building EEPROM...")
|
||||
os.execute("luacomp src/loader.lua -O pkg/bios/managed.bios")
|
||||
|
@ -22,20 +24,28 @@ status("\n\nBuilding modules.")
|
|||
if (os.execute("stat mods 1>/dev/null 2>&1")) then
|
||||
for l in io.popen("ls mods"):lines() do
|
||||
status("MOD\t"..l)
|
||||
os.execute("zsh -c 'cd mods/"..l.."; luacomp init.lua -mluamin | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
|
||||
if (os.execute("stat mods/"..l.."/.nomin 1>/dev/null 2>&1")) then
|
||||
os.execute("sh -c 'cd mods/"..l.."; luacomp -mnone init.lua | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
|
||||
else
|
||||
os.execute("sh -c 'cd mods/"..l.."; luacomp -mluamin init.lua | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
|
||||
end
|
||||
end
|
||||
end
|
||||
status("Module build complete.\n\nBuilding libraries.")
|
||||
if (os.execute("stat lib 1>/dev/null 2>&1")) then
|
||||
for l in io.popen("ls lib"):lines() do
|
||||
status("LIB\t"..l)
|
||||
os.execute("zsh -c 'cd lib/"..l.."; luacomp init.lua -mluamin | lua ../../utils/zlua.lua > ../../pkg/lib/"..l..".zy2l'")
|
||||
os.execute("sh -c 'cd lib/"..l.."; luacomp -mluamin init.lua | lua ../../utils/zlua.lua > ../../pkg/lib/"..l..".zy2l'")
|
||||
end
|
||||
end
|
||||
status("Library build complete.\n\nBuilding installer...")
|
||||
os.execute("cp utils/ser.lua pkg/init.lua")
|
||||
os.execute("cp -r installer_dat pkg")
|
||||
status("Packing installer...")
|
||||
os.execute("cd pkg; find * -depth | cpio -o | lua ../utils/mkselfextract.lua > ../zorya-neo-installer.lua")
|
||||
os.execute("cd pkg; find * -depth | lua ../utils/make_tsar.lua | lua ../utils/mkselfextract.lua > ../release/zorya-neo-installer.lua")
|
||||
status("Making OpenOS util installer...")
|
||||
os.execute("cd util; find * -depth | lua ../utils/make_tsar.lua | lua ../utils/mkselfextract.lua > ../release/zorya-neo-utils-installer.lua")
|
||||
print("Making update tsar...")
|
||||
os.execute("cd pkg; find bios lib mods -depth | lua ../utils/make_tsar.lua > ../release/zorya-neo-update.tsar")
|
||||
status("Build complete.")
|
||||
status(string.format("Took %ds.", os.time()-start))
|
|
@ -1,2 +1,2 @@
|
|||
--#include "src/lzss.lua"
|
||||
return assert(load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua -mluamin 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua"))(lzss_decompress)
|
||||
return assert(load(lzss_decompress(%s), "=BOOTSTRAP.lua"))(lzss_decompress)
|
|
@ -1,4 +1,4 @@
|
|||
function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
|
||||
local function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
|
||||
e=c.byte(a,b)b=b+1
|
||||
for k=0,7 do h=c.sub
|
||||
g=h(a,b,b)if e>>k&1<1 and b<#a then
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
_ZLOADER = "initramfs"
|
||||
--[[local readfile=function(f,h)
|
||||
local b=""
|
||||
local d,r=f.read(h,math.huge)
|
||||
if not d and r then error(r)end
|
||||
b=d
|
||||
while d do
|
||||
local d,r=f.read(h,math.huge)
|
||||
b=b..(d or "")
|
||||
if(not d)then break end
|
||||
end
|
||||
f.close(h)
|
||||
return b
|
||||
end]]
|
||||
|
||||
local bfs = {}
|
||||
|
||||
local cfg = cproxy(clist("eeprom")()).getData()
|
||||
|
||||
local baddr = cfg:sub(1, 36)
|
||||
local bootfs = cproxy(baddr)
|
||||
|
||||
assert(bootfs.exists(".zy2/image.tsar"), "No boot image!")
|
||||
|
||||
local romfs_file = assert(bootfs.open(".zy2/image.tsar", "rb"))
|
||||
local rfs = readfile(bootfs.address, romfs_file)
|
||||
|
||||
--[[local romfs_dev = tsar.read(function(a)
|
||||
local c = ""
|
||||
local d
|
||||
while a > 0 do
|
||||
d = bootfs.read(romfs_file, a)
|
||||
a = a - #d
|
||||
c = c .. d
|
||||
end
|
||||
return c
|
||||
end, function(a)
|
||||
return bootfs.seek(romfs_file, "cur", a)
|
||||
end, function()
|
||||
return bootfs.close(romfs_file)
|
||||
end)]]
|
||||
local h = 1
|
||||
local romfs_dev = tsar.read(function(a)
|
||||
local d = rfs:sub(h, h+a-1)
|
||||
h = h+a
|
||||
return d
|
||||
end, function(a)
|
||||
h = h + a
|
||||
return h
|
||||
end, function()
|
||||
rfs = nil
|
||||
end)
|
||||
|
||||
function bfs.getfile(path)
|
||||
return romfs_dev:fetch(path)
|
||||
end
|
||||
|
||||
function bfs.exists(path)
|
||||
return romfs_dev:exists(path)
|
||||
end
|
||||
|
||||
function bfs.getstream(path)
|
||||
return romfs_dev:stream(path)
|
||||
end
|
||||
|
||||
function bfs.getcfg()
|
||||
local h = assert(bootfs.open(".zy2/cfg.lua", "r"))
|
||||
return readfile(bootfs.address, h)
|
||||
end
|
||||
|
||||
bfs.addr = baddr
|
|
@ -1,4 +1,5 @@
|
|||
local readfile=function(f,h)
|
||||
_ZLOADER = "managed"
|
||||
--[[local readfile=function(f,h)
|
||||
local b=""
|
||||
local d,r=f.read(h,math.huge)
|
||||
if not d and r then error(r)end
|
||||
|
@ -10,21 +11,28 @@ local readfile=function(f,h)
|
|||
end
|
||||
f.close(h)
|
||||
return b
|
||||
end
|
||||
end]]
|
||||
|
||||
local bfs = {}
|
||||
|
||||
local cfg = component.proxy(component.list("eeprom")()).getData()
|
||||
local cfg = cproxy(clist("eeprom")()).getData()
|
||||
|
||||
local baddr = cfg:sub(1, 36)
|
||||
local bootfs = component.proxy(baddr)
|
||||
local bootfs = cproxy(baddr)
|
||||
|
||||
assert(bootfs.exists(".zy2/image.romfs"), "No boot image!")
|
||||
assert(bootfs.exists(".zy2/image.tsar"), "No boot image!")
|
||||
|
||||
local romfs_file = assert(bootfs.open(".zy2/image.romfs", "rb"))
|
||||
local romfs_file = assert(bootfs.open(".zy2/image.tsar", "rb"))
|
||||
|
||||
local romfs_dev = romfs.read(function(a)
|
||||
return bootfs.read(romfs_file, a)
|
||||
local romfs_dev = tsar.read(function(a)
|
||||
local c = ""
|
||||
local d
|
||||
while a > 0 do
|
||||
d = bootfs.read(romfs_file, a)
|
||||
a = a - #d
|
||||
c = c .. d
|
||||
end
|
||||
return c
|
||||
end, function(a)
|
||||
return bootfs.seek(romfs_file, "cur", a)
|
||||
end, function()
|
||||
|
@ -39,9 +47,13 @@ function bfs.exists(path)
|
|||
return romfs_dev:exists(path)
|
||||
end
|
||||
|
||||
function bfs.getstream(path)
|
||||
return romfs_dev:stream(path)
|
||||
end
|
||||
|
||||
function bfs.getcfg()
|
||||
local h = assert(bootfs.open(".zy2/cfg.lua", "r"))
|
||||
return readfile(bootfs, h)
|
||||
return readfile(bootfs.address, h)
|
||||
end
|
||||
|
||||
bfs.addr = baddr
|
|
@ -1,38 +1,47 @@
|
|||
local osdi = {}
|
||||
local bfs = {}
|
||||
|
||||
local function int(str)
|
||||
local t=0
|
||||
for i=1, #str do
|
||||
t = t | (str:byte(i) << ((i-1)*8))
|
||||
end
|
||||
return t
|
||||
end
|
||||
local cfg = cproxy(clist("eeprom")()).getData()
|
||||
|
||||
local function get_part_info(meta, part)
|
||||
local info = meta:sub((part*32)+1, ((part+1)*32))
|
||||
local start = int(info:sub(1, 4))
|
||||
local size = int(info:sub(5, 8))
|
||||
local ptype = info:sub(9, 16)
|
||||
local flags = int(info:sub(17, 19))
|
||||
local label = info:sub(20):gsub("\0", "")
|
||||
return {start = start,
|
||||
size = size,
|
||||
ptype = ptype,
|
||||
flags = flags,
|
||||
label = label
|
||||
}
|
||||
end
|
||||
local baddr, part = cfg:sub(1, 36)
|
||||
local bootfs = cproxy(baddr)
|
||||
|
||||
local function pad(str, len)
|
||||
return str .. string.rep(" ", len-#str)
|
||||
end
|
||||
|
||||
function osdi.get_table(volume)
|
||||
local t = {}
|
||||
local meta = component.invoke(volume, "readSector", 1)
|
||||
for i=2, 16 do
|
||||
t[i-1] = get_part_info(meta, i)
|
||||
--find active partition
|
||||
local bs, p, t, ss = bootfs.readSector(1), "I4I4c8I3c13", {}
|
||||
for i=1, 15 do
|
||||
t = {sunpack(p, bs:sub((i*32)+1, (i+1)*32))}
|
||||
if (t[4] & 0x200 and t[4] & 0x40) then
|
||||
ss = t[1]
|
||||
end
|
||||
end
|
||||
|
||||
return osdi
|
||||
local h = 1
|
||||
local romfs_dev = tsar.read(function(a)
|
||||
local sz, c, st, p, d = math.ceil(a/512), "", (h//512), (h & 511)+1
|
||||
for i=1, sz do
|
||||
c = c .. bootfs.readSector(ss+i+st)
|
||||
end
|
||||
d = c:sub(p, p+a-1)
|
||||
h = h+a
|
||||
return d
|
||||
end, function(a)
|
||||
h = h + a
|
||||
return h
|
||||
end, function()
|
||||
|
||||
end)
|
||||
|
||||
function bfs.getfile(path)
|
||||
return romfs_dev:fetch(path)
|
||||
end
|
||||
|
||||
function bfs.exists(path)
|
||||
return romfs_dev:exists(path)
|
||||
end
|
||||
|
||||
function bfs.getstream(path)
|
||||
return romfs_dev:stream(path)
|
||||
end
|
||||
|
||||
function bfs.getcfg()
|
||||
return romfs_dev:fetch(".zy2/cfg.lua")
|
||||
end
|
|
@ -0,0 +1,38 @@
|
|||
local bfs = {}
|
||||
|
||||
local cfg = cproxy(clist("eeprom")()).getData()
|
||||
|
||||
local baddr = cfg:sub(1, 36)
|
||||
local bootfs = cproxy(baddr)
|
||||
|
||||
local h = 1
|
||||
local romfs_dev = tsar.read(function(a)
|
||||
local sz, c, st, p, d = math.ceil(a/512), "", (h//512)+1, (h & 511)+1
|
||||
for i=1, sz do
|
||||
c = c .. bootfs.blockRead(i+st)
|
||||
end
|
||||
d = c:sub(p, p+a-1)
|
||||
h = h+a
|
||||
return d
|
||||
end, function(a)
|
||||
h = h + a
|
||||
return h
|
||||
end, function()
|
||||
|
||||
end)
|
||||
|
||||
function bfs.getfile(path)
|
||||
return romfs_dev:fetch(path)
|
||||
end
|
||||
|
||||
function bfs.exists(path)
|
||||
return romfs_dev:exists(path)
|
||||
end
|
||||
|
||||
function bfs.getstream(path)
|
||||
return romfs_dev:stream(path)
|
||||
end
|
||||
|
||||
function bfs.getcfg()
|
||||
return romfs_dev:fetch(".zy2/cfg.lua")
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
--#error "Not implemented."
|
||||
local rfs = {}
|
||||
|
||||
local bfs = {}
|
||||
|
||||
function bfs.getfile(path)
|
||||
|
||||
end
|
||||
|
||||
function bfs.exists(path)
|
||||
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue