mirror of
https://github.com/Adorable-Catgirl/Zorya-NEO.git
synced 2024-11-23 10:48:06 +11:00
Oh yeah, big stuff.
This commit is contained in:
commit
4d4be905c1
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
pkg/**
|
||||
debug.lua
|
||||
luapreproc.lua
|
||||
zorya-neo-installer.lua
|
||||
bsrc/**
|
31
Makefile
Normal file
31
Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
6
installer_dat/bios_list.lua
Normal file
6
installer_dat/bios_list.lua
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
{type="managed", path="bios/managed.bios"},
|
||||
--{type="osdi", path="bios/osdi.bios"},
|
||||
--{type="romfs", path="bios/romfs.bios"},
|
||||
--{type="proxfs", path="bios/proxfs.bios"}
|
||||
}
|
34
installer_dat/lang/en_US.lua
Normal file
34
installer_dat/lang/en_US.lua
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
["bios_managed_name"] = "Standard Zorya BIOS",
|
||||
["bios_managed_desc"] = "Zorya BIOS boots off of a managed drive.",
|
||||
["bios_osdi_name"] = "OSDI Zorya BIOS",
|
||||
["bios_osdi_desc"] = "Zorya BIOS boots off of an OSDI BOOTCODE partition.",
|
||||
["bios_romfs_name"] = "ROMFS Zorya BIOS",
|
||||
["bios_romfs_desc"] = "Zorya BIOS boots off of a ROMFS formatted EEPROM card.",
|
||||
["bios_proxfs_name"] = "ProximaFS Zorya BIOS",
|
||||
["bios_proxfs_desc"] = "placeholder",
|
||||
["mod_util_zlan_name"] = "Zorya LAN",
|
||||
["mod_util_zlan_desc"] = "Provides the ability to use the Zorya LAN Boot (zlan) protocol.",
|
||||
["mod_loader_openos_name"] = "OpenOS",
|
||||
["mod_loader_openos_desc"] = "Provides a utility to allow for BIOS threads to work while using OpenOS.",
|
||||
["mod_loader_tsuki_name"] = "Tsuki",
|
||||
["mod_loader_tsuki_desc"] = "Allows for easier loading of the Tsuki kernel.",
|
||||
["mod_util_romfs_name"] = "ROMFS",
|
||||
["mod_util_romfs_desc"] = "Allows loading romfs files",
|
||||
["mod_util_cpio_name"] = "cpio",
|
||||
["mod_util_cpio_desc"] = "Allows the reading of CPIO archives",
|
||||
["mod_util_frequest_name"] = "frequest",
|
||||
["mod_util_frequest_desc"] = "Allows fetching of files over frequest.",
|
||||
["mod_net_minitel_name"] = "Minitel",
|
||||
["mod_net_minitel_desc"] = "Allows use of Minitel in Zorya.",
|
||||
["mod_util_vdev_name"] = "vdev",
|
||||
["mod_util_vdev_desc"] = "Allows for the creation of virtual devices.",
|
||||
["mod_rtmod_vdevrt_name"] = "vdev",
|
||||
["mod_rtmod_vdevrt_desc"] = "rtmod version of vdev",
|
||||
["cat_bios"] = "BIOS",
|
||||
["cat_util"] = "Utilities",
|
||||
["cat_loader"] = "Loaders",
|
||||
["cat_rtmod"] = "Runtime modifiers",
|
||||
["cat_net"] = "Networking",
|
||||
["cat_vdev"] = "Virtual Devices"
|
||||
}
|
18
installer_dat/package_list.lua
Normal file
18
installer_dat/package_list.lua
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
{name="zlan", cat="util", path="lib/util_zlan.zy2l"},
|
||||
--{name="openos", cat="loader", path="mods/loader_openos.zy2m"},
|
||||
--{name="tsuki", cat="loader", path="mods/loader_tsuki.zy2m"},
|
||||
--{name="romfs", cat="util", path="mods/util_romfs.zy2m"},
|
||||
--{name="cpio", cat="util", path="mods/util_cpio.zy2m"},
|
||||
--{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="vdev", cat="util", path="mods/util_vdev.zy2m"},
|
||||
{name="menu", 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"},
|
||||
--{name="zflash", cat="rtmod", path="mods/rtmod_zflash.zy2m", warning="warn_mod_zflash"},
|
||||
--{name="bioscomp", cat="vdev", path="mods/vdev_bioscomp.zy2m"},
|
||||
--{name="luadata", cat="vdev", path="mods/vdev_luadata.zy2m"}
|
||||
}
|
45
ksrc/kinit.lua
Normal file
45
ksrc/kinit.lua
Normal file
@ -0,0 +1,45 @@
|
||||
-- lkern is the light kernel used by Zorya NEO to simplify development.
|
||||
@[[local lfs = require("lfs")]]
|
||||
--#include "ksrc/require.lua"
|
||||
@[[function lib_include(name)]]
|
||||
krlib["@[{name}]"] = (function()
|
||||
@[[call_directive("kinit.lua:10","include","ksrc/libs/"..name..".lua")]]
|
||||
end)()
|
||||
@[[end]]
|
||||
|
||||
@[[for ent in lfs.dir("ksrc/libs") do
|
||||
if (ent:match("%.lua$")) then
|
||||
lib_include(ent:sub(1, #ent-4))
|
||||
end
|
||||
end]]
|
||||
|
||||
local ps = computer.pullSignal
|
||||
local thd = krequire("thd")
|
||||
local last_sig = {}
|
||||
krlib["system"] = (function()
|
||||
local sys = {}
|
||||
function sys.start()
|
||||
while thd.run() do end
|
||||
end
|
||||
local prun_i = 0
|
||||
function sys.protected_run(code, name)
|
||||
name = name or "lkprc$"..prun_i
|
||||
--Spin up a new thread
|
||||
local env = {}
|
||||
for k, v in pairs(_G) do
|
||||
env[k] = v
|
||||
end
|
||||
env._ENV = env
|
||||
env._G = env
|
||||
env.krequire = nil
|
||||
thd.add(name, assert(load(code, "="..name, "t", env)))
|
||||
end
|
||||
function sys.add_lib(lib, tbl)
|
||||
krlib[lib] = tbl
|
||||
end
|
||||
function sys.add_search(search)
|
||||
krfind[#krfind+1] = search
|
||||
end
|
||||
return sys
|
||||
end)()
|
||||
krlib["sys"] = krlib["system"]
|
91
ksrc/libs/thd.lua
Normal file
91
ksrc/libs/thd.lua
Normal file
@ -0,0 +1,91 @@
|
||||
local thd = {}
|
||||
|
||||
local threads = {}
|
||||
|
||||
local idx = 1
|
||||
|
||||
local computer = computer
|
||||
local unpack = unpack or table.unpack
|
||||
local coroutine = coroutine
|
||||
local c_create = coroutine.create
|
||||
local c_yield = coroutine.yield
|
||||
local c_resume = coroutine.resume
|
||||
local c_status = coroutine.status
|
||||
|
||||
function thd.add(name, func)
|
||||
local t = assert(c_create(func))
|
||||
--component.proxy(component.list("sandbox")()).debug_log(name, t, func)
|
||||
threads[#threads+1] = {name, t, {}, 0, ".+"}
|
||||
threads[t] = threads[#threads]
|
||||
end
|
||||
|
||||
local sigs = {}
|
||||
local ps = computer.pullSignal
|
||||
function thd.autosleep()
|
||||
local msleep = math.huge
|
||||
for i=1, #threads do
|
||||
if (threads[i][4] and threads[i][4] < msleep) then
|
||||
msleep = threads[i][4]
|
||||
end
|
||||
end
|
||||
local rsleep = msleep-computer.uptime()
|
||||
if (rsleep < 0 or #sigs > 0) then
|
||||
rsleep = 0
|
||||
end
|
||||
local sig = {ps(rsleep)}
|
||||
if (#sigs > 0) then
|
||||
if (#sig > 0) then
|
||||
sigs[#sigs+1] = sig
|
||||
end
|
||||
sig = sigs[1]
|
||||
table.remove(sigs, 1)
|
||||
end
|
||||
return sig
|
||||
end
|
||||
|
||||
local last_sig = {}
|
||||
|
||||
function thd.run()
|
||||
last_sig = thd.autosleep()
|
||||
for i=1, #threads do
|
||||
if (threads[i][4] <= computer.uptime() or #last_sig > 0) then
|
||||
if (c_status(threads[i][2]) ~= "running") then
|
||||
local er, dl = c_resume(threads[i][2], unpack(last_sig))
|
||||
if (not er) then error(threads[i][1]..": "..dl) end
|
||||
dl = computer.uptime() + (dl or math.huge)
|
||||
threads[i][4] = dl
|
||||
sigs[#sigs+1] = {ps(0)}
|
||||
end
|
||||
end
|
||||
end
|
||||
local t = {}
|
||||
for k,v in pairs(threads) do
|
||||
if (c_status(v[2]) ~= "dead" and not v[6]) then
|
||||
if (type(k) == "number") then
|
||||
t[#t+1] = v
|
||||
else
|
||||
t[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
threads = t
|
||||
return #threads > 0
|
||||
end
|
||||
|
||||
function thd.kill(i)
|
||||
threads[i][6] = true
|
||||
end
|
||||
|
||||
function thd.sched_end()
|
||||
return #threads == idx
|
||||
end
|
||||
|
||||
function thd.get_threads()
|
||||
return threads
|
||||
end
|
||||
|
||||
function computer.pullSignal(t)
|
||||
return c_yield(t)
|
||||
end
|
||||
|
||||
return thd
|
13
ksrc/require.lua
Normal file
13
ksrc/require.lua
Normal file
@ -0,0 +1,13 @@
|
||||
local kpkg = {}
|
||||
kpkg.libs = {}
|
||||
local krlib = kpkg.libs
|
||||
kpkg.search = {}
|
||||
local krfind = kpkg.search
|
||||
function krequire(pkg)
|
||||
if (krlib[pkg]) then return krlib[pkg] end
|
||||
for i=1, #krfind do
|
||||
local r = krfind[i](pkg)
|
||||
if (r) then krlib[pkg] = r() return krlib[pkg] end
|
||||
end
|
||||
end
|
||||
local krequire = krequire
|
2
lib/net_minitel/README.md
Normal file
2
lib/net_minitel/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# lib_net_minitel
|
||||
Microtel with tweaks.
|
8
lib/net_minitel/init.lua
Normal file
8
lib/net_minitel/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local component = component
|
||||
local computer = computer
|
||||
--#include "microtel/microtel-3.lua"
|
||||
--#include "microtel/microtel-4.lua"
|
||||
--#include "microtel/microtel-5-core.lua"
|
||||
--#include "microtel/microtel-5-open.lua"
|
||||
--#include "microtel/microtel-5-listen.lua"
|
||||
return net
|
82
lib/net_minitel/microtel/microtel-3-mini.lua
Normal file
82
lib/net_minitel/microtel/microtel-3-mini.lua
Normal file
@ -0,0 +1,82 @@
|
||||
_G.net={}
|
||||
do
|
||||
local M,pQ,pC,rC,C,Y={},{},{},{},computer,table.unpack
|
||||
net.port,net.hostname,net.route,net.hook,U=4096,C.address():sub(1,8),true,{},C.uptime
|
||||
for a in component.list("modem") do
|
||||
M[a]=component.proxy(a)
|
||||
M[a].open(net.port)
|
||||
end
|
||||
local function gP()
|
||||
local pID=""
|
||||
for i=1,16 do
|
||||
pID=pID .. string.char(math.random(32,126))
|
||||
end
|
||||
return pID
|
||||
end
|
||||
local function rS(pID,pT,T,from,vP,D)
|
||||
if rC[T] then
|
||||
M[rC[T][1]].send(rC[T][2],net.port,pID,pT,T,from,vP,D)
|
||||
else
|
||||
for k,v in pairs(M) do
|
||||
v.broadcast(net.port,pID,pT,T,from,vP,D)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function sP(pID,pT,T,vP,D)
|
||||
pC[pID]=U()
|
||||
rS(pID,pT,T,net.hostname,vP,D)
|
||||
end
|
||||
function net.send(T,vP,D,pT,pID)
|
||||
pT,pID=pT or 1,pID or gP()
|
||||
pQ[pID]={pT,T,vP,D,0}
|
||||
sP(pID,pT,T,vP,D)
|
||||
end
|
||||
local function cC(pID)
|
||||
for k,v in pairs(pC) do
|
||||
if k==pID then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
local rCPE=C.pullSignal
|
||||
function C.pullSignal(t)
|
||||
local Z={rCPE(t)}
|
||||
for k,v in pairs(net.hook) do
|
||||
pcall(v,Y(Z))
|
||||
end
|
||||
for k,v in pairs(pC) do
|
||||
if U()>v+30 then
|
||||
pC[k]=nil
|
||||
end
|
||||
end
|
||||
for k,v in pairs(rC) do
|
||||
if U()>v[3]+30 then
|
||||
rC[k]=nil
|
||||
end
|
||||
end
|
||||
if Z[1]=="modem_message" and (Z[4]==net.port or Z[4]==0) and cC(Z[6]) then
|
||||
rC[Z[9]]={Z[2],Z[3],U()}
|
||||
if Z[8]==net.hostname then
|
||||
if Z[7]~=2 then
|
||||
C.pushSignal("net_msg",Z[9],Z[10],Z[11])
|
||||
if Z[7]==1 then
|
||||
sP(gP(),2,Z[9],Z[10],Z[6])
|
||||
end
|
||||
else
|
||||
pQ[Z[11]]=nil
|
||||
end
|
||||
elseif net.route and cC(Z[6]) then
|
||||
rS(Z[6],Z[7],Z[8],Z[9],Z[10],Z[11])
|
||||
end
|
||||
pC[Z[6]]=U()
|
||||
end
|
||||
for k,v in pairs(pQ) do
|
||||
if U()>v[5] then
|
||||
sP(k,Y(v))
|
||||
v[5]=U()+30
|
||||
end
|
||||
end
|
||||
return Y(Z)
|
||||
end
|
||||
end
|
93
lib/net_minitel/microtel/microtel-3.lua
Normal file
93
lib/net_minitel/microtel/microtel-3.lua
Normal file
@ -0,0 +1,93 @@
|
||||
local thd = krequire("thd")
|
||||
local net={}
|
||||
|
||||
do
|
||||
local modems,packetQueue,packetCache,routeCache,C,Y = {},{},{},{},COMPUTER,UNPACK
|
||||
net.port,net.hostname,net.route,net.hook,U=4096,computer.address():sub(1,8),true,{},UPTIME
|
||||
|
||||
for a in component.list("modem") do
|
||||
modems[a] = component.proxy(a)
|
||||
modems[a].open(net.port)
|
||||
end
|
||||
|
||||
local function genPacketID()
|
||||
local packetID = ""
|
||||
for i = 1, 16 do
|
||||
packetID = packetID .. string.char(math.random(32,126))
|
||||
end
|
||||
return packetID
|
||||
end
|
||||
|
||||
local function rawSendPacket(packetID,packetType,to,from,vport,data)
|
||||
if routeCache[to] then
|
||||
modems[routeCache[to][1]].send(routeCache[to][2],net.port,packetID,packetType,to,from,vport,data)
|
||||
else
|
||||
for k,v in pairs(modems) do
|
||||
v.broadcast(net.port,packetID,packetType,to,from,vport,data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function sendPacket(packetID,packetType,to,vport,data)
|
||||
packetCache[packetID] = computer.uptime()
|
||||
rawSendPacket(packetID,packetType,to,net.hostname,vport,data)
|
||||
end
|
||||
|
||||
function net.send(to,vport,data,packetType,packetID)
|
||||
packetType,packetID = packetType or 1, packetID or genPacketID()
|
||||
packetQueue[packetID] = {packetType,to,vport,data,0}
|
||||
sendPacket(packetID,packetType,to,vport,data)
|
||||
end
|
||||
|
||||
local function checkCache(packetID)
|
||||
for k,v in pairs(packetCache) do
|
||||
if k == packetID then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--local realComputerPullSignal = computer.pullSignal
|
||||
thd.add(function()
|
||||
while true do
|
||||
local eventTab = {computer.pullSignal(0)}
|
||||
for k,v in pairs(net.hook) do
|
||||
pcall(v,table.unpack(eventTab))
|
||||
end
|
||||
for k,v in pairs(packetCache) do
|
||||
if computer.uptime() > v+30 then
|
||||
packetCache[k] = nil
|
||||
end
|
||||
end
|
||||
for k,v in pairs(routeCache) do
|
||||
if computer.uptime() > v[3]+30 then
|
||||
routeCache[k] = nil
|
||||
end
|
||||
end
|
||||
if eventTab[1] == "modem_message" and (eventTab[4] == net.port or eventTab[4] == 0) and checkCache(eventTab[6]) then
|
||||
routeCache[eventTab[9]] = {eventTab[2],eventTab[3],computer.uptime()}
|
||||
if eventTab[8] == net.hostname then
|
||||
if eventTab[7] ~= 2 then
|
||||
computer.pushSignal("net_msg",eventTab[9],eventTab[10],eventTab[11])
|
||||
if eventTab[7] == 1 then
|
||||
sendPacket(genPacketID(),2,eventTab[9],eventTab[10],eventTab[6])
|
||||
end
|
||||
else
|
||||
packetQueue[eventTab[11]] = nil
|
||||
end
|
||||
elseif net.route and checkCache(eventTab[6]) then
|
||||
rawSendPacket(eventTab[6],eventTab[7],eventTab[8],eventTab[9],eventTab[10],eventTab[11])
|
||||
end
|
||||
packetCache[eventTab[6]] = computer.uptime()
|
||||
end
|
||||
for k,v in pairs(packetQueue) do
|
||||
if computer.uptime() > v[5] then
|
||||
sendPacket(k,table.unpack(v))
|
||||
v[5]=computer.uptime()+30
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
end
|
24
lib/net_minitel/microtel/microtel-3.lua.min
Normal file
24
lib/net_minitel/microtel/microtel-3.lua.min
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
{"eventTab","Z"},
|
||||
{"modems","M"},
|
||||
{"qPacket","A"},
|
||||
{"packetID","B"},
|
||||
{"packetType","E"},
|
||||
{"to","T"},
|
||||
{"vport","F"},
|
||||
{"data","D"},
|
||||
{"rawSendPacket","G"},
|
||||
{"sendPacket","I"},
|
||||
{"genPacketID","J"},
|
||||
{"packetCache","L"},
|
||||
{"checkCache","N"},
|
||||
{"routeCache","O"},
|
||||
{"realComputerPullSignal","X"},
|
||||
{"packetQueue","P"},
|
||||
{"computer","C"},
|
||||
{"C.uptime","U"},
|
||||
{"table.unpack","Y"},
|
||||
{"COMPUTER","computer"},
|
||||
{"UPTIME","C.uptime"},
|
||||
{"UNPACK","table.unpack"},
|
||||
}
|
24
lib/net_minitel/microtel/microtel-3.lua.min-old
Normal file
24
lib/net_minitel/microtel/microtel-3.lua.min-old
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
{"eventTab","Z"},
|
||||
{"modems","M"},
|
||||
{"qPacket","qP"},
|
||||
{"packetID","pID"},
|
||||
{"packetType","pT"},
|
||||
{"to","T"},
|
||||
{"vport","vP"},
|
||||
{"data","D"},
|
||||
{"rawSendPacket","rS"},
|
||||
{"sendPacket","sP"},
|
||||
{"genPacketID","gP"},
|
||||
{"packetCache","pC"},
|
||||
{"checkCache","cC"},
|
||||
{"routeCache","rC"},
|
||||
{"realComputerPullSignal","rCPE"},
|
||||
{"packetQueue","pQ"},
|
||||
{"computer","C"},
|
||||
{"C.uptime","U"},
|
||||
{"table.unpack","Y"},
|
||||
{"COMPUTER","computer"},
|
||||
{"UPTIME","C.uptime"},
|
||||
{"UNPACK","table.unpack"},
|
||||
}
|
11
lib/net_minitel/microtel/microtel-4-mini.lua
Normal file
11
lib/net_minitel/microtel/microtel-4-mini.lua
Normal file
@ -0,0 +1,11 @@
|
||||
net.mtu=4096
|
||||
function net.lsend(T,P,L)
|
||||
local D={}
|
||||
for i=1,L:len(),net.mtu do
|
||||
D[#D+1]=L:sub(1,net.mtu)
|
||||
L=L:sub(net.mtu+1)
|
||||
end
|
||||
for k,v in ipairs(D) do
|
||||
net.send(T,P,v)
|
||||
end
|
||||
end
|
11
lib/net_minitel/microtel/microtel-4.lua
Normal file
11
lib/net_minitel/microtel/microtel-4.lua
Normal file
@ -0,0 +1,11 @@
|
||||
net.mtu = 4096
|
||||
function net.lsend(to,vport,ldata)
|
||||
local tdata = {}
|
||||
for i = 1, ldata:len(), net.mtu do
|
||||
tdata[#tdata+1] = ldata:sub(1,net.mtu)
|
||||
ldata = ldata:sub(net.mtu+1)
|
||||
end
|
||||
for k,v in ipairs(tdata) do
|
||||
net.send(to,vport,v)
|
||||
end
|
||||
end
|
6
lib/net_minitel/microtel/microtel-4.lua.min
Normal file
6
lib/net_minitel/microtel/microtel-4.lua.min
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
{"to","T"},
|
||||
{"vport","P"},
|
||||
{"ldata","L"},
|
||||
{"tdata","D"},
|
||||
}
|
27
lib/net_minitel/microtel/microtel-5-core-mini.lua
Normal file
27
lib/net_minitel/microtel/microtel-5-core-mini.lua
Normal file
@ -0,0 +1,27 @@
|
||||
function net.socket(A,P,S)
|
||||
local C,rb={},""
|
||||
C.s,C.b,C.P,C.A="o","",tonumber(P),A
|
||||
function C.r(self,l)
|
||||
rb=self.buffer:sub(1,l)
|
||||
self.buffer=self.buffer:sub(l+1)
|
||||
return rb
|
||||
end
|
||||
function C.w(self,D)
|
||||
net.lsend(self.A,self.P,D)
|
||||
end
|
||||
function C.c(s)
|
||||
net.send(C.A,C.P,S)
|
||||
end
|
||||
function h(E,F,P,D)
|
||||
if F==C.A and P==C.P then
|
||||
if D==S then
|
||||
net.hook[S]=nil
|
||||
C.s="c"
|
||||
return
|
||||
end
|
||||
C.b=C.b..D
|
||||
end
|
||||
end
|
||||
net.hook[S]=h
|
||||
return C
|
||||
end
|
27
lib/net_minitel/microtel/microtel-5-core.lua
Normal file
27
lib/net_minitel/microtel/microtel-5-core.lua
Normal file
@ -0,0 +1,27 @@
|
||||
function net.socket(address, port, sclose)
|
||||
local conn, rb = {}, ""
|
||||
conn.state, conn.buffer, conn.port, conn.address = "o", "", tonumber(port), address
|
||||
function conn.r(self,l)
|
||||
rb=self.buffer:sub(1,l)
|
||||
self.buffer=self.buffer:sub(l+1)
|
||||
return rb
|
||||
end
|
||||
function conn.w(self,data)
|
||||
net.lsend(self.address,self.port,data)
|
||||
end
|
||||
function conn.c(s)
|
||||
net.send(conn.address,conn.port,sclose)
|
||||
end
|
||||
function h(etype, from, port, data)
|
||||
if from == conn.address and port == conn.port then
|
||||
if data == sclose then
|
||||
net.hook[sclose] = nil
|
||||
conn.state = "c"
|
||||
return
|
||||
end
|
||||
conn.buffer = conn.buffer..data
|
||||
end
|
||||
end
|
||||
net.hook[sclose] = h
|
||||
return conn
|
||||
end
|
15
lib/net_minitel/microtel/microtel-5-core.lua.min
Normal file
15
lib/net_minitel/microtel/microtel-5-core.lua.min
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
{"address","A"},
|
||||
{"vport","V"},
|
||||
{"sclose","S"},
|
||||
{"port","P"},
|
||||
{"conn.state","conn.s"},
|
||||
{"conn.buffer","conn.b"},
|
||||
{"self.buffer","self.b"},
|
||||
{"self.state","self.s"},
|
||||
{"self","s"},
|
||||
{"conn","C"},
|
||||
{"etype","E"},
|
||||
{"from","F"},
|
||||
{"data","D"},
|
||||
}
|
11
lib/net_minitel/microtel/microtel-5-flisten-mini.lua
Normal file
11
lib/net_minitel/microtel/microtel-5-flisten-mini.lua
Normal file
@ -0,0 +1,11 @@
|
||||
function net.flisten(V,handler)
|
||||
local function h(E,F,P,D)
|
||||
if P==V and D=="openstream" then
|
||||
local nP,S=math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(F,P,tostring(nP))
|
||||
net.send(F,nP,S)
|
||||
handler(net.socket(F,nP,S))
|
||||
end
|
||||
end
|
||||
net.hook[V]=h
|
||||
end
|
11
lib/net_minitel/microtel/microtel-5-flisten.lua
Normal file
11
lib/net_minitel/microtel/microtel-5-flisten.lua
Normal file
@ -0,0 +1,11 @@
|
||||
function net.flisten(vport,handler)
|
||||
local function h(etype,from,port,data)
|
||||
if port == vport and data == "openstream" then
|
||||
local nport,sclose = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(from,port,tostring(nport))
|
||||
net.send(from,nport,sclose)
|
||||
handler(net.socket(from,nport,sclose))
|
||||
end
|
||||
end
|
||||
net.hook[vport] = h
|
||||
end
|
12
lib/net_minitel/microtel/microtel-5-flisten.lua.min
Normal file
12
lib/net_minitel/microtel/microtel-5-flisten.lua.min
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
{"address","A"},
|
||||
{"vport","V"},
|
||||
{"sclose","S"},
|
||||
{"port","P"},
|
||||
{"conn.state","conn.s"},
|
||||
{"conn.buffer","conn.b"},
|
||||
{"conn","C"},
|
||||
{"etype","E"},
|
||||
{"from","F"},
|
||||
{"data","D"},
|
||||
}
|
10
lib/net_minitel/microtel/microtel-5-listen-mini.lua
Normal file
10
lib/net_minitel/microtel/microtel-5-listen-mini.lua
Normal file
@ -0,0 +1,10 @@
|
||||
function net.listen(V)
|
||||
local F,P,D
|
||||
repeat
|
||||
_,F,P,D=computer.pullSignal(0.5)
|
||||
until P==V and D=="openstream"
|
||||
local nP,S=math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(F,P,tostring(nP))
|
||||
net.send(F,nP,S)
|
||||
return net.socket(F,nP,S)
|
||||
end
|
10
lib/net_minitel/microtel/microtel-5-listen.lua
Normal file
10
lib/net_minitel/microtel/microtel-5-listen.lua
Normal file
@ -0,0 +1,10 @@
|
||||
function net.listen(vport)
|
||||
local from,port,data
|
||||
repeat
|
||||
_, from, port, data = computer.pullSignal(0.5)
|
||||
until port == vport and data == "openstream"
|
||||
local nport,sclose = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(from,port,tostring(nport))
|
||||
net.send(from,nport,sclose)
|
||||
return net.socket(from,nport,sclose)
|
||||
end
|
12
lib/net_minitel/microtel/microtel-5-listen.lua.min
Normal file
12
lib/net_minitel/microtel/microtel-5-listen.lua.min
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
{"address","A"},
|
||||
{"vport","V"},
|
||||
{"sclose","S"},
|
||||
{"port","P"},
|
||||
{"conn.state","conn.s"},
|
||||
{"conn.buffer","conn.b"},
|
||||
{"conn","C"},
|
||||
{"etype","E"},
|
||||
{"from","F"},
|
||||
{"data","D"},
|
||||
}
|
14
lib/net_minitel/microtel/microtel-5-open-mini.lua
Normal file
14
lib/net_minitel/microtel/microtel-5-open-mini.lua
Normal file
@ -0,0 +1,14 @@
|
||||
net.timeout=60
|
||||
function net.open(A,V)
|
||||
local st,F,P,D=computer.uptime()
|
||||
net.send(A,V,"openstream")
|
||||
repeat
|
||||
_,F,P,D=computer.pullSignal(0.5)
|
||||
if computer.uptime()>st+net.timeout then return false end
|
||||
until F==A and P==V and tonumber(D)
|
||||
V=tonumber(D)
|
||||
repeat
|
||||
_,F,P,D=computer.pullSignal(0.5)
|
||||
until F==A and P==V
|
||||
return net.socket(A,V,D)
|
||||
end
|
14
lib/net_minitel/microtel/microtel-5-open.lua
Normal file
14
lib/net_minitel/microtel/microtel-5-open.lua
Normal file
@ -0,0 +1,14 @@
|
||||
net.timeout = 60
|
||||
function net.open(address,vport)
|
||||
local st,from,port,data=computer.uptime()
|
||||
net.send(address,vport,"openstream")
|
||||
repeat
|
||||
_, from, port, data = computer.pullSignal(0.5)
|
||||
if computer.uptime() > st+net.timeout then return false end
|
||||
until from == address and port == vport and tonumber(data)
|
||||
vport=tonumber(data)
|
||||
repeat
|
||||
_, from, port, data = computer.pullSignal(0.5)
|
||||
until from == address and port == vport
|
||||
return net.socket(address,vport,data)
|
||||
end
|
12
lib/net_minitel/microtel/microtel-5-open.lua.min
Normal file
12
lib/net_minitel/microtel/microtel-5-open.lua.min
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
{"address","A"},
|
||||
{"vport","V"},
|
||||
{"sclose","S"},
|
||||
{"port","P"},
|
||||
{"conn.state","conn.s"},
|
||||
{"conn.buffer","conn.b"},
|
||||
{"conn","C"},
|
||||
{"etype","E"},
|
||||
{"from","F"},
|
||||
{"data","D"},
|
||||
}
|
0
lib/util_cpio/init.lua
Normal file
0
lib/util_cpio/init.lua
Normal file
0
lib/util_romfs/init.lua
Normal file
0
lib/util_romfs/init.lua
Normal file
22
lib/util_urf/init.lua
Normal file
22
lib/util_urf/init.lua
Normal file
@ -0,0 +1,22 @@
|
||||
-- P A I N
|
||||
|
||||
local flag_crit = 1 << 6
|
||||
local flag_required = 1 << 7
|
||||
local flag_ext = 1 << 8
|
||||
|
||||
local function read_ali(fs, h)
|
||||
local tmp = 0
|
||||
local ctr = 0
|
||||
while true do
|
||||
local b = fs.read(h, 1):byte()
|
||||
tmp = tmp | ((b & 0x7F) << (ctr*7))
|
||||
if (b & 0x80 > 0) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return tmp
|
||||
end
|
||||
|
||||
local function read_entrydat(fs, h)
|
||||
local etype = fs.read(h, 1):byte()
|
||||
end
|
46
lib/util_zlan/init.lua
Normal file
46
lib/util_zlan/init.lua
Normal file
@ -0,0 +1,46 @@
|
||||
local component = component
|
||||
local computer = computer
|
||||
|
||||
local mt = krequire("net_minitel")
|
||||
|
||||
local zlan = {}
|
||||
--#include "pack.lua"
|
||||
function zlan.exists(host, file)
|
||||
local sock = net.open(host, 9900)
|
||||
sock:w(string.char(2, 1, #file)..file.."x")
|
||||
local dat = recv_full_pack(sock)
|
||||
sock:c()
|
||||
return dat and dat:byte() > 0
|
||||
end
|
||||
|
||||
function zlan.info(host, file)
|
||||
if (not zlan.exists(host, file)) then return nil, "not found" end
|
||||
local sock = net.open(host, 9900)
|
||||
sock:w(string.char(2, 1, #file)..file.."i")
|
||||
local info = recv_full_pack(sock)
|
||||
local size = string.char(1) | (string.char(2) << 8) | (string.char(3) << 16)
|
||||
local nz = string.char(4)
|
||||
local name = string.sub(5, 5+nz)
|
||||
local vz = string.char(6+nz)
|
||||
local ver = string.sub(7+nz, 7+nz+vz)
|
||||
local format = string.char(8+nz+vz)
|
||||
sock:c()
|
||||
return {
|
||||
size = size,
|
||||
name = name,
|
||||
version = version,
|
||||
format = format
|
||||
}
|
||||
end
|
||||
|
||||
--Do decoding yourself.
|
||||
function zlan.download(host, file)
|
||||
if (not zlan.exists(host, file)) then return nil, "not found" end
|
||||
local sock = net.open(host, 9900)
|
||||
sock:w(string.char(2, 1, #file)..file.."d")
|
||||
local fd = recv_full_pack(sock)
|
||||
sock:c()
|
||||
return fd
|
||||
end
|
||||
|
||||
return zlan
|
26
lib/util_zlan/pack.lua
Normal file
26
lib/util_zlan/pack.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local function recv_pack_head(sock)
|
||||
local head = sock:r(6)
|
||||
local jv = head:byte(1)
|
||||
local nv = head:byte(2)
|
||||
local id = head:byte(3)
|
||||
local mx = head:byte(4)
|
||||
local size = head:byte(5) | (head:byte(6) << 8)
|
||||
return jv, nv, id, mx, head:r(size)
|
||||
end
|
||||
|
||||
local function recv_full_pack(sock)
|
||||
local packets = {}
|
||||
local rt = 0
|
||||
while true do
|
||||
if not computer.pullSignal(2) then
|
||||
rt = rt + 1
|
||||
if (rt > 3) then
|
||||
return nil, "timeout"
|
||||
end
|
||||
else
|
||||
local _, _, _, mx, dat = recv_pack_head(sock)
|
||||
packets[#packets+1] = dat
|
||||
end
|
||||
end
|
||||
return table.concat(packets, "")
|
||||
end
|
8
mods/menu_bios/init.lua
Normal file
8
mods/menu_bios/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local menu = {}
|
||||
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
gpu.bind(component.list("screen")())
|
||||
|
||||
gpu.set(1, 1, "Zorya NEO v2.0 BIOS/Bootloader")
|
||||
gpu.set(1, 2, "(c) 2020 Adorable-Catgirl")
|
||||
gpu.set(1, 4, "Memory: "..math.floor(computer.totalMemory()/1024).."K")
|
119
mods/menu_classic/init.lua
Normal file
119
mods/menu_classic/init.lua
Normal file
@ -0,0 +1,119 @@
|
||||
local border_chars = {
|
||||
"┌", "─", "┐", "│", "└", "┘"
|
||||
}
|
||||
local menu = {}
|
||||
|
||||
local entries = {}
|
||||
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
local screen = component.list("screen")()
|
||||
gpu.bind(screen) --fuck off ocemu
|
||||
|
||||
local bg, fg = 0, 0xFFFFFF
|
||||
local timeout = 5
|
||||
|
||||
function menu.setfgcolor(color)
|
||||
fg = color
|
||||
end
|
||||
|
||||
function menu.setbgcolor(color)
|
||||
bg = color
|
||||
end
|
||||
|
||||
function menu.settimeout(to)
|
||||
timeout = to
|
||||
end
|
||||
|
||||
function menu.add(text, func)
|
||||
entries[#entries+1] = {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
|
||||
gpu.set((w/2)-7, 1, "Zorya NEO BIOS")
|
||||
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()
|
||||
gpu.setBackground(bg)
|
||||
gpu.setForeground(fg)
|
||||
gpu.fill(1, h-2, w, 1, " ")
|
||||
if (autosel) then
|
||||
gpu.set(1, h-2, "Automatically booting in "..math.floor(timeout-(computer.uptime()-stime)).."s.")
|
||||
end
|
||||
for i=1, h-6 do
|
||||
local entry = entries[ypos+i-1]
|
||||
if not entry then break end
|
||||
local name = entry[1]
|
||||
if not name then break end
|
||||
local short = name:sub(1, w-2)
|
||||
if (short ~= name) then
|
||||
short = short:sub(1, #sub-3).."..."
|
||||
end
|
||||
if (#short < w-2) then
|
||||
short = short .. string.rep(" ", w-2-#short)
|
||||
end
|
||||
if (sel == ypos+i-1) then
|
||||
gpu.setBackground(fg)
|
||||
gpu.setForeground(bg)
|
||||
else
|
||||
gpu.setBackground(bg)
|
||||
gpu.setForeground(fg)
|
||||
end
|
||||
gpu.set(2, i+2, short)
|
||||
end
|
||||
end
|
||||
redraw()
|
||||
sel = 1
|
||||
while true do
|
||||
local sig, _, key, code = computer.pullSignal(0.01)
|
||||
if (sig == "key_down") then
|
||||
autosel = false
|
||||
if (key == 0 and code == 200) then
|
||||
sel = sel - 1
|
||||
if (sel < 1) then
|
||||
sel = 1
|
||||
end
|
||||
if (sel < ypos) then
|
||||
ypos = ypos - 1
|
||||
end
|
||||
elseif (key == 0 and code == 208) then
|
||||
sel = sel + 1
|
||||
if (sel > #entries) then
|
||||
sel = #entries
|
||||
end
|
||||
if (sel > ypos+h-7) then
|
||||
ypos = ypos+1
|
||||
end
|
||||
elseif (key == 13 and code == 28) then
|
||||
gpu.setBackground(0)
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
entries[sel][2]()
|
||||
end
|
||||
end
|
||||
if (((computer.uptime()-stime) >= timeout) and autosel) then
|
||||
entries[sel][2]()
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
|
||||
return menu
|
0
mods/util_oefiv2/init.lua
Normal file
0
mods/util_oefiv2/init.lua
Normal file
161
mods/util_vdev/init.lua
Normal file
161
mods/util_vdev/init.lua
Normal file
@ -0,0 +1,161 @@
|
||||
local comp = component
|
||||
|
||||
local vdev = {}
|
||||
|
||||
local types = {}
|
||||
local devices = {}
|
||||
|
||||
local unpack = unpack or table.unpack
|
||||
|
||||
function vdev.register_type(dtype, prototype)
|
||||
types[dtype] = prototype
|
||||
end
|
||||
|
||||
function vdev.add_device(address, dtype)
|
||||
devices[#devices+1] = {addr=address, type=dtype}
|
||||
computer.pushSignal("component_added", address, dtype)
|
||||
return address
|
||||
end
|
||||
|
||||
function vdev.gen_address()
|
||||
local bytes = {}
|
||||
for i=1, 16 do
|
||||
bytes[#bytes+1] = math.random(0, 255)
|
||||
end
|
||||
return string.format("%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x", unpack(bytes))
|
||||
end
|
||||
|
||||
function vdev.remove_device(address)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == address) then
|
||||
computer.pushSignal("component_removed", address, devices[i].type)
|
||||
table.remove(devices, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Override component library, and computer.getDeviceInfo()
|
||||
|
||||
local cdevinfo = computer.getDeviceInfo
|
||||
|
||||
component = {}
|
||||
|
||||
for k, v in pairs(comp) do
|
||||
component[k] = v
|
||||
end
|
||||
|
||||
function component.list(dtype)
|
||||
local lpos = 0
|
||||
local func = comp.list(dtype)
|
||||
local ft = {}
|
||||
for k, v in pairs(func) do
|
||||
ft[k] = v
|
||||
end
|
||||
for i=1, #devices do
|
||||
if (devices[i].type:find(dtype, true) == 1) then
|
||||
ft[ devices[i].addr ] = devices[i].type
|
||||
end
|
||||
end
|
||||
return setmetatable(ft, {__call=function()
|
||||
if (lpos > #devices or #devices == 0) then
|
||||
return func()
|
||||
end
|
||||
while true do
|
||||
lpos = lpos + 1
|
||||
if (lpos > #devices) then
|
||||
return func()
|
||||
end
|
||||
if (devices[lpos].type:find(dtype, true) == 1) then
|
||||
return devices[lpos].addr
|
||||
end
|
||||
end
|
||||
end})
|
||||
end
|
||||
|
||||
function component.proxy(addr)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
return setmetatable({}, {__index=function(self, index)
|
||||
if (types[devices[i].type].methods[index]) then
|
||||
local func = setmetatable({}, {__call=function(...)
|
||||
return types[devices[i].type].methods[index](devices[i].addr, ...)
|
||||
end, __tostring = function()
|
||||
return types[devices[i].type].doc[index]
|
||||
end})
|
||||
self[index] = func
|
||||
end
|
||||
end})
|
||||
end
|
||||
end
|
||||
return comp.proxy(addr)
|
||||
end
|
||||
|
||||
function component.invoke(addr, meth, ...)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
if (types[devices[i].type][meth]) then
|
||||
types[devices[i].type].methods[meth](addr, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
return comp.invoke(addr, meth, ...)
|
||||
end
|
||||
|
||||
function component.doc(addr, meth)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
if (types[devices[i].type].methods[meth]) then
|
||||
return types[devices[i].type].doc[meth]
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
return comp.doc(addr, meth)
|
||||
end
|
||||
|
||||
function component.type(addr)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
return devices[i].type
|
||||
end
|
||||
end
|
||||
return comp.type(addr)
|
||||
end
|
||||
|
||||
function component.slot(addr)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
return -1
|
||||
end
|
||||
end
|
||||
return comp.slot(addr)
|
||||
end
|
||||
|
||||
function component.methods(addr)
|
||||
for i=1, #devices do
|
||||
if (devices[i].addr == addr) then
|
||||
local m = {}
|
||||
for k, v in pairs(types[devices[i].type].methods) do
|
||||
m[k] = true
|
||||
end
|
||||
return m
|
||||
end
|
||||
end
|
||||
return comp.methods(addr)
|
||||
end
|
||||
|
||||
function computer.getDeviceInfo()
|
||||
local tbl = cdevinfo()
|
||||
for i=1, #devices do
|
||||
local info = {}
|
||||
tbl[devices[i].addr] = info
|
||||
local dtype = types[devices[i].type]
|
||||
info.vendor = dtype.vendor
|
||||
info.product = dtype.product
|
||||
info.class = dtype.class
|
||||
dtype.getinfo(devices[i].addr, info)
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
return vdev
|
0
mods/vdev_biosdev/init.lua
Normal file
0
mods/vdev_biosdev/init.lua
Normal file
19
release.lua
Normal file
19
release.lua
Normal file
@ -0,0 +1,19 @@
|
||||
--Makes a release CPIO
|
||||
os.execute("rm -rf pkg")
|
||||
os.execute("mkdir -p pkg/mods")
|
||||
os.execute("mkdir -p pkg/lib")
|
||||
os.execute("mkdir -p pkg/bios")
|
||||
os.execute("luacomp src/loader.lua -O pkg/bios/managed.bios")
|
||||
if (os.execute("stat mods 1>/dev/null 2>&1")) then
|
||||
for l in io.popen("ls mods"):lines() do
|
||||
os.execute("zsh -c 'cd mods/"..l.."; luacomp init.lua | lua ../../utils/zlua.lua > ../../pkg/mods/"..l..".zy2m'")
|
||||
end
|
||||
end
|
||||
if (os.execute("stat lib 1>/dev/null 2>&1")) then
|
||||
for l in io.popen("ls lib"):lines() do
|
||||
os.execute("zsh -c 'cd lib/"..l.."; luacomp init.lua -mluamin | lua ../../utils/zlua.lua > ../../pkg/lib/"..l..".zy2l'")
|
||||
end
|
||||
end
|
||||
os.execute("cp utils/ser.lua pkg/init.lua")
|
||||
os.execute("cp -r installer_dat pkg")
|
||||
os.execute("cd pkg; find * -depth | cpio -o | lua ../utils/mkselfextract.lua > ../zorya-neo-installer.lua")
|
25
src/loader.lua
Normal file
25
src/loader.lua
Normal file
@ -0,0 +1,25 @@
|
||||
--#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 src/lzssc.lua | lua utils/mkluastring.lua ]]), "=bios.lua")(lzss_decompress)
|
40
src/lzss.lua
Normal file
40
src/lzss.lua
Normal file
@ -0,0 +1,40 @@
|
||||
local s, t = string, table
|
||||
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
|
118
src/lzssc.lua
Normal file
118
src/lzssc.lua
Normal file
@ -0,0 +1,118 @@
|
||||
local f = io.stdin:read("*a")
|
||||
|
||||
--[[----------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
io.stdout:write(M.compress(f))
|
31
src/zy-neo/builtins/init_managed/init.lua
Normal file
31
src/zy-neo/builtins/init_managed/init.lua
Normal file
@ -0,0 +1,31 @@
|
||||
local readfile=function(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
|
||||
|
||||
local bfs = {}
|
||||
|
||||
local cfg = component.proxy(component.list("eeprom")()).getData()
|
||||
|
||||
local baddr = cfg:sub(1, 36)
|
||||
|
||||
function bfs.getfile(path)
|
||||
local h = assert(component.invoke(baddr, "open", path, "r"))
|
||||
return readfile(baddr, h)
|
||||
end
|
||||
|
||||
function bfs.exists(path)
|
||||
return component.invoke(baddr, "exists", path)
|
||||
end
|
||||
|
||||
|
||||
bfs.addr = baddr
|
38
src/zy-neo/builtins/init_osdi/init.lua
Normal file
38
src/zy-neo/builtins/init_osdi/init.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local osdi = {}
|
||||
|
||||
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 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 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)
|
||||
end
|
||||
end
|
||||
|
||||
return osdi
|
3
src/zy-neo/builtins/init_proxfs/init.lua
Normal file
3
src/zy-neo/builtins/init_proxfs/init.lua
Normal file
@ -0,0 +1,3 @@
|
||||
--#error "Not implemented."
|
||||
local pfs = {}
|
||||
|
1
src/zy-neo/builtins/init_romfs/init.lua
Normal file
1
src/zy-neo/builtins/init_romfs/init.lua
Normal file
@ -0,0 +1 @@
|
||||
--#error "Not implemented."
|
0
src/zy-neo/builtins/mod_menu/init.lua
Normal file
0
src/zy-neo/builtins/mod_menu/init.lua
Normal file
4
src/zy-neo/init.lua
Normal file
4
src/zy-neo/init.lua
Normal file
@ -0,0 +1,4 @@
|
||||
@[[if not svar.get("ZY_PLATFORM") then]]
|
||||
--#define "ZY_PLATFORM" "managed"
|
||||
@[[end]]
|
||||
--#include @[{"src/zy-neo/builtins/init_"..svar.get("ZY_PLATFORM").."/init.lua"}]
|
119
src/zy-neo/zinit.lua
Normal file
119
src/zy-neo/zinit.lua
Normal file
@ -0,0 +1,119 @@
|
||||
local lzss_decompress = {...}
|
||||
--Zorya NEO itself.
|
||||
_BIOS = "Zorya NEO"
|
||||
_ZVSTR = "2.0"
|
||||
_ZVER = 2.0
|
||||
_ZPAT = 0
|
||||
--#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 = {}
|
||||
|
||||
local th_i = 0
|
||||
local function th_a(func)
|
||||
thd.add("zyneo$"..th_i, func)
|
||||
end
|
||||
|
||||
local builtins = {}
|
||||
|
||||
sys.add_lib("zorya", (function()
|
||||
|
||||
local mod_search = {}
|
||||
|
||||
local zy = {}
|
||||
function zy.get_bootlist()
|
||||
|
||||
end
|
||||
|
||||
function zy.boot(i)
|
||||
th_a(zcfg[i][2](zcfg[i][3]))
|
||||
booted = true
|
||||
end
|
||||
|
||||
function zy.loadmod(mod)
|
||||
for i=1, #mod_search do
|
||||
local r = mod_search[i](mod)
|
||||
if r then return r end
|
||||
end
|
||||
end
|
||||
|
||||
function zy.loader_run(func, env)
|
||||
func(env)
|
||||
end
|
||||
|
||||
function zy.add_mod_search(func)
|
||||
mod_search[#mod_search+1] = func
|
||||
end
|
||||
|
||||
function zy.lkthdn()
|
||||
return #thd.getthreads()
|
||||
end
|
||||
|
||||
function zy.lkthdi(i)
|
||||
return thd.getthreads()[i][1]
|
||||
end
|
||||
return zy
|
||||
end)())
|
||||
|
||||
--#include "src/zy-neo/init.lua"
|
||||
|
||||
builtins["menu"] = (function()
|
||||
--#include "src/zy-neo/builtins/mod_menu/init.lua"
|
||||
end)
|
||||
|
||||
local function load_lua(src, ...)
|
||||
if (src:sub(1, 4) == "\27ZLS") then
|
||||
src = lzss_decompress(src:sub(5))
|
||||
end
|
||||
return assert(load(src, ...))
|
||||
end
|
||||
|
||||
-- Zorya's handler thread.
|
||||
th_a(function()
|
||||
local er
|
||||
xpcall(function()
|
||||
local zy = krequire("zorya")
|
||||
zy.add_mod_search(function(mod)
|
||||
if (builtins[mod]) then
|
||||
return builtins[mod]
|
||||
end
|
||||
end)
|
||||
zy.add_mod_search(function(mod)
|
||||
if (bfs.exists(".zy2/mods/"..mod..".zy2m")) then
|
||||
return assert(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")()
|
||||
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")()
|
||||
end
|
||||
end)
|
||||
local zycfg = bfs.getfile(".zy2/cfg.lua")
|
||||
-- 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
|
||||
end
|
||||
env._G = env
|
||||
env._ENV = env
|
||||
return assert(load(zycfg, "=zycfg", "t", env))()
|
||||
end, function(e)
|
||||
er = e..": "..debug.traceback()
|
||||
end)
|
||||
if er then error(er) end
|
||||
end)
|
||||
|
||||
sys.start()
|
0
utils/lua_to_blt.lua
Normal file
0
utils/lua_to_blt.lua
Normal file
40
utils/mkluastring.lua
Normal file
40
utils/mkluastring.lua
Normal file
@ -0,0 +1,40 @@
|
||||
local f = io.stdin:read("*a")
|
||||
|
||||
--[[io.stdout:write("\"")
|
||||
for i=1, #f do
|
||||
if (f:byte(i) < 32 or f:byte(i) > 126) then
|
||||
io.stdout:write(string.format("\\x%.2x",f:byte(i)))
|
||||
elseif (f:sub(i,i) == "\\") then
|
||||
io.stdout:write("\\\\")
|
||||
elseif (f:sub(i,i) == "\"") then
|
||||
io.stdout:write("\\\"")
|
||||
elseif (f:sub(i,i) == "\n") then
|
||||
io.stdout:write("\\n")
|
||||
elseif (f:sub(i,i) == "\r") then
|
||||
io.stdout:write("\\r")
|
||||
else
|
||||
io.stdout:write(f:sub(i,i))
|
||||
end
|
||||
end
|
||||
io.stdout:write("\"\n")]]
|
||||
local function mkstr(d)
|
||||
local dat = "\""
|
||||
for i=1, #f do
|
||||
if (d:byte(i) == 0) then
|
||||
dat = dat .. "\0"
|
||||
elseif (d:sub(i,i) == "\\") then
|
||||
dat = dat .. ("\\\\")
|
||||
elseif (d:sub(i,i) == "\"") then
|
||||
dat = dat .. ("\\\"")
|
||||
elseif (d:sub(i,i) == "\n") then
|
||||
dat = dat .. ("\\n")
|
||||
elseif (d:sub(i,i) == "\r") then
|
||||
dat = dat .. ("\\r")
|
||||
else
|
||||
dat = dat .. (d:sub(i,i))
|
||||
end
|
||||
end
|
||||
dat = dat .. ("\"")
|
||||
return dat
|
||||
end
|
||||
io.stdout:write(mkstr(f))
|
86
utils/mkselfextract.lua
Normal file
86
utils/mkselfextract.lua
Normal file
@ -0,0 +1,86 @@
|
||||
local f = io.stdin:read("*a")
|
||||
|
||||
local function mkstr(d)
|
||||
local dat = "\""
|
||||
for i=1, #f do
|
||||
if (d:byte(i) == 0) then
|
||||
dat = dat .. "\0"
|
||||
elseif (d:sub(i,i) == "\\") then
|
||||
dat = dat .. ("\\\\")
|
||||
elseif (d:sub(i,i) == "\"") then
|
||||
dat = dat .. ("\\\"")
|
||||
elseif (d:sub(i,i) == "\n") then
|
||||
dat = dat .. ("\\n")
|
||||
elseif (d:sub(i,i) == "\r") then
|
||||
dat = dat .. ("\\r")
|
||||
else
|
||||
dat = dat .. (d:sub(i,i))
|
||||
end
|
||||
end
|
||||
dat = dat .. ("\"")
|
||||
return dat
|
||||
end
|
||||
|
||||
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 lzss_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
|
||||
|
||||
local tmp = os.tmpname()
|
||||
local h = io.popen("luacomp ../utils/selfextract.lua -O"..tmp, "w")
|
||||
h:write(mkstr(lzss_compress(f)))
|
||||
h:close()
|
||||
local f = io.open(tmp, "rb")
|
||||
io.stdout:write(f:read("*a"))
|
||||
f:close()
|
||||
os.remove(tmp)
|
105
utils/selfextract.lua
Normal file
105
utils/selfextract.lua
Normal file
@ -0,0 +1,105 @@
|
||||
local arg = arg or {...}
|
||||
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 lzss_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
|
||||
print("Decompressing CPIO...")
|
||||
local code = lzss_decompress(@[{io.stdin:read("*a")}])
|
||||
local dat = code
|
||||
local tbl = {}
|
||||
|
||||
local pos = 1
|
||||
local function read(n)
|
||||
local d = dat:sub(pos, pos+n)
|
||||
pos = pos + n
|
||||
return d
|
||||
end
|
||||
|
||||
local function readint(amt, rev)
|
||||
local tmp = 0
|
||||
for i=(rev and amt) or 1, (rev and 1) or amt, (rev and -1) or 1 do
|
||||
tmp = tmp | (read(1):byte() << ((i-1)*8))
|
||||
end
|
||||
return tmp
|
||||
end
|
||||
|
||||
while true do
|
||||
local dent = {}
|
||||
dent.magic = readint(2)
|
||||
local rev = false
|
||||
if (dent.magic ~= tonumber("070707", 8)) then rev = true end
|
||||
dent.dev = readint(2)
|
||||
dent.ino = readint(2)
|
||||
dent.mode = readint(2)
|
||||
dent.uid = readint(2)
|
||||
dent.gid = readint(2)
|
||||
dent.nlink = readint(2)
|
||||
dent.rdev = readint(2)
|
||||
dent.mtime = (readint(2) << 16) | readint(2)
|
||||
dent.namesize = readint(2)
|
||||
dent.filesize = (readint(2) << 16) | readint(2)
|
||||
local name = read(dent.namesize):sub(1, dent.namesize-1)
|
||||
if (name == "TRAILER!!!") then break end
|
||||
--for k, v in pairs(dent) do
|
||||
-- print(k, v)
|
||||
--end
|
||||
dent.name = name
|
||||
if (dent.namesize % 2 ~= 0) then
|
||||
pos = pos + 1
|
||||
end
|
||||
if (dent.mode & 32768 ~= 0) then
|
||||
--fwrite()
|
||||
end
|
||||
dent.pos = pos
|
||||
pos = pos + dent.filesize
|
||||
if (dent.filesize % 2 ~= 0) then
|
||||
pos = pos + 1
|
||||
end
|
||||
tbl[#tbl+1] = dent
|
||||
end
|
||||
|
||||
local unpack = unpack or table.unpack
|
||||
|
||||
for i=1, #tbl do
|
||||
if (tbl[i].name == "init.lua") then
|
||||
load(dat:sub(tbl[i].pos, tbl[i].pos+tbl[i].filesize-1))(tbl, dat, unpack(arg))
|
||||
end
|
||||
end
|
158
utils/ser.lua
Normal file
158
utils/ser.lua
Normal file
@ -0,0 +1,158 @@
|
||||
local args = {...}
|
||||
local tbl = args[1]
|
||||
local dat = args[2]
|
||||
table.remove(args, 1)
|
||||
table.remove(args, 1)
|
||||
|
||||
local comp = component or require("component")
|
||||
local computer = computer or require("computer")
|
||||
|
||||
function getfile(path)
|
||||
for i=1, #tbl do
|
||||
if (tbl[i].name == path) then
|
||||
return dat:sub(tbl[i].pos, tbl[i].pos+tbl[i].filesize-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[local baddr = computer.getBootAddress()
|
||||
local c = comp.proxy(baddr)
|
||||
print("Making directories...")
|
||||
c.makeDirectory(".zy2")
|
||||
c.makeDirectory(".zy2/mods")
|
||||
c.makeDirectory(".zy2/lib")
|
||||
print("Copying files...")
|
||||
for i=1, #tbl do
|
||||
if (tbl[i].name:sub(1, 13) ~= "installer_dat" and tbl[i].name:sub(1, 4) ~= "bios" and tbl[i].mode & 32768 ~= 0) then
|
||||
local h = c.open(".zy2/"..tbl[i].name, "w")
|
||||
c.write(h, getfile(tbl[i].name))
|
||||
c.close(h)
|
||||
end
|
||||
end
|
||||
computer.pullSignal(0)
|
||||
print("Flashing BIOS...")
|
||||
local eeprom = comp.proxy(comp.list("eeprom")())
|
||||
eeprom.set(getfile("bios/managed.bios"))
|
||||
eeprom.setData(baddr)]]
|
||||
|
||||
--pastebin installer: HW3rz1gt
|
||||
local characters = {
|
||||
"╔", "╗", "═", "║", "╚", "╝"
|
||||
}
|
||||
local computer = computer or require("computer")
|
||||
local fsaddr = args[1] or computer.getBootAddress()
|
||||
print(fsaddr)
|
||||
local component = component or require("component")
|
||||
local proxy, list = component.proxy, component.list
|
||||
local gpu = proxy(list("gpu")())
|
||||
if (not gpu.getScreen()) then
|
||||
gpu.bind(list("screen")())
|
||||
end
|
||||
--Load palette
|
||||
gpu.setPaletteColor(0, 0x000000)
|
||||
gpu.setPaletteColor(1, 0xFFFFFF)
|
||||
gpu.setPaletteColor(2, 0x4444FF)
|
||||
gpu.setPaletteColor(3, 0xFF7F44)
|
||||
gpu.setPaletteColor(4, 0x00007F)
|
||||
gpu.setPaletteColor(5, 0x7F00FF)
|
||||
gpu.setPaletteColor(6, 0x595959)
|
||||
gpu.setBackground(0, true)
|
||||
local w, h = gpu.getViewport()
|
||||
gpu.fill(1, 2, w, h-1, " ")
|
||||
gpu.setBackground(5, true)
|
||||
gpu.fill(1, 1, w, 1, " ")
|
||||
local title = "Zorya NEO Installer v2.0"
|
||||
local spos = (w/2)-(#title/2)
|
||||
gpu.setForeground(1, true)
|
||||
gpu.set(spos, 1, title)
|
||||
gpu.setForeground(1, true)
|
||||
gpu.setBackground(5, true)
|
||||
gpu.fill(6,6,w-12,h-12, " ")
|
||||
gpu.set(6,6,characters[1])
|
||||
gpu.set(w-6,6,characters[2])
|
||||
gpu.set(6,h-6,characters[5])
|
||||
gpu.set(w-6,h-6,characters[6])
|
||||
gpu.fill(7,6,w-13,1,characters[3])
|
||||
gpu.fill(7,h-6,w-13,1,characters[3])
|
||||
gpu.fill(6,7,1,h-13,characters[4])
|
||||
gpu.fill(w-6,7,1,h-13,characters[4])
|
||||
function setStatus(stat)
|
||||
gpu.setBackground(5, true)
|
||||
gpu.setForeground(1, true)
|
||||
gpu.fill(7,(h/2)-3, w-13, 1, " ")
|
||||
gpu.set((w/2)-(#stat/2), (h/2)-3, stat)
|
||||
end
|
||||
function setBar(pos)
|
||||
gpu.setBackground(6, true)
|
||||
gpu.fill(8, (h/2)+1, w-16, 1, " ")
|
||||
gpu.setBackground(2, true)
|
||||
gpu.fill(8, (h/2)+1, ((w-16)/100)*pos, 1, " ")
|
||||
end
|
||||
|
||||
function writeFile(fs, path, data)
|
||||
local hand = fs.open(path, "w")
|
||||
fs.write(hand, data)
|
||||
fs.close(hand)
|
||||
end
|
||||
|
||||
function mkdir(fs, path)
|
||||
fs.makeDirectory(path)
|
||||
end
|
||||
|
||||
|
||||
setStatus("Setting up directories...")
|
||||
setBar(100)
|
||||
local fs = proxy(fsaddr)
|
||||
fs.makeDirectory(".zy2")
|
||||
fs.makeDirectory(".zy2/mods")
|
||||
fs.makeDirectory(".zy2/lib")
|
||||
|
||||
setStatus("Getting file list...")
|
||||
setBar(0)
|
||||
local bios_files = load("return "..getfile("installer_dat/bios_list.lua"))()
|
||||
setBar(33)
|
||||
local pkg_files = load("return "..getfile("installer_dat/package_list.lua"))()
|
||||
setBar(67)
|
||||
local lang = load("return "..getfile("installer_dat/lang/en_US.lua"))()
|
||||
setBar(100)
|
||||
|
||||
setStatus("Extracting files...")
|
||||
setBar(0)
|
||||
for i=1, #pkg_files do
|
||||
setStatus("Extracting "..(lang["mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name"] or "#mod_"..pkg_files[i].cat.."_"..pkg_files[i].name.."_name").."... ("..i.." of "..#pkg_files..")")
|
||||
setBar(100*(i/#pkg_files))
|
||||
writeFile(fs, ".zy2/"..pkg_files[i].path, getfile(pkg_files[i].path))
|
||||
end
|
||||
|
||||
setStatus("Extracting EEPROM...")
|
||||
setBar(0)
|
||||
local bios = getfile(bios_files[1].path)
|
||||
|
||||
setStatus("Flashing EEPROM...")
|
||||
setBar(33)
|
||||
local eeprom = proxy(list("eeprom")())
|
||||
eeprom.set(bios)
|
||||
setStatus("Writing configuration data...")
|
||||
setBar(66)
|
||||
function hexid_to_binid(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
|
||||
eeprom.setData(fs.address)
|
||||
eeprom.setLabel("Zorya NEO BIOS v2.0")
|
||||
setBar(100)
|
||||
setStatus("Rebooting in 5 seconds...")
|
||||
computer = computer or require("computer")
|
||||
local stime = computer.uptime()
|
||||
while true do
|
||||
setStatus("Rebooting in "..math.ceil(5-(computer.uptime()-stime)).." seconds...")
|
||||
if (computer.uptime()-stime > 5) then
|
||||
computer.shutdown(true)
|
||||
end
|
||||
computer.pullSignal(0.01)
|
||||
setBar((computer.uptime()-stime)*20)
|
||||
end
|
118
utils/zlua.lua
Normal file
118
utils/zlua.lua
Normal file
@ -0,0 +1,118 @@
|
||||
local f = io.stdin:read("*a")
|
||||
|
||||
--[[----------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
io.stdout:write("\27ZLS"..M.compress(f))
|
Loading…
Reference in New Issue
Block a user