OC-Tsuki/extras/crescent/velx.lua
Jane Roxanne 501561ba4a Crescent
2020-05-24 09:18:28 -05:00

39 lines
946 B
Lua

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("<c5BBBBxxxxI3xxxxxxxxxx", fs.read(h, 13))
if (magic ~= "\27VelX" or fver ~= 1 or osid ~= 127) then
return
end
local rdat = psize
local dat = ""
local buf = ""
repeat
buf = fs.read(h, rdat)
if (buf) then
dat = dat .. buf
end
rdat = psize - #dat
y = y - 1
status("loading kernel... "..lsc())
until rdat == 0 or not buf or buf == ""
y = y - 1
status("loading kernel... ")
if (comp == 1) then
status("decompressing kernel...")
buf = lzss_decompress(buf)
end
end