From 8fdc5012e4bb47dd7e8bb893db31948ce61f97d2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 20 Aug 2017 12:18:36 -0400 Subject: [PATCH] Updated `TapePlayer` and `BinaryTapePlayer` to be sleepers. --- Storage/Tape/Tape.cpp | 14 +++++++++++++- Storage/Tape/Tape.hpp | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index 280b02100..c71f43779 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -65,10 +65,15 @@ void Tape::set_offset(uint64_t offset) { #pragma mark - Player +bool TapePlayer::is_sleeping() { + return !tape_ || tape_->is_at_end(); +} + void TapePlayer::set_tape(std::shared_ptr tape) { tape_ = tape; reset_timer(); get_next_pulse(); + update_sleep_observer(); } std::shared_ptr TapePlayer::get_tape() { @@ -81,8 +86,10 @@ bool TapePlayer::has_tape() { void TapePlayer::get_next_pulse() { // get the new pulse - if(tape_) + if(tape_) { current_pulse_ = tape_->get_next_pulse(); + if(tape_->is_at_end()) update_sleep_observer(); + } else { current_pulse_.length.length = 1; current_pulse_.length.clock_rate = 1; @@ -113,8 +120,13 @@ BinaryTapePlayer::BinaryTapePlayer(unsigned int input_clock_rate) : TapePlayer(input_clock_rate), motor_is_running_(false), input_level_(false), delegate_(nullptr) {} +bool BinaryTapePlayer::is_sleeping() { + return !motor_is_running_ || TapePlayer::is_sleeping(); +} + void BinaryTapePlayer::set_motor_control(bool enabled) { motor_is_running_ = enabled; + update_sleep_observer(); } void BinaryTapePlayer::set_tape_output(bool set) { diff --git a/Storage/Tape/Tape.hpp b/Storage/Tape/Tape.hpp index e76f6470e..25e53ed81 100644 --- a/Storage/Tape/Tape.hpp +++ b/Storage/Tape/Tape.hpp @@ -12,6 +12,8 @@ #include #include "../../ClockReceiver/ClockReceiver.hpp" +#include "../../ClockReceiver/Sleeper.hpp" + #include "../TimedEventLoop.hpp" namespace Storage { @@ -93,7 +95,7 @@ class Tape { Will call @c process_input_pulse instantaneously upon reaching *the end* of a pulse. Therefore a subclass can decode pulses into data within process_input_pulse, using the supplied pulse's @c length and @c type. */ -class TapePlayer: public TimedEventLoop { +class TapePlayer: public TimedEventLoop, public Sleeper { public: TapePlayer(unsigned int input_clock_rate); @@ -105,6 +107,8 @@ class TapePlayer: public TimedEventLoop { void run_for_input_pulse(); + bool is_sleeping(); + protected: virtual void process_next_event(); virtual void process_input_pulse(const Tape::Pulse &pulse) = 0; @@ -139,6 +143,8 @@ class BinaryTapePlayer: public TapePlayer { }; void set_delegate(Delegate *delegate); + bool is_sleeping(); + protected: Delegate *delegate_; virtual void process_input_pulse(const Storage::Tape::Tape::Pulse &pulse);