Exemplo n.º 1
0
    def decode_raw(self, track):
        raw = RawTrack(clock=2e-6, data=track)
        bits, _ = raw.get_all_data()

        for offs in bits.itersearch(sync):

            if self.nr_missing() == 0:
                break

            sec = bits[offs:offs + 544 * 16].tobytes()
            if len(sec) != 1088:
                continue

            header = decode(sec[4:12])
            format, track, sec_id, togo = tuple(header)
            if format != 0xff or track != self.tracknr \
               or not(sec_id < self.nsec and 0 < togo <= self.nsec) \
               or self.exists(sec_id, togo):
                continue

            label = decode(sec[12:44])
            hsum, = struct.unpack('>I', decode(sec[44:52]))
            if hsum != checksum(header + label):
                continue

            dsum, = struct.unpack('>I', decode(sec[52:60]))
            data = decode(sec[60:1084])
            gap = decode(sec[1084:1088])
            if dsum != checksum(data):
                continue

            self.add(sec_id, togo, label, data)
Exemplo n.º 2
0
 def emit_track(self, cyl, side, track):
     flux = track.flux()
     flux.cue_at_index()
     raw = RawTrack(clock=5e-4 / self.bitrate, data=flux)
     bits, _ = raw.get_revolution(0)
     bits.bytereverse()
     self.to_track[cyl, side] = (len(bits), bits.tobytes())
Exemplo n.º 3
0
    def verify_track(self, flux):
        flux.cue_at_index()
        raw = RawTrack(time_per_rev=self.time_per_rev,
                       clock=self.time_per_rev / len(self.bits),
                       data=flux)
        bits, _ = raw.get_all_data()
        weak_iter = it.chain(self.weak, [(self.verify_len + 1, 1)])
        weak = next(weak_iter)

        # Start checking from the IAM sync
        dump_start = self._find_sync(bits, mfm.iam_sync, 0)
        self_start = self._find_sync(self.bits, mfm.iam_sync, 0)

        # Include the IAM pre-sync header
        if dump_start is None:
            return False
        dump_start -= self.gap_presync * 16
        self_start -= self.gap_presync * 16

        while self_start is not None and dump_start is not None:

            # Find the weak areas immediately before and after the current
            # region to be checked.
            s, n = None, None
            while self_start > weak[0]:
                s, n = weak
                weak = next(weak_iter)

            # If there is a weak area preceding us, move the start point to
            # immediately follow the weak area.
            if s is not None:
                delta = self_start - (s + n + 16)
                self_start -= delta
                dump_start -= delta

            # Truncate the region at the next weak area, or the last sector.
            self_end = max(self_start, min(weak[0], self.verify_len + 1))
            dump_end = dump_start + self_end - self_start

            # Extract the corresponding areas from the pristine track and
            # from the dump, and check that they match.
            if bits[dump_start:dump_end] != self.bits[self_start:self_end]:
                return False

            # Find the next A1A1A1 sync pattern
            dump_start = self._find_sync(bits, mfm.sync, dump_end)
            self_start = self._find_sync(self.bits, mfm.sync, self_end)

        # Did we verify all regions in the pristine track?
        return self_start is None
Exemplo n.º 4
0
 def verify_track(self, flux):
     flux.cue_at_index()
     raw = RawTrack(clock=self.time_per_rev / len(self.bits), data=flux)
     raw_bits, _ = raw.get_all_data()
     for s, l in IPFTrack.strong_data(self.sectors, self.weak):
         sector = self.bits[s:s + l]
         # Search within an area +/- the pre-defined # bitcells tolerance
         raw_area = raw_bits[max(self.splice + s -
                                 self.tolerance, 0):self.splice + s + l +
                             self.tolerance]
         # All we care about is at least one match (this is a bit fuzzy)
         if next(raw_area.itersearch(sector), None) is None:
             return False
     return True
Exemplo n.º 5
0
 def emit_track(self, cyl, side, track):
     if self.opts.bitrate is None:
         t = track.raw_track() if hasattr(track, 'raw_track') else track
         b = getattr(t, 'bitrate', None)
         error.check(
             hasattr(t, 'bitrate'), 'HFE: Requires bitrate to be specified'
             ' (eg. filename.hfe::bitrate=500)')
         self.opts.bitrate = round(t.bitrate / 2e3)
         print('HFE: Data bitrate detected: %d kbit/s' % self.opts.bitrate)
     flux = track.flux()
     flux.cue_at_index()
     raw = RawTrack(clock=5e-4 / self.opts.bitrate, data=flux)
     bits, _ = raw.get_revolution(0)
     bits.bytereverse()
     self.to_track[cyl, side] = (len(bits), bits.tobytes())
Exemplo n.º 6
0
    def decode_raw(self, track):
        track.cue_at_index()
        raw = RawTrack(clock = 1e-6, data = track)
        bits, _ = raw.get_all_data()

        areas = []
        idam = None

        ## 1. Calculate offsets within dump
        
        for offs in bits.itersearch(iam_sync):
            mark = decode(bits[offs+3*16:offs+4*16].tobytes())[0]
            if mark == IBM_MFM.IAM:
                areas.append(IAM(offs, offs+4*16))
                self.has_iam = True

        for offs in bits.itersearch(sync):

            mark = decode(bits[offs+3*16:offs+4*16].tobytes())[0]
            if mark == IBM_MFM.IDAM:
                s, e = offs, offs+10*16
                b = decode(bits[s:e].tobytes())
                c,h,r,n = struct.unpack(">4x4B2x", b)
                crc = crc16.new(b).crcValue
                if idam is not None:
                    areas.append(idam)
                idam = IDAM(s, e, crc, c=c, h=h, r=r, n=n)
            elif mark == IBM_MFM.DAM or mark == IBM_MFM.DDAM:
                if idam is None or idam.end - offs > 1000:
                    areas.append(DAM(offs, offs+4*16, 0xffff, mark=mark))
                else:
                    sz = 128 << idam.n
                    s, e = offs, offs+(4+sz+2)*16
                    b = decode(bits[s:e].tobytes())
                    crc = crc16.new(b).crcValue
                    dam = DAM(s, e, crc, mark=mark, data=b[4:-2])
                    areas.append(Sector(idam, dam))
                idam = None
            else:
                print("Unknown mark %02x" % mark)

        if idam is not None:
            areas.append(idam)

        # Convert to offsets within track
        areas.sort(key=lambda x:x.start)
        index = iter(raw.revolutions)
        p, n = 0, next(index)
        for a in areas:
            if a.start >= n:
                p = n
                try:
                    n = next(index)
                except StopIteration:
                    n = float('inf')
            a.delta(p)
        areas.sort(key=lambda x:x.start)

        # Add to the deduped lists
        for a in areas:
            match = False
            if isinstance(a, IAM):
                list = self.iams
            elif isinstance(a, Sector):
                list = self.sectors
            else:
                continue
            for s in list:
                if abs(s.start - a.start) < 1000:
                    match = True
                    break
            if match and list == self.sectors and s.crc != 0 and a.crc == 0:
                self.sectors = [x for x in self.sectors if x != a]
                match = False
            if not match:
                list.append(a)
Exemplo n.º 7
0
 def emit_track(self, cyl, side, track):
     raw = RawTrack(clock=5e-4 / self.bitrate, data=track)
     bits, _ = raw.get_revolution(0)
     bits.bytereverse()
     self.to_track[cyl, side] = (len(bits), bits.tobytes())
Exemplo n.º 8
0
 def append_track(self, track):
     raw = RawTrack(clock=5e-4 / self.bitrate, data=track)
     bits, _ = raw.get_revolution(0)
     bits.bytereverse()
     self.track_list.append((len(bits), bits.tobytes()))