mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-24 20:16:41 +00:00
Factors out commonalities in SSD/DSD and ADF implementations.
This commit is contained in:
@@ -12,14 +12,12 @@
|
||||
|
||||
namespace {
|
||||
static const unsigned int sectors_per_track = 10;
|
||||
static const size_t bytes_per_sector = 256;
|
||||
static const unsigned int sector_size = 1;
|
||||
}
|
||||
|
||||
using namespace Storage::Disk;
|
||||
|
||||
SSD::SSD(const char *file_name) :
|
||||
Storage::FileHolder(file_name) {
|
||||
SSD::SSD(const char *file_name) : MFMSectorDump(file_name) {
|
||||
// very loose validation: the file needs to be a multiple of 256 bytes
|
||||
// and not ungainly large
|
||||
|
||||
@@ -32,6 +30,8 @@ SSD::SSD(const char *file_name) :
|
||||
track_count_ = (unsigned int)(file_stats_.st_size / (256 * 10));
|
||||
if(track_count_ < 40) track_count_ = 40;
|
||||
else if(track_count_ < 80) track_count_ = 80;
|
||||
|
||||
set_geometry(sectors_per_track, sector_size, false);
|
||||
}
|
||||
|
||||
unsigned int SSD::get_head_position_count() {
|
||||
@@ -42,37 +42,6 @@ unsigned int SSD::get_head_count() {
|
||||
return head_count_;
|
||||
}
|
||||
|
||||
bool SSD::get_is_read_only() {
|
||||
return is_read_only_;
|
||||
}
|
||||
|
||||
long SSD::get_file_offset_for_position(unsigned int head, unsigned int position) {
|
||||
return (position * head_count_ + head) * 256 * 10;
|
||||
}
|
||||
|
||||
std::shared_ptr<Track> SSD::get_track_at_position(unsigned int head, unsigned int position) {
|
||||
uint8_t sectors[bytes_per_sector*sectors_per_track];
|
||||
|
||||
if(head >= head_count_) return nullptr;
|
||||
long file_offset = get_file_offset_for_position(head, position);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_guard(file_access_mutex_);
|
||||
fseek(file_, file_offset, SEEK_SET);
|
||||
fread(sectors, 1, sizeof(sectors), file_);
|
||||
}
|
||||
|
||||
return track_for_sectors(sectors, (uint8_t)position, (uint8_t)head, 0, sector_size, false);
|
||||
}
|
||||
|
||||
void SSD::set_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track) {
|
||||
uint8_t parsed_track[bytes_per_sector*sectors_per_track];
|
||||
decode_sectors(*track, parsed_track, 0, sectors_per_track-1, sector_size, false);
|
||||
|
||||
long file_offset = get_file_offset_for_position(head, position);
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user