ws-arch2: d64 type annotations
This commit is contained in:
1 parent
5ca22c4431
commit
66d785de11
1 file changed
+4
-4
@@ -34,7 +34,7 @@ export type EncodeOptions = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local TYPES = { [0] = "del", "seq", "prg", "usr", "rel", "cbm", "dir" }
|
||||
local TYPE_CODE = { del = 0, seq = 1, prg = 2, usr = 3, rel = 4 }
|
||||
local TYPE_CODE: { [string]: number } = { del = 0, seq = 1, prg = 2, usr = 3, rel = 4 }
|
||||
|
||||
type Geometry = { kind: string, tracks: number, offsets: { number }, spt: { number }, dirTrack: number, total: number }
|
||||
|
||||
@@ -57,8 +57,8 @@ end
|
||||
|
||||
-- image sizes -> geometry (sizes with the error-info block appended too)
|
||||
local function detect(len: number): Geometry?
|
||||
for _, g in { { "d64", 35 }, { "d64", 40 }, { "d64", 42 }, { "d71", 70 }, { "d81", 80 } } do
|
||||
local geo = geometry(g[1], g[2])
|
||||
for _, g in { { "d64", 35 }, { "d64", 40 }, { "d64", 42 }, { "d71", 70 }, { "d81", 80 } } :: { { any } } do
|
||||
local geo = geometry(g[1] :: string, g[2] :: number)
|
||||
local sectors = geo.total // 256
|
||||
if len == geo.total or (g[1] ~= "d81" and len == geo.total + sectors) then
|
||||
return geo
|
||||
@@ -399,7 +399,7 @@ function D64.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
table.insert(dirSectors, nextS)
|
||||
end
|
||||
local e = dir + dirSector * 256 + slot * 32
|
||||
local ty = if type(f.entry.type) == "string" and TYPE_CODE[f.entry.type] then TYPE_CODE[f.entry.type] else 2
|
||||
local ty: number = if type(f.entry.type) == "string" and TYPE_CODE[f.entry.type] then TYPE_CODE[f.entry.type] :: number else 2
|
||||
buffer.writeu8(img, e + 2, 0x80 + ty)
|
||||
buffer.writeu8(img, e + 3, first_t)
|
||||
buffer.writeu8(img, e + 4, first_s)
|
||||
|
||||
Reference in new issue
Block a user