From b534cb9b163df09978d3f8a44e9a5b58b8e2461e Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 20 Jul 2025 22:21:51 -0700 Subject: [PATCH] start of splubp prototype --- splubp.p8 | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 splubp.p8 diff --git a/splubp.p8 b/splubp.p8 new file mode 100644 index 0000000..8a32f60 --- /dev/null +++ b/splubp.p8 @@ -0,0 +1,97 @@ +pico-8 cartridge // http://www.pico-8.com +version 42 +__lua__ +-- splubp data transport +-- by kistaro windrider + +-- main + +-- >8 +-- utilities + +-- generate standard "overlay" +-- constructor for type tt. +-- if tt.init is defined, generated +-- new calls tt.init(ret) after +-- ret is definitely not nil, +-- after calling setmetatable. +-- use to initialize mutables. +-- +-- if there was a previous new, +-- it is invoked before +-- setting tt's metatable, so +-- each new will see its +-- inheritance chain. +function mknew(tt) + local mt,oldinit,more = {__index=tt},tt.superinit,rawget(tt, "init") + tt.new=function(ret) + if(not ret) ret = {} + ret.new = false + setmetatable(ret, mt) + if(oldinit) oldinit(ret) + if (more) more(ret) + return ret + end + + if oldinit and more then + tt.superinit = function(ret) + oldinit(ret) + more(ret) + end + elseif more then + tt.superinit = more + end + return tt +end + +function set(t) + local ret = {} + for v in all(t) do + ret[v]=true + end + return ret +end + +whitespace = set(split" ,\t,\n") + +function trim(s) + local f, e = 1, #s + while (f <= e and whitespace[s[f]]) f += 1 + while (e >= f and whitespace[s[e]]) e -= 1 + if (f8 +-- writer + +splubp_writer = mknew{ + init = function(self) + -- fill from single file + self.fmts = self.fmts or {} + if self.ffile then + for f in all(split(self.ffile, "===", false)) do + local ext, fmt = split(f, "---") + self.fmts[trim(ext)] = trim(fmt) + end + end + end +} + + +-->8 +-- loader + +-- essay: `e` directive +-- reads int16 char count, +-- then parses that many bytes +-- into a string (via chr). +-- returns string, new read offset. +function splubp_read_essay(addr) + local cs, n = {}, %addr + for a2 = addr+2, addr+n+1 do + add(cs, @a2) + end + return chr(unpack(cs)), addr+2+n +end +