From 5cd15147ebaf8f3c73ad5c20b72dd1dec2b9cb60 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 29 Apr 2018 16:18:14 -0400 Subject: [PATCH] Introduces interleaving of sector numbers. --- Storage/Disk/DiskImage/Formats/AppleDSK.cpp | 9 +++++++-- Storage/Disk/DiskImage/Formats/AppleDSK.hpp | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp index b32a63876..5915f56cd 100644 --- a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp @@ -41,12 +41,17 @@ std::shared_ptr AppleDSK::get_track_at_position(Track::Address address) { // In either case below, the code aims for exactly 50,000 bits per track. if(sectors_per_track_ == 16) { // Write the sectors. - for(uint8_t c = 0; c < 16; ++c) { + uint8_t sector_number_ = 0; + for(std::size_t c = 0; c < 16; ++c) { segments.push_back(Encodings::AppleGCR::six_and_two_sync(10)); - segments.push_back(Encodings::AppleGCR::header(0, track, c)); + segments.push_back(Encodings::AppleGCR::header(0, track, sector_number_)); segments.push_back(Encodings::AppleGCR::six_and_two_sync(10)); segments.push_back(Encodings::AppleGCR::six_and_two_data(&track_data[c * 256])); segments.push_back(Encodings::AppleGCR::six_and_two_sync(10)); + + // DOS and Pro DOS interleave sectors on disk, and they're represented in a disk + // image in physical order rather than logical. So that skew needs to be applied here. + sector_number_ = (sector_number_ + (is_prodos_ ? 8 : 7)) % 15; } // Pad if necessary. diff --git a/Storage/Disk/DiskImage/Formats/AppleDSK.hpp b/Storage/Disk/DiskImage/Formats/AppleDSK.hpp index 465c73e87..92fd152d0 100644 --- a/Storage/Disk/DiskImage/Formats/AppleDSK.hpp +++ b/Storage/Disk/DiskImage/Formats/AppleDSK.hpp @@ -37,7 +37,8 @@ class AppleDSK: public DiskImage { private: Storage::FileHolder file_; - int sectors_per_track_; + int sectors_per_track_ = 16; + bool is_prodos_ = false; }; }