archive formats: comments are specs only
This commit is contained in:
1 parent
8bd1a9327c
commit
e792c419d9
36 files changed
+172
-442
No files matched your search
@@ -1,14 +1,7 @@
|
||||
--!strict
|
||||
-- archive/d64: Commodore disk images as an Archive: D64 (1541: 35 / 40 / 42 tracks, with or without the error-info
|
||||
-- block), D71 (1571: 70 tracks, double sided) and D81 (1581: 80 tracks of 40 sectors). The BAM / header (disk name and
|
||||
-- id in meta.disk / meta.id), the directory chain, and every file's sector chain; PRG / SEQ / USR / REL files are
|
||||
-- entries (entry.type, entry.blocks, entry.locked, entry.closed; REL files read their data chain, the side sectors are
|
||||
-- skipped), deleted entries are skipped, unclosed ("splat") files are flagged closed = false. Names are PETSCII
|
||||
-- translated as VICE's c1541 does (0x41..0x5A -> a..z, 0xC1..0xDA and 0x61..0x7A -> A..Z, other bytes to U+E0xx so the
|
||||
-- name survives a round trip); entry.rawName keeps the 16 bytes. Writes D64 (35 tracks) / D71 / D81 images from any
|
||||
-- Archive (files as PRG, or entry.type), allocating sectors near the directory track with interleave 10 as CBM DOS
|
||||
-- does (not the same sectors as a real drive). Written from the 1541 / 1571 / 1581 DOS documentation (Peter Schepers'
|
||||
-- disk format notes). Not supported: GEOS VLIR files (read as their first chain), 1581 partitions (CBM type) contents.
|
||||
-- archive/d64: Commodore D64 (1541: 35 / 40 / 42 tracks, error block), D71, D81 (Peter Schepers' notes); PETSCII names
|
||||
-- as VICE's c1541 (0x41..0x5A -> a..z, 0xC1..0xDA / 0x61..0x7A -> A..Z, else U+E0xx); writes with interleave 10 as
|
||||
-- CBM DOS (not a real drive's sectors). Not supported: GEOS VLIR files (first chain), 1581 partition contents.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -28,8 +21,8 @@ local D64 = {
|
||||
export type DecodeOptions = { maxEntries: number? } -- default 4096
|
||||
export type EncodeOptions = {
|
||||
variant: ("d64" | "d71" | "d81")?, -- default: the variant read, else "d64"
|
||||
disk: string?, -- disk name (default "rosetta" / the name read)
|
||||
id: string?, -- two-character disk id (default "fl")
|
||||
disk: string?, -- default "rosetta" / the name read
|
||||
id: string?, -- default "fl"
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -129,7 +122,6 @@ local function encoder(a: any, o: any?): (buffer?, Err.Err?)
|
||||
return D64.encode(a, o)
|
||||
end
|
||||
|
||||
-- the bytes of a sector chain starting at (t, s); nil, message when it leaves the disk or loops
|
||||
local function chain(b: buffer, base: number, geo: Geometry, t: number, s: number): (buffer?, string?)
|
||||
local w = Bytes.writer()
|
||||
local seen: { [number]: boolean } = {}
|
||||
@@ -174,7 +166,6 @@ function D64.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
a.meta.tracks = geo.tracks
|
||||
a.meta.errorInfo = r:size() ~= geo.total
|
||||
a.meta.source = { format = "d64", variant = geo.kind, tracks = geo.tracks }
|
||||
-- the directory chain
|
||||
local t, s = buffer.readu8(b, hdr), buffer.readu8(b, hdr + 1)
|
||||
local seen: { [number]: boolean } = {}
|
||||
local count = 0
|
||||
@@ -236,7 +227,6 @@ end
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
-- BAM layout per variant: where each track's free count + bitmap lives
|
||||
local function bamEntry(geo: Geometry, img: buffer, t: number): (number, number, number)
|
||||
-- returns (offset of the free count, offset of the bitmap, bitmap bytes)
|
||||
local dir = geo.offsets[geo.dirTrack]
|
||||
if geo.kind == "d81" then
|
||||
local side = if t <= 40 then 1 else 2
|
||||
@@ -286,7 +276,6 @@ function D64.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local function pad16(s: string): string
|
||||
return s .. string.rep("\160", 16 - #s)
|
||||
end
|
||||
-- header / BAM
|
||||
local firstDir
|
||||
if variant == "d81" then
|
||||
buffer.writestring(img, dir, "\40\3\68\0")
|
||||
@@ -413,7 +402,6 @@ function D64.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
-- new(variant?) -> an empty disk: a:add(name, data); a:write({ disk = "name", id = "ab" })
|
||||
function D64.new(variant: string?): any
|
||||
local a = Archive.new("d64", encoder)
|
||||
a.meta.variant = variant or "d64"
|
||||
|
||||
Reference in new issue
Block a user