1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Updated TapePlayer and BinaryTapePlayer to be sleepers.

This commit is contained in:
Thomas Harte 2017-08-20 12:18:36 -04:00
parent e88a51e75e
commit 8fdc5012e4
2 changed files with 20 additions and 2 deletions

View File

@ -65,10 +65,15 @@ void Tape::set_offset(uint64_t offset) {
#pragma mark - Player #pragma mark - Player
bool TapePlayer::is_sleeping() {
return !tape_ || tape_->is_at_end();
}
void TapePlayer::set_tape(std::shared_ptr<Storage::Tape::Tape> tape) { void TapePlayer::set_tape(std::shared_ptr<Storage::Tape::Tape> tape) {
tape_ = tape; tape_ = tape;
reset_timer(); reset_timer();
get_next_pulse(); get_next_pulse();
update_sleep_observer();
} }
std::shared_ptr<Storage::Tape::Tape> TapePlayer::get_tape() { std::shared_ptr<Storage::Tape::Tape> TapePlayer::get_tape() {
@ -81,8 +86,10 @@ bool TapePlayer::has_tape() {
void TapePlayer::get_next_pulse() { void TapePlayer::get_next_pulse() {
// get the new pulse // get the new pulse
if(tape_) if(tape_) {
current_pulse_ = tape_->get_next_pulse(); current_pulse_ = tape_->get_next_pulse();
if(tape_->is_at_end()) update_sleep_observer();
}
else { else {
current_pulse_.length.length = 1; current_pulse_.length.length = 1;
current_pulse_.length.clock_rate = 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) 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) { void BinaryTapePlayer::set_motor_control(bool enabled) {
motor_is_running_ = enabled; motor_is_running_ = enabled;
update_sleep_observer();
} }
void BinaryTapePlayer::set_tape_output(bool set) { void BinaryTapePlayer::set_tape_output(bool set) {

View File

@ -12,6 +12,8 @@
#include <memory> #include <memory>
#include "../../ClockReceiver/ClockReceiver.hpp" #include "../../ClockReceiver/ClockReceiver.hpp"
#include "../../ClockReceiver/Sleeper.hpp"
#include "../TimedEventLoop.hpp" #include "../TimedEventLoop.hpp"
namespace Storage { 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 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. 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: public:
TapePlayer(unsigned int input_clock_rate); TapePlayer(unsigned int input_clock_rate);
@ -105,6 +107,8 @@ class TapePlayer: public TimedEventLoop {
void run_for_input_pulse(); void run_for_input_pulse();
bool is_sleeping();
protected: protected:
virtual void process_next_event(); virtual void process_next_event();
virtual void process_input_pulse(const Tape::Pulse &pulse) = 0; virtual void process_input_pulse(const Tape::Pulse &pulse) = 0;
@ -139,6 +143,8 @@ class BinaryTapePlayer: public TapePlayer {
}; };
void set_delegate(Delegate *delegate); void set_delegate(Delegate *delegate);
bool is_sleeping();
protected: protected:
Delegate *delegate_; Delegate *delegate_;
virtual void process_input_pulse(const Storage::Tape::Tape::Pulse &pulse); virtual void process_input_pulse(const Storage::Tape::Tape::Pulse &pulse);