Skip to content

Commit fbc88e6

Browse files
committed
scp: More fixes:
1. Detect non-index-cued images and clip first partial revolutions 2. Detect and handle empty TDH structures (no flux samples) 3. Set the 96tpi flag in exported SCP images
1 parent 84acade commit fbc88e6

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

  • scripts/greaseweazle/image

scripts/greaseweazle/image/scp.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def from_file(cls, dat):
4242
(sig, _, _, nr_revs, _, _, flags, _, single_sided, _, _) = header
4343
error.check(sig == b"SCP", "SCP: Bad signature")
4444

45+
index_cued = flags & 1 or nr_revs == 1
46+
if not index_cued:
47+
nr_revs -= 1
48+
4549
# Some tools generate a short TLUT. We handle this by truncating the
4650
# TLUT at the first Track Data Header.
4751
trk_offs = struct.unpack("<168I", dat[16:0x2b0])
@@ -68,12 +72,21 @@ def from_file(cls, dat):
6872

6973
# Parse the SCP track header and extract the flux data.
7074
thdr = dat[trk_off:trk_off+4+12*nr_revs]
71-
sig, tnr, _, _, s_off = struct.unpack("<3sB3I", thdr[:16])
75+
sig, tnr = struct.unpack("<3sB", thdr[:4])
7276
error.check(sig == b"TRK", "SCP: Missing track signature")
7377
error.check(tnr == trknr, "SCP: Wrong track number in header")
78+
_off = 12 if index_cued else 24 # skip first partial rev
79+
s_off, = struct.unpack("<I", thdr[_off:_off+4])
7480
_, e_nr, e_off = struct.unpack("<3I", thdr[-12:])
75-
tdat = dat[trk_off+s_off:trk_off+e_off+e_nr*2]
7681

82+
e_off += e_nr*2
83+
if s_off == e_off:
84+
# FluxEngine creates dummy TDHs for empty tracks.
85+
# Bail on them here.
86+
scp.track_list.append((None, None))
87+
continue
88+
89+
tdat = dat[trk_off+s_off:trk_off+e_off]
7790
scp.track_list.append((thdr[4:], tdat))
7891

7992
# s[side] is True iff there are non-empty tracks on @side
@@ -228,7 +241,7 @@ def get_image(self):
228241
0, # Version
229242
0x80, # DiskType = Other
230243
self.nr_revs, 0, len(track_list) - 1,
231-
0x01, # Flags = Index
244+
0x03, # Flags = Index, 96TPI
232245
0, # 16-bit cell width
233246
single_sided,
234247
0, # 25ns capture

0 commit comments

Comments
 (0)