2016-11-06 21:13:13 +00:00
|
|
|
//
|
|
|
|
// Acorn.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 06/11/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Storage_Tape_Parsers_Acorn_hpp
|
|
|
|
#define Storage_Tape_Parsers_Acorn_hpp
|
|
|
|
|
|
|
|
#include "TapeParser.hpp"
|
|
|
|
#include "../../../NumberTheory/CRC.hpp"
|
2017-09-23 02:39:23 +00:00
|
|
|
#include "../../Disk/DPLL/DigitalPhaseLockedLoop.hpp"
|
2016-11-06 21:13:13 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Tape {
|
|
|
|
namespace Acorn {
|
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
class Shifter: public Storage::DigitalPhaseLockedLoop::Delegate {
|
|
|
|
public:
|
|
|
|
Shifter();
|
|
|
|
|
|
|
|
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
|
|
|
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual void acorn_shifter_output_bit(int value) = 0;
|
|
|
|
};
|
|
|
|
void set_delegate(Delegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void digital_phase_locked_loop_output_bit(int value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Storage::DigitalPhaseLockedLoop pll_;
|
|
|
|
bool was_high_;
|
|
|
|
|
|
|
|
unsigned int input_pattern_;
|
|
|
|
unsigned int input_bit_counter_;
|
|
|
|
|
|
|
|
Delegate *delegate_;
|
|
|
|
};
|
|
|
|
|
2016-11-06 21:13:13 +00:00
|
|
|
enum class SymbolType {
|
|
|
|
One, Zero
|
|
|
|
};
|
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
class Parser: public Storage::Tape::Parser<SymbolType>, public Shifter::Delegate {
|
2016-11-06 21:13:13 +00:00
|
|
|
public:
|
|
|
|
Parser();
|
|
|
|
|
|
|
|
int get_next_bit(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
int get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
2017-10-18 02:34:49 +00:00
|
|
|
unsigned int get_next_short(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
unsigned int get_next_word(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
2016-11-06 21:13:13 +00:00
|
|
|
void reset_crc();
|
|
|
|
uint16_t get_crc();
|
|
|
|
|
2017-07-16 23:24:01 +00:00
|
|
|
void acorn_shifter_output_bit(int value);
|
|
|
|
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
2017-07-15 23:07:35 +00:00
|
|
|
|
2016-11-06 21:13:13 +00:00
|
|
|
private:
|
2017-07-16 23:24:01 +00:00
|
|
|
bool did_update_shifter(int new_value, int length);
|
2016-12-03 17:05:19 +00:00
|
|
|
NumberTheory::CRC16 crc_;
|
2017-07-16 23:24:01 +00:00
|
|
|
Shifter shifter_;
|
2016-11-06 21:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Acorn_hpp */
|