2016-12-03 17:18:08 +00:00
|
|
|
//
|
|
|
|
// Tape.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/12/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Electron_Tape_h
|
|
|
|
#define Electron_Tape_h
|
|
|
|
|
2017-07-26 00:20:55 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2016-12-03 17:18:08 +00:00
|
|
|
#include "../../Storage/Tape/Tape.hpp"
|
2017-07-16 23:24:01 +00:00
|
|
|
#include "../../Storage/Tape/Parsers/Acorn.hpp"
|
2016-12-03 17:18:08 +00:00
|
|
|
#include "Interrupts.hpp"
|
|
|
|
|
|
|
|
namespace Electron {
|
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
class Tape:
|
|
|
|
public Storage::Tape::TapePlayer,
|
|
|
|
public Storage::Tape::Acorn::Shifter::Delegate {
|
2016-12-03 17:18:08 +00:00
|
|
|
public:
|
|
|
|
Tape();
|
|
|
|
|
2017-07-28 02:05:29 +00:00
|
|
|
void run_for(const Cycles cycles);
|
2017-07-26 00:01:30 +00:00
|
|
|
using Storage::Tape::TapePlayer::run_for;
|
2016-12-03 17:18:08 +00:00
|
|
|
|
|
|
|
uint8_t get_data_register();
|
|
|
|
void set_data_register(uint8_t value);
|
|
|
|
void set_counter(uint8_t value);
|
|
|
|
|
|
|
|
inline uint8_t get_interrupt_status() { return interrupt_status_; }
|
|
|
|
void clear_interrupts(uint8_t interrupts);
|
|
|
|
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual void tape_did_change_interrupt_status(Tape *tape) = 0;
|
|
|
|
};
|
|
|
|
inline void set_delegate(Delegate *delegate) { delegate_ = delegate; }
|
|
|
|
|
|
|
|
inline void set_is_running(bool is_running) { is_running_ = is_running; }
|
|
|
|
inline void set_is_enabled(bool is_enabled) { is_enabled_ = is_enabled; }
|
|
|
|
void set_is_in_input_mode(bool is_in_input_mode);
|
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
void acorn_shifter_output_bit(int value);
|
|
|
|
|
2016-12-03 17:18:08 +00:00
|
|
|
private:
|
2017-07-16 23:49:31 +00:00
|
|
|
void process_input_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
2016-12-03 17:18:08 +00:00
|
|
|
inline void push_tape_bit(uint16_t bit);
|
|
|
|
inline void get_next_tape_pulse();
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int minimum_bits_until_full;
|
2017-09-01 02:29:24 +00:00
|
|
|
} input_ = {0};
|
2016-12-03 17:18:08 +00:00
|
|
|
struct {
|
|
|
|
unsigned int cycles_into_pulse;
|
|
|
|
unsigned int bits_remaining_until_empty;
|
2017-09-01 02:29:24 +00:00
|
|
|
} output_ = {.bits_remaining_until_empty = 0, .cycles_into_pulse = 0};
|
2016-12-03 17:18:08 +00:00
|
|
|
|
2017-09-01 02:29:24 +00:00
|
|
|
bool is_running_ = false;
|
|
|
|
bool is_enabled_ = false;
|
|
|
|
bool is_in_input_mode_ = false;
|
2016-12-03 17:18:08 +00:00
|
|
|
|
|
|
|
inline void evaluate_interrupts();
|
2017-09-01 02:29:24 +00:00
|
|
|
uint16_t data_register_ = 0;
|
2016-12-03 17:18:08 +00:00
|
|
|
|
2017-09-01 02:29:24 +00:00
|
|
|
uint8_t interrupt_status_ = 0;
|
|
|
|
uint8_t last_posted_interrupt_status_ = 0;
|
|
|
|
Delegate *delegate_ = nullptr;
|
2016-12-03 17:18:08 +00:00
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
::Storage::Tape::Acorn::Shifter shifter_;
|
2016-12-03 17:18:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Electron_Tape_h */
|