From 648618d2802d5f2a7f86f0efd1f6d1a61abb7b89 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 13 Jul 2017 21:26:05 -0400 Subject: [PATCH] Tweaked bit timing decision. --- Storage/Tape/Parsers/Acorn.cpp | 41 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Storage/Tape/Parsers/Acorn.cpp b/Storage/Tape/Parsers/Acorn.cpp index 35865a88f..1f7e2d8c7 100644 --- a/Storage/Tape/Parsers/Acorn.cpp +++ b/Storage/Tape/Parsers/Acorn.cpp @@ -14,27 +14,22 @@ Parser::Parser() : ::Storage::Tape::Parser(), crc_(0x1021, 0x0000) {} -int Parser::get_next_bit(const std::shared_ptr &tape) -{ +int Parser::get_next_bit(const std::shared_ptr &tape) { SymbolType symbol = get_next_symbol(tape); return (symbol == SymbolType::One) ? 1 : 0; } -int Parser::get_next_byte(const std::shared_ptr &tape) -{ +int Parser::get_next_byte(const std::shared_ptr &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 &tape) return value; } -int Parser::get_next_short(const std::shared_ptr &tape) -{ +int Parser::get_next_short(const std::shared_ptr &tape) { int result = get_next_byte(tape); result |= get_next_byte(tape) << 8; return result; } -int Parser::get_next_word(const std::shared_ptr &tape) -{ +int Parser::get_next_word(const std::shared_ptr &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 &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 &waves) -{ +void Parser::inspect_waves(const std::vector &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 &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; }