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

Merge pull request #210 from TomHarte/TrackSize

Various MFM and DSK fixes
This commit is contained in:
Thomas Harte 2017-08-17 15:50:27 -04:00 committed by GitHub
commit dc0ca83003
3 changed files with 21 additions and 4 deletions

View File

@ -37,6 +37,7 @@ std::shared_ptr<Track> Disk::get_track_at_position(unsigned int head, unsigned i
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
std::shared_ptr<Track> track = get_uncached_track_at_position(head, position);
if(!track) return nullptr;
cached_tracks_[address] = track;
return track;
}

View File

@ -11,6 +11,8 @@
#include "../PCMTrack.hpp"
#include "../../../NumberTheory/CRC.hpp"
#include <set>
using namespace Storage::Encodings::MFM;
class MFMEncoder: public Encoder {
@ -173,6 +175,7 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
}
while(segment.data.size() < expected_track_bytes) shifter.add_byte(0x00);
if(segment.data.size() > expected_track_bytes) segment.data.resize(expected_track_bytes);
segment.number_of_bits = (unsigned int)(segment.data.size() * 8);
return std::shared_ptr<Storage::Disk::Track>(new Storage::Disk::PCMTrack(std::move(segment)));
@ -273,13 +276,20 @@ std::shared_ptr<Sector> Parser::get_sector(uint8_t head, uint8_t track, uint8_t
seek_to_track(track);
int track_index = get_index(head, track, 0);
// Populate the sector cache if it's not already populated.
// Populate the sector cache if it's not already populated by asking for sectors unless and until
// one is returned that has already been seen.
if(decoded_tracks_.find(track_index) == decoded_tracks_.end()) {
std::shared_ptr<Sector> first_sector = get_next_sector();
std::set<uint8_t> visited_sectors;
if(first_sector) {
while(1) {
std::shared_ptr<Sector> next_sector = get_next_sector();
if(!next_sector || next_sector->sector == first_sector->sector) break;
if(next_sector) {
if(visited_sectors.find(next_sector->sector) != visited_sectors.end()) {
break;
}
visited_sectors.insert(next_sector->sector);
}
}
}
decoded_tracks_.insert(track_index);

View File

@ -57,8 +57,14 @@ std::shared_ptr<Track> CPCDSK::get_uncached_track_at_position(unsigned int head,
// All DSK images reserve 0x100 bytes for their headers.
long file_offset = 0x100;
if(is_extended_) {
// Tracks are a variable size in the original DSK file format; sum the lengths
// of all tracks prior to the interesting one to get a file offset.
// Tracks are a variable size in the original DSK file format.
// Check that there is anything stored for this track.
if(!track_sizes_[chronological_track]) {
return nullptr;
}
// Sum the lengths of all tracks prior to the interesting one to get a file offset.
unsigned int t = 0;
while(t < chronological_track && t < track_sizes_.size()) {
file_offset += track_sizes_[t];