diff --git a/installer_dat/package_list.lua b/installer_dat/package_list.lua index 51a5d0a..0d2489c 100644 --- a/installer_dat/package_list.lua +++ b/installer_dat/package_list.lua @@ -10,6 +10,7 @@ {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="thd", cat="core", path="lib/thd.zy2l"} --{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"}, diff --git a/lib/core_thd/init.lua b/lib/core_thd/init.lua new file mode 100644 index 0000000..7fb19df --- /dev/null +++ b/lib/core_thd/init.lua @@ -0,0 +1,92 @@ +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 + if (dl == "k") then + threads[i][6] = true + end + dl = computer.uptime() + (dl or math.huge) + threads[i][4] = dl + sigs[#sigs+1] = {ps(0)} + end + end + end + local t = {} + for i=1, #threads do + local v = threads[i] + if (c_status(v[2]) ~= "dead" and not v[6]) then + t[#t+1] = v + t[v[2]] = v + 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 \ No newline at end of file diff --git a/src/loader.lua b/src/loader.lua index 1a26008..14562c8 100644 --- a/src/loader.lua +++ b/src/loader.lua @@ -1,2 +1,2 @@ --#include "src/lzss.lua" -return assert(load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua"))(lzss_decompress) \ No newline at end of file +return assert(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) \ No newline at end of file diff --git a/src/zy-neo/builtins/util_romfs.lua b/src/zy-neo/builtins/util_romfs.lua index 1479c16..1d592fc 100644 --- a/src/zy-neo/builtins/util_romfs.lua +++ b/src/zy-neo/builtins/util_romfs.lua @@ -8,7 +8,6 @@ end function romfs.read(read, seek, close) local sig = read(7) - utils.debug_log("SIGNATURE", sig, #sig) assert(sig, "Read error!") if sig ~= "romfs\1\0" then error(string.format("Invalid romfs (%.14x != %.14x)", string.unpack("i7", sig), string.unpack("i7", "romfs\1\0"))) end local tbl = {} @@ -19,21 +18,17 @@ function romfs.read(read, seek, close) local fsize = readint(read, 2) local exec = read(1) tbl[#tbl+1] = {name = name, size = fsize, exec = exec == "x", pos = seek(0)} - utils.debug_log(name, fsize, exec) seek(fsize) lname = name end tbl[#tbl] = nil - utils.debug_log("ROMFS loaded!") 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 - utils.debug_log("DEBUG", self.tbl[i].pos, self.tbl[i].size) self.seek(self.tbl[i].pos-self.seek(0)) - utils.debug_log("DEBUG2", self.seek(0)) return self.read(self.tbl[i].size) end end diff --git a/src/zy-neo/utils.lua b/src/zy-neo/utils.lua index 1ff5b5c..91f3eff 100644 --- a/src/zy-neo/utils.lua +++ b/src/zy-neo/utils.lua @@ -57,5 +57,4 @@ function utils.deepcopy(src, dest) end return dest end -utils.debug_log("Zorya NEO Started!") builtins.utils = function() return utils end \ No newline at end of file diff --git a/src/zy-neo/zinit.lua b/src/zy-neo/zinit.lua index 720f4a3..a9d6a22 100644 --- a/src/zy-neo/zinit.lua +++ b/src/zy-neo/zinit.lua @@ -27,7 +27,6 @@ local function load_lua(src, ...) if (src:sub(1, 4) == "\27ZLS") then src = lzss_decompress(src:sub(5)) end - log("DECOMPRESS", src) return load(src, ...) end