@@ -235,6 +235,7 @@ def emit_track(self, cyl: int, side: int, track) -> None:
235235 bits = t .bits [index :] + t .bits [:index ]
236236 bit_ticks = (t .bit_ticks [index :] + t .bit_ticks [:index ]
237237 if t .bit_ticks else None )
238+ hardsector_bits = t .hardsector_bits
238239 # Rotate the weak areas
239240 weak = []
240241 for s , n in t .weak :
@@ -255,9 +256,12 @@ def emit_track(self, cyl: int, side: int, track) -> None:
255256 if bit_ticks is not None :
256257 bit_ticks = [x for x in bit_ticks for _ in range (2 )]
257258 weak = [(2 * x ,2 * y ) for (x ,y ) in weak ]
259+ if hardsector_bits is not None :
260+ hardsector_bits = [2 * x for x in hardsector_bits ]
258261 mt = MasterTrack (
259262 bits = bits , time_per_rev = t .time_per_rev ,
260- bit_ticks = bit_ticks , weak = weak )
263+ bit_ticks = bit_ticks , weak = weak ,
264+ hardsector_bits = hardsector_bits )
261265 else :
262266 flux = t .flux ()
263267 flux .cue_at_index ()
@@ -385,14 +389,15 @@ def add_weak(weak: List[HFEv3_Range], pos: int, nr: int) -> None:
385389 bits = bitarray (endian = 'big' )
386390 ticks : List [int ] = []
387391 weak : List [HFEv3_Range ] = []
392+ index : List [int ] = []
388393
389394 i = rate = 0
390395 while i < len (tdat ):
391396 x , i = tdat [i ], i + 1
392397 if x == HFEv3_Op .Nop :
393398 pass
394399 elif x == HFEv3_Op .Index :
395- pass # TODO: Support hard-sector images
400+ index . append ( len ( bits ))
396401 elif x == HFEv3_Op .Bitrate :
397402 if i + 1 > len (tdat ):
398403 # Non fatal: This has been observed in HFEv3 images created
@@ -433,11 +438,24 @@ def add_weak(weak: List[HFEv3_Range], pos: int, nr: int) -> None:
433438 if ticks [i ] != 0 : break
434439 ticks [i ] = rate
435440
441+ # This only works if the track is index aligned, with the first sector
442+ # starting at bit 0.
443+ hardsector_bits : Optional [List [int ]] = None
444+ if len (index ) > 1 :
445+ pos = 0
446+ hardsector_bits = []
447+ for x in index [1 :]:
448+ hardsector_bits .append (x - pos )
449+ pos = x
450+ # The last index pulse is the pre-index hole: extend to end of track
451+ hardsector_bits [- 1 ] += len (bits ) - pos
452+
436453 mt = MasterTrack (
437454 bits = bits ,
438455 time_per_rev = sum (ticks )/ 36e6 ,
439456 bit_ticks = cast (List [float ], ticks ), # mypy
440- weak = list (map (lambda x : (x .s , x .n ), weak ))
457+ weak = list (map (lambda x : (x .s , x .n ), weak )),
458+ hardsector_bits = hardsector_bits
441459 )
442460 return HFETrack (mt )
443461
0 commit comments