Browse Source

edsk: Support standard DSK image files.

Keir Fraser 4 years ago
parent
commit
8f6cd9e59d
2 changed files with 10 additions and 4 deletions
  1. 3 0
      scripts/greaseweazle/codec/ibm/mfm.py
  2. 7 4
      scripts/greaseweazle/image/edsk.py

+ 3 - 0
scripts/greaseweazle/codec/ibm/mfm.py

@@ -25,6 +25,9 @@ sync.frombytes(sync_bytes)
 
 crc16 = crcmod.predefined.Crc('crc-ccitt-false')
 
+def sec_sz(n):
+    return 128 << n if n <= 7 else 128 <= 8
+
 class TrackArea:
     def __init__(self, start, end, crc=None):
         self.start = start

+ 7 - 4
scripts/greaseweazle/image/edsk.py

@@ -111,7 +111,7 @@ class EDSK(Image):
             if weak:
                 s, e = min(s, weak[0]), max(e, weak[-1])
         return [(s,e-s+1)] if s <= e else []
-        
+
     @classmethod
     def from_file(cls, name):
 
@@ -133,7 +133,7 @@ class EDSK(Image):
             tsizes = list(dat[52:52+ncyls*nsides])
             tsizes = list(map(lambda x: x*256, tsizes))
         else:
-            raise error.Fatal('Standard CPC DSK file not yet supported')
+            tsizes = [track_sz] * (ncyls * nsides)
 
         o = 256 # skip disk header and track-size table
         for tsize in tsizes:
@@ -161,9 +161,11 @@ class EDSK(Image):
                     c, h, r, n, stat1, stat2, actual_length = struct.unpack(
                         '<6BH', secs[:8])
                     secs = secs[8:]
-                    size = 128 << n
+                    size = mfm.sec_sz(n)
                     weak = []
-                    if size != actual_length:
+                    if not extended:
+                        actual_length = mfm.sec_sz(sec_sz)
+                    elif size != actual_length:
                         error.check(actual_length != 0
                                     and actual_length % size == 0,
                                     'EDSK: Weird sector size (GAP protection?)')
@@ -221,6 +223,7 @@ class EDSK(Image):
                             '(%d bits @ GAP3=%d; %d bits @ GAP3=0)'
                             % (cyl, head, len(t)*8, gap_3,
                                (len(t)//2-gap_3*nsecs)*16))
+                #print('EDSK: GAP3 reduced (%d -> %d)' % (gap_3, new_gap_3))
                 gap_3 = new_gap_3
 
             # Pre-index gap