2017-07-17 02:04:40 +00:00
|
|
|
//
|
|
|
|
// PulseQueuedTape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/07/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-07-17 02:04:40 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "PulseQueuedTape.hpp"
|
|
|
|
|
|
|
|
using namespace Storage::Tape;
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
bool PulseQueuedSerialiser::is_at_end() const {
|
2017-07-17 02:04:40 +00:00
|
|
|
return is_at_end_;
|
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
void PulseQueuedSerialiser::set_is_at_end(const bool is_at_end) {
|
2017-07-17 02:04:40 +00:00
|
|
|
is_at_end_ = is_at_end;
|
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
void PulseQueuedSerialiser::clear() {
|
2017-07-17 02:04:40 +00:00
|
|
|
queued_pulses_.clear();
|
|
|
|
pulse_pointer_ = 0;
|
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
bool PulseQueuedSerialiser::empty() const {
|
2017-07-17 02:04:40 +00:00
|
|
|
return queued_pulses_.empty();
|
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
void PulseQueuedSerialiser::emplace_back(const Pulse::Type type, const Time length) {
|
2017-07-17 02:04:40 +00:00
|
|
|
queued_pulses_.emplace_back(type, length);
|
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
void PulseQueuedSerialiser::push_back(const Pulse pulse) {
|
2024-12-03 22:33:09 +00:00
|
|
|
queued_pulses_.push_back(pulse);
|
2017-07-17 02:04:40 +00:00
|
|
|
}
|
|
|
|
|
2024-12-04 03:28:57 +00:00
|
|
|
Pulse PulseQueuedSerialiser::get_next_pulse() {
|
2024-12-03 22:33:09 +00:00
|
|
|
const auto silence = [] {
|
2024-12-04 03:28:57 +00:00
|
|
|
return Pulse(Pulse::Type::Zero, Storage::Time(1, 1));
|
2024-12-03 22:33:09 +00:00
|
|
|
};
|
|
|
|
|
2017-07-17 02:04:40 +00:00
|
|
|
if(is_at_end_) {
|
|
|
|
return silence();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pulse_pointer_ == queued_pulses_.size()) {
|
|
|
|
clear();
|
|
|
|
get_next_pulses();
|
|
|
|
|
|
|
|
if(is_at_end_ || pulse_pointer_ == queued_pulses_.size()) {
|
|
|
|
return silence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-03 22:33:09 +00:00
|
|
|
const std::size_t read_pointer = pulse_pointer_;
|
2017-07-17 02:04:40 +00:00
|
|
|
pulse_pointer_++;
|
|
|
|
return queued_pulses_[read_pointer];
|
|
|
|
}
|