1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 05:29:23 +00:00

Tweaked bit timing decision.

This commit is contained in:
Thomas Harte 2017-07-13 21:26:05 -04:00
parent ae1a130843
commit 648618d280

View File

@ -14,27 +14,22 @@ Parser::Parser() :
::Storage::Tape::Parser<WaveType, SymbolType>(),
crc_(0x1021, 0x0000) {}
int Parser::get_next_bit(const std::shared_ptr<Storage::Tape::Tape> &tape)
{
int Parser::get_next_bit(const std::shared_ptr<Storage::Tape::Tape> &tape) {
SymbolType symbol = get_next_symbol(tape);
return (symbol == SymbolType::One) ? 1 : 0;
}
int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape)
{
int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape) {
int value = 0;
int c = 8;
if(get_next_bit(tape))
{
if(get_next_bit(tape)) {
set_error_flag();
return -1;
}
while(c--)
{
while(c--) {
value = (value >> 1) | (get_next_bit(tape) << 7);
}
if(!get_next_bit(tape))
{
if(!get_next_bit(tape)) {
set_error_flag();
return -1;
}
@ -42,15 +37,13 @@ int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape)
return value;
}
int Parser::get_next_short(const std::shared_ptr<Storage::Tape::Tape> &tape)
{
int Parser::get_next_short(const std::shared_ptr<Storage::Tape::Tape> &tape) {
int result = get_next_byte(tape);
result |= get_next_byte(tape) << 8;
return result;
}
int Parser::get_next_word(const std::shared_ptr<Storage::Tape::Tape> &tape)
{
int Parser::get_next_word(const std::shared_ptr<Storage::Tape::Tape> &tape) {
int result = get_next_short(tape);
result |= get_next_short(tape) << 8;
return result;
@ -59,28 +52,25 @@ int Parser::get_next_word(const std::shared_ptr<Storage::Tape::Tape> &tape)
void Parser::reset_crc() { crc_.reset(); }
uint16_t Parser::get_crc() { return crc_.get_value(); }
void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse)
{
switch(pulse.type)
{
void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse) {
switch(pulse.type) {
default: break;
case Storage::Tape::Tape::Pulse::High:
case Storage::Tape::Tape::Pulse::Low:
float pulse_length = pulse.length.get_float();
if(pulse_length >= 0.35 / 2400.0 && pulse_length < 0.7 / 2400.0) { push_wave(WaveType::Short); return; }
if(pulse_length >= 0.35 / 1200.0 && pulse_length < 0.7 / 1200.0) { push_wave(WaveType::Long); return; }
if(pulse_length >= 0.35 / 2400.0 && pulse_length < 0.7 / 1200.0) {
push_wave(pulse_length > 1.0 / 3000.0 ? WaveType::Long : WaveType::Short); return;
}
break;
}
push_wave(WaveType::Unrecognised);
}
void Parser::inspect_waves(const std::vector<WaveType> &waves)
{
void Parser::inspect_waves(const std::vector<WaveType> &waves) {
if(waves.size() < 2) return;
if(waves[0] == WaveType::Long && waves[1] == WaveType::Long)
{
if(waves[0] == WaveType::Long && waves[1] == WaveType::Long) {
push_symbol(SymbolType::Zero, 2);
return;
}
@ -90,8 +80,7 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves)
if( waves[0] == WaveType::Short &&
waves[1] == WaveType::Short &&
waves[2] == WaveType::Short &&
waves[3] == WaveType::Short)
{
waves[3] == WaveType::Short) {
push_symbol(SymbolType::One, 4);
return;
}