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

It probably needs a better name, but hastily implemented track caching at the Disk level.

This commit is contained in:
Thomas Harte 2016-11-26 14:27:06 +08:00
parent 2f86b07cfa
commit 5c8ecd3051
12 changed files with 32 additions and 11 deletions

View File

@ -7,3 +7,16 @@
//
#include "Disk.hpp"
using namespace Storage::Disk;
std::shared_ptr<Track> Disk::get_track_at_position(unsigned int head, unsigned int position)
{
int address = (int)(position * get_head_count() + head);
std::map<int, std::shared_ptr<Track>>::iterator cached_track = cached_tracks_.find(address);
if(cached_track != cached_tracks_.end()) return cached_track->second;
std::shared_ptr<Track> track = virtual_get_track_at_position(head, position);
cached_tracks_[address] = track;
return track;
}

View File

@ -10,6 +10,7 @@
#define Disk_hpp
#include <memory>
#include <map>
#include "../Storage.hpp"
namespace Storage {
@ -81,7 +82,13 @@ class Disk {
/*!
Returns the @c Track at @c position if there are any detectable events there; returns @c nullptr otherwise.
*/
virtual std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position) = 0;
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
protected:
virtual std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position) = 0;
private:
std::map<int, std::shared_ptr<Track>> cached_tracks_;
};
}

View File

@ -47,7 +47,7 @@ unsigned int AcornADF::get_head_count()
return 1;
}
std::shared_ptr<Track> AcornADF::get_track_at_position(unsigned int head, unsigned int position)
std::shared_ptr<Track> AcornADF::virtual_get_track_at_position(unsigned int head, unsigned int position)
{
std::shared_ptr<Track> track;

View File

@ -35,7 +35,8 @@ class AcornADF: public Disk, public Storage::FileHolder {
// implemented to satisfy @c Disk
unsigned int get_head_position_count();
unsigned int get_head_count();
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private:
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
};
}

View File

@ -41,7 +41,7 @@ unsigned int D64::get_head_position_count()
return number_of_tracks_*2;
}
std::shared_ptr<Track> D64::get_track_at_position(unsigned int head, unsigned int position)
std::shared_ptr<Track> D64::virtual_get_track_at_position(unsigned int head, unsigned int position)
{
// every other track is missing, as is any head above 0
if(position&1 || head)

View File

@ -34,9 +34,9 @@ class D64: public Disk, public Storage::FileHolder {
// implemented to satisfy @c Disk
unsigned int get_head_position_count();
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private:
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
unsigned int number_of_tracks_;
uint16_t disk_id_;
};

View File

@ -40,7 +40,7 @@ unsigned int G64::get_head_position_count()
return number_of_tracks_ > 84 ? number_of_tracks_ : 84;
}
std::shared_ptr<Track> G64::get_track_at_position(unsigned int head, unsigned int position)
std::shared_ptr<Track> G64::virtual_get_track_at_position(unsigned int head, unsigned int position)
{
std::shared_ptr<Track> resulting_track;

View File

@ -37,9 +37,9 @@ class G64: public Disk, public Storage::FileHolder {
// implemented to satisfy @c Disk
unsigned int get_head_position_count();
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private:
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
uint8_t number_of_tracks_;
uint16_t maximum_track_size_;
};

View File

@ -36,7 +36,7 @@ unsigned int OricMFMDSK::get_head_count()
return head_count_;
}
std::shared_ptr<Track> OricMFMDSK::get_track_at_position(unsigned int head, unsigned int position)
std::shared_ptr<Track> OricMFMDSK::virtual_get_track_at_position(unsigned int head, unsigned int position)
{
long seek_offset = 0;
switch(geometry_type_)

View File

@ -35,9 +35,9 @@ class OricMFMDSK: public Disk, public Storage::FileHolder {
// implemented to satisfy @c Disk
unsigned int get_head_position_count();
unsigned int get_head_count();
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private:
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
uint32_t head_count_;
uint32_t track_count_;
uint32_t geometry_type_;

View File

@ -40,7 +40,7 @@ unsigned int SSD::get_head_count()
return head_count_;
}
std::shared_ptr<Track> SSD::get_track_at_position(unsigned int head, unsigned int position)
std::shared_ptr<Track> SSD::virtual_get_track_at_position(unsigned int head, unsigned int position)
{
std::shared_ptr<Track> track;

View File

@ -35,9 +35,9 @@ class SSD: public Disk, public Storage::FileHolder {
// implemented to satisfy @c Disk
unsigned int get_head_position_count();
unsigned int get_head_count();
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private:
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
unsigned int head_count_;
unsigned int track_count_;
};