mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-08 03:54:27 +00:00
Made something of a first attempt at a parser. Which is failing terribly.
This commit is contained in:
parent
8b933182af
commit
149cbb327b
@ -89,21 +89,16 @@ class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, Symbol
|
|||||||
|
|
||||||
void inspect_waves(const std::vector<WaveType> &waves)
|
void inspect_waves(const std::vector<WaveType> &waves)
|
||||||
{
|
{
|
||||||
while(waves.size() && waves[0] == WaveType::Unrecognised)
|
if(waves.size() < 2) return;
|
||||||
{
|
|
||||||
remove_waves(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(waves.size() >= 2 && waves[0] == WaveType::Long && waves[1] == WaveType::Long)
|
if(waves[0] == WaveType::Long && waves[1] == WaveType::Long)
|
||||||
{
|
{
|
||||||
push_symbol(SymbolType::Zero, 2);
|
push_symbol(SymbolType::Zero, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(waves.size() >= 4)
|
if(waves.size() < 4) return;
|
||||||
{
|
|
||||||
// If this makes a 1, post it.
|
|
||||||
if( waves[0] == WaveType::Short &&
|
if( waves[0] == WaveType::Short &&
|
||||||
waves[1] == WaveType::Short &&
|
waves[1] == WaveType::Short &&
|
||||||
waves[2] == WaveType::Short &&
|
waves[2] == WaveType::Short &&
|
||||||
@ -113,10 +108,7 @@ class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, Symbol
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, eject at least one wave as all options are exhausted.
|
|
||||||
remove_waves(1);
|
remove_waves(1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_to_crc(uint8_t value)
|
void add_to_crc(uint8_t value)
|
||||||
|
@ -8,11 +8,107 @@
|
|||||||
|
|
||||||
#include "Tape.hpp"
|
#include "Tape.hpp"
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include "../TapeParser.hpp"
|
||||||
|
|
||||||
using namespace StaticAnalyser::Commodore;
|
using namespace StaticAnalyser::Commodore;
|
||||||
|
|
||||||
|
enum class WaveType {
|
||||||
|
Short, Medium, Long, Unrecognised
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class SymbolType {
|
||||||
|
One, Zero, Word, EndOfBlock, LeadIn
|
||||||
|
};
|
||||||
|
|
||||||
|
class CommodoreROMTapeParser: public StaticAnalyer::TapeParser<WaveType, SymbolType> {
|
||||||
|
public:
|
||||||
|
CommodoreROMTapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) :
|
||||||
|
TapeParser(tape),
|
||||||
|
_wave_period(0.0f),
|
||||||
|
_previous_was_high(false) {}
|
||||||
|
|
||||||
|
void spin()
|
||||||
|
{
|
||||||
|
while(!is_at_end())
|
||||||
|
{
|
||||||
|
SymbolType symbol = get_next_symbol();
|
||||||
|
switch(symbol)
|
||||||
|
{
|
||||||
|
case SymbolType::One: printf("1"); break;
|
||||||
|
case SymbolType::Zero: printf("0"); break;
|
||||||
|
case SymbolType::Word: printf(" "); break;
|
||||||
|
case SymbolType::EndOfBlock: printf("\n"); break;
|
||||||
|
case SymbolType::LeadIn: printf("-"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void process_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||||
|
{
|
||||||
|
bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||||
|
_wave_period += pulse.length.get_float();
|
||||||
|
|
||||||
|
if(!is_high && _previous_was_high)
|
||||||
|
{
|
||||||
|
if(_wave_period >= 0.000592 && _wave_period < 0.000752) push_wave(WaveType::Long);
|
||||||
|
else if(_wave_period >= 0.000432 && _wave_period < 0.000592) push_wave(WaveType::Medium);
|
||||||
|
else if(_wave_period >= 0.000272 && _wave_period < 0.000432) push_wave(WaveType::Short);
|
||||||
|
else push_wave(WaveType::Unrecognised);
|
||||||
|
|
||||||
|
_wave_period = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
_previous_was_high = is_high;
|
||||||
|
}
|
||||||
|
bool _previous_was_high;
|
||||||
|
float _wave_period;
|
||||||
|
|
||||||
|
void inspect_waves(const std::vector<WaveType> &waves)
|
||||||
|
{
|
||||||
|
if(waves.size() < 2) return;
|
||||||
|
|
||||||
|
if(waves[0] == WaveType::Long && waves[1] == WaveType::Medium)
|
||||||
|
{
|
||||||
|
push_symbol(SymbolType::Word, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(waves[0] == WaveType::Long && waves[1] == WaveType::Short)
|
||||||
|
{
|
||||||
|
push_symbol(SymbolType::EndOfBlock, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(waves[0] == WaveType::Short && waves[1] == WaveType::Medium)
|
||||||
|
{
|
||||||
|
push_symbol(SymbolType::Zero, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(waves[0] == WaveType::Medium && waves[1] == WaveType::Short)
|
||||||
|
{
|
||||||
|
push_symbol(SymbolType::One, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(waves[0] == WaveType::Short)
|
||||||
|
{
|
||||||
|
push_symbol(SymbolType::LeadIn, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, eject at least one wave as all options are exhausted.
|
||||||
|
remove_waves(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||||
{
|
{
|
||||||
std::list<File> file_list;
|
CommodoreROMTapeParser parser(tape);
|
||||||
|
parser.spin();
|
||||||
|
|
||||||
|
std::list<File> file_list;
|
||||||
return file_list;
|
return file_list;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user