mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-26 15:32:04 +00:00
Liberated the tape parser template.
This commit is contained in:
parent
463b74301d
commit
05c24222d8
@ -776,6 +776,7 @@
|
||||
4BCA98C21D065CA20062F44C /* 6522.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = 6522.hpp; sourceTree = "<group>"; };
|
||||
4BD14B0F1D74627C0088EAD6 /* AcornAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AcornAnalyser.cpp; path = ../../StaticAnalyser/Acorn/AcornAnalyser.cpp; sourceTree = "<group>"; };
|
||||
4BD14B101D74627C0088EAD6 /* AcornAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AcornAnalyser.hpp; path = ../../StaticAnalyser/Acorn/AcornAnalyser.hpp; sourceTree = "<group>"; };
|
||||
4BD328FD1D7E3EB5003B8C44 /* TapeParser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = TapeParser.hpp; path = ../../StaticAnalyser/TapeParser.hpp; sourceTree = "<group>"; };
|
||||
4BD5F1931D13528900631CD1 /* CSBestEffortUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSBestEffortUpdater.h; path = Updater/CSBestEffortUpdater.h; sourceTree = "<group>"; };
|
||||
4BD5F1941D13528900631CD1 /* CSBestEffortUpdater.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CSBestEffortUpdater.m; path = Updater/CSBestEffortUpdater.m; sourceTree = "<group>"; };
|
||||
4BEE0A6A1D72496600532C7B /* Cartridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cartridge.cpp; sourceTree = "<group>"; };
|
||||
@ -1604,6 +1605,7 @@
|
||||
4BF1354B1D6D2C300054B2EA /* StaticAnalyser.hpp */,
|
||||
4BC830D21D6E7C6D0000A26F /* Commodore */,
|
||||
4BD14B121D7462810088EAD6 /* Acorn */,
|
||||
4BD328FD1D7E3EB5003B8C44 /* TapeParser.hpp */,
|
||||
);
|
||||
name = StaticAnalyser;
|
||||
sourceTree = "<group>";
|
||||
|
@ -9,62 +9,10 @@
|
||||
#include "Tape.hpp"
|
||||
|
||||
#include <deque>
|
||||
#include "../TapeParser.hpp"
|
||||
|
||||
using namespace StaticAnalyser::Acorn;
|
||||
|
||||
/*!
|
||||
A partly-abstract base class to help in the authorship of tape format parsers;
|
||||
provides hooks for a
|
||||
*/
|
||||
template <typename WaveType, typename SymbolType> class TapeParser {
|
||||
public:
|
||||
TapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) : _tape(tape), _has_next_symbol(false) {}
|
||||
|
||||
void reset_error_flag() { _error_flag = false; }
|
||||
bool get_error_flag() { return _error_flag; }
|
||||
bool is_at_end() { return _tape->is_at_end(); }
|
||||
|
||||
protected:
|
||||
bool _error_flag;
|
||||
void push_wave(WaveType wave)
|
||||
{
|
||||
_wave_queue.push_back(wave);
|
||||
inspect_waves(_wave_queue);
|
||||
}
|
||||
|
||||
void remove_waves(int number_of_waves)
|
||||
{
|
||||
_wave_queue.erase(_wave_queue.begin(), _wave_queue.begin()+number_of_waves);
|
||||
}
|
||||
|
||||
void push_symbol(SymbolType symbol, int number_of_waves)
|
||||
{
|
||||
_has_next_symbol = true;
|
||||
_next_symbol = symbol;
|
||||
remove_waves(number_of_waves);
|
||||
}
|
||||
|
||||
SymbolType get_next_symbol()
|
||||
{
|
||||
while(!_has_next_symbol && !is_at_end())
|
||||
{
|
||||
process_pulse(_tape->get_next_pulse());
|
||||
}
|
||||
_has_next_symbol = false;
|
||||
return _next_symbol;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void process_pulse(Storage::Tape::Tape::Pulse pulse) = 0;
|
||||
virtual void inspect_waves(const std::vector<WaveType> &waves) = 0;
|
||||
|
||||
std::vector<WaveType> _wave_queue;
|
||||
SymbolType _next_symbol;
|
||||
bool _has_next_symbol;
|
||||
|
||||
std::shared_ptr<Storage::Tape::Tape> _tape;
|
||||
};
|
||||
|
||||
enum class WaveType {
|
||||
Short, Long, Unrecognised
|
||||
};
|
||||
@ -73,7 +21,7 @@ enum class SymbolType {
|
||||
One, Zero
|
||||
};
|
||||
|
||||
class Acorn1200BaudTapeParser: public TapeParser<WaveType, SymbolType> {
|
||||
class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, SymbolType> {
|
||||
public:
|
||||
Acorn1200BaudTapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) : TapeParser(tape) {}
|
||||
|
||||
|
69
StaticAnalyser/TapeParser.hpp
Normal file
69
StaticAnalyser/TapeParser.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// TapeParser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 05/09/2016.
|
||||
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef TapeParser_hpp
|
||||
#define TapeParser_hpp
|
||||
|
||||
namespace StaticAnalyer {
|
||||
|
||||
/*!
|
||||
A partly-abstract base class to help in the authorship of tape format parsers;
|
||||
provides hooks for a
|
||||
*/
|
||||
template <typename WaveType, typename SymbolType> class TapeParser {
|
||||
public:
|
||||
TapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) : _tape(tape), _has_next_symbol(false) {}
|
||||
|
||||
void reset_error_flag() { _error_flag = false; }
|
||||
bool get_error_flag() { return _error_flag; }
|
||||
bool is_at_end() { return _tape->is_at_end(); }
|
||||
|
||||
protected:
|
||||
bool _error_flag;
|
||||
void push_wave(WaveType wave)
|
||||
{
|
||||
_wave_queue.push_back(wave);
|
||||
inspect_waves(_wave_queue);
|
||||
}
|
||||
|
||||
void remove_waves(int number_of_waves)
|
||||
{
|
||||
_wave_queue.erase(_wave_queue.begin(), _wave_queue.begin()+number_of_waves);
|
||||
}
|
||||
|
||||
void push_symbol(SymbolType symbol, int number_of_waves)
|
||||
{
|
||||
_has_next_symbol = true;
|
||||
_next_symbol = symbol;
|
||||
remove_waves(number_of_waves);
|
||||
}
|
||||
|
||||
SymbolType get_next_symbol()
|
||||
{
|
||||
while(!_has_next_symbol && !is_at_end())
|
||||
{
|
||||
process_pulse(_tape->get_next_pulse());
|
||||
}
|
||||
_has_next_symbol = false;
|
||||
return _next_symbol;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void process_pulse(Storage::Tape::Tape::Pulse pulse) = 0;
|
||||
virtual void inspect_waves(const std::vector<WaveType> &waves) = 0;
|
||||
|
||||
std::vector<WaveType> _wave_queue;
|
||||
SymbolType _next_symbol;
|
||||
bool _has_next_symbol;
|
||||
|
||||
std::shared_ptr<Storage::Tape::Tape> _tape;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* TapeParser_hpp */
|
Loading…
x
Reference in New Issue
Block a user