diff --git a/Storage/Disk/Encodings/MFM.cpp b/Storage/Disk/Encodings/MFM.cpp index efb0797b2..4e5180b23 100644 --- a/Storage/Disk/Encodings/MFM.cpp +++ b/Storage/Disk/Encodings/MFM.cpp @@ -9,42 +9,3 @@ #include "MFM.hpp" using namespace Storage::Encodings; - -void Shifter::add_sync() -{ - // i.e. 0100 0100 1000 1001 - output = (uint16_t)((output << 15) | 0x4489); -} - -void MFMShifter::shift(uint8_t input) -{ - uint16_t spread_value = - (uint16_t)( - ((input & 0x01) << 0) | - ((input & 0x02) << 1) | - ((input & 0x04) << 2) | - ((input & 0x08) << 3) | - ((input & 0x10) << 4) | - ((input & 0x20) << 5) | - ((input & 0x40) << 6) | - ((input & 0x80) << 7) - ); - uint16_t or_bits = (uint16_t)((spread_value << 1) | (spread_value >> 1) | (output << 15)); - output = spread_value | ((~or_bits) & 0xaaaa); -} - -void FMShifter::shift(uint8_t input) -{ - output = - (uint16_t)( - ((input & 0x01) << 0) | - ((input & 0x02) << 1) | - ((input & 0x04) << 2) | - ((input & 0x08) << 3) | - ((input & 0x10) << 4) | - ((input & 0x20) << 5) | - ((input & 0x40) << 6) | - ((input & 0x80) << 7) | - 0xaaaa - ); -} diff --git a/Storage/Disk/Encodings/MFM.hpp b/Storage/Disk/Encodings/MFM.hpp index 2e3c8f2c4..3c07e5dd2 100644 --- a/Storage/Disk/Encodings/MFM.hpp +++ b/Storage/Disk/Encodings/MFM.hpp @@ -14,21 +14,98 @@ namespace Storage { namespace Encodings { -class Shifter { +template class Shifter { public: - virtual void shift(uint8_t input) = 0; - void add_sync(); - uint16_t output; + virtual void add_byte(uint8_t input) = 0; + virtual void add_index_address_mark() = 0; + virtual void add_ID_address_mark() = 0; + virtual void add_data_address_mark() = 0; + virtual void add_deleted_data_address_mark() = 0; + + protected: + // override me! + void output_short(uint16_t value); }; -class MFMShifter: public Shifter { +template class MFMShifter: public Shifter { public: - void shift(uint8_t input); + void add_byte(uint8_t input) { + uint16_t spread_value = + (uint16_t)( + ((input & 0x01) << 0) | + ((input & 0x02) << 1) | + ((input & 0x04) << 2) | + ((input & 0x08) << 3) | + ((input & 0x10) << 4) | + ((input & 0x20) << 5) | + ((input & 0x40) << 6) | + ((input & 0x80) << 7) + ); + uint16_t or_bits = (uint16_t)((spread_value << 1) | (spread_value >> 1) | (output_ << 15)); + output_ = spread_value | ((~or_bits) & 0xaaaa); + static_cast(this)->output_short(output_); + } + + void add_index_address_mark() { + static_cast(this)->output_short(output_ = 0x5224); + add_byte(0xfc); + } + + void add_ID_address_mark() { + static_cast(this)->output_short(output_ = 0x4489); + add_byte(0xfe); + } + + void add_data_address_mark() { + static_cast(this)->output_short(output_ = 0x4489); + add_byte(0xfb); + } + + void add_deleted_data_address_mark() { + static_cast(this)->output_short(output_ = 0x4489); + add_byte(0xf8); + } + + private: + uint16_t output_; }; -class FMShifter: public Shifter { +template class FMShifter: public Shifter { public: - void shift(uint8_t input); + void add_byte(uint8_t input) { + static_cast(this)->output_short( + (uint16_t)( + ((input & 0x01) << 1) | + ((input & 0x02) << 2) | + ((input & 0x04) << 3) | + ((input & 0x08) << 4) | + ((input & 0x10) << 5) | + ((input & 0x20) << 6) | + ((input & 0x40) << 7) | + ((input & 0x80) << 8) | + 0x5555 + )); + } + + void add_index_address_mark() { + // data 0xfc, with clock 0xd7 => 1111 1100 with clock 1101 0111 => 1111 1011 1011 0101 + static_cast(this)->output_short(0xfbb5); + } + + void add_ID_address_mark() { + // data 0xfe, with clock 0xc7 => 1111 1110 with clock 1100 0111 => 1111 1010 1011 1101 + static_cast(this)->output_short(0xfabd); + } + + void add_data_address_mark() { + // data 0xfb, with clock 0xc7 => 1111 1011 with clock 1100 0111 => 1111 1010 1001 1111 + static_cast(this)->output_short(0xfa9f); + } + + void add_deleted_data_address_mark() { + // data 0xf8, with clock 0xc7 => 1111 1000 with clock 1100 0111 => 1111 1010 1001 0101 + static_cast(this)->output_short(0xfa95); + } }; }