diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index 1465a4f62..47f9c7286 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -67,7 +67,7 @@ (value); - bits_since_token_++; + ++bits_since_token_; token_ = Token::None; if(should_obey_syncs_) { @@ -57,6 +57,20 @@ void Shifter::add_input_bit(int value) { } else { switch(shift_register_ & 0xffff) { case Storage::Encodings::MFM::MFMIndexSync: + // This models a bit of slightly weird WD behaviour; + // if an index sync was detected where it wasn't expected, + // the WD will resync but also may return the clock bits + // rather than data bits as the next byte read, depending + // on framing. + // + // TODO: make this optional, if ever a Shifter with + // well-defined non-WD behaviour is needed. + // + // TODO: Verify WD behaviour. + if(bits_since_token_&1) { + shift_register_ >>= 1; + } + bits_since_token_ = 0; is_awaiting_marker_value_ = true; diff --git a/Storage/Disk/Encodings/MFM/Shifter.hpp b/Storage/Disk/Encodings/MFM/Shifter.hpp index 46bd252f6..35234c1ca 100644 --- a/Storage/Disk/Encodings/MFM/Shifter.hpp +++ b/Storage/Disk/Encodings/MFM/Shifter.hpp @@ -27,6 +27,10 @@ namespace MFM { It will ordinarily honour sync patterns; that should be turned off when within a sector because false syncs can occur. See @c set_should_obey_syncs. + It aims to implement the same behaviour as WD177x-series controllers when + detecting a false sync — the received byte value will be either a 0xc1 or 0x14, + depending on phase. + Bits should be fed in with @c add_input_bit. The current output token can be read with @c get_token. It will usually be None but @@ -62,14 +66,14 @@ class Shifter { } private: - // Bit stream input state + // Bit stream input state. int bits_since_token_ = 0; unsigned int shift_register_ = 0; bool is_awaiting_marker_value_ = false; bool should_obey_syncs_ = true; Token token_ = None; - // input configuration + // Input configuration. bool is_double_density_ = false; std::unique_ptr owned_crc_generator_;