1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Added writing for Acorn ADF disks, plus appropriate TODOs in both similar bits of boilerplate.

This commit is contained in:
Thomas Harte 2016-12-30 18:03:30 -05:00
parent c85450648f
commit 07dacff42d
4 changed files with 36 additions and 20 deletions

View File

@ -40,25 +40,6 @@ AcornADF::AcornADF(const char *file_name) :
AcornADF::~AcornADF()
{
flush_updates();
// if(get_is_modified())
// {
// for(unsigned int head = 0; head < get_head_count(); head++)
// {
// for(unsigned int track = 0; track < get_head_position_count(); track++)
// {
// std::shared_ptr<Storage::Disk::Track> modified_track = get_modified_track_at_position(head, track);
// if(modified_track)
// {
// Storage::Encodings::MFM::Parser parser(true, modified_track);
// for(unsigned int c = 0; c < sectors_per_track; c++)
// {
// std::shared_ptr<Storage::Encodings::MFM::Sector> sector = parser.get_sector((uint8_t)track, (uint8_t)c);
// printf("Sector %d: %p\n", c, sector.get());
// }
// }
// }
// }
// }
}
unsigned int AcornADF::get_head_position_count()
@ -76,12 +57,17 @@ bool AcornADF::get_is_read_only()
return is_read_only_;
}
long AcornADF::get_file_offset_for_position(unsigned int head, unsigned int position)
{
return (position * 1 + head) * bytes_per_sector * sectors_per_track;
}
std::shared_ptr<Track> AcornADF::get_uncached_track_at_position(unsigned int head, unsigned int position)
{
std::shared_ptr<Track> track;
if(head >= 2) return track;
long file_offset = (position * 1 + head) * bytes_per_sector * sectors_per_track;
long file_offset = get_file_offset_for_position(head, position);
fseek(file_, file_offset, SEEK_SET);
std::vector<Storage::Encodings::MFM::Sector> sectors;
@ -104,3 +90,27 @@ std::shared_ptr<Track> AcornADF::get_uncached_track_at_position(unsigned int hea
return track;
}
void AcornADF::store_updated_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track, std::mutex &file_access_mutex)
{
std::vector<uint8_t> parsed_track;
Storage::Encodings::MFM::Parser parser(true, track);
for(unsigned int c = 0; c < sectors_per_track; c++)
{
std::shared_ptr<Storage::Encodings::MFM::Sector> sector = parser.get_sector((uint8_t)position, (uint8_t)c);
if(sector)
{
parsed_track.insert(parsed_track.end(), sector->data.begin(), sector->data.end());
}
else
{
// TODO: what's correct here? Warn the user that whatever has been written to the disk,
// it can no longer be stored as an SSD? If so, warn them by what route?
parsed_track.resize(parsed_track.size() + bytes_per_sector);
}
}
std::lock_guard<std::mutex> lock_guard(file_access_mutex);
fseek(file_, get_file_offset_for_position(head, position), SEEK_SET);
fwrite(parsed_track.data(), 1, parsed_track.size(), file_);
}

View File

@ -37,8 +37,11 @@ class AcornADF: public Disk, public Storage::FileHolder {
unsigned int get_head_position_count();
unsigned int get_head_count();
bool get_is_read_only();
private:
void store_updated_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track, std::mutex &file_access_mutex);
std::shared_ptr<Track> get_uncached_track_at_position(unsigned int head, unsigned int position);
long get_file_offset_for_position(unsigned int head, unsigned int position);
};
}

View File

@ -99,6 +99,8 @@ void SSD::store_updated_track_at_position(unsigned int head, unsigned int positi
}
else
{
// TODO: what's correct here? Warn the user that whatever has been written to the disk,
// it can no longer be stored as an SSD? If so, warn them by what route?
parsed_track.resize(parsed_track.size() + 256);
}
}

View File

@ -42,6 +42,7 @@ class SSD: public Disk, public Storage::FileHolder {
void store_updated_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track, std::mutex &file_access_mutex);
std::shared_ptr<Track> get_uncached_track_at_position(unsigned int head, unsigned int position);
long get_file_offset_for_position(unsigned int head, unsigned int position);
unsigned int head_count_;
unsigned int track_count_;
};