From 501561ba4ada7dbf2e11f89612d4e133fa855aec Mon Sep 17 00:00:00 2001 From: Jane Roxanne Date: Sun, 24 May 2020 09:18:28 -0500 Subject: [PATCH] Crescent --- build.lua | 7 +++-- docs/foxfs.md | 0 extras/crescent/init.lua | 48 ++++++++++++++++++++++++++++++ extras/crescent/loader.lua | 6 ++++ extras/crescent/tsar.lua | 0 extras/crescent/velx.lua | 39 ++++++++++++++++++++++++ extras/velxboot/init.lua | 32 +++++++++++++++++++- ksrc/buffer.lua | 5 ++++ ksrc/exec.lua | 4 +-- ksrc/execs/velx_spec/velxspec.lua | 1 + ksrc/fs/foxfs/find_file.lua | 0 ksrc/init.lua | 2 ++ ksrc/kio.lua | 8 +++++ tkrnl.velx | Bin 3407 -> 3624 bytes utils/gendocs.lua | 2 ++ utils/velxdump.lua | 16 ++++++++-- 16 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 docs/foxfs.md create mode 100644 extras/crescent/init.lua create mode 100644 extras/crescent/loader.lua create mode 100644 extras/crescent/tsar.lua create mode 100644 extras/crescent/velx.lua create mode 100644 ksrc/fs/foxfs/find_file.lua create mode 100644 ksrc/kio.lua diff --git a/build.lua b/build.lua index 475040e..0647514 100644 --- a/build.lua +++ b/build.lua @@ -144,6 +144,7 @@ local function struct(tbl) end}) end + local velx_spec = struct { endian = "<", {magic="c5"}, @@ -151,6 +152,7 @@ local velx_spec = struct { {compression="B"}, {lver="B"}, {os="B"}, + {arctype="c4"}, {psize="I3"}, {lsize="I3"}, {ssize="I3"}, @@ -160,9 +162,9 @@ local velx_spec = struct { -- This builds Tsuki into a VELX executable. print("Compiling kernel...") local h = io.popen("luacomp ksrc/init.lua", "r") -os.execute("luacomp ksrc/init.lua -O debug.lua") local krnl = h:read("*a") h:close() +os.execute("luacomp ksrc/init.lua -O debug.lua 2>/dev/null") print("Generating docs and stripping comments...") os.execute("mkdir .docs") h = io.popen("lua utils/gendocs.lua .docs 2>.ktmp", "w") @@ -187,7 +189,8 @@ local header = velx_spec({ psize = #data, lsize=0, ssize=0, - rsize=#arc + rsize=#arc, + arctype="tsar" }) h:write(header) h:write(data) diff --git a/docs/foxfs.md b/docs/foxfs.md new file mode 100644 index 0000000..e69de29 diff --git a/extras/crescent/init.lua b/extras/crescent/init.lua new file mode 100644 index 0000000..5ab9dd9 --- /dev/null +++ b/extras/crescent/init.lua @@ -0,0 +1,48 @@ +local version = "1.0" + +local gpu = component.list("gpu")() +local w, h +local screen = component.list('screen')() +for address in component.list('screen') do + if #component.invoke(address, 'getKeyboards') > 0 then + screen = address + end +end +local cls = function()end +if gpu and screen then + component.invoke(gpu, "bind", screen) + w, h = component.invoke(gpu, "getResolution") + component.invoke(gpu, "setResolution", w, h) + component.invoke(gpu, "setBackground", 0x000000) + component.invoke(gpu, "setForeground", 0xFFFFFF) + component.invoke(gpu, "fill", 1, 1, w, h, " ") + cls = function()component.invoke(gpu,"fill", 1, 1, w, h, " ")end +end +local y = 1 +local function status(msg) + if gpu and screen then + component.invoke(gpu, "set", 1, y, msg) + if y == h then + component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1) + component.invoke(gpu, "fill", 1, h, w, 1, " ") + else + y = y + 1 + end + end +end + +local loadspin = 1 +local spins = { + "-", "\\", "|", "/" +} + +local function lsc() + loadspin = (loadspin % 4) + 1 + return spins[loadspin] +end + +--#include "crescent/velx.lua" +--#include "crescent/tsar.lua" +--#include "crescent/loader.lua" + +status("crescent loader v"..version) \ No newline at end of file diff --git a/extras/crescent/loader.lua b/extras/crescent/loader.lua new file mode 100644 index 0000000..e881848 --- /dev/null +++ b/extras/crescent/loader.lua @@ -0,0 +1,6 @@ +function boot_kernel(...) + local knl, env = load_velx(computer.getBootAddress(), "kernel.velx") + local iramfs = load_tsar(computer.getBootAddress(), "initramfs.tsar") + env._ARCHIVE = iramfs + knl(...) +end \ No newline at end of file diff --git a/extras/crescent/tsar.lua b/extras/crescent/tsar.lua new file mode 100644 index 0000000..e69de29 diff --git a/extras/crescent/velx.lua b/extras/crescent/velx.lua new file mode 100644 index 0000000..98149da --- /dev/null +++ b/extras/crescent/velx.lua @@ -0,0 +1,39 @@ +local function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do +e=c.byte(a,b)b=b+1 +for k=0,7 do h=c.sub +g=h(a,b,b)if e>>k&1<1 and b<#a then +i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1 +end +b=b+1 +c=c..g +d=h(d..g,-4^6)end +end +return c end + +local function load_velx(addr, path) + status("loading kernel... "..lsc()) + local fs = component.proxy(addr) + local h = fs.open(path) + local magic, fver, comp, lver, osid, psize = string.unpack(">k&1<1 and b<#a then +i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1 +end +b=b+1 +c=c..g +d=h(d..g,-4^6)end +end +return c end local function boot_velx(addr, path) - + local fs = component.proxy(addr) + local h = fs.open(path) + local magic, fver, comp, lver, osid, psize = string.unpack("8QuXBt~l|LXv7Sla63)l4jBYVrrVED#U6VYojO_8%;gLR7AMzYO2$AzkM_B zz3+R!-+SMidEf8!!nb}HSkwr)Cs4FLpvaWephLd@KGY&e#O3E{g%$V+kQK>KD?~(b zawbg22@#s&fJiCeo(-Ug8S)Gpp?Dxj0Jr@PN2@8xEu*29o2{766*bJ-atE>jBVamB zb@n~rL_;FQO7baWVj~-P3bmpQ-s}~i2@O$%GiF57|4B>_8uCW#(c|cl*?bc;VY(;> zrju?$#V;WuRD2PrPzvSbV1#IC%?2$b*@U)nHYA!Lvo*cpm=W3oX>YkCy9w=}rY{@d zNM{YpyYYmcI42%65@B6{P?|;f_W%)J4s5oB_e|il;(@%%+8{Sgp`BVJ;f&eOi`0v> zmp}*O)3ny;3@JL}k!0VEiI^VE(z3hS+||UAACv%IT!^r1z6v4j6k)F(WfrUX&vnkR%5u z__5-`B5+i3EAvur*a*GUdX>Q~hzpMbtr9_|v zws@cfKLuOhiiT2AOUdvwCDEQlr09&oR{CIxVUeN4Vyof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|_guG%GkzaT&z zLyeR7^l+6;^^3~#l`DmN1ygZ%KH+bDR-(Bvd?U;P?xt!Ir{1~Q7sI>g+KNi_rvFDY zIOXWgqsvyUzVVxyb=6pTF;T3)W83tvsfy}b`jN^fuZ&n$SJvEGbnn>BiP_s@w^9(F zL)3Yo!-N`bwPipjg5Su$l{5d@r|eH&=n5*k626raKk)^~?il}J-TL0&gQP5d6lH(( zY6}GED2^2M-*?|ZHvv%}8z-LFSl3CE1NzC@wG!Ew(rQD0RQ<=J__LoNayTZl^O2$J cdctpw|0DbV0#K_h4!T|bee(ZJE}E$QHxgp>>Hq)$ diff --git a/utils/gendocs.lua b/utils/gendocs.lua index 96fac1a..f2d3e8f 100644 --- a/utils/gendocs.lua +++ b/utils/gendocs.lua @@ -112,6 +112,7 @@ for line in io.stdin:lines() do if (cdoc) then if (cfunc) then cdoc.methods[#cdoc.methods+1] = cfunc + cfunc = nil end docs[#docs+1] = cdoc end @@ -126,6 +127,7 @@ for line in io.stdin:lines() do if (cdoc) then if (cfunc) then cdoc.methods[#cdoc.methods+1] = cfunc + cfunc = nil end docs[#docs+1] = cdoc end diff --git a/utils/velxdump.lua b/utils/velxdump.lua index 49d10ee..9fc3ebf 100644 --- a/utils/velxdump.lua +++ b/utils/velxdump.lua @@ -151,6 +151,7 @@ local velx_spec = struct { {compression="B"}, {lver="B"}, {os="B"}, + {arctype="c4"}, {psize="I3"}, {lsize="I3"}, {ssize="I3"}, @@ -167,6 +168,13 @@ local os = { [0x7F] = "BIOS", } +local commands = { + ["cpio"] = "cpio -t", + ["tar"] = "tar -t", + ["tsar"] = "tsar -t", + ["zip"] = "jar -t" +} + local f = io.open(arg[1], "rb") local header = velx_spec(f:read(#velx_spec)) local program = f:read(header.psize) @@ -179,13 +187,15 @@ io.stdout:write(string.format([[File Version: %d Compression: %s Type: %s OS: %s -Lua Version: %s]], +Lua Version: %s +Archive type: %s]], header.fver, compression[header.compression] or "Unknown", (((header.os & 0x80) > 0) and "Library") or "Executable", os[header.os & 0x7F] or "Unknown", -lver),"\n") -local h = io.popen("tsar -t", "w") +lver, +header.arctype:gsub("\0", "")),"\n") +local h = io.popen(commands[header.arctype:gsub("\0", "")], "w") h:write(archive) h:close() if (header.compression == 1) then