mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 23:52:26 +00:00
Merge pull request #155 from TomHarte/MissingByte
Corrects infrastructure that led to the final bit of a ZX80 or ZX81 tape never exiting the parser
This commit is contained in:
commit
4dec9716c4
@ -35,7 +35,7 @@ template <typename SymbolType> class Parser {
|
|||||||
while(!has_next_symbol_ && !tape->is_at_end()) {
|
while(!has_next_symbol_ && !tape->is_at_end()) {
|
||||||
process_pulse(tape->get_next_pulse());
|
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;
|
has_next_symbol_ = false;
|
||||||
return next_symbol_;
|
return next_symbol_;
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,8 @@ void Parser::post_pulse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Parser::mark_end() {
|
void Parser::mark_end() {
|
||||||
// Push the last thing detected, and post an 'unrecognised' to ensure
|
// Post a long gap to cap any bit that's in the process of recognition.
|
||||||
// the queue empties out.
|
push_wave(WaveType::LongGap);
|
||||||
post_pulse();
|
|
||||||
push_wave(WaveType::Unrecognised);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::inspect_waves(const std::vector<WaveType> &waves) {
|
void Parser::inspect_waves(const std::vector<WaveType> &waves) {
|
||||||
@ -76,14 +74,11 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves) {
|
|||||||
number_of_pulses++;
|
number_of_pulses++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If those pulses were followed by a gap then they might be
|
// If those pulses were followed by something not recognised as a pulse, check for a bit
|
||||||
// a recognised symbol.
|
if(number_of_pulses + wave_offset < waves.size()) {
|
||||||
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
|
||||||
(waves[number_of_pulses + wave_offset] == WaveType::LongGap || waves[number_of_pulses + wave_offset] == WaveType::Gap)) {
|
// act simply to terminate the gap beforehand and won't be logged as a pulse. So counts to
|
||||||
// A 1 is 18 up/down waves, a 0 is 8. But the final down will be indistinguishable from
|
// check are 8 and 3.
|
||||||
// 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.
|
|
||||||
size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0);
|
size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0);
|
||||||
switch(number_of_pulses) {
|
switch(number_of_pulses) {
|
||||||
case 8: push_symbol(SymbolType::One, (int)(number_of_pulses + gaps_to_swallow)); break;
|
case 8: push_symbol(SymbolType::One, (int)(number_of_pulses + gaps_to_swallow)); break;
|
||||||
|
Loading…
Reference in New Issue
Block a user