From ca53fac73256c26ecccab7ef8492df32be45c6ff Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 26 Sep 2016 21:20:30 -0400 Subject: [PATCH] Switched to assuming a single-sided disk, moved out magic constants. --- Storage/Disk/Formats/AcornADF.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Storage/Disk/Formats/AcornADF.cpp b/Storage/Disk/Formats/AcornADF.cpp index 13956ed3d..c82d27e65 100644 --- a/Storage/Disk/Formats/AcornADF.cpp +++ b/Storage/Disk/Formats/AcornADF.cpp @@ -11,6 +11,11 @@ #include #include "../Encodings/MFM.hpp" +namespace { + static const unsigned int sectors_per_track = 16; + static const unsigned int bytes_per_sector = 256; +} + using namespace Storage::Disk; AcornADF::AcornADF(const char *file_name) : _file(nullptr) @@ -20,8 +25,8 @@ AcornADF::AcornADF(const char *file_name) : _file(nullptr) // very loose validation: the file needs to be a multiple of 256 bytes // and not ungainly large - if(file_stats.st_size & 255) throw ErrorNotAcornADF; - if(file_stats.st_size < 7 * 256) throw ErrorNotAcornADF; + if(file_stats.st_size % bytes_per_sector) throw ErrorNotAcornADF; + if(file_stats.st_size < 7 * bytes_per_sector) throw ErrorNotAcornADF; _file = fopen(file_name, "rb"); if(!_file) throw ErrorCantOpen; @@ -49,7 +54,7 @@ unsigned int AcornADF::get_head_position_count() unsigned int AcornADF::get_head_count() { - return 2; + return 1; } std::shared_ptr AcornADF::get_track_at_position(unsigned int head, unsigned int position) @@ -57,19 +62,19 @@ std::shared_ptr AcornADF::get_track_at_position(unsigned int head, unsign std::shared_ptr track; if(head >= 2) return track; - long file_offset = (position * 2 + head) * 256 * 16; + long file_offset = (position * 1 + head) * bytes_per_sector * sectors_per_track; fseek(_file, file_offset, SEEK_SET); std::vector sectors; - for(int sector = 0; sector < 16; sector++) + for(int sector = 0; sector < sectors_per_track; sector++) { Storage::Encodings::MFM::Sector new_sector; new_sector.track = (uint8_t)position; - new_sector.side = 0; + new_sector.side = (uint8_t)head; new_sector.sector = (uint8_t)sector; - new_sector.data.resize(256); - fread(&new_sector.data[0], 1, 256, _file); + new_sector.data.resize(bytes_per_sector); + fread(&new_sector.data[0], 1, bytes_per_sector, _file); if(feof(_file)) break;