diff --git a/bonecrunch.lua b/bonecrunch.lua new file mode 100644 index 0000000..b87fe11 --- /dev/null +++ b/bonecrunch.lua @@ -0,0 +1,87 @@ +-- This is released into the public domain. +-- No warranty is provided, implied or otherwise. + +-- This program tries to crunch down the installer a bit further. +-- Specific target in mind, it has no support for string escapes. +-- It also does this: +for i = 1, 3 do + print(io.read()) +end + +local sequences = { + {"\n", " "}, + {" ", " "}, + {" #", "#"}, + {"# ", "#"}, + {" ,", ","}, + {", ", ","}, + {" (", "("}, + {"( ", "("}, + {" )", ")"}, + {") ", ")"}, + {" <", "<"}, + {"< ", "<"}, + {" >", ">"}, + {"> ", ">"}, + {" *", "*"}, + {"* ", "*"}, + {" ~", "~"}, + {"~ ", "~"}, + {" /", "/"}, + {"/ ", "/"}, + {" %", "%"}, + {"% ", "%"}, + {" =", "="}, + {"= ", "="}, + {" -", "-"}, + {"- ", "-"}, + {" +", "+"}, + {"+ ", "+"}, + {".. ", ".."}, + {" ..", ".."}, + {"\"\" ", "\"\""}, + {"=0 t", "=0t"}, + {">0 t", ">0t"}, + {">1 t", ">1t"}, + {"=1 w", "=1w"}, + {"=380 l", "=380l"}, + {"=127 t", "=127t"}, + {"=128 t", "=128t"}, + {">255 t", ">255t"}, + {"=512 t", "=512t"} +} + +local function pass(buffer) + local ob = "" + local smode = false + while #buffer > 0 do + if not smode then + local ds = true + while ds do + ds = false + for _, v in ipairs(sequences) do + if buffer:sub(1, #(v[1])) == v[1] then + buffer = v[2] .. buffer:sub(#(v[1]) + 1) + ds = true + end + end + end + end + local ch = buffer:sub(1, 1) + buffer = buffer:sub(2) + ob = ob .. ch + if ch == "\"" then + smode = not smode + end + end + return ob +end +local op = io.read("*a") +while true do + local np = pass(op) + if np == op then + io.write(np) + return + end + op = np +end diff --git a/com2/bdivide.lua b/com2/bdivide.lua index fcf800c..490fcc5 100644 --- a/com2/bdivide.lua +++ b/com2/bdivide.lua @@ -52,7 +52,7 @@ local function runBlock(blk) end end -while true do +while 1 do local blkd = io.read(512) runBlock(blkd) if #blkd < 512 then diff --git a/com2/bundiv.lua b/com2/bundiv.lua index e52b1b1..29b8052 100644 --- a/com2/bundiv.lua +++ b/com2/bundiv.lua @@ -3,36 +3,38 @@ local sector = io.write -- XX -- BUNDIVIDE reference implementation for integration XX local Cs,Cbu,Cb,Cw,Cp,Ct,Ci,CP,CB,CD={},128,"",128,"","" -CP=function(d,b) - Ct=Ct..d +CP = function(d,b) + Ct = Ct .. d while#Ct>2 do - b=Ct:byte() - Ct=Ct:sub(2) - if b==127then - b=Ct:byte() - Ct=Ct:sub(2) - if b==127then - b=Ct:byte()+254 - if b>255then - b=b-256 + b = Ct:byte() + Ct = Ct:sub(2) + if b == 127 then + b = Ct:byte() + Ct = Ct:sub(2) + if b == 127 then + b = Ct:byte()+254 + if b > 255then + b = b - 256 end - Ct=Ct:sub(2) + Ct = Ct:sub(2) else - b=b+127 + b = b + 127 end end - Cp=Cp..string.char(b) - if #Cp==512then + Cp = Cp..string.char(b) + if #Cp == 512 then sector(Cp) - Cp="" + Cp = "" end end end -for i=128,127+Cbu do Cs[i]=("\x00"):rep(512) end -Cs[Cw]="" -CB=function(d,i,d2,x,y) +for i = 128, 127 + Cbu do + Cs[i] = ("\x00"):rep(512) +end +Cs[Cw] = "" +CB = function (d, i, d2, x, y) i=1 - while i<=#d-2 do + while i <= #d - 2 do b=d:byte(i) d2=d:sub(i,i) i=i+1 @@ -41,13 +43,15 @@ CB=function(d,i,d2,x,y) Ci=1 end else - if b>=128then - x=d:byte(i)i=i+1 - y=(d:byte(i)+((x%2)*256))i=i+1 - d2=Cs[b]:sub(y+1,y+3+math.floor(x/2)) + if b >= 128 then + x = d:byte(i) + i = i + 1 + y=d:byte(i) + ((x % 2) * 256) + i = i + 1 + d2=Cs[b]:sub(y + 1,y + 3 + math.floor(x / 2)) end Cs[Cw]=Cs[Cw]..d2 - if #Cs[Cw]>=512then + if #Cs[Cw]>=512 then CP(Cs[Cw]) Cw=((Cw-127)%Cbu)+128 Cs[Cw]="" @@ -56,9 +60,9 @@ CB=function(d,i,d2,x,y) end return i end -CD=function(d) - Cb=Cb..d - Cb=Cb:sub(CB(Cb)) +CD = function(d) + Cb = Cb .. d + Cb = Cb:sub(CB(Cb)) end CD(io.read("*a")) -- XX --D.remove("init-bdivide.lua")-- diff --git a/heroes.lua b/heroes.lua index 35bb986..4b65f66 100644 --- a/heroes.lua +++ b/heroes.lua @@ -10,11 +10,8 @@ local src = io.open("com2/bundiv.lua", "r") while true do local line = src:read() if not line then - src:close() - io.write("--[[") io.flush() - os.execute("cat com2/code.tar.bd") - io.write("]]") + src:close() return end local endix = line:sub(#line-1,#line) diff --git a/insthead.lua b/insthead.lua index 33aa77a..695cd3e 100644 --- a/insthead.lua +++ b/insthead.lua @@ -1,11 +1,10 @@ -- KOSNEO inst. -- This is released into the public domain. -- No warranty is provided, implied or otherwise. - local C, O, G, D = component, computer if not C then - error("Copy to init.lua on a blank disk. Thank you!") + error("Copy as init.lua to a blank disk, then remove all other disks and reboot. Thank you!") end local sa = C.list("screen", true)() @@ -28,16 +27,12 @@ end D = C.proxy(O.getBootAddress()) -local tF = nil -local tFN = "Starting..." -local tFSR = 0 -local tW = 0 +local tFN,tFSR,tW,tF="Starting...",0,0 -local convoct -convoct = function (oct) +local function tO(oct) local v = oct:byte(#oct) - 0x30 if #oct > 1 then - return (convoct(oct:sub(1, #oct - 1)) * 8) + v + return (tO(oct:sub(1, #oct - 1)) * 8) + v end return v end @@ -56,7 +51,7 @@ local function tA(s) end else tFN = s:sub(1, 100):gsub("\x00", "") - local sz = convoct(s:sub(125, 135)) + local sz = tO(s:sub(125, 135)) if tFN:sub(1, 5) ~= "code/" then tW = math.ceil(sz / 512) else @@ -79,12 +74,8 @@ local function tA(s) end end -local dieCB = function () end - -local sN = 0 -local sC = 0 - -local function sector(n) +local sN,sC,dieCB,sector=0,0 +function sector(n) tA(n) sN = sN + 1 if G then diff --git a/mkucinst.lua b/mkucinst.lua index 4e40903..7dbe047 100644 --- a/mkucinst.lua +++ b/mkucinst.lua @@ -14,6 +14,7 @@ while true do end df:close() local df = io.open("code.tar", "rb") +f:write("dieCB = function () end") f:write("sC = " .. sc .. "\n") while true do local d = df:read(512) diff --git a/package.sh b/package.sh index e2ab61f..7e5b333 100755 --- a/package.sh +++ b/package.sh @@ -7,7 +7,10 @@ rm code.tar # Hey, look behind you, there's nothing to see here. # ... ok, are they seriously all named "Mann"? tar --owner=gray:0 --group=mann:0 -cf code.tar code -lua heroes.lua `wc -c code.tar` > inst.lua +lua heroes.lua `wc -c code.tar` | lua bonecrunch.lua > inst.lua +echo -n "--[[" >> inst.lua +cat com2/code.tar.bd >> inst.lua +echo -n "]]" >> inst.lua stat repobuild/data/app-claw/local.lua && rm -rf repobuild mkdir repobuild