1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Opted to pass times by reference and added enough to PCMPatchedTrack that it could start being used by the disk controller, albeit that it doesn't work.

This commit is contained in:
Thomas Harte 2016-12-17 16:26:45 -05:00
parent dc08a23ceb
commit f1a08b7ab5
5 changed files with 30 additions and 12 deletions

View File

@ -48,7 +48,7 @@ class Track {
@returns the time jumped to.
*/
virtual Time seek_to(Time time_since_index_hole) = 0;
virtual Time seek_to(const Time &time_since_index_hole) = 0;
};
/*!

View File

@ -10,7 +10,23 @@
using namespace Storage::Disk;
PCMPatchedTrack::PCMPatchedTrack(Track &underlying_track) :
underlying_track_(underlying_track),
active_patch_((size_t)-1)
{}
void PCMPatchedTrack::add_segment(const Time &start_position, const PCMSegment &segment)
{
patches_.emplace_back(start_position, segment);
}
Track::Event PCMPatchedTrack::get_next_event()
{
// if(active_patch_ == (size_t)-1)
return underlying_track_.get_next_event();
}
Storage::Time PCMPatchedTrack::seek_to(const Time &time_since_index_hole)
{
return underlying_track_.seek_to(time_since_index_hole);
}

View File

@ -23,7 +23,7 @@ class PCMPatchedTrack: public Track {
Constructs a @c PCMPatchedTrack that will return events from @c underlying_track in
regions where it has not had alternative PCM data installed.
*/
PCMPatchedTrack(const PCMTrack &underlying_track);
PCMPatchedTrack(Track &underlying_track);
/*!
Replaces whatever is currently on the track from @c start_position to @c start_position + segment length
@ -33,16 +33,17 @@ class PCMPatchedTrack: public Track {
// To satisfy Storage::Disk::Track
Event get_next_event();
Time seek_to(Time time_since_index_hole);
Time seek_to(const Time &time_since_index_hole);
private:
const PCMTrack &underlying_track_;
Track &underlying_track_;
struct Patch {
Time start_position;
PCMSegment segment;
Patch(const Time &start_position, const PCMSegment &segment) : start_position(start_position), segment(segment) {}
};
std::vector<Patch> patches_;
size_t active_patch_;
};
}

View File

@ -25,7 +25,7 @@ PCMTrack::PCMTrack(PCMSegment segment)
fix_length();
}
PCMTrack::Event PCMTrack::get_next_event()
Track::Event PCMTrack::get_next_event()
{
// find the next 1 in the input stream, keeping count of length as we go, and assuming it's going
// to be a flux transition
@ -61,15 +61,16 @@ PCMTrack::Event PCMTrack::get_next_event()
return next_event_;
}
Storage::Time PCMTrack::seek_to(Time time_since_index_hole)
Storage::Time PCMTrack::seek_to(const Time &time_since_index_hole)
{
segment_pointer_ = 0;
// pick a common clock rate for counting time on this track and multiply up the time being sought appropriately
Time time_so_far;
time_so_far.clock_rate = NumberTheory::least_common_multiple(next_event_.length.clock_rate, time_since_index_hole.clock_rate);
time_since_index_hole.length *= time_so_far.clock_rate / time_since_index_hole.clock_rate;
time_since_index_hole.clock_rate = time_so_far.clock_rate;
Time target_time = time_since_index_hole;
time_so_far.clock_rate = NumberTheory::least_common_multiple(next_event_.length.clock_rate, target_time.clock_rate);
target_time.length *= time_so_far.clock_rate / target_time.clock_rate;
target_time.clock_rate = time_so_far.clock_rate;
while(segment_pointer_ < segments_.size())
{
@ -79,7 +80,7 @@ Storage::Time PCMTrack::seek_to(Time time_since_index_hole)
unsigned int time_in_this_segment = bit_length * segments_[segment_pointer_].number_of_bits;
// if this segment goes on longer than the time being sought, end here
unsigned int time_remaining = time_since_index_hole.length - time_so_far.length;
unsigned int time_remaining = target_time.length - time_so_far.length;
if(time_in_this_segment >= time_remaining)
{
// get the amount of time actually to move into this segment
@ -97,7 +98,7 @@ Storage::Time PCMTrack::seek_to(Time time_since_index_hole)
time_so_far.length += time_in_this_segment;
segment_pointer_++;
}
return time_since_index_hole;
return target_time;
}
void PCMTrack::fix_length()

View File

@ -48,7 +48,7 @@ class PCMTrack: public Track {
// as per @c Track
Event get_next_event();
Time seek_to(Time time_since_index_hole);
Time seek_to(const Time &time_since_index_hole);
private:
// storage for the segments that describe this track