mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-18 16:30:29 +00:00
Switches to providing a full record of changes to disk images, rather than feeding them a track at a time.
Gets explicit about `override`s while doing so, to ensure full adaptation.
This commit is contained in:
parent
b37787a414
commit
44cdc124af
@ -49,9 +49,9 @@ class DiskImage {
|
|||||||
virtual std::shared_ptr<Track> get_track_at_position(Track::Address address) = 0;
|
virtual std::shared_ptr<Track> get_track_at_position(Track::Address address) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Replaces the Track at position @c position underneath @c head with @c track. Ignored if this disk is read-only.
|
Replaces the Tracks indicated by the map, that maps from physical address to track content.
|
||||||
*/
|
*/
|
||||||
virtual void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {}
|
virtual void set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Communicates that it is likely to be a while before any more tracks are written.
|
Communicates that it is likely to be a while before any more tracks are written.
|
||||||
|
@ -30,10 +30,7 @@ template <typename T> void DiskImageHolder<T>::flush_tracks() {
|
|||||||
unwritten_tracks_.clear();
|
unwritten_tracks_.clear();
|
||||||
|
|
||||||
update_queue_->enqueue([this, track_copies]() {
|
update_queue_->enqueue([this, track_copies]() {
|
||||||
// TODO: communicate these as a batch, not one by one.
|
disk_image_.set_tracks(*track_copies);
|
||||||
for(auto &pair : *track_copies) {
|
|
||||||
disk_image_.set_track_at_position(pair.first, pair.second);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@ class AcornADF: public MFMSectorDump {
|
|||||||
ErrorNotAcornADF,
|
ErrorNotAcornADF,
|
||||||
};
|
};
|
||||||
|
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
int get_head_count();
|
int get_head_count() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long get_file_offset_for_position(Track::Address address);
|
long get_file_offset_for_position(Track::Address address) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ class CPCDSK: public DiskImage, public Storage::FileHolder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
int get_head_count();
|
int get_head_count() override;
|
||||||
using DiskImage::get_is_read_only;
|
using DiskImage::get_is_read_only;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int head_count_;
|
int head_count_;
|
||||||
|
@ -33,9 +33,9 @@ class D64: public DiskImage, public Storage::FileHolder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
using DiskImage::get_is_read_only;
|
using DiskImage::get_is_read_only;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int number_of_tracks_;
|
int number_of_tracks_;
|
||||||
|
@ -36,8 +36,8 @@ class G64: public DiskImage, public Storage::FileHolder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
using DiskImage::get_is_read_only;
|
using DiskImage::get_is_read_only;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -84,24 +84,26 @@ std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) {
|
|||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HFE::set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {
|
void HFE::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {
|
||||||
std::unique_lock<std::mutex> lock_guard(file_access_mutex_);
|
for(auto &track : tracks) {
|
||||||
uint16_t track_length = seek_track(address);
|
std::unique_lock<std::mutex> lock_guard(file_access_mutex_);
|
||||||
lock_guard.unlock();
|
uint16_t track_length = seek_track(track.first);
|
||||||
|
lock_guard.unlock();
|
||||||
|
|
||||||
PCMSegment segment = Storage::Disk::track_serialisation(*track, Storage::Time(1, track_length * 8));
|
PCMSegment segment = Storage::Disk::track_serialisation(*track.second, Storage::Time(1, track_length * 8));
|
||||||
Storage::Data::BitReverse::reverse(segment.data);
|
Storage::Data::BitReverse::reverse(segment.data);
|
||||||
uint16_t data_length = std::min(static_cast<uint16_t>(segment.data.size()), track_length);
|
uint16_t data_length = std::min(static_cast<uint16_t>(segment.data.size()), track_length);
|
||||||
|
|
||||||
lock_guard.lock();
|
lock_guard.lock();
|
||||||
seek_track(address);
|
seek_track(track.first);
|
||||||
|
|
||||||
uint16_t c = 0;
|
uint16_t c = 0;
|
||||||
while(c < data_length) {
|
while(c < data_length) {
|
||||||
uint16_t length = (uint16_t)std::min(256, data_length - c);
|
uint16_t length = (uint16_t)std::min(256, data_length - c);
|
||||||
fwrite(&segment.data[c], 1, length, file_);
|
fwrite(&segment.data[c], 1, length, file_);
|
||||||
c += length;
|
c += length;
|
||||||
fseek(file_, 256, SEEK_CUR);
|
fseek(file_, 256, SEEK_CUR);
|
||||||
|
}
|
||||||
|
lock_guard.unlock();
|
||||||
}
|
}
|
||||||
lock_guard.unlock();
|
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,11 @@ class HFE: public DiskImage, public Storage::FileHolder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
int get_head_count();
|
int get_head_count() override;
|
||||||
using Storage::FileHolder::get_is_read_only;
|
using Storage::FileHolder::get_is_read_only;
|
||||||
void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track);
|
void set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) override;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t seek_track(Track::Address address);
|
uint16_t seek_track(Track::Address address);
|
||||||
|
@ -35,16 +35,21 @@ std::shared_ptr<Track> MFMSectorDump::get_track_at_position(Track::Address addre
|
|||||||
return track_for_sectors(sectors, static_cast<uint8_t>(address.position), static_cast<uint8_t>(address.head), 0, sector_size_, is_double_density_);
|
return track_for_sectors(sectors, static_cast<uint8_t>(address.position), static_cast<uint8_t>(address.head), 0, sector_size_, is_double_density_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFMSectorDump::set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {
|
void MFMSectorDump::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {
|
||||||
uint8_t parsed_track[(128 << sector_size_)*sectors_per_track_];
|
uint8_t parsed_track[(128 << sector_size_)*sectors_per_track_];
|
||||||
// Assumption here: sector IDs will run from 0.
|
|
||||||
decode_sectors(*track, parsed_track, 0, static_cast<uint8_t>(sectors_per_track_-1), sector_size_, is_double_density_);
|
|
||||||
|
|
||||||
long file_offset = get_file_offset_for_position(address);
|
// TODO: it would be more efficient from a file access and locking point of view to parse the sectors
|
||||||
|
// in one loop, then write in another.
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
for(auto &track : tracks) {
|
||||||
ensure_file_is_at_least_length(file_offset);
|
// Assumption here: sector IDs will run from 0.
|
||||||
fseek(file_, file_offset, SEEK_SET);
|
decode_sectors(*track.second, parsed_track, 0, static_cast<uint8_t>(sectors_per_track_-1), sector_size_, is_double_density_);
|
||||||
fwrite(parsed_track, 1, sizeof(parsed_track), file_);
|
long file_offset = get_file_offset_for_position(track.first);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
||||||
|
ensure_file_is_at_least_length(file_offset);
|
||||||
|
fseek(file_, file_offset, SEEK_SET);
|
||||||
|
fwrite(parsed_track, 1, sizeof(parsed_track), file_);
|
||||||
|
}
|
||||||
fflush(file_);
|
fflush(file_);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ class MFMSectorDump: public DiskImage, public Storage::FileHolder {
|
|||||||
void set_geometry(int sectors_per_track, uint8_t sector_size, bool is_double_density);
|
void set_geometry(int sectors_per_track, uint8_t sector_size, bool is_double_density);
|
||||||
|
|
||||||
using Storage::FileHolder::get_is_read_only;
|
using Storage::FileHolder::get_is_read_only;
|
||||||
void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track);
|
void set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) override;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex file_access_mutex_;
|
std::mutex file_access_mutex_;
|
||||||
|
@ -114,49 +114,51 @@ std::shared_ptr<Track> OricMFMDSK::get_track_at_position(Track::Address address)
|
|||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OricMFMDSK::set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {
|
void OricMFMDSK::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {
|
||||||
PCMSegment segment = Storage::Disk::track_serialisation(*track, Storage::Encodings::MFM::MFMBitLength);
|
for(auto &track : tracks) {
|
||||||
Storage::Encodings::MFM::Shifter shifter;
|
PCMSegment segment = Storage::Disk::track_serialisation(*track.second, Storage::Encodings::MFM::MFMBitLength);
|
||||||
shifter.set_is_double_density(true);
|
Storage::Encodings::MFM::Shifter shifter;
|
||||||
shifter.set_should_obey_syncs(true);
|
shifter.set_is_double_density(true);
|
||||||
std::vector<uint8_t> parsed_track;
|
shifter.set_should_obey_syncs(true);
|
||||||
int size = 0;
|
std::vector<uint8_t> parsed_track;
|
||||||
int offset = 0;
|
int size = 0;
|
||||||
bool capture_size = false;
|
int offset = 0;
|
||||||
|
bool capture_size = false;
|
||||||
|
|
||||||
for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) {
|
for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) {
|
||||||
shifter.add_input_bit(segment.bit(bit));
|
shifter.add_input_bit(segment.bit(bit));
|
||||||
if(shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::None) continue;
|
if(shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::None) continue;
|
||||||
parsed_track.push_back(shifter.get_byte());
|
parsed_track.push_back(shifter.get_byte());
|
||||||
|
|
||||||
if(offset) {
|
if(offset) {
|
||||||
offset--;
|
offset--;
|
||||||
if(!offset) {
|
if(!offset) {
|
||||||
shifter.set_should_obey_syncs(true);
|
shifter.set_should_obey_syncs(true);
|
||||||
|
}
|
||||||
|
if(capture_size && offset == 2) {
|
||||||
|
size = parsed_track.back();
|
||||||
|
capture_size = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(capture_size && offset == 2) {
|
|
||||||
size = parsed_track.back();
|
if( shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::Data ||
|
||||||
capture_size = false;
|
shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::DeletedData) {
|
||||||
|
offset = 128 << size;
|
||||||
|
shifter.set_should_obey_syncs(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::ID) {
|
||||||
|
offset = 6;
|
||||||
|
shifter.set_should_obey_syncs(false);
|
||||||
|
capture_size = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::Data ||
|
long file_offset = get_file_offset_for_position(track.first);
|
||||||
shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::DeletedData) {
|
|
||||||
offset = 128 << size;
|
|
||||||
shifter.set_should_obey_syncs(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(shifter.get_token() == Storage::Encodings::MFM::Shifter::Token::ID) {
|
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
||||||
offset = 6;
|
fseek(file_, file_offset, SEEK_SET);
|
||||||
shifter.set_should_obey_syncs(false);
|
size_t track_size = std::min((size_t)6400, parsed_track.size());
|
||||||
capture_size = true;
|
fwrite(parsed_track.data(), 1, track_size, file_);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long file_offset = get_file_offset_for_position(address);
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
|
||||||
fseek(file_, file_offset, SEEK_SET);
|
|
||||||
size_t track_size = std::min((size_t)6400, parsed_track.size());
|
|
||||||
fwrite(parsed_track.data(), 1, track_size, file_);
|
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,11 @@ class OricMFMDSK: public DiskImage, public Storage::FileHolder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// implemented to satisfy @c Disk
|
// implemented to satisfy @c Disk
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
int get_head_count();
|
int get_head_count() override;
|
||||||
using Storage::FileHolder::get_is_read_only;
|
using Storage::FileHolder::get_is_read_only;
|
||||||
void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track);
|
void set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) override;
|
||||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
std::shared_ptr<Track> get_track_at_position(Track::Address address) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex file_access_mutex_;
|
std::mutex file_access_mutex_;
|
||||||
|
@ -31,11 +31,11 @@ class SSD: public MFMSectorDump {
|
|||||||
ErrorNotSSD,
|
ErrorNotSSD,
|
||||||
};
|
};
|
||||||
|
|
||||||
int get_head_position_count();
|
int get_head_position_count() override;
|
||||||
int get_head_count();
|
int get_head_count() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long get_file_offset_for_position(Track::Address address);
|
long get_file_offset_for_position(Track::Address address) override;
|
||||||
|
|
||||||
int head_count_;
|
int head_count_;
|
||||||
int track_count_;
|
int track_count_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user