From 5b3512f1df81016068951f138de5f86dc62275a0 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 3 Jul 2018 20:10:22 -0400 Subject: [PATCH] Attempts to pick an intelligent place to pad out tracks. --- Storage/Disk/DiskImage/Formats/NIB.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/NIB.cpp b/Storage/Disk/DiskImage/Formats/NIB.cpp index 2dec8e55c..9a730759c 100644 --- a/Storage/Disk/DiskImage/Formats/NIB.cpp +++ b/Storage/Disk/DiskImage/Formats/NIB.cpp @@ -147,20 +147,29 @@ void NIB::set_tracks(const std::map> &tra std::vector track; track.reserve(track_length); uint8_t shifter = 0; + int bit_count = 0; + size_t sync_location = 0, location = 0; for(const auto bit: segment.data) { shifter = static_cast((shifter << 1) | (bit ? 1 : 0)); + ++bit_count; + ++location; if(shifter & 0x80) { track.push_back(shifter); + if(bit_count == 10) { + sync_location = location; + } shifter = 0; + bit_count = 0; } } - // Pad out to track_length. + // Trim or pad out to track_length. if(track.size() > track_length) { track.resize(track_length); } else { while(track.size() < track_length) { - track.push_back(0xff); + std::vector extra_data(static_cast(track_length) - track.size(), 0xff); + track.insert(track.begin() + static_cast(sync_location), extra_data.begin(), extra_data.end()); } }