From 1ffba2416634f3d92a3004d1ef19a1561fc39b4f Mon Sep 17 00:00:00 2001 From: Sam Roxanne Date: Thu, 18 Jun 2020 14:49:36 -0500 Subject: [PATCH] i split it all up --- .buildactions/31_installer.lua | 10 ++++- installer_dat/lang/en_US.lua | 42 ++++++++++++++++++++- installer_dat/package_list.lua | 1 + lib/fs_arcfs/init.lua | 2 +- lib/util_cpio/init.lua | 20 ++++++++++ lib/util_urf/init.lua | 20 ++++++++++ mods/util_velx/init.lua | 25 ++++++++++++ mods/util_velx/velx.lua | 38 +++++++++++++++++++ src/zy-neo/builtins/init_initramfs/init.lua | 2 +- util/OpenOS/config.d/03_fuchas.lua | 16 ++++++++ util/OpenOS/config.d/04_mineos.lua | 30 +++++++++++++++ util/OpenOS/config.d/99_menu.lua | 3 ++ 12 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 mods/util_velx/init.lua create mode 100644 mods/util_velx/velx.lua create mode 100644 util/OpenOS/config.d/03_fuchas.lua create mode 100644 util/OpenOS/config.d/04_mineos.lua diff --git a/.buildactions/31_installer.lua b/.buildactions/31_installer.lua index a15c3a0..ab1cebc 100644 --- a/.buildactions/31_installer.lua +++ b/.buildactions/31_installer.lua @@ -1,6 +1,14 @@ function actions.installer() os.execute("cp utils/ser.lua pkg/init.lua") - os.execute("cp -r installer_dat pkg") + 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/lang/"..line) + end + h:close() makeselfextract("pkg", "release/zorya-neo-installer.lua") end diff --git a/installer_dat/lang/en_US.lua b/installer_dat/lang/en_US.lua index 4eb7c3f..12c8fa9 100644 --- a/installer_dat/lang/en_US.lua +++ b/installer_dat/lang/en_US.lua @@ -1,3 +1,43 @@ { - + -- 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") + ]] } \ No newline at end of file diff --git a/installer_dat/package_list.lua b/installer_dat/package_list.lua index 7396419..0c14e76 100644 --- a/installer_dat/package_list.lua +++ b/installer_dat/package_list.lua @@ -1,6 +1,7 @@ { {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"}, diff --git a/lib/fs_arcfs/init.lua b/lib/fs_arcfs/init.lua index adab888..2bdf897 100644 --- a/lib/fs_arcfs/init.lua +++ b/lib/fs_arcfs/init.lua @@ -41,7 +41,7 @@ function arcfs.make(arc) end function proxy.size(path) - + return end function proxy.read(hand, count) diff --git a/lib/util_cpio/init.lua b/lib/util_cpio/init.lua index 2567d71..9fc131a 100644 --- a/lib/util_cpio/init.lua +++ b/lib/util_cpio/init.lua @@ -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 \ No newline at end of file diff --git a/lib/util_urf/init.lua b/lib/util_urf/init.lua index 6345813..2d3712d 100644 --- a/lib/util_urf/init.lua +++ b/lib/util_urf/init.lua @@ -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 \ No newline at end of file diff --git a/mods/util_velx/init.lua b/mods/util_velx/init.lua new file mode 100644 index 0000000..bbc8ea0 --- /dev/null +++ b/mods/util_velx/init.lua @@ -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 \ No newline at end of file diff --git a/mods/util_velx/velx.lua b/mods/util_velx/velx.lua new file mode 100644 index 0000000..db2d9ad --- /dev/null +++ b/mods/util_velx/velx.lua @@ -0,0 +1,38 @@ +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" + 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 \ No newline at end of file diff --git a/src/zy-neo/builtins/init_initramfs/init.lua b/src/zy-neo/builtins/init_initramfs/init.lua index eab1e79..b0a3ad7 100644 --- a/src/zy-neo/builtins/init_initramfs/init.lua +++ b/src/zy-neo/builtins/init_initramfs/init.lua @@ -23,7 +23,7 @@ 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, romfs_file) +local rfs = readfile(bootfs.address, romfs_file) --[[local romfs_dev = tsar.read(function(a) local c = "" diff --git a/util/OpenOS/config.d/03_fuchas.lua b/util/OpenOS/config.d/03_fuchas.lua new file mode 100644 index 0000000..f9fbb10 --- /dev/null +++ b/util/OpenOS/config.d/03_fuchas.lua @@ -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 \ No newline at end of file diff --git a/util/OpenOS/config.d/04_mineos.lua b/util/OpenOS/config.d/04_mineos.lua new file mode 100644 index 0000000..d3542c9 --- /dev/null +++ b/util/OpenOS/config.d/04_mineos.lua @@ -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 \ No newline at end of file diff --git a/util/OpenOS/config.d/99_menu.lua b/util/OpenOS/config.d/99_menu.lua index e89b4d8..4850528 100644 --- a/util/OpenOS/config.d/99_menu.lua +++ b/util/OpenOS/config.d/99_menu.lua @@ -1,4 +1,7 @@ local cfgadd = ... cfgadd([[ +menu.add("Lua Console", function() + loadmod("util_luaconsole")() +end) menu.draw() ]]) \ No newline at end of file