72 lines
1.7 KiB
Lua
72 lines
1.7 KiB
Lua
|
local a,sn,dp,rB=...
|
||
|
local function readBytes(off,count)
|
||
|
return rB(dp,off,count):gsub("%\0","")
|
||
|
end
|
||
|
|
||
|
local FileTable = readBytes(2502,8)
|
||
|
if FileTable ~= "FILES " then
|
||
|
error("can't find filetable at offset 2502 " ..FileTable)
|
||
|
end
|
||
|
local function loadFileTable(offset)
|
||
|
local fileTable = {}
|
||
|
if not offset then
|
||
|
offset = 2513
|
||
|
end
|
||
|
while true do
|
||
|
local Filename = readBytes(offset,16)
|
||
|
if Filename ~= "" then
|
||
|
if Filename == "EOFTEOFTEOFTEOFT" then
|
||
|
break
|
||
|
end
|
||
|
local file = {
|
||
|
["name"]=Filename,
|
||
|
["offset"]=tonumber(readBytes(offset+16,8),10),
|
||
|
["size"]=tonumber(readBytes(offset+24,2),10)
|
||
|
}
|
||
|
table.insert(fileTable, file)
|
||
|
end
|
||
|
offset = offset + 32
|
||
|
end
|
||
|
return fileTable
|
||
|
end
|
||
|
local fileTable = loadFileTable()
|
||
|
|
||
|
-- the first file should be the file SYSTEM.lua
|
||
|
local function findFile(filename)
|
||
|
for i = 1, #fileTable do
|
||
|
if fileTable[i]["name"] == filename then
|
||
|
return i
|
||
|
end
|
||
|
end
|
||
|
return nil
|
||
|
end
|
||
|
|
||
|
local fileIndex = findFile("SYSTEM.lua")
|
||
|
local Offset = fileTable[fileIndex]["offset"]
|
||
|
local Size = fileTable[fileIndex]["size"]
|
||
|
local FileHead = readBytes(Offset,9)
|
||
|
|
||
|
if FileHead ~= "STARTFILE" then
|
||
|
error("filehead is not correct" .. FileHead)
|
||
|
end
|
||
|
|
||
|
local data = readBytes(Offset+9,Size*dp.getSectorSize()-9)
|
||
|
local systemData, err = load(data, "=SYSTEM.lua", "bt", _G)
|
||
|
|
||
|
if err then
|
||
|
error(err)
|
||
|
end
|
||
|
|
||
|
if systemData == nil then
|
||
|
error("systemData is nil!")
|
||
|
end
|
||
|
|
||
|
systemData(a,sn,dp,rB,readBytes,loadFileTable,findFile)
|
||
|
|
||
|
local ts=os.time()
|
||
|
while 1 do
|
||
|
if os.time() - ts >= 0.5 then
|
||
|
coroutine.yield()
|
||
|
end
|
||
|
end
|