From b07af2660d6d3fbb62fd98b5ff69286006ad9245 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 8 Jun 2017 21:33:35 -0400 Subject: [PATCH] Adjusted to make sure that the very end of a tape is properly measured. --- Storage/Tape/Parsers/ZX8081.cpp | 20 +++++++++++++++----- Storage/Tape/Parsers/ZX8081.hpp | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Storage/Tape/Parsers/ZX8081.cpp b/Storage/Tape/Parsers/ZX8081.cpp index 1f4ab5ce2..9dc00211d 100644 --- a/Storage/Tape/Parsers/ZX8081.cpp +++ b/Storage/Tape/Parsers/ZX8081.cpp @@ -18,7 +18,10 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse) { if(pulse_is_high == pulse_was_high_) return; pulse_was_high_ = pulse_is_high; + post_pulse(); +} +void Parser::post_pulse() { const float expected_pulse_length = 150.0f / 1000000.0f; const float expected_gap_length = 1300.0f / 1000000.0f; float pulse_time = pulse_time_.get_float(); @@ -38,6 +41,13 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse 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); +} + void Parser::inspect_waves(const std::vector &waves) { // A long gap is a file gap. if(waves[0] == WaveType::LongGap) { @@ -77,7 +87,7 @@ int Parser::get_next_byte(const std::shared_ptr &tape) { int c = 8; int result = 0; while(c--) { - if(tape->is_at_end()) return -1; + if(is_at_end(tape)) return -1; SymbolType symbol = get_next_symbol(tape); if(symbol == SymbolType::FileGap) { return_symbol(symbol); @@ -92,20 +102,20 @@ int Parser::get_next_byte(const std::shared_ptr &tape) { } std::shared_ptr> Parser::get_next_file_data(const std::shared_ptr &tape) { - if(tape->is_at_end()) return nullptr; + if(is_at_end(tape)) return nullptr; SymbolType symbol = get_next_symbol(tape); if(symbol != SymbolType::FileGap) { return nullptr; } - while(symbol == SymbolType::FileGap && !tape->is_at_end()) { + while(symbol == SymbolType::FileGap && !is_at_end(tape)) { symbol = get_next_symbol(tape); } - if(tape->is_at_end()) return nullptr; + if(is_at_end(tape)) return nullptr; return_symbol(symbol); std::shared_ptr> result(new std::vector); int byte; - while(!tape->is_at_end()) { + while(!is_at_end(tape)) { byte = get_next_byte(tape); if(byte == -1) return result; result->push_back((uint8_t)byte); diff --git a/Storage/Tape/Parsers/ZX8081.hpp b/Storage/Tape/Parsers/ZX8081.hpp index a6fb3f2e9..8fc5873fb 100644 --- a/Storage/Tape/Parsers/ZX8081.hpp +++ b/Storage/Tape/Parsers/ZX8081.hpp @@ -48,7 +48,11 @@ class Parser: public Storage::Tape::Parser { private: bool pulse_was_high_; Time pulse_time_; + void post_pulse(); + void process_pulse(Storage::Tape::Tape::Pulse pulse); + void mark_end(); + void inspect_waves(const std::vector &waves); std::shared_ptr> get_next_file_data(const std::shared_ptr &tape);