1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-08 19:48:07 +11:00
OC-KittenOS/inst/bdivide/instdeco.lua

77 lines
1.8 KiB
Lua
Raw Normal View History

-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
-- BDIVIDE (r5 edition) and PREPROC (r9 edition)
-- decompression engine for installer
2020-03-31 03:47:27 +11:00
-- a: temporary
-- touched by q,L
-- b: sector accumulator
-- c: bdivide accumulator
-- d: temporary
-- touched by q,L
-- t: preproc accumulator
-- q: function to submit to preproc
-- s: temporary
-- touched by L
-- w: bdivide window
2020-03-31 03:47:27 +11:00
-- L: function to submit to bdivide
2020-03-31 03:47:27 +11:00
b,t,c,w="","","",("\x00"):rep(2^16)
-- High-level breakdown:
2020-03-31 03:47:27 +11:00
-- q is unescaper & TAR-sector-breakup.
-- It'll only begin to input if at least 3 bytes are available,
-- so you'll want to throw in 2 extra zeroes at the end of stream as done here.
2020-03-31 03:47:27 +11:00
-- It uses t (input buffer) and p (output buffer).
-- Ignore its second argument, as that's a lie, it's just there for a local.
2020-03-31 03:47:27 +11:00
-- L is the actual decompressor. It has the same quirk as q, wanting two more bytes.
-- It stores to c (compressed), and w (window).
-- It outputs that which goes to the window to q also.
-- And it also uses a fake local.
-- SEE compress.lua FOR THIS FUNCTION
function p(x, y)
if x == 126 then
return string.char(y), 3
elseif x == 127 then
return string.char(128 + y), 3
elseif x >= 32 then
return string.char(x), 2
elseif x == 31 then
return "\n", 2
elseif x == 30 then
return "\x00", 2
end
2020-03-31 03:47:27 +11:00
return string.char(("enart"):byte(x % 5 + 1), ("ndtelh"):byte((x - x % 5) / 5 + 1)), 2
end
2020-03-31 03:47:27 +11:00
function q(w)
t = t .. w
while #t > 1 do
d, a = p(t:byte(), t:byte(2))
b = b .. d
t = t:sub(a)
if #b > 511 then
M(b:sub(1, 512))
b = b:sub(513)
end
end
end
2020-03-31 03:47:27 +11:00
function L(d)
c = c .. d
while #c > 2 do
s = c:byte()
if s < 128 then
s, c = c:sub(1, 1), c:sub(2)
else
2020-03-31 03:47:27 +11:00
a = c:byte(2) * 256 + c:byte(3) + 1
s, c = w:sub(a, a + s - 125), c:sub(4)
end
2020-03-31 03:47:27 +11:00
q(s)
w = (w .. s):sub(-2^16)
end
end