mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-11 04:28:58 +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:
parent
ad3c9842d7
commit
83c7d34df2
@ -66,6 +66,8 @@ static void InspectDataCatalogue(
|
|||||||
static void InspectSystemCatalogue(
|
static void InspectSystemCatalogue(
|
||||||
const std::unique_ptr<Storage::Disk::CPM::Catalogue> &data_catalogue,
|
const std::unique_ptr<Storage::Disk::CPM::Catalogue> &data_catalogue,
|
||||||
StaticAnalyser::Target &target) {
|
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.
|
// If this is a system disk, then launch it as though it were CP/M.
|
||||||
target.loadingCommand = "|cpm\n";
|
target.loadingCommand = "|cpm\n";
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
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.
|
// Check cache for sector.
|
||||||
int index = get_index(head, track, sector);
|
int index = get_index(head, track, sector);
|
||||||
auto cached_sector = sectors_by_index_.find(index);
|
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;
|
return cached_sector->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failing that, set the proper head and track, and search for the sector. get_sector automatically
|
// If it wasn't found, it doesn't exist.
|
||||||
// inserts everything found into sectors_by_index_.
|
return nullptr;
|
||||||
if(head_ != head) {
|
|
||||||
drive_->set_head(head);
|
|
||||||
invalidate_track();
|
|
||||||
}
|
|
||||||
seek_to_track(track);
|
|
||||||
return get_sector(sector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> Parser::get_track(uint8_t track) {
|
std::vector<uint8_t> Parser::get_track(uint8_t track) {
|
||||||
|
@ -140,6 +140,7 @@ class Parser: public Storage::Disk::Controller {
|
|||||||
std::vector<uint8_t> get_track();
|
std::vector<uint8_t> get_track();
|
||||||
|
|
||||||
std::map<int, std::shared_ptr<Storage::Encodings::MFM::Sector>> sectors_by_index_;
|
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);
|
int get_index(uint8_t head, uint8_t track, uint8_t sector);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user