From c6e48dfd566c6daefc0da86712ab16257bd3b938 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 8 Jun 2017 21:31:54 -0400 Subject: [PATCH] Given that a final gap is semantically part of describing tape contents, ensured one formally appears before declaring that the tape has ended. --- Storage/Tape/Formats/ZX80O.cpp | 12 ++++++++++-- Storage/Tape/Formats/ZX80O.hpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Storage/Tape/Formats/ZX80O.cpp b/Storage/Tape/Formats/ZX80O.cpp index bd56528ff..a306ad768 100644 --- a/Storage/Tape/Formats/ZX80O.cpp +++ b/Storage/Tape/Formats/ZX80O.cpp @@ -40,29 +40,37 @@ ZX80O::ZX80O(const char *file_name) : void ZX80O::virtual_reset() { fseek(file_, 0, SEEK_SET); is_past_silence_ = false; + has_ended_final_byte_ = false; is_high_ = true; bit_pointer_ = wave_pointer_ = 0; } +bool ZX80O::has_finished_data() { + return (ftell(file_) == end_of_file_ - 0x4000) && !wave_pointer_ && !bit_pointer_; +} + bool ZX80O::is_at_end() { - return ftell(file_) == end_of_file_ - 0x4000; + return has_finished_data() && has_ended_final_byte_; } Tape::Pulse ZX80O::virtual_get_next_pulse() { Tape::Pulse pulse; // Start with 1 second of silence. - if(!is_past_silence_ || (is_at_end() && !wave_pointer_)) { + if(!is_past_silence_ || has_finished_data()) { pulse.type = Pulse::Type::Low; pulse.length.length = 5; pulse.length.clock_rate = 1; is_past_silence_ = true; + has_ended_final_byte_ = has_finished_data(); return pulse; } // For each byte, output 8 bits and then silence. if(!bit_pointer_ && !wave_pointer_) { byte_ = (uint8_t)fgetc(file_); + if(has_finished_data()) + printf(""); bit_pointer_ = 0; wave_pointer_ = 0; } diff --git a/Storage/Tape/Formats/ZX80O.hpp b/Storage/Tape/Formats/ZX80O.hpp index 5535adea5..1c2a9b539 100644 --- a/Storage/Tape/Formats/ZX80O.hpp +++ b/Storage/Tape/Formats/ZX80O.hpp @@ -38,11 +38,12 @@ class ZX80O: public Tape, public Storage::FileHolder { private: void virtual_reset(); Pulse virtual_get_next_pulse(); + bool has_finished_data(); uint8_t byte_; int bit_pointer_; int wave_pointer_; - bool is_past_silence_; + bool is_past_silence_, has_ended_final_byte_; bool is_high_; uint16_t end_of_file_;