1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 19:17:52 +00:00

Factored out from the UEF implementation the concept of being a tape that has a queue of pending pulses and manages that queue.

This commit is contained in:
Thomas Harte
2017-07-16 22:04:40 -04:00
parent 238348c885
commit 8f72fc4a44
5 changed files with 174 additions and 133 deletions
+61
View File
@@ -0,0 +1,61 @@
//
// PulseQueuedTape.cpp
// Clock Signal
//
// Created by Thomas Harte on 16/07/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "PulseQueuedTape.hpp"
using namespace Storage::Tape;
PulseQueuedTape::PulseQueuedTape() : pulse_pointer_(0) {}
bool PulseQueuedTape::is_at_end() {
return is_at_end_;
}
void PulseQueuedTape::set_is_at_end(bool is_at_end) {
is_at_end_ = is_at_end;
}
void PulseQueuedTape::clear() {
queued_pulses_.clear();
pulse_pointer_ = 0;
}
bool PulseQueuedTape::empty() {
return queued_pulses_.empty();
}
void PulseQueuedTape::emplace_back(Tape::Pulse::Type type, Time length) {
queued_pulses_.emplace_back(type, length);
}
Tape::Pulse PulseQueuedTape::silence() {
Pulse silence;
silence.type = Pulse::Zero;
silence.length.length = 1;
silence.length.clock_rate = 1;
return silence;
}
Tape::Pulse PulseQueuedTape::virtual_get_next_pulse() {
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();
}
}
size_t read_pointer = pulse_pointer_;
pulse_pointer_++;
return queued_pulses_[read_pointer];
}