50 lines
1.2 KiB
Lua
50 lines
1.2 KiB
Lua
local AWEFS_version = "01"
|
|
|
|
local drive = component.list("drive", true)()
|
|
local eeprom = component.list("eeprom")()
|
|
component.invoke(eeprom, "setData", drive)
|
|
drive = component.proxy(drive)
|
|
|
|
|
|
local function readBytes(driveProxy,offset, count)
|
|
local buffer = ""
|
|
for i = 1, count do
|
|
local byte = math.abs(driveProxy.readByte(offset))
|
|
buffer = buffer .. utf8.char(byte)
|
|
offset = offset + 1
|
|
end
|
|
return buffer
|
|
end
|
|
|
|
local function tryLoad(driveProxy)
|
|
local signature = readBytes(driveProxy,1,8)
|
|
if signature ~= "AWEFS " then
|
|
return false, nil, "mismatched signature"
|
|
end
|
|
local version = readBytes(driveProxy,9,2)
|
|
if version ~= AWEFS_version then
|
|
return false, nil, "mismatched version"
|
|
end
|
|
|
|
local bootSec = readBytes(driveProxy,65,959)
|
|
local sn = readBytes(driveProxy,11,8)
|
|
|
|
bootSec = bootSec:gsub("%\0","")
|
|
|
|
local init, err = load(
|
|
bootSec, string.format("=%s",sn), "bt", _G)
|
|
|
|
return true,init,err,sn
|
|
end
|
|
|
|
local success,init,err, sn = tryLoad(drive)
|
|
|
|
if not success then
|
|
error(err)
|
|
end
|
|
|
|
if not init then
|
|
error("no bootable medium found :( " .. err)
|
|
end
|
|
|
|
return init(drive.address,sn,drive,readBytes) |