Skip to content

Commit

Permalink
gw read/write/convert: New option --reverse to reverse track data for…
Browse files Browse the repository at this point in the history
… flippy disks

Examples:
gw convert --tracks=h=0:hswap --reverse a.scp a_side1.scp
gw convert --tracks=h=0:hswap --reverse a.scp a_side1.do
gw read --tracks=c=0-39:h=0:hswap --reverse a_side1.do
gw write --tracks=hswap --reverse a_side1.do

Refs #460
  • Loading branch information
keirf committed Aug 22, 2024
1 parent 4153208 commit aca38b8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/greaseweazle/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/greaseweazle/tools/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/greaseweazle/tools/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 12 additions & 2 deletions src/greaseweazle/tools/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions src/greaseweazle/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aca38b8

Please sign in to comment.