1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-13 14:08:07 +11:00
This commit is contained in:
Jane Roxanne 2020-03-11 17:19:08 -05:00
parent 7ea507d2fd
commit 77e542785e
17 changed files with 304 additions and 32 deletions

View File

@ -7,6 +7,9 @@
{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="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"},
@ -14,7 +17,7 @@
--{name="loadfile", cat="loader", path="mods/loader_loadfile.zy2m"},
{name="minitel", cat="net", path="lib/net_minitel.zy2l"},
--{name="vdev", cat="util", path="mods/util_vdev.zy2m"},
{name="menu", cat="menu", path="mods/menu_classic.zy2m"},
{name="classic", cat="menu", path="mods/menu_classic.zy2m"},
--{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

@ -10,4 +10,4 @@ function krequire(pkg)
if (r) then krlib[pkg] = r() return krlib[pkg] end
end
end
local krequire = krequire
local krequire = krequire

View File

@ -49,7 +49,7 @@ local function checkCache(packetID)
end
--local realComputerPullSignal = computer.pullSignal
thd.add(function()
thd.add("minitel_handler", function()
while true do
local eventTab = {computer.pullSignal(0)}
for k,v in pairs(net.hook) do

View File

@ -21,6 +21,7 @@ end
return function(addr, args)
--oefi.getExtensions().ZyNeo_ExecOEFIApp(addr, ".efi/fuchas.efi2", ...)
--We don't do that here.
local fuch = {}
fuch.env = oefi.getExtensions().ZyNeo_GetOEFIEnv(addr)
fuch.env.computer.supportsOEFI = function()
return true

View File

@ -12,6 +12,7 @@ return function(addr)
end
function computer.setBootAddress()end
--log(env, env.computer, env.computer.getBootAddress, env.computer.getBootAddress())
local old_dl = utils.debug_log
load(utils.readfile(fs.address, fs.open("init.lua")), "=init.lua", "t")()
krequire = kr
end

View File

@ -29,31 +29,33 @@ function menu.add(text, func)
end
function menu.draw()
local w, h = gpu.getViewport()
local cls = function()gpu.fill(1,1,w,h," ")end
gpu.setBackground(bg)
gpu.setForeground(fg)
cls()
--Draw some things
local namestr = _BIOS .. " " .. string.format("%.1f.%d %s", _ZVER, _ZPAT, _ZGIT)
gpu.set((w/2)-(#namestr/2), 1, namestr)
gpu.set(1, 2, border_chars[1])
gpu.set(2, 2, border_chars[2]:rep(w-2))
gpu.set(w, 2, border_chars[3])
for i=1, h-6 do
gpu.set(1, i+2, border_chars[4])
gpu.set(w, i+2, border_chars[4])
end
gpu.set(1, h-3, border_chars[5])
gpu.set(2, h-3, border_chars[2]:rep(w-2))
gpu.set(w, h-3, border_chars[6])
gpu.set(1, h-1, "Use ↑ and ↓ keys to select which entry is highlighted.")
gpu.set(1, h, "Use ENTER to boot the selected entry.")
local stime = computer.uptime()
local autosel = true
local ypos = 1
local sel = 1
local function redraw()
local w, h = gpu.getViewport()
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, " ")

View File

@ -0,0 +1,35 @@
local zy = krequire("zorya")
local sys = krequire("sys")
local utils = krequire("utils")
local computer, component = computer, component
local sp = {}
function sp.add_mod_path(drive, path)
local px = component.proxy(drive)
zy.add_mod_search(function(mod)
if (px.exists(path.."/"..mod..".zy2m")) then
local h = px.open(path.."/"..mod..".zy2m", "r")
return utils.load_lua(utils.readfile(drive, h))
elseif (px.exists(path.."/"..mod.."/init.zy2m")) then
local h = px.open(path.."/"..mod.."/init.zy2m", "r")
return utils.load_lua(utils.readfile(drive, h))
end
end)
end
function sp.add_lib_path(drive, path)
local px = component.proxy(drive)
sys.add_search(function(mod)
if (px.exists(path.."/"..mod..".zy2l")) then
local h = px.open(path.."/"..mod..".zy2l", "r")
return utils.load_lua(utils.readfile(drive, h))
elseif (px.exists(path.."/"..mod.."/init.zy2l")) then
local h = px.open(path.."/"..mod.."/init.zy2l", "r")
return utils.load_lua(utils.readfile(drive, h))
end
end)
end
return sp

View File

@ -1,6 +1,6 @@
local zy = krequire("zorya")
local vdev = krequire("util_vcomponent")
vdev.register("ZORYA_BIOS", "zybios", {
vdev.register("ZORYA_BIOS", "zybios",
{
get_threads_info = function()
local threads = {}
@ -8,13 +8,13 @@ vdev.register("ZORYA_BIOS", "zybios", {
local info = zy.lkthdi(i)
threads[i] = {
name = info[1],
deadline = info[6]
deadline = info[4]
}
end
return threads
end,
get_version = function()
return string.format("%f.%d", _ZVER, _ZPAT)
return string.format("%1.1f.%d", _ZVER, _ZPAT)
end,
get_git_revision = function()
return _ZGIT
@ -25,6 +25,6 @@ vdev.register("ZORYA_BIOS", "zybios", {
get_version = "get_version():string -- Returns the Zorya NEO version.",
get_git_revision = "get_git_revision():string -- Returns the git revision of the build."
}
})
)
return true

View File

83
mods/vdev_vbios/init.lua Normal file
View File

@ -0,0 +1,83 @@
local vdev = krequire("util_vcomponent")
local utils = krequire("utils")
local thd = krequire("thd")
local comp = component
local eeprom = {}
local lua_code = [[
--#include "luabios.lua"
]]
local function generate_vbios(f_, path)
local fs = comp.proxy(f_)
if not fs.exists(path) then
fs.makeDirectory(path)
end
if not fs.exists(path.."/code.lua") then
local h = fs.open(path.."/code.lua", "wb")
fs.write(h, lua_code)
fs.close(h)
end
if not fs.exists(path.."/data.bin") then
local h = fs.open(path.."/data.bin", "wb")
fs.write(h, "")
fs.close(h)
end
if not fs.exists(path.."/label.txt") then
local h = fs.open(path.."/label.txt", "wb")
fs.write(h, "Lua BIOS")
fs.close(h)
end
local tbl = {
get = function()
local h = fs.open(path.."/code.lua", "rb")
return utils.readfile(f_, h)
end,
getData = function()
local h = fs.open(path.."/data.bin", "rb")
return utils.readfile(f_, h)
end,
getLabel = function()
local h = fs.open(path.."/label.txt", "rb")
return utils.readfile(f_, h)
end,
set = function(data)
local h = fs.open(path.."/code.lua", "wb")
fs.write(h, data)
fs.close(h)
end,
setData = function(data)
local h = fs.open(path.."/data.bin", "wb")
fs.write(h, data)
fs.close(h)
end,
setLabel = function(label)
local h = fs.open(path.."/label.txt", "wb")
fs.write(h, label:sub(1, 16))
fs.close(h)
end,
getDataSize = function()
return fs.spaceTotal()
end,
getSize = function()
return fs.spaceTotal()
end,
getChecksum = function()
return 0/0
end,
makeReadonly = function()
return
end
}
vdev.register("vdev-ZY_VBIOS", "eeprom", tbl)
local nice = function()
--#include "machine.lua"
end
return nice, tbl
end
return generate_vbios

View File

@ -0,0 +1,64 @@
local init
do
local component_invoke = component.invoke
local function boot_invoke(address, method, ...)
local result = table.pack(pcall(component_invoke, address, method, ...))
if not result[1] then
return nil, result[2]
else
return table.unpack(result, 2, result.n)
end
end
-- backwards compatibility, may remove later
local eeprom = component.list("eeprom")()
computer.getBootAddress = function()
return boot_invoke(eeprom, "getData")
end
computer.setBootAddress = function(address)
return boot_invoke(eeprom, "setData", address)
end
do
local screen = component.list("screen")()
local gpu = component.list("gpu")()
if gpu and screen then
boot_invoke(gpu, "bind", screen)
end
end
local function tryLoadFrom(address)
local handle, reason = boot_invoke(address, "open", "/init.lua")
if not handle then
return nil, reason
end
local buffer = ""
repeat
local data, reason = boot_invoke(address, "read", handle, math.huge)
if not data and reason then
return nil, reason
end
buffer = buffer .. (data or "")
until not data
boot_invoke(address, "close", handle)
return load(buffer, "=init")
end
local reason
if computer.getBootAddress() then
init, reason = tryLoadFrom(computer.getBootAddress())
end
if not init then
computer.setBootAddress()
for address in component.list("filesystem") do
init, reason = tryLoadFrom(address)
if init then
computer.setBootAddress(address)
break
end
end
end
if not init then
error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
end
computer.beep(1000, 0.2)
end
init()

View File

@ -0,0 +1,73 @@
-- This our custom machine.lua
local utils = krequire("utils")
local computer = computer
xpcall(function()
utils.debug_log("Copying env...")
local env = utils.deepcopy(_G)
utils.debug_log("Coppied env.")
env._G = env
env._ENV = env
env.krequire = nil
env._BIOS = nil
env._ZVSTR = nil
env._ZVER = nil
env._ZPAT = nil
env._ZGIT = nil
vdev.install(env)
local _oldlist = env.component.list
local thdid = string.format("%.4x", math.random(0, 2^16-1))
function env.component.list(...)
local ol = _oldlist(...)
local tcall = function()
local a, t = ol()
if (a ~= "vdev-ZY_VBIOS" and t == "eeprom") then
a, t = ol()
end
return a, t
end
for k, v in pairs(ol) do
if (k ~= "vdev-ZY_VBIOS" and v == "eeprom") then
ol[k] = nil
end
end
return setmetatable({}, {__index=ol, __call=tcall})
end
function env.load(code, name, mode, e, ...)
local e = e or env
return load(code, name, mode, e, ...)
end
local ded = false
function env.computer.returnToBios()
local thds = thd.get_threads()
local vbname = "vbios$"..tbl.getLabel().."#"..thdid
for i=1, #thds do
if (thds[i][1] == vbname) then
thds[i][6] = true
end
end
ded = true
utils.debug_log("Returning to BIOS...")
end
utils.debug_log("Loading vBIOS...")
thd.add("vbios$"..tbl.getLabel().."#"..thdid, function()
xpcall(function()
utils.debug_log("Starting BIOS.")
assert(load(tbl.get(), "=vbios", "t", env))()
end, function(err)
utils.debug_log("ERROR", "vBIOS error!")
utils.debug_log(err, debug.traceback())
end)
utils.debug_log("Sending signal.")
computer.pushSignal("vbios_dead")
end)
while true do
if computer.pullSignal() == "vbios_dead" then
utils.debug_log("Got signal.")
break
end
end
utils.debug_log("Dead.")
end, function(err)
utils.debug_log("ERROR", "vBIOS error!")
utils.debug_log(err, debug.traceback())
end)

2
mods/vfs/init.lua Normal file
View File

@ -0,0 +1,2 @@
local component, computer = component, computer
local vfs = {}

View File

@ -22,14 +22,14 @@ status("\n\nBuilding modules.")
if (os.execute("stat mods 1>/dev/null 2>&1")) then
for l in io.popen("ls mods"):lines() do
status("MOD\t"..l)
os.execute("zsh -c 'cd mods/"..l.."; luacomp init.lua -mluamin | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
os.execute("zsh -c 'cd mods/"..l.."; luacomp init.lua | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
end
end
status("Module build complete.\n\nBuilding libraries.")
if (os.execute("stat lib 1>/dev/null 2>&1")) then
for l in io.popen("ls lib"):lines() do
status("LIB\t"..l)
os.execute("zsh -c 'cd lib/"..l.."; luacomp init.lua -mluamin | lua ../../utils/zlua.lua > ../../pkg/lib/"..l..".zy2l'")
os.execute("zsh -c 'cd lib/"..l.."; luacomp init.lua | lua ../../utils/zlua.lua > ../../pkg/lib/"..l..".zy2l'")
end
end
status("Library build complete.\n\nBuilding installer...")

View File

@ -24,7 +24,14 @@ assert(bootfs.exists(".zy2/image.romfs"), "No boot image!")
local romfs_file = assert(bootfs.open(".zy2/image.romfs", "rb"))
local romfs_dev = romfs.read(function(a)
return bootfs.read(romfs_file, 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()

View File

@ -57,4 +57,5 @@ function utils.deepcopy(src, dest)
end
return dest
end
builtins.utils = function() return utils end

View File

@ -72,11 +72,11 @@ sys.add_lib("zorya", (function()
end
function zy.lkthdn()
return #thd.getthreads()
return #thd.get_threads()
end
function zy.lkthdi(i)
return thd.getthreads()[i][1]
return thd.get_threads()[i]
end
return zy
end)())
@ -93,7 +93,7 @@ th_a(function()
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 load_lua(bfs.getfile(".zy2/mods/"..mod.."/init.zy2m"), "=.zy2/mods/"..mod.."/init.zy2m")()
return assert(load_lua(bfs.getfile(".zy2/mods/"..mod.."/init.zy2m"), "=.zy2/mods/"..mod.."/init.zy2m"))()
end
end)
sys.add_search(function(mod)