diff --git a/src/greaseweazle/flux.py b/src/greaseweazle/flux.py index 219b1f2f..f2b7d0b0 100644 --- a/src/greaseweazle/flux.py +++ b/src/greaseweazle/flux.py @@ -130,6 +130,31 @@ def cue_at_index(self) -> None: self.sector_list = self.sector_list[1:] + def reverse(self) -> None: + + assert self.sector_list is None + + was_index_cued = self.index_cued + flux_sum = sum(self.list) + + self.index_cued = False + self.list.reverse() + self.index_list.reverse() + + to_index = flux_sum - sum(self.index_list) + if to_index <= 0: + if to_index < 0: + self.list.insert(0, -to_index) + flux_sum += -to_index + self.index_list = self.index_list[1:] + self.index_cued = True + else: + self.index_list = [to_index] + self.index_list[:-1] + + if was_index_cued: + self.index_list.append(flux_sum - sum(self.index_list)) + + def set_nr_revs(self, revs:int) -> None: self.cue_at_index() diff --git a/src/greaseweazle/tools/convert.py b/src/greaseweazle/tools/convert.py index 8df29a18..3a7ce205 100644 --- a/src/greaseweazle/tools/convert.py +++ b/src/greaseweazle/tools/convert.py @@ -49,6 +49,10 @@ def process_input_track( if track is None: return None + if args.reverse: + track = track.flux() + track.reverse() + if args.hard_sectors: track = track.flux() track.identify_hard_sectors() @@ -132,6 +136,8 @@ def main(argv) -> None: help="manual PLL parameter override") parser.add_argument("--hard-sectors", action="store_true", help="convert index positions to hard sectors") + parser.add_argument("--reverse", action="store_true", + help="reverse track data (flippy disk)") parser.add_argument("in_file", help="input filename") parser.add_argument("out_file", help="output filename") parser.description = description diff --git a/src/greaseweazle/tools/read.py b/src/greaseweazle/tools/read.py index c4ec8042..88a684bb 100644 --- a/src/greaseweazle/tools/read.py +++ b/src/greaseweazle/tools/read.py @@ -43,6 +43,8 @@ def read_and_normalise(usb: USB.Unit, args, revs: int, ticks=0) -> Flux: else: flux = usb.read_track(revs=revs, ticks=ticks) flux._ticks_per_rev = args.drive_ticks_per_rev + if args.reverse: + flux.reverse() if args.adjust_speed is not None: flux.scale(args.adjust_speed / flux.time_per_rev) return flux @@ -211,6 +213,8 @@ def main(argv) -> None: help="manual PLL parameter override") parser.add_argument("--densel", "--dd", type=util.level, metavar="LEVEL", help="drive interface density select on pin 2 (H,L)") + parser.add_argument("--reverse", action="store_true", + help="reverse track data (flippy disk)") parser.add_argument("file", help="output filename") parser.description = description parser.prog += ' ' + argv[1] diff --git a/src/greaseweazle/tools/write.py b/src/greaseweazle/tools/write.py index d3f6b076..1f414f7c 100644 --- a/src/greaseweazle/tools/write.py +++ b/src/greaseweazle/tools/write.py @@ -69,8 +69,14 @@ def write_from_image(usb: USB.Unit, args, image: image.Image) -> None: if isinstance(track, codec.Codec): track = track.master_track() - if args.precomp is not None and isinstance(track, MasterTrack): - track.precomp = args.precomp.track_precomp(cyl) + if isinstance(track, MasterTrack): + if args.reverse: + track.reverse() + if args.precomp is not None: + track.precomp = args.precomp.track_precomp(cyl) + elif args.reverse: + track = track.flux() + track.reverse() wflux = track.flux_for_writeout(cue_at_index = not no_index) # @factor adjusts flux times for speed variations between the @@ -127,6 +133,8 @@ def write_from_image(usb: USB.Unit, args, image: image.Image) -> None: else: v_flux = usb.read_track(revs = v_revs, ticks = v_ticks) v_flux._ticks_per_rev = drive_ticks_per_rev + if args.reverse: + v_flux.reverse() verified = verify.verify_track(v_flux) if verified: verified_count += 1 @@ -205,6 +213,8 @@ def main(argv) -> None: help="number of retries on verify failure") parser.add_argument("--precomp", type=PrecompSpec, help="write precompensation") + parser.add_argument("--reverse", action="store_true", + help="reverse track data (flippy disk)") densel_group = parser.add_mutually_exclusive_group(required=False) densel_group.add_argument( "--densel", "--dd", type=util.level, metavar="LEVEL", diff --git a/src/greaseweazle/track.py b/src/greaseweazle/track.py index e4114b64..330488c0 100644 --- a/src/greaseweazle/track.py +++ b/src/greaseweazle/track.py @@ -149,6 +149,17 @@ def summary_string(self) -> str: s += ')' return s + def reverse(self) -> None: + bitlen = len(self.bits) + if bitlen == 0: return + self.bits.reverse() + if self.bit_ticks is not None: + self.bit_ticks.reverse() + self.splice = -self.splice % bitlen + self.weak = list(map(lambda x: (-x[0] % bitlen, x[1]), self.weak)) + if self.hardsector_bits is not None: + self.hardsector_bits.reverse() + def flux(self, revs: Optional[int] = None) -> Flux: flux = self._flux(for_writeout=False, cue_at_index=True, revs=revs) assert isinstance(flux, Flux)