From 35296017b5d2331f97228a9d5eeaebf107a030b2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 17 Jul 2017 21:36:05 -0400 Subject: [PATCH] Clarified meaning of is_high_ flag and ensured it is honoured properly. --- Storage/Tape/Formats/TZX.cpp | 13 +++++++------ Storage/Tape/Formats/TZX.hpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Storage/Tape/Formats/TZX.cpp b/Storage/Tape/Formats/TZX.cpp index 7960ae549..ede3b011a 100644 --- a/Storage/Tape/Formats/TZX.cpp +++ b/Storage/Tape/Formats/TZX.cpp @@ -16,7 +16,7 @@ const unsigned int StandardTZXClock = 3500000; TZX::TZX(const char *file_name) : Storage::FileHolder(file_name), - is_high_(false) { + next_is_high_(false) { // Check for signature followed by a 0x1a char identifier[7]; @@ -36,6 +36,7 @@ TZX::TZX(const char *file_name) : void TZX::virtual_reset() { clear(); set_is_at_end(false); + next_is_high_ = false; fseek(file_, 0x0a, SEEK_SET); } @@ -136,9 +137,9 @@ void TZX::get_generalised_segment(uint32_t output_symbols, uint8_t max_pulses_pe // Mutate initial output level. switch(symbol.flags & 3) { case 0: break; - case 1: is_high_ ^= true; break; - case 2: is_high_ = true; break; - case 3: is_high_ = false; break; + case 1: next_is_high_ ^= true; break; + case 2: next_is_high_ = false; break; + case 3: next_is_high_ = true; break; } // Output waves. @@ -151,8 +152,8 @@ void TZX::get_generalised_segment(uint32_t output_symbols, uint8_t max_pulses_pe } void TZX::post_pulse(unsigned int length) { - is_high_ ^= true; - emplace_back(is_high_ ? Tape::Pulse::High : Tape::Pulse::Low, Storage::Time(length, StandardTZXClock)); + emplace_back(next_is_high_ ? Tape::Pulse::High : Tape::Pulse::Low, Storage::Time(length, StandardTZXClock)); + next_is_high_ ^= true; } void TZX::get_standard_speed_data_block() { diff --git a/Storage/Tape/Formats/TZX.hpp b/Storage/Tape/Formats/TZX.hpp index c37334043..e0eb6b432 100644 --- a/Storage/Tape/Formats/TZX.hpp +++ b/Storage/Tape/Formats/TZX.hpp @@ -35,7 +35,7 @@ class TZX: public PulseQueuedTape, public Storage::FileHolder { void virtual_reset(); void get_next_pulses(); - bool is_high_; + bool next_is_high_; void get_standard_speed_data_block(); void get_turbo_speed_data_block();