diff --git a/Storage/Tape/Parsers/TapeParser.hpp b/Storage/Tape/Parsers/TapeParser.hpp index c696b205d..4ae1d092f 100644 --- a/Storage/Tape/Parsers/TapeParser.hpp +++ b/Storage/Tape/Parsers/TapeParser.hpp @@ -35,7 +35,7 @@ template class Parser { while(!has_next_symbol_ && !tape->is_at_end()) { process_pulse(tape->get_next_pulse()); } - if(tape->is_at_end()) mark_end(); + if(!has_next_symbol_ && tape->is_at_end()) mark_end(); has_next_symbol_ = false; return next_symbol_; } diff --git a/Storage/Tape/Parsers/ZX8081.cpp b/Storage/Tape/Parsers/ZX8081.cpp index 68d3fc4b1..e1411f791 100644 --- a/Storage/Tape/Parsers/ZX8081.cpp +++ b/Storage/Tape/Parsers/ZX8081.cpp @@ -45,10 +45,8 @@ void Parser::post_pulse() { } void Parser::mark_end() { - // Push the last thing detected, and post an 'unrecognised' to ensure - // the queue empties out. - post_pulse(); - push_wave(WaveType::Unrecognised); + // Post a long gap to cap any bit that's in the process of recognition. + push_wave(WaveType::LongGap); } void Parser::inspect_waves(const std::vector &waves) { @@ -76,14 +74,11 @@ void Parser::inspect_waves(const std::vector &waves) { number_of_pulses++; } - // If those pulses were followed by a gap then they might be - // a recognised symbol. - if(number_of_pulses + wave_offset < waves.size() && - (waves[number_of_pulses + wave_offset] == WaveType::LongGap || waves[number_of_pulses + wave_offset] == WaveType::Gap)) { - // A 1 is 18 up/down waves, a 0 is 8. But the final down will be indistinguishable from - // the gap that follows the bit due to the simplified "high is high, everything else is low" - // logic applied to pulse detection. So those two things will merge. Meaning we're looking for - // 17 and/or 7 pulses. + // If those pulses were followed by something not recognised as a pulse, check for a bit + if(number_of_pulses + wave_offset < waves.size()) { + // A 1 is 9 waves, a 0 is 4. Counting upward zero transitions, the first in either group will + // act simply to terminate the gap beforehand and won't be logged as a pulse. So counts to + // check are 8 and 3. size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0); switch(number_of_pulses) { case 8: push_symbol(SymbolType::One, (int)(number_of_pulses + gaps_to_swallow)); break;