2016-01-18 21:46:41 +00:00
|
|
|
//
|
|
|
|
// Tape.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/01/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Tape_hpp
|
|
|
|
#define Tape_hpp
|
|
|
|
|
2016-06-26 23:03:57 +00:00
|
|
|
#include <memory>
|
|
|
|
#include "../../SignalProcessing/Stepper.hpp"
|
2016-01-18 21:46:41 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
class Tape {
|
|
|
|
public:
|
|
|
|
struct Time {
|
|
|
|
unsigned int length, clock_rate;
|
|
|
|
};
|
|
|
|
|
2016-01-18 23:06:09 +00:00
|
|
|
struct Pulse {
|
2016-01-18 21:46:41 +00:00
|
|
|
enum {
|
|
|
|
High, Low, Zero
|
|
|
|
} type;
|
|
|
|
Time length;
|
|
|
|
};
|
|
|
|
|
2016-01-18 23:06:09 +00:00
|
|
|
virtual Pulse get_next_pulse() = 0;
|
2016-01-18 21:46:41 +00:00
|
|
|
virtual void reset() = 0;
|
|
|
|
|
|
|
|
virtual void seek(Time seek_time);
|
|
|
|
};
|
|
|
|
|
2016-06-26 23:03:57 +00:00
|
|
|
class TapePlayer {
|
|
|
|
public:
|
|
|
|
TapePlayer(unsigned int input_clock_rate);
|
|
|
|
|
|
|
|
void set_tape(std::shared_ptr<Storage::Tape> tape);
|
|
|
|
bool has_tape();
|
|
|
|
|
|
|
|
void run_for_cycles(unsigned int number_of_cycles);
|
|
|
|
void run_for_input_pulse();
|
2016-01-18 21:46:41 +00:00
|
|
|
|
2016-06-26 23:03:57 +00:00
|
|
|
protected:
|
|
|
|
virtual void process_input_pulse(Tape::Pulse pulse) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline void get_next_pulse();
|
|
|
|
|
|
|
|
unsigned int _input_clock_rate;
|
|
|
|
std::shared_ptr<Storage::Tape> _tape;
|
|
|
|
struct {
|
|
|
|
Tape::Pulse current_pulse;
|
|
|
|
std::unique_ptr<SignalProcessing::Stepper> pulse_stepper;
|
|
|
|
uint32_t time_into_pulse;
|
|
|
|
} _input;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-01-18 21:46:41 +00:00
|
|
|
|
|
|
|
#endif /* Tape_hpp */
|