1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-27 04:38:06 +11:00

I forgot what I did again.

This commit is contained in:
sam 2020-03-06 07:47:12 -05:00
parent 4559069d08
commit 2a778b976f
9 changed files with 279 additions and 76 deletions

View File

@ -0,0 +1,209 @@
local component = component
local computer = computer
local _component = {}
local proxylist = {}
local proxyobjs = {}
local typelist = {}
local doclist = {}
local oproxy = component.proxy
function _component.proxy(address)
checkArg(1,address,"string")
if proxyobjs[address] ~= nil then
return proxyobjs[address]
end
return oproxy(address)
end
local olist = component.list
function _component.list(filter, exact)
checkArg(1,filter,"string","nil")
local result = {}
local data = {}
for k,v in olist(filter, exact) do
data[#data + 1] = k
data[#data + 1] = v
result[k] = v
end
for k,v in pairs(typelist) do
if filter == nil or (exact and v == filter) or (not exact and v:find(filter, nil, true)) then
data[#data + 1] = k
data[#data + 1] = v
result[k] = v
end
end
local place = 1
return setmetatable(result,
{__call=function()
local addr,type = data[place], data[place + 1]
place = place + 2
return addr, type
end}
)
end
local otype = component.type
function _component.type(address)
checkArg(1,address,"string")
if typelist[address] ~= nil then
return typelist[address]
end
return otype(address)
end
local odoc = component.doc
function _component.doc(address, method)
checkArg(1,address,"string")
checkArg(2,method,"string")
if proxylist[address] ~= nil then
if proxylist[address][method] == nil then
error("no such method",2)
end
if doclist[address] ~= nil then
return doclist[address][method]
end
return nil
end
return odoc(address, method)
end
local oslot = component.slot
function _component.slot(address)
checkArg(1,address,"string")
if proxylist[address] ~= nil then
return -1 -- vcomponents do not exist in a slot
end
return oslot(address)
end
local omethods = component.methods
function _component.methods(address)
checkArg(1,address,"string")
if proxylist[address] ~= nil then
local methods = {}
for k,v in pairs(proxylist[address]) do
if type(v) == "function" then
methods[k] = true -- All vcomponent methods are direct
end
end
return methods
end
return omethods(address)
end
local oinvoke = component.invoke
function _component.invoke(address, method, ...)
checkArg(1,address,"string")
checkArg(2,method,"string")
if proxylist[address] ~= nil then
if proxylist[address][method] == nil then
error("no such method",2)
end
return proxylist[address][method](...)
end
return oinvoke(address, method, ...)
end
local ofields = component.fields
function _component.fields(address)
checkArg(1,address,"string")
if proxylist[address] ~= nil then
return {} -- What even is this?
end
return ofields(address)
end
local componentCallback =
{
__call = function(self, ...) return proxylist[self.address][self.name](...) end,
__tostring = function(self) return (doclist[self.address] ~= nil and doclist[self.address][self.name] ~= nil) and doclist[self.address][self.name] or "function" end
}
local vcomponent = {}
function vcomponent.register(address, ctype, proxy, doc)
checkArg(1,address,"string")
checkArg(2,ctype,"string")
checkArg(3,proxy,"table")
if proxylist[address] ~= nil then
return nil, "component already at address"
elseif component.type(address) ~= nil then
return nil, "cannot register over real component"
end
proxy.address = address
proxy.type = ctype
local proxyobj = {}
for k,v in pairs(proxy) do
if type(v) == "function" then
proxyobj[k] = setmetatable({name=k,address=address},componentCallback)
else
proxyobj[k] = v
end
end
proxylist[address] = proxy
proxyobjs[address] = proxyobj
typelist[address] = ctype
doclist[address] = doc
computer.pushSignal("component_added",address,ctype)
return true
end
function vcomponent.unregister(address)
checkArg(1,address,"string")
if proxylist[address] == nil then
if component.type(address) ~= nil then
return nil, "cannot unregister real component"
else
return nil, "no component at address"
end
end
local thetype = typelist[address]
proxylist[address] = nil
proxyobjs[address] = nil
typelist[address] = nil
doclist[address] = nil
computer.pushSignal("component_removed",address,thetype)
return true
end
function vcomponent.list()
local list = {}
for k,v in pairs(proxylist) do
list[#list + 1] = {k,typelist[k],v}
end
return list
end
function vcomponent.resolve(address, componentType)
checkArg(1, address, "string")
checkArg(2, componentType, "string", "nil")
for k,v in pairs(typelist) do
if componentType == nil or v == componentType then
if k:sub(1, #address) == address then
return k
end
end
end
return nil, "no such component"
end
local r = math.random
function vcomponent.uuid()
return string.format("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
r(0,255),r(0,255),r(0,255),r(0,255),
r(0,255),r(0,255),
r(64,79),r(0,255),
r(128,191),r(0,255),
r(0,255),r(0,255),r(0,255),r(0,255),r(0,255),r(0,255))
end
function vcomponent.install(env)
env.component = {}
for k, v in pairs(_component) do
env.component[k] = v
end
end
return vcomponent

View File

@ -6,6 +6,18 @@ local thd = krequire("thd")
local oefi = zy.loadmod("util_oefiv2") local oefi = zy.loadmod("util_oefiv2")
local fuchas = {} local fuchas = {}
function fuchas:karg(key, value)
self.args[key] = value
end
function fuchas:boot()
thd.add("fuchas", function()
self.env.loadfile("Fuchas/Kernel/boot.lua")() --This is how we do.
computer.pushSignal("fuchas_dead")
end)
while true do if computer.pullSignal() == "fuchas_dead" then break end end
end
return function(addr, args) return function(addr, args)
--oefi.getExtensions().ZyNeo_ExecOEFIApp(addr, ".efi/fuchas.efi2", ...) --oefi.getExtensions().ZyNeo_ExecOEFIApp(addr, ".efi/fuchas.efi2", ...)
--We don't do that here. --We don't do that here.
@ -17,15 +29,3 @@ return function(addr, args)
fuch.env.loadfile = fuch.env.oefi.loadfile fuch.env.loadfile = fuch.env.oefi.loadfile
return setmetatable(fuch, {__index=fuchas}) return setmetatable(fuch, {__index=fuchas})
end end
function fuchas:karg(key, value)
self.args[key] = value
end
function fuchas:boot()
thd.add("fuchas", function()
self.env.loadfile("Fuchas/Kernel/boot.lua")() --This is how we do.
computer.pushSignal("fuchas_dead")
end)
while true do if computer.pullSignal() == "fuchas_dead" then break end end
end

View File

@ -1,5 +1,5 @@
local zy = krequire("zorya") local zy = krequire("zorya")
local vdev = zy.loadmod("util_vcomponent") local vdev = krequire("util_vcomponent")
vdev.register("ZORYA_BIOS", "zybios", { vdev.register("ZORYA_BIOS", "zybios", {
{ {
get_threads_info = function() get_threads_info = function()

View File

@ -1,25 +1,2 @@
--#include "src/lzss.lua" --#include "src/lzss.lua"
local c = component
local gpu = c.proxy(c.list("gpu")())
local screen = c.list("screen")()
gpu.bind(screen)
local w, h = gpu.getResolution()
gpu.setResolution(w, h)
gpu.setBackground(0)
gpu.setForeground(0xFFFFFF)
gpu.fill(1, 1, w, h, " ")
cls = function()gpu.fill(1,1,w,h," ")end
local y = 1
function status(msg)
if gpu and screen then
gpu.set(1, y, msg)
if y == h then
gpu.copy(1, 2, w, h-1, 0, -1)
gpu.fill(1, h, w, 1, " ")
else
y = y + 1
end
end
end
status("Decompressing image...")
return load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua -mluamin 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua")(lzss_decompress) return load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua -mluamin 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua")(lzss_decompress)

View File

@ -1,40 +1 @@
local s, t = string, table local function lzss_decompress(a)local b,c,d,e,f,g,h,i=1,'',''while b<=#a do e=c.byte(a,b)b=b+1;for j=0,7 do h=c.sub;i=h(a,b,b)if e>>j&1<1 and b<#a then g=c.unpack('>I2',a,b)f=1+g>>4;i=h(d,f,f+g&15+2)b=b+1 end;b=b+1;c=c..i;d=h(d..i,-4^6)end end;return c end
local ss = s.sub
--------------------------------------------------------------------------------
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
local function lzss_decompress(input)
local offset, output = 1, {}
local window = ''
while offset <= #input do
local flags = s.byte(input, offset)
offset = offset + 1
for i = 1, 8 do
local str = nil
if (flags & 1) ~= 0 and offset <= #input then
str = ss(input, offset, offset)
offset = offset + 1
elseif offset + 1 <= #input then
local tmp = s.unpack('>I2', input, offset)
offset = offset + 2
local pos = (tmp >> LEN_BITS) + 1
local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN
str = ss(window, pos, pos + len - 1)
end
flags = flags >> 1
if str then
output[#output + 1] = str
window = ss(window .. str, -POS_SIZE)
end
end
end
return t.concat(output)
end

View File

@ -0,0 +1,52 @@
local romfs = {}
local arc = {}
local function readint(r, n)
return string.unpack("<i"..n, r(n))
end
function romfs.read(read, seek, close)
if read(7) ~= "romfs\1\0" then error("Invalid romfs") end
local tbl = {}
local lname
while lname ~= "TRAILER!!!" do
local name = read(readint(read, 1))
local fsize = readint(read, 2)
local exec = read(1)
tbl[#tbl+1] = {name = name, size = size, exec = exec == "x", pos = seek(0)}
seek(fsize)
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: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

@ -48,6 +48,10 @@ sys.add_lib("zorya", (function()
local loaded_mods = {} local loaded_mods = {}
loaded_mods.util_romfs = (function()
--#include "src/zy-neo/builtins/util_romfs.lua"
end)()
function zy.loadmod(mod) function zy.loadmod(mod)
if (loaded_mods[mod]) then return loaded_mods[mod] end if (loaded_mods[mod]) then return loaded_mods[mod] end
for i=1, #mod_search do for i=1, #mod_search do

BIN
test.lua

Binary file not shown.

0
utils/romfs.lua Normal file
View File