Browse Source

python: Clip the partial first revolution of a GW track read in the core code.

Keir Fraser 5 years ago
parent
commit
f4cb24a39f
2 changed files with 26 additions and 15 deletions
  1. 3 13
      scripts/greaseweazle/scp.py
  2. 23 2
      scripts/gw.py

+ 3 - 13
scripts/greaseweazle/scp.py

@@ -96,7 +96,7 @@ class SCP:
     # the current image-in-progress.
     def append_track(self, flux):
 
-        nr_revs = len(flux.index_list) - 1
+        nr_revs = len(flux.index_list)
         if not self.nr_revs:
             self.nr_revs = nr_revs
         else:
@@ -114,16 +114,6 @@ class SCP:
 
         for x in flux.list:
 
-            # Are we processing initial samples before the first revolution?
-            if rev == 0:
-                if to_index >= x:
-                    # Discard initial samples
-                    to_index -= x
-                    continue
-                # Now starting the first full revolution
-                rev = 1
-                to_index += flux.index_list[rev]
-
             # Does the next flux interval cross the index mark?
             while to_index < x:
                 # Append to the TDH for the previous full revolution
@@ -134,7 +124,7 @@ class SCP:
                 # Set up for the next revolution
                 len_at_index = len(dat)
                 rev += 1
-                if rev > nr_revs:
+                if rev >= nr_revs:
                     # We're done: We simply discard any surplus flux samples
                     self.track_list.append((tdh, dat))
                     return
@@ -155,7 +145,7 @@ class SCP:
             dat.append(val&255)
 
         # Header for last track(s) in case we ran out of flux timings.
-        while rev <= nr_revs:
+        while rev < nr_revs:
             tdh += struct.pack("<III",
                                int(round(flux.index_list[rev]*factor)),
                                (len(dat) - len_at_index) // 2,

+ 23 - 2
scripts/gw.py

@@ -20,11 +20,16 @@ from greaseweazle.scp import SCP
 # read_to_scp:
 # Reads a floppy disk and dumps it into a new Supercard Pro image file.
 def read_to_scp(usb, args):
+
     scp = SCP(args.scyl, args.nr_sides)
+
     for cyl in range(args.scyl, args.ecyl+1):
         for side in range(0, args.nr_sides):
+
             print("\rReading Track %u.%u..." % (cyl, side), end="")
             usb.seek(cyl, side)
+
+            # Physically read the track.
             for retry in range(1, 5):
                 ack, index_list, enc_flux = usb.read_track(args.revs+1)
                 if ack == USB.Ack.Okay:
@@ -33,9 +38,25 @@ def read_to_scp(usb, args):
                     print("Retry #%u..." % (retry))
                 else:
                     raise CmdError(ack)
-            flux = Flux(index_list, usb.decode_flux(enc_flux), usb.sample_freq)
-            scp.append_track(flux)
+
+            # Decode the flux and clip the initial partial revolution.
+            flux_list = usb.decode_flux(enc_flux)
+            del enc_flux
+            to_index = index_list[0]
+            for i in range(len(flux_list)):
+                to_index -= flux_list[i]
+                if to_index < 0:
+                    flux_list[i] = -to_index
+                    flux_list = flux_list[i:]
+                    index_list = index_list[1:]
+                    break
+                
+            # Stash the data for later writeout to the image file.
+            scp.append_track(Flux(index_list, flux_list, usb.sample_freq))
+
     print()
+
+    # Write the image file.
     with open(args.file, "wb") as f:
         f.write(scp.get_image())