mirror of
https://github.com/TomHarte/CLK.git
synced 2024-10-11 08:23:43 +00:00
It probably needs a better name, but hastily implemented track caching at the Disk level.
This commit is contained in:
parent
2f86b07cfa
commit
5c8ecd3051
@ -7,3 +7,16 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "Disk.hpp"
|
#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;
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#define Disk_hpp
|
#define Disk_hpp
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
#include "../Storage.hpp"
|
#include "../Storage.hpp"
|
||||||
|
|
||||||
namespace Storage {
|
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.
|
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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ unsigned int AcornADF::get_head_count()
|
|||||||
return 1;
|
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;
|
std::shared_ptr<Track> track;
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ class AcornADF: public Disk, public Storage::FileHolder {
|
|||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
unsigned int get_head_position_count();
|
unsigned int get_head_position_count();
|
||||||
unsigned int get_head_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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ unsigned int D64::get_head_position_count()
|
|||||||
return number_of_tracks_*2;
|
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
|
// every other track is missing, as is any head above 0
|
||||||
if(position&1 || head)
|
if(position&1 || head)
|
||||||
|
@ -34,9 +34,9 @@ class D64: public Disk, public Storage::FileHolder {
|
|||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
unsigned int get_head_position_count();
|
unsigned int get_head_position_count();
|
||||||
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
|
||||||
unsigned int number_of_tracks_;
|
unsigned int number_of_tracks_;
|
||||||
uint16_t disk_id_;
|
uint16_t disk_id_;
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@ unsigned int G64::get_head_position_count()
|
|||||||
return number_of_tracks_ > 84 ? number_of_tracks_ : 84;
|
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;
|
std::shared_ptr<Track> resulting_track;
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ class G64: public Disk, public Storage::FileHolder {
|
|||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
unsigned int get_head_position_count();
|
unsigned int get_head_position_count();
|
||||||
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
|
||||||
uint8_t number_of_tracks_;
|
uint8_t number_of_tracks_;
|
||||||
uint16_t maximum_track_size_;
|
uint16_t maximum_track_size_;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ unsigned int OricMFMDSK::get_head_count()
|
|||||||
return 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;
|
long seek_offset = 0;
|
||||||
switch(geometry_type_)
|
switch(geometry_type_)
|
||||||
|
@ -35,9 +35,9 @@ class OricMFMDSK: public Disk, public Storage::FileHolder {
|
|||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
unsigned int get_head_position_count();
|
unsigned int get_head_position_count();
|
||||||
unsigned int get_head_count();
|
unsigned int get_head_count();
|
||||||
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
|
||||||
uint32_t head_count_;
|
uint32_t head_count_;
|
||||||
uint32_t track_count_;
|
uint32_t track_count_;
|
||||||
uint32_t geometry_type_;
|
uint32_t geometry_type_;
|
||||||
|
@ -40,7 +40,7 @@ unsigned int SSD::get_head_count()
|
|||||||
return 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;
|
std::shared_ptr<Track> track;
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ class SSD: public Disk, public Storage::FileHolder {
|
|||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
unsigned int get_head_position_count();
|
unsigned int get_head_position_count();
|
||||||
unsigned int get_head_count();
|
unsigned int get_head_count();
|
||||||
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<Track> virtual_get_track_at_position(unsigned int head, unsigned int position);
|
||||||
unsigned int head_count_;
|
unsigned int head_count_;
|
||||||
unsigned int track_count_;
|
unsigned int track_count_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user