diff --git a/Storage/Disk/Encodings/MFM.hpp b/Storage/Disk/Encodings/MFM.hpp index ff271afc0..f1545407d 100644 --- a/Storage/Disk/Encodings/MFM.hpp +++ b/Storage/Disk/Encodings/MFM.hpp @@ -48,10 +48,10 @@ class Encoder { virtual void add_ID_address_mark() = 0; virtual void add_data_address_mark() = 0; virtual void add_deleted_data_address_mark() = 0; + virtual void output_short(uint16_t value); void add_crc(); protected: - virtual void output_short(uint16_t value); NumberTheory::CRC16 crc_generator_; private: diff --git a/Storage/Disk/Formats/OricMFMDSK.cpp b/Storage/Disk/Formats/OricMFMDSK.cpp index 7ab373bd7..c0de30f9e 100644 --- a/Storage/Disk/Formats/OricMFMDSK.cpp +++ b/Storage/Disk/Formats/OricMFMDSK.cpp @@ -57,6 +57,7 @@ std::shared_ptr OricMFMDSK::get_uncached_track_at_position(unsigned int h size_t track_offset = 0; uint8_t last_header[6]; std::unique_ptr encoder = Encodings::MFM::GetMFMEncoder(segment.data); + bool did_sync = false; while(track_offset < 6250) { uint8_t next_byte = (uint8_t)fgetc(file_); @@ -65,32 +66,46 @@ std::shared_ptr OricMFMDSK::get_uncached_track_at_position(unsigned int h switch(next_byte) { default: - encoder->add_byte(next_byte); - break; - - case 0xfe: // an ID synchronisation { - encoder->add_ID_address_mark(); - - for(int byte = 0; byte < 6; byte++) + encoder->add_byte(next_byte); + if(did_sync) { - last_header[byte] = (uint8_t)fgetc(file_); - encoder->add_byte(last_header[byte]); - track_offset++; - if(track_offset == 6250) break; + switch(next_byte) + { + default: break; + + case 0xfe: + for(int byte = 0; byte < 6; byte++) + { + last_header[byte] = (uint8_t)fgetc(file_); + encoder->add_byte(last_header[byte]); + track_offset++; + if(track_offset == 6250) break; + } + break; + + case 0xfb: + for(int byte = 0; byte < (128 << last_header[3]) + 2; byte++) + { + encoder->add_byte((uint8_t)fgetc(file_)); + track_offset++; + if(track_offset == 6250) break; + } + break; + } } + + did_sync = false; } break; - case 0xfb: // a data synchronisation - encoder->add_data_address_mark(); + case 0xa1: // a synchronisation mark that implies a sector or header coming + encoder->output_short(Storage::Encodings::MFM::MFMSync); + did_sync = true; + break; - for(int byte = 0; byte < (128 << last_header[3]) + 2; byte++) - { - encoder->add_byte((uint8_t)fgetc(file_)); - track_offset++; - if(track_offset == 6250) break; - } + case 0xc2: // an 'ordinary' synchronisation mark + encoder->output_short(Storage::Encodings::MFM::MFMIndexSync); break; } }