1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Switched to populating the sector cache with everything in a track the first time anything on that track is requested. That avoids the problem whereby each request of a non-existent sector costs two spins.

This commit is contained in:
Thomas Harte 2017-08-11 18:40:16 -04:00
parent ad3c9842d7
commit 83c7d34df2
3 changed files with 25 additions and 8 deletions

View File

@ -66,6 +66,8 @@ static void InspectDataCatalogue(
static void InspectSystemCatalogue(
const std::unique_ptr<Storage::Disk::CPM::Catalogue> &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";
}

View File

@ -266,6 +266,26 @@ void Parser::seek_to_track(uint8_t track) {
}
std::shared_ptr<Sector> 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<Sector> first_sector = get_next_sector();
if(first_sector) {
while(1) {
std::shared_ptr<Sector> 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<Sector> 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<uint8_t> Parser::get_track(uint8_t track) {

View File

@ -140,6 +140,7 @@ class Parser: public Storage::Disk::Controller {
std::vector<uint8_t> get_track();
std::map<int, std::shared_ptr<Storage::Encodings::MFM::Sector>> sectors_by_index_;
std::set<int> decoded_tracks_;
int get_index(uint8_t head, uint8_t track, uint8_t sector);
};