mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 23:52:26 +00:00
Now the CRC is a factoring out.
This commit is contained in:
parent
180c3df2d4
commit
5ebca62bba
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include "../TapeParser.hpp"
|
#include "../TapeParser.hpp"
|
||||||
|
#include "../../NumberTheory/CRC.hpp"
|
||||||
|
|
||||||
using namespace StaticAnalyser::Acorn;
|
using namespace StaticAnalyser::Acorn;
|
||||||
|
|
||||||
@ -23,7 +24,9 @@ enum class SymbolType {
|
|||||||
|
|
||||||
class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, SymbolType> {
|
class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, SymbolType> {
|
||||||
public:
|
public:
|
||||||
Acorn1200BaudTapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) : TapeParser(tape) {}
|
Acorn1200BaudTapeParser(const std::shared_ptr<Storage::Tape::Tape> &tape) :
|
||||||
|
TapeParser(tape),
|
||||||
|
_crc(0x1021, 0x0000) {}
|
||||||
|
|
||||||
int get_next_bit()
|
int get_next_bit()
|
||||||
{
|
{
|
||||||
@ -49,7 +52,7 @@ class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, Symbol
|
|||||||
set_error_flag();
|
set_error_flag();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
add_to_crc((uint8_t)value);
|
_crc.add((uint8_t)value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +70,8 @@ class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, Symbol
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_crc() { _crc = 0; }
|
void reset_crc() { _crc.reset(); }
|
||||||
uint16_t get_crc() { return _crc; }
|
uint16_t get_crc() { return _crc.get_value(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void process_pulse(Storage::Tape::Tape::Pulse pulse)
|
void process_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||||
@ -111,17 +114,7 @@ class Acorn1200BaudTapeParser: public StaticAnalyer::TapeParser<WaveType, Symbol
|
|||||||
remove_waves(1);
|
remove_waves(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_to_crc(uint8_t value)
|
NumberTheory::CRC16 _crc;
|
||||||
{
|
|
||||||
_crc ^= (uint16_t)value << 8;
|
|
||||||
for(int c = 0; c < 8; c++)
|
|
||||||
{
|
|
||||||
uint16_t exclusive_or = (_crc&0x8000) ? 0x1021 : 0x0000;
|
|
||||||
_crc = (uint16_t)(_crc << 1) ^ exclusive_or;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t _crc;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::unique_ptr<File::Chunk> GetNextChunk(Acorn1200BaudTapeParser &parser)
|
static std::unique_ptr<File::Chunk> GetNextChunk(Acorn1200BaudTapeParser &parser)
|
||||||
|
Loading…
Reference in New Issue
Block a user