1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-09 21:29:53 +00:00

Factors HFE track seeking out from the track fetching method.

This commit is contained in:
Thomas Harte 2017-10-03 20:33:55 -04:00
parent 7b01c1bee6
commit 1cc85615d5
2 changed files with 19 additions and 2 deletions

View File

@ -36,7 +36,14 @@ unsigned int HFE::get_head_count() {
return head_count_; return head_count_;
} }
std::shared_ptr<Track> HFE::get_track_at_position(unsigned int head, unsigned int position) { /*!
Seeks to the beginning of the track at @c position underneath @c head,
returning its length in bytes.
To read the track, start from the current file position, read 256 bytes,
skip 256 bytes, read 256 bytes, skip 256 bytes, etc.
*/
uint16_t HFE::seek_track(unsigned int head, unsigned int position) {
// Get track position and length from the lookup table; data is then always interleaved // Get track position and length from the lookup table; data is then always interleaved
// based on an assumption of two heads. // based on an assumption of two heads.
fseek(file_, track_list_offset_ + position * 4, SEEK_SET); fseek(file_, track_list_offset_ + position * 4, SEEK_SET);
@ -47,8 +54,14 @@ std::shared_ptr<Track> HFE::get_track_at_position(unsigned int head, unsigned in
fseek(file_, track_offset, SEEK_SET); fseek(file_, track_offset, SEEK_SET);
if(head) fseek(file_, 256, SEEK_CUR); if(head) fseek(file_, 256, SEEK_CUR);
return track_length / 2;
}
std::shared_ptr<Track> HFE::get_track_at_position(unsigned int head, unsigned int position) {
uint16_t track_length = seek_track(head, position);
PCMSegment segment; PCMSegment segment;
uint16_t side_length = track_length / 2; uint16_t side_length = track_length;
segment.data.resize(side_length); segment.data.resize(side_length);
segment.number_of_bits = side_length * 8; segment.number_of_bits = side_length * 8;
@ -68,3 +81,5 @@ std::shared_ptr<Track> HFE::get_track_at_position(unsigned int head, unsigned in
return track; return track;
} }
void HFE::set_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track) {
}

View File

@ -37,9 +37,11 @@ class HFE: public DiskImage, public Storage::FileHolder {
unsigned int get_head_position_count(); unsigned int get_head_position_count();
unsigned int get_head_count(); unsigned int get_head_count();
using Storage::FileHolder::get_is_read_only; using Storage::FileHolder::get_is_read_only;
void set_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track);
std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position); std::shared_ptr<Track> get_track_at_position(unsigned int head, unsigned int position);
private: private:
uint16_t seek_track(unsigned int head, unsigned int position);
unsigned int head_count_; unsigned int head_count_;
unsigned int track_count_; unsigned int track_count_;