From a144937e244bacf5260d6bc6daaeab6e4008d4b3 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 5 Aug 2023 10:19:07 +1000 Subject: [PATCH] implement proper tape support, also speed up loading from tapes. --- partition/driveboot.lua | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/partition/driveboot.lua b/partition/driveboot.lua index 20c7b10..56341c5 100644 --- a/partition/driveboot.lua +++ b/partition/driveboot.lua @@ -1,10 +1,11 @@ +return (function() +local component = component function computer.getBootAddress() return component.invoke(component.list("eeprom")(),"getData") end function computer.setBootAddress(a) return component.invoke(component.list("eeprom")(),"setData",a) end -return (function() local rv local function getProxy(addr) if type(addr) == "string" then @@ -13,14 +14,22 @@ local function getProxy(addr) return addr end local function aop(td,n,mn,...) - local rts = td.seek(-math.huge) - td.seek(n) - local rv = {td[mn](...)} - td.seek(-math.huge) - td.seek(rts) + local rv + if td.getPosition then + local rts = td.getPosition() + if rts ~= n then + td.seek(n - rts) + end + rv = {td[mn](...)} + else + local rts = td.seek(-math.huge) + td.seek(n) + rv = {td[mn](...)} + td.seek(-math.huge) + td.seek(rts) + end return table.unpack(rv) end - local eformat = "c20c4>I4>I4" function parsePartitions(s) local rt = {} @@ -33,7 +42,6 @@ function parsePartitions(s) end return rt end - function getPartitions(drive) local rv if drive.type == "tape_drive" then @@ -45,7 +53,6 @@ function getPartitions(drive) end return rv[1][2] == "mtpt" and rv end - local function offsetSector(part,sector) if sector < 1 or sector > part[4] then error("invalid offset, not in a usable sector") end return (part[3] - 1) + sector @@ -54,16 +61,16 @@ local function readSector(drive,part,sector) return drive.readSector(offsetSector(part,sector)):gsub("\0+$","") end local function readPart(drive,part) - if drive.type == "tape_drive" then - return aop(drive, (part[3]-1)*512, "read", part[4] * 512) - end local rv = "" for i = 1, part[4] do - rv=rv .. readSector(drive,part,i) + if drive.type == "tape_drive" then + rv=rv .. aop(drive, ((part[3]-2) + i)*512, "read", 512):gsub("\0+$","") + else + rv=rv .. readSector(drive,part,i) + end end return rv end - local pB = computer.getBootAddress() local candidates={pB,[pB] = true} if not component.type(pB) then candidates[1] = nil end @@ -71,11 +78,10 @@ for a,t in component.list() do candidates[#candidates+1] = not candidates[a] and (t == "drive" or t == "filesystem" or t == "tape_drive") and a or nil candidates[a] = true end - local function wL() return false end -local cL = wL +local cL=wL local ga, sa = component.list("gpu")(), component.list("screen")() if ga and sa then local g, cl = component.proxy(ga), 1 @@ -110,7 +116,6 @@ if ga and sa then end until computer.uptime() >= to end - for i,a in ipairs(candidates) do computer.beep(("."):rep(i)) wL("Attempting to load from "..a)