1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-13 14:08:07 +11:00

Compare commits

..

31 Commits

Author SHA1 Message Date
lunaboards-dev
bc9617228f
Merge pull request #7 from Ocawesome101/patch-2
add ULOS loader
2021-12-05 16:06:09 -05:00
i develop things
52c9da6fe3
add cynosure loader 2021-09-03 16:27:00 -04:00
i develop things
d96ffb10da
remove loader_ulos.lua 2021-09-03 16:25:41 -04:00
i develop things
001234bcd5
add cynosure detection 2021-09-03 16:25:11 -04:00
i develop things
b1f64f97a1
add ULOS loader 2021-09-03 16:22:40 -04:00
sam
831d96de84 io module 2020-12-21 00:14:39 -05:00
sam
13f8190cbf lzss 2020-12-13 15:41:24 -05:00
sam
99adfbb54a velxv2 2020-12-13 15:37:13 -05:00
Adorable-Catgirl
66076af6bd
Merge pull request #4 from Ocawesome101/patch-1
Add Monolith loader
2020-06-18 17:03:13 -04:00
Ocawesome101
813bf47319
Add monolith detection 2020-06-18 17:02:05 -04:00
Sam Roxanne
7b4fab427d wow^2 2020-06-18 15:35:20 -05:00
Sam Roxanne
ed447d98fa wow 2020-06-18 15:34:28 -05:00
Ocawesome101
722606b419
Add Monolith loader
This is untested as I unfortunately couldn't get Zorya to build.
2020-06-18 16:01:42 -04:00
Sam Roxanne
1ffba24166 i split it all up 2020-06-18 14:49:36 -05:00
Sam Roxanne
3c18756141 I've finally split up the BIOS a bit. 2020-06-17 00:22:48 -05:00
Sam Roxanne
ea6e5da1c3 Small fixes. 2020-06-06 14:19:16 -05:00
Sam Roxanne
39ff04c2b6 Oops. 2020-06-05 19:48:36 -05:00
Sam Roxanne
93158455e4 New build system, VELX, and more 2020-06-05 19:45:08 -05:00
sam
d09c52f6c2 Block devices. 2020-05-21 00:17:17 -04:00
Jane Roxanne
06d43e99ad Merge branch 'master' of https://github.com/Adorable-Catgirl/Zorya-NEO 2020-05-17 18:55:11 -05:00
Jane Roxanne
530796bf5f I dunno what this does. 2020-05-17 18:55:09 -05:00
sam
d4b07eebc1 Fixed performance issue. 2020-05-17 00:23:43 -04:00
Jane Roxanne
3b484d8c5c Version bump. 2020-04-10 10:40:20 -05:00
Jane Roxanne
4318a82965 We got a console now. 2020-04-10 10:38:52 -05:00
Jane Roxanne
0e7f55624a Because someone complained about boot speed. 2020-03-29 11:52:53 -05:00
Adorable-Catgirl
760bec1eb7
Merge pull request #1 from JakobCh/master
Make selfextract actually print out the "bad magic" error, p9k loader.
2020-03-23 15:52:02 -04:00
Adorable-Catgirl
782c99df08
Use assert instead of print. 2020-03-23 15:50:55 -04:00
JakobCh
376ccc11a3 Add support to boot from plan9k filesystems 2020-03-23 13:33:27 +01:00
JakobCh
d496ba127e Make selfextract actually print out the "bad magic" error 2020-03-23 12:30:44 +01:00
sam
2ff54eceb9 Docs? 2020-03-22 16:09:49 -04:00
sam
a900ff3b54 Updated readme, added docs folder. 2020-03-22 16:07:10 -04:00
124 changed files with 5470 additions and 329 deletions

3
.build/00_setup.lua Normal file
View File

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

222
.build/01_velx.lua Normal file
View File

@ -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

92
.build/02_lzss.lua Normal file
View File

@ -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

86
.build/10_bios.lua Normal file
View File

@ -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"]]

35
.build/11_modules.lua Normal file
View File

@ -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"

33
.build/12_libraries.lua Normal file
View File

@ -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)

3
.build/20_pkg.lua Normal file
View File

@ -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)

22
.build/30_selfextract.lua Normal file
View File

@ -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)

17
.build/ff_meta.lua Normal file
View File

@ -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)

View File

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

219
.buildactions/01_velx.lua Normal file
View File

@ -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

92
.buildactions/02_lzss.lua Normal file
View File

@ -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

55
.buildactions/10_bios.lua Normal file
View File

@ -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"

View File

@ -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"

View File

@ -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"

5
.buildactions/20_pkg.lua Normal file
View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,5 @@
function actions.utils()
makeselfextract("util", "release/zorya-neo-utils-installer.lua")
end
actions[#actions+1] = "utils"

View File

@ -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

View File

@ -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

View File

@ -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>

36
build.lua Normal file
View File

@ -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.")

2
build.sh Executable file
View File

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

2
docs/Developing.md Normal file
View File

@ -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.

0
docs/README.md Normal file
View File

View File

@ -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"}
}

View File

@ -1,28 +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_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.",
["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")
]]
}

View File

@ -1,24 +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="vbios", cat="vdev", path="mods/vdev_vbios.zy2m"},
{name="biosdev", cat="vdev", path="mods/vdev_biosdev.zy2m"},
{name="searchpaths", cat="util", path="mods/util_searchpaths.zy2m"},
{name="vfs", cat="core", path="mods/vfs.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="classic", 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"},

View File

@ -59,7 +59,7 @@ function thd.run()
dl = computer.uptime() + (dl or math.huge)
threads[i][4] = dl
threads[i].delta = computer.uptime() - dt
sigs[#sigs+1] = {ps(0)}
--sigs[#sigs+1] = {ps(0)}
end
end
end

0
lib/exec_velx/init.lua Normal file
View File

View File

@ -3,9 +3,53 @@ 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

View File

@ -49,9 +49,10 @@ local function checkCache(packetID)
end
--local realComputerPullSignal = computer.pullSignal
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

View File

@ -95,4 +95,24 @@ function arc:list_dir(path)
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

View File

@ -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

View File

@ -301,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

297
luabuild.lua Normal file
View File

@ -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()))

1
mods/fs_fat/init.lua Normal file
View File

@ -0,0 +1 @@
--#include "msdosfs.lua"

1172
mods/fs_fat/msdosfs.lua Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,27 +5,41 @@ 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

View File

@ -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

View File

@ -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

View File

@ -1,8 +1,20 @@
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)
--vdev.overwrite(_G)
@ -16,10 +28,21 @@ return function(addr)
env.krequire = nil]]
--vdev.install(env)
--log(env, env.computer, env.computer.getBootAddress, env.computer.getBootAddress())
function computer.getBootAddress()
return addr
-- 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
function computer.setBootAddress()end
local old_dl = utils.debug_log
load(utils.readfile(fs.address, fs.open("init.lua")), "=init.lua", "t", env)()
end

View File

@ -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"
}

17
mods/menu_bios/config.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -37,25 +37,6 @@ function menu.draw()
local sel = 1
local function 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.")
gpu.setBackground(bg)
gpu.setForeground(fg)
gpu.fill(1, h-2, w, 1, " ")
@ -84,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)
@ -110,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

12
mods/net_minitel/init.lua Normal file
View File

@ -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"

View File

View File

View File

@ -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

64
mods/util_blkdev/hdd.lua Normal file
View File

@ -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

57
mods/util_blkdev/init.lua Normal file
View File

@ -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

79
mods/util_blkdev/osdi.lua Normal file
View File

@ -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

64
mods/util_blkdev/prom.lua Normal file
View File

@ -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

View File

View File

@ -0,0 +1,5 @@
local arg = ...
if (arg == "") then
arg = "init.lua"
end
load_exec(arg)()

View File

@ -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")

View File

@ -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.")

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
for d in component.list("filesystem") do
print(d)
end

View File

@ -0,0 +1,4 @@
local threads = krequire("thd").get_threads()
for i=1, #threads do
print(threads[i][1])
end

View File

@ -0,0 +1 @@
computer.shutdown(true)

View File

@ -0,0 +1,6 @@
local fs = ...
for f in component.list("filesystem") do
if (f:sub(1, #fs) == fs) then
_DRIVE = f
end
end

View File

@ -0,0 +1 @@
computer.shutdown()

View File

@ -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)

View File

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -11,10 +11,10 @@ function sp.add_mod_path(drive, path)
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))
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))
return utils.load_lua(utils.readfile(drive, h))()
end
end)
end

25
mods/util_velx/init.lua Normal file
View File

@ -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

39
mods/util_velx/velx.lua Normal file
View File

@ -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

0
mods/vdev_vbios/.nomin Normal file
View File

View File

@ -3,10 +3,8 @@
local computer = computer
xpcall(function()
utils.debug_log("Copying env...")
local env = utils.deepcopy(_G)
local env = utils.make_env()
utils.debug_log("Coppied env.")
env._G = env
env._ENV = env
env.krequire = nil
env._BIOS = nil
env._ZVSTR = nil

View File

@ -24,7 +24,11 @@ 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("sh -c 'cd mods/"..l.."; luacomp -mluamin init.lua | 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.")

View File

@ -1,2 +1,2 @@
--#include "src/lzss.lua"
return assert(load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua -mluamin 2>/dev/null | lua5.3 utils/makezbios.lua ]]), "=bios.lua"))(lzss_decompress)
return assert(load(lzss_decompress(%s), "=BOOTSTRAP.lua"))(lzss_decompress)

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
_ZLOADER = "managed"
local readfile=function(f,h)
--[[local readfile=function(f,h)
local b=""
local d,r=f.read(h,math.huge)
if not d and r then error(r)end
@ -11,14 +11,14 @@ 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.tsar"), "No boot image!")
@ -47,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

View File

@ -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

View File

@ -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

View File

@ -1,12 +0,0 @@
--#error "Not implemented."
local rfs = {}
local bfs = {}
function bfs.getfile(path)
end
function bfs.exists(path)
end

View File

@ -9,7 +9,7 @@ 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
if sig ~= "romfs\1\0" then error(string.format("Invalid romfs (%.14x != %.14x)", sunpack("i7", sig), sunpack("i7", "romfs\1\0"))) end
local tbl = {}
local lname
while lname ~= "TRAILER!!!" do

View File

@ -1,19 +1,20 @@
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 en = true
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, "bad magic" end
local m = sunpack(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)
ent.magic, ent.namesize, ent.mode, ent.uid, ent.gid, ent.filesize, ent.mtime = sunpack(e..header_fmt, dat)
ent.mtime = ent.mtime/1000
return ent
end
@ -49,20 +50,51 @@ function arc:list(path)
return ent
end
function arc:stream(path)
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
function arc:close()
self.close()
end
return {
function arc:meta(path)
for i=1, #self.tbl do
if (self.tbl[i].name == path and self.tbl[i].mode & 32768 > 0) then
return self.tbl[i]
end
end
return nil, "file not found"
end
local tsar = {
read = function(read, seek, close)
local tbl = {}
local lname = ""
while lname ~= "TRAILER!!!" do
local dat = read(22)
local et = read_header(dat)
local et = assert(read_header(dat))
et.name = read(et.namesize)
et.pos = seek(et.namesize & 1)
seek(et.filesize + (et.filesize & 1))
local t = (et.filesize & 1)
seek(et.filesize + t)
lname = et.name
if lname ~= "TRAILER!!!" then
tbl[#tbl+1] = et

View File

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

View File

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

61
src/zy-neo/neoinit.lua Normal file
View File

@ -0,0 +1,61 @@
-- I am an idiot.
local decompress = ...
local krq = krequire
local sunpack = string.unpack
local ct, cr = component, computer
-- I now must debug every fucking thing.
@[[if svar.get("DEBUG") then]]
do
local cinvoke, clist, cproxy = ct.invoke, ct.list, ct.proxy
function component.invoke(addr, meth, ...)
cinvoke(clist("ocemu")(), "log", addr, meth, ..., debug.getinfo(2).source, debug.getinfo(2).linedefined)
return cinvoke(addr, meth, ...)
end
function component.proxy(addr)
local proxy = cproxy(addr)
return setmetatable({}, {__index=function(_, i)
if proxy[i] then
return function(...)
cinvoke(clist("ocemu")(), "log", addr, i, ..., debug.getinfo(3).source, debug.getinfo(3).linedefined)
return proxy[i](...)
end
end
end})
end
end
@[[end]]
local cinvoke, clist, cproxy = ct.invoke, ct.list, ct.proxy
local function readfile(f,h)
local b=""
local d,r=cinvoke(f,"read",h,math.huge)
if not d and r then error(r)end
b=d
while d do
local d,r=cinvoke(f,"read",h,math.huge)
b=b..(d or "")
if(not d)then break end
end
cinvoke(f,"close",h)
return b
end
local xxh = (function()
--#include "src/zy-neo/builtins/util_xxh64.lua"
end)()
--#include "src/zy-neo/builtins/util_tsar.lua"
@[[if not svar.get("ZY_PLATFORM") then]]
--#define "ZY_PLATFORM" "managed"
@[[end]]
--#include @[{"src/zy-neo/builtins/init_"..svar.get("ZY_PLATFORM").."/init.lua"}]
--component.invoke(component.list("sandbox")(), "log", "test")
if not bfs.exists("bootstrap.bin") then
error("No bootstrap.bin!")
end
local raw = bfs.getfile("bootstrap.bin")
local code = decompress(raw)
--component.invoke(component.list("sandbox")(), "log", code or "<null>")
assert(load(code, "=bootstrap.bin"))(decompress, tsar, bfs, readfile)

View File

@ -1,35 +1,28 @@
local utils = {}
@[[if svar.get("DEBUG") then]]
function utils.debug_log(...)
local sb = component.list("sandbox")() or component.list("ocemu")()
if (sb) then component.invoke(sb, "log", ...) end
local sb = clist("sandbox")() or clist("ocemu")()
if (sb) then cinvoke(sb, "log", ...) end
end
@[[else]]
function utils.debug_log()end
@[[end]]
function utils.baddr(address)
--[[function utils.baddr(address)
local address = address:gsub("-", "", true)
local b = ""
for i=1, #address, 2 do
b = b .. string.char(tonumber(address:sub(i, i+1), 16))
end
return b
end
end]]
function utils.readfile(f,h)
local b=""
local d,r=component.invoke(f,"read",h,math.huge)
if not d and r then error(r)end
b=d
while d do
local d,r=component.invoke(f,"read",h,math.huge)
b=b..(d or "")
if(not d)then break end
end
component.invoke(f,"close",h)
return b
end
utils.readfile = readfile
utils.load_lua = load_lua
utils.lzss_decompress = lzss_decompress
-- Hell yeah, deepcopy time.
function utils.deepcopy(src, dest)
dest = dest or {}
@ -38,10 +31,10 @@ function utils.deepcopy(src, dest)
local cout = {dest}
while #cin > 0 do
for k, v in pairs(cin[1]) do
if (type(v) ~= "table") then
if type(v) ~= "table" then
cout[1][k] = v
else
if (coppied[v]) then
if coppied[v] then
cout[1][k] = coppied[v]
else
local t = {}
@ -58,4 +51,91 @@ function utils.deepcopy(src, dest)
return dest
end
local velx_header = "<c5BBBBc4I3I3I3I4"
function utils.load_velx(read, seek, close, name)
local spos = seek()
-- Load a VELX format library.
local magic, fver, compression, lver, osid, arctype, psize, lsize, ssize, rsize = sunpack(velx_header, read(string.packsize(velx_header)))
if magic ~= "\27VelX" then
return nil, "bad magic ("..magic..")"
end
if (fver == 2) then
seek(spos-seek())
local vx2 = utils.velx2(read, seek, close, name)
if (vx2.type > 0) then
return nil, "not an executable"
end
local code = vx2:getsection(0x5A, "lua")
local t = vx2:gettag(0x5A, "archive", "type")
local env = {}
if (t and t ~= "tsar") then
return nil, "bad arctype"
elseif (t) then
env._ARCHIVE = tsar.read(vx2:getstream(0x5A, "archive"))
end
setmetatable(env, {__index=_G, __newindex=function(_, i, v) _G[i] = v end})
return load(code, "="..(name or "(loaded velx)"), "t", env)
end
if osid & 0x7F ~= 0x5A then
return nil, string.format("wrong os (%x ~= 0x5A)", osid & 0x7F)
end
if compression > 1 then
return nil, "bad compression"
end
if arctype ~= "\0\0\0\0" and arctype ~= "tsar" 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
local _RENV = _G
function utils.make_env()
local env = utils.deepcopy(_RENV)
env._G = env
env.load = function(scr, name, mode, e)
return load(scr, name, mode, e or env)
end
return env
end
function utils.console_panic(er)
local gaddr = clist("gpu")()
local con, gpu = krq("zorya").loadmod("util_luaconsole"), cproxy(gaddr)
if not gpu.getScreen() or gpu.getScreen() == "" then
local saddr = clist("screen")()
gpu.bind(saddr)
end
if con then
con(string.format("tty.setcolor(0x4) print([[%s]])", er:gsub("\t", " ")))
return true
end
--gs = gpu.set
gpu.set(1, 1, "Kernel panic!")
local y = 2
for m in er:gmatch("(.+)\n") do
gpu.set(1,y,m)
y = y + 1
end
gpu.set(1, y, "Press any key to shut down.")
while true do
if (cr.pullSignal() == "key_down") then cr.shutdown() end
end
end
_RENV = utils.make_env()
builtins.utils = function() return utils end

View File

@ -1,44 +1,25 @@
local lzss_decompress = ...
local lzss_decompress, tsar, bfs, readfile = ...
--Zorya NEO itself.
_BIOS = "Zorya NEO"
_ZVSTR = "2.0"
_ZVER = 2.0
_ZPAT = 0
_ZGIT = "$[[git rev-parse --short HEAD]]"
_BIOS, _ZVSTR, _ZVER, _ZPAT, _ZGIT = "Zorya NEO", "2.0-rc5", 2.0, 0, "$[[git rev-parse --short HEAD]]"
--#include "ksrc/kinit.lua"
local thd = krequire("thd")
local util = krequire("util")
local sys = krequire("sys")
local component = component
local computer = computer
local booted = false
local zcfg = {}
function log(...)
local c = component.list("ocemu")() or component.list("sandbox")()
if c then
component.proxy(c).log(...)
end
end
local th_i = 0
local function th_a(func)
thd.add("zyneo$"..th_i, func)
th_i = th_i + 1
end
local krq = krequire
local sunpack = string.unpack
local thd, sys, ct, cr = krq"thd", krq"sys", component, computer
local cinvoke, clist, cproxy = ct.invoke, ct.list, ct.proxy
local function load_lua(src, ...)
log(#src)
if (src:sub(1, 4) == "\27ZLS") then
src = lzss_decompress(src:sub(5))
end
return load(src, ...)
end
---#include "src/zy-neo/builtins/util_tsar.lua"
local builtins = {}
--#include "src/zy-neo/utils.lua"
local tsar = load([[
--#include "src/zy-neo/builtins/util_tsar.lua"
]])()
local log = utils.debug_log
builtins.utils_tsar = function() return tsar end
builtins.util_xxh64 = function() return xxh end
sys.add_lib("zorya", (function()
@ -56,8 +37,6 @@ sys.add_lib("zorya", (function()
local loaded_mods = {}
loaded_mods.util_tsar = tsar
function zy.loadmod(mod)
if (loaded_mods[mod]) then return loaded_mods[mod] end
for i=1, #mod_search do
@ -67,38 +46,26 @@ sys.add_lib("zorya", (function()
end
end
function zy.loader_run(func, env)
func(env)
end
function zy.add_mod_search(func)
mod_search[#mod_search+1] = func
log(#mod_search)
end
function zy.lkthdn()
return #thd.get_threads()
end
function zy.lkthdi(i)
return thd.get_threads()[i]
end
return zy
end)())
--#include "src/zy-neo/init.lua"
---#include "src/zy-neo/init.lua"
-- Zorya's handler thread.
th_a(function()
thd.add("zyneo", function()
local er
xpcall(function()
local zy = krequire("zorya")
local zy = krq"zorya"
zy.add_mod_search(function(mod)
if (bfs.exists(".zy2/mods/"..mod..".zy2m")) then
utils.debug_log(mod, ".zy2m")
return load_lua(bfs.getfile(".zy2/mods/"..mod..".zy2m"), "=.zy2/mods/"..mod..".zy2m")()
elseif (bfs.exists(".zy2/mods/"..mod.."/init.zy2m")) then
return assert(load_lua(bfs.getfile(".zy2/mods/"..mod.."/init.zy2m"), "=.zy2/mods/"..mod.."/init.zy2m"))()
if (bfs.exists(".zy2/mods/"..mod..".velx")) then
--utils.debug_log(mod, ".zy2m")
--return load_lua(bfs.getfile(".zy2/mods/"..mod..".zy2m"), "=.zy2/mods/"..mod..".zy2m")()
local r,s,c = bfs.getstream(".zy2/mods/"..mod..".velx")
return assert(utils.load_velx(r,s,c,".zy2/mods/"..mod..".velx"))()
end
end)
sys.add_search(function(mod)
@ -107,30 +74,37 @@ th_a(function()
end
end)
sys.add_search(function(mod)
if (bfs.exists(".zy2/lib/"..mod..".zy2l")) then
return load_lua(bfs.getfile(".zy2/lib/"..mod..".zy2l"), "=.zy2/lib/"..mod..".zy2l")
elseif (bfs.exists(".zy2/lib/"..mod.."/init..zy2l")) then
return load_lua(bfs.getfile(".zy2/lib/"..mod.."/init.zy2l"), "=.zy2/lib/"..mod.."/init.zy2l")
if (bfs.exists(".zy2/lib/"..mod..".velx")) then
local r,s,c = bfs.getstream(".zy2/lib/"..mod..".velx")
return utils.load_velx(r,s,c,".zy2/lib/"..mod..".velx")
--return load_lua(bfs.getfile(".zy2/lib/"..mod..".velx"), "=.zy2/lib/"..mod..".zy2l")
end
end)
local zycfg = bfs.getcfg()
-- Config loaded, now we can do our shit.
local env = {
zorya = zy,
loadmod = zy.loadmod,
loadfile = bfs.getfile,
_BOOTADDR = bfs.addr
}
for k, v in pairs(_G) do
env[k] = v
local env = utils.make_env()
env.zorya = zy
env.loadmod = zy.loadmod
env.loadfile = bfs.getfile
env._BOOTADDR = bfs.addr
local c, e = load(zycfg, "=zycfg", "t", env)
if c then
xpcall(function()
return c()
end,
function(e)
er = debug.traceback(e)
utils.console_panic(er)
end)
else
utils.console_panic(e)
end
env._G = env
env._ENV = env
return assert(load(zycfg, "=zycfg", "t", env))()
end, function(e)
er = e..": "..debug.traceback()
utils.console_panic(er)
end)
if er then error(er) end
if er then utils.console_panic(er) end
end)
sys.start()

View File

@ -0,0 +1,12 @@
local cfgadd = ...
local comp = require("component")
for fs in comp.list("filesystem") do
if comp.invoke(fs, "getLabel") == "Plan9k" and comp.invoke(fs, "exists", "init.lua") then
print("Plan9k discovered on "..fs)
cfgadd(string.format([[
menu.add("Plan9k on %s", function()
return loadmod("loader_openos")("%s")
end)
]], fs:sub(1, 3), fs))
end
end

View File

@ -0,0 +1,16 @@
local cfgadd = ...
local comp = require("component")
for fs in comp.list("filesystem") do
if comp.invoke(fs, "exists", ".efi/fuchas.efi2") then
print("Fuchas discovered on "..fs)
cfgadd(string.format([[
menu.add("Fuchas on %s", function()
local baddr = "%s"
local ldr = loadmod("loader_fuchas")(baddr)
ldr:karg("--boot-address", baddr)
ldr:karg("--bios-compat", "zy-neo")
ldr:boot()
end)
]], fs:sub(1, 3), fs))
end
end

View File

@ -0,0 +1,30 @@
local cfgadd = ...
local comp = require("component")
local fs = require("filesystem")
for fs in comp.list("filesystem") do
if comp.invoke(fs, "exists", "OS.lua") then
print("MineOS discovered on "..fs)
cfgadd(string.format([[
menu.add("MineOS on %s", function()
local thd = krequire("thd")
local utils = krequire("utils")
thd.add("mineos", function()
local fsaddr = "%s"
local env = utils.make_env()
function env.computer.getBootAddress()
return fsaddr
end
function env.computer.setBootAddress()end
load(utils.readfile(fsaddr, component.invoke(fsaddr, "open", "OS.lua")), "=OS.lua", "t", env)()
computer.pushSignal("mineos_dead")
end)
while true do
if computer.pullSignal() == "mineos_dead" then
utils.debug_log("Got signal.")
break
end
end
end)
]], fs:sub(1, 3), fs))
end
end

View File

@ -0,0 +1,12 @@
local cfgadd = ...
local component = require("component")
for fs in component.list("filesystem") do
if (component.invoke(fs, "getLabel") == "Monolith" or component.invoke(fs, "exists", "/boot/monolith")) and component.invoke(fs, "exists", "init.lua") then
print("Monolith discovered on " .. fs)
cfgadd(string.format([[
menu.add("Monolith on %s", function()
return loadmod("loader_monolith")("%s")
end)
]], fs:sub(1,3), fs))
end
end

View File

@ -0,0 +1,12 @@
local cfgadd = ...
local component = require("component")
for fs in component.list("filesystem") do
if component.invoke(fs, "exists", "/boot/cynosure.lua") then
print("Cynosure kernel discovered on " .. fs)
cfgadd(string.format([[
menu.add("Cynosure kernel on %s", function()
return loadmod("loader_cynosure")("%s")
end)
]], fs:sub(1,3), fs))
end
end

View File

@ -1,9 +1,6 @@
local cfgadd = ...
local addr = require("component").eeprom.getData()
--local addr = require("component").eeprom.getData()
local fs = require("filesystem")
if not fs.exists("/.zy2/vbios/") then
return
end
cfgadd([[
do
local function add_bios(drive, path)
@ -16,8 +13,10 @@ do
end)
end
]])
for ent in fs.list("/.zy2/vbios") do
cfgadd(string.format([[ add_bios("%s", ".zy2/vbios/%s")]].."\n", addr, ent:sub(1, #ent-1)))
for ent in fs.list("/etc/zorya-neo/vbios/") do
local prox, path = fs.get("/etc/zorya-neo/vbios/"..ent)
local rpath = ("/etc/zorya-neo/vbios/"..ent):sub(#path+1)
cfgadd(string.format([[ add_bios("%s", "%s")]].."\n", prox.address, rpath:sub(1, #rpath-1)))
end
cfgadd[[
end

Some files were not shown because too many files have changed in this diff Show More