diff --git a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp index 8fcb1839e..bdf536ed6 100644 --- a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp +++ b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp @@ -66,6 +66,8 @@ static void InspectDataCatalogue( static void InspectSystemCatalogue( const std::unique_ptr &data_catalogue, StaticAnalyser::Target &target) { + // TODO: does track 0, side 0, sector 0x41 exist? If not, InspectDataCatalogue. + // If this is a system disk, then launch it as though it were CP/M. target.loadingCommand = "|cpm\n"; } diff --git a/Storage/Disk/Encodings/MFM.cpp b/Storage/Disk/Encodings/MFM.cpp index aab85facb..a49f3f40b 100644 --- a/Storage/Disk/Encodings/MFM.cpp +++ b/Storage/Disk/Encodings/MFM.cpp @@ -266,6 +266,26 @@ void Parser::seek_to_track(uint8_t track) { } std::shared_ptr Parser::get_sector(uint8_t head, uint8_t track, uint8_t sector) { + // Switch head and track if necessary. + if(head_ != head) { + drive_->set_head(head); + invalidate_track(); + } + seek_to_track(track); + int track_index = get_index(head, track, 0); + + // Populate the sector cache if it's not already populated. + if(decoded_tracks_.find(track_index) == decoded_tracks_.end()) { + std::shared_ptr first_sector = get_next_sector(); + if(first_sector) { + while(1) { + std::shared_ptr next_sector = get_next_sector(); + if(next_sector->sector == first_sector->sector) break; + } + } + decoded_tracks_.insert(track_index); + } + // Check cache for sector. int index = get_index(head, track, sector); auto cached_sector = sectors_by_index_.find(index); @@ -273,14 +293,8 @@ std::shared_ptr Parser::get_sector(uint8_t head, uint8_t track, uint8_t return cached_sector->second; } - // Failing that, set the proper head and track, and search for the sector. get_sector automatically - // inserts everything found into sectors_by_index_. - if(head_ != head) { - drive_->set_head(head); - invalidate_track(); - } - seek_to_track(track); - return get_sector(sector); + // If it wasn't found, it doesn't exist. + return nullptr; } std::vector Parser::get_track(uint8_t track) { diff --git a/Storage/Disk/Encodings/MFM.hpp b/Storage/Disk/Encodings/MFM.hpp index eed23e5b3..2ae651555 100644 --- a/Storage/Disk/Encodings/MFM.hpp +++ b/Storage/Disk/Encodings/MFM.hpp @@ -140,6 +140,7 @@ class Parser: public Storage::Disk::Controller { std::vector get_track(); std::map> sectors_by_index_; + std::set decoded_tracks_; int get_index(uint8_t head, uint8_t track, uint8_t sector); };