Compare commits

...

3 Commits

4 changed files with 171 additions and 0 deletions

60
cpioloader/tapeloader.lua Normal file
View File

@ -0,0 +1,60 @@
local fs = component.proxy(computer.tmpAddress())
local init = function() end
do
local tape = component.proxy(component.list("tape_drive")())
local rev,namesize,filesize,name,mode = false, 0, 0, "", 0
local function readint(amt)
local tmp = 0
for i=(rev and amt) or 1, (rev and 1) or amt, (rev and -1) or 1 do
tmp = tmp | (tape.read(1):byte() << ((i-1)*8))
end
return tmp
end
local function fwrite()
local dir = name:match("(.+)/.*%.?.+")
if (dir) then
fs.makeDirectory("/"..dir)
end
local fh = fs.open(name, "w")
fs.write(fh,tape.read(filesize))
fs.close(fh)
end
tape.seek(-math.huge)
while true do
local magic = readint(2)
if magic == 51057 then rev = true end
tape.seek(4)
mode = readint(2)
tape.seek(12)
namesize = readint(2)
filesize = (readint(2) << 16) | readint(2)
name = tape.read(namesize):sub(1, namesize-1)
if name == "TRAILER!!!" then break end
if (namesize % 2 ~= 0) then
tape.seek(1)
end
if (mode & 32768 ~= 0) then
fwrite()
end
if (filesize % 2 ~= 0) then
tape.seek(1)
end
computer.beep()
end
end
do
local f=fs.open("/init.lua","rb")
if not f then error("no init.lua") end
local initstr = ""
local data = ""
repeat
initstr = initstr .. data
data = fs.read(f,2048)
until data == nil
init = load(initstr)
end
computer.getBootAddress = computer.tmpAddress
init()

24
tapeloader/mkarchive.lua Normal file
View File

@ -0,0 +1,24 @@
local tArgs = {...}
local function cint(n,l)
local t={}
for i = 0, 7 do
t[i+1] = (n >> (i * 8)) & 0xFF
end
return string.reverse(string.char(table.unpack(t)):sub(1,l))
end
local function genHeader(fname,len)
return string.format("%s%s%s",cint(fname:len(),2),fname,cint(len,2))
end
for k,v in ipairs(tArgs) do
local f = io.open(v,"rb")
if f then
local content = f:read("*a")
f:close()
io.write(genHeader(v,content:len()))
io.write(content)
end
end
io.write(string.char(0):rep(2))

58
tapeloader/tapeloader.lua Normal file
View File

@ -0,0 +1,58 @@
local fs = component.proxy(computer.tmpAddress())
local init = function() end
if fs.exists("/init.lua") then
do
local tape = component.proxy(component.list("tape_drive")())
local function toint(s)
s=s or ""
local n = 0
local i = 1
while true do
local p = s:sub(i,i)
if p == "" then break end
local b = string.byte(p)
n = n << 8
n = n | b
i=i+1
end
return n
end
local function fwrite(name,len)
local dir = name:match("(.+)/.*%.?.+")
if (dir) then
fs.makeDirectory("/"..dir)
end
local fh = fs.open(name, "w")
fs.write(fh,tape.read(len))
fs.close(fh)
end
tape.seek(-math.huge)
while true do
local nlen = toint(tape.read(2))
if nlen == 0 then
break
end
local name = tape.read(nlen)
local fsize = toint(tape.read(2))
fwrite(name,fsize)
computer.beep()
end
end
end
do
local f=fs.open("/init.lua","rb")
if not f then error("no init.lua") end
local initstr = ""
local data = ""
repeat
initstr = initstr .. data
data = fs.read(f,2048)
until data == nil
init = load(initstr)
end
computer.getBootAddress = computer.tmpAddress
init()

29
tapeloader/unarchive.lua Normal file
View File

@ -0,0 +1,29 @@
local tArgs = {...}
local function toint(s)
s=s or ""
local n = 0
local i = 1
while true do
local p = s:sub(i,i)
if p == "" then break end
local b = string.byte(p)
n = n << 8
n = n | b
i=i+1
end
return n
end
local fi = io.open(tArgs[1])
while true do
local nlen = toint(fi:read(2))
if nlen == 0 then
break
end
local name = fi:read(nlen)
local fsize = toint(fi:read(2))
local fcontent = fi:read(fsize)
print(name,fsize)
end
fi:close()