mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-28 07:29:45 +00:00
Merge pull request #210 from TomHarte/TrackSize
Various MFM and DSK fixes
This commit is contained in:
commit
dc0ca83003
@ -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::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
||||||
std::shared_ptr<Track> track = get_uncached_track_at_position(head, position);
|
std::shared_ptr<Track> track = get_uncached_track_at_position(head, position);
|
||||||
|
if(!track) return nullptr;
|
||||||
cached_tracks_[address] = track;
|
cached_tracks_[address] = track;
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "../PCMTrack.hpp"
|
#include "../PCMTrack.hpp"
|
||||||
#include "../../../NumberTheory/CRC.hpp"
|
#include "../../../NumberTheory/CRC.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace Storage::Encodings::MFM;
|
using namespace Storage::Encodings::MFM;
|
||||||
|
|
||||||
class MFMEncoder: public Encoder {
|
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);
|
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);
|
segment.number_of_bits = (unsigned int)(segment.data.size() * 8);
|
||||||
return std::shared_ptr<Storage::Disk::Track>(new Storage::Disk::PCMTrack(std::move(segment)));
|
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);
|
seek_to_track(track);
|
||||||
int track_index = get_index(head, track, 0);
|
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()) {
|
if(decoded_tracks_.find(track_index) == decoded_tracks_.end()) {
|
||||||
std::shared_ptr<Sector> first_sector = get_next_sector();
|
std::shared_ptr<Sector> first_sector = get_next_sector();
|
||||||
|
std::set<uint8_t> visited_sectors;
|
||||||
if(first_sector) {
|
if(first_sector) {
|
||||||
while(1) {
|
while(1) {
|
||||||
std::shared_ptr<Sector> next_sector = get_next_sector();
|
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);
|
decoded_tracks_.insert(track_index);
|
||||||
|
@ -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.
|
// All DSK images reserve 0x100 bytes for their headers.
|
||||||
long file_offset = 0x100;
|
long file_offset = 0x100;
|
||||||
if(is_extended_) {
|
if(is_extended_) {
|
||||||
// Tracks are a variable size in the original DSK file format; sum the lengths
|
// Tracks are a variable size in the original DSK file format.
|
||||||
// of all tracks prior to the interesting one to get a file offset.
|
|
||||||
|
// 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;
|
unsigned int t = 0;
|
||||||
while(t < chronological_track && t < track_sizes_.size()) {
|
while(t < chronological_track && t < track_sizes_.size()) {
|
||||||
file_offset += track_sizes_[t];
|
file_offset += track_sizes_[t];
|
||||||
|
Loading…
Reference in New Issue
Block a user