mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Minor style improvements: some local const
s, and override
s.
This commit is contained in:
parent
d93d380c88
commit
40516c9cec
@ -24,12 +24,13 @@ int Parser::get_next_bit(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)) {
|
||||
set_error_flag();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
int c = 8;
|
||||
while(c--) {
|
||||
value = (value >> 1) | (get_next_bit(tape) << 7);
|
||||
}
|
||||
@ -74,7 +75,7 @@ Shifter::Shifter() :
|
||||
void Shifter::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
pll_.run_for(Cycles(int(float(PLLClockRate) * pulse.length.get<float>())));
|
||||
|
||||
bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
const bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(is_high != was_high_) {
|
||||
pll_.add_pulse();
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ class Parser: public Storage::Tape::Parser<SymbolType>, public Shifter::Delegate
|
||||
void reset_crc();
|
||||
uint16_t get_crc();
|
||||
|
||||
void acorn_shifter_output_bit(int value);
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
||||
|
||||
private:
|
||||
void acorn_shifter_output_bit(int value) override;
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse) override;
|
||||
|
||||
bool did_update_shifter(int new_value, int length);
|
||||
CRC::Generator<uint16_t, 0x0000, 0x0000, false, false> crc_;
|
||||
Shifter shifter_;
|
||||
|
@ -76,7 +76,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
reset_parity_byte();
|
||||
|
||||
// get header type
|
||||
uint8_t header_type = get_next_byte(tape);
|
||||
const uint8_t header_type = get_next_byte(tape);
|
||||
switch(header_type) {
|
||||
default: header->type = Header::Unknown; break;
|
||||
case 0x01: header->type = Header::RelocatableProgram; break;
|
||||
@ -92,7 +92,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
header->data.push_back(get_next_byte(tape));
|
||||
}
|
||||
|
||||
uint8_t parity_byte = get_parity_byte();
|
||||
const uint8_t parity_byte = get_parity_byte();
|
||||
header->parity_was_valid = get_next_byte(tape) == parity_byte;
|
||||
|
||||
// parse if this is not pure data
|
||||
@ -110,7 +110,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
return header;
|
||||
}
|
||||
|
||||
void Header::serialise(uint8_t *target, uint16_t length) {
|
||||
void Header::serialise(uint8_t *target, [[maybe_unused]] uint16_t length) {
|
||||
switch(type) {
|
||||
default: target[0] = 0xff; break;
|
||||
case Header::RelocatableProgram: target[0] = 0x01; break;
|
||||
@ -121,7 +121,6 @@ void Header::serialise(uint8_t *target, uint16_t length) {
|
||||
}
|
||||
|
||||
// TODO: validate length.
|
||||
(void)length;
|
||||
|
||||
std::memcpy(&target[1], data.data(), 191);
|
||||
}
|
||||
@ -178,7 +177,7 @@ void Parser::proceed_to_landing_zone(const std::shared_ptr<Storage::Tape::Tape>
|
||||
*/
|
||||
void Parser::proceed_to_symbol(const std::shared_ptr<Storage::Tape::Tape> &tape, SymbolType required_symbol) {
|
||||
while(!tape->is_at_end()) {
|
||||
SymbolType symbol = get_next_symbol(tape);
|
||||
const SymbolType symbol = get_next_symbol(tape);
|
||||
if(symbol == required_symbol) return;
|
||||
}
|
||||
}
|
||||
@ -187,7 +186,7 @@ void Parser::proceed_to_symbol(const std::shared_ptr<Storage::Tape::Tape> &tape,
|
||||
Swallows the next byte; sets the error flag if it is not equal to @c value.
|
||||
*/
|
||||
void Parser::expect_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, uint8_t value) {
|
||||
uint8_t next_byte = get_next_byte(tape);
|
||||
const uint8_t next_byte = get_next_byte(tape);
|
||||
if(next_byte != value) set_error_flag();
|
||||
}
|
||||
|
||||
@ -247,7 +246,7 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
// short: 182us => 0.000364s cycle
|
||||
// medium: 262us => 0.000524s cycle
|
||||
// long: 342us => 0.000684s cycle
|
||||
bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
const bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(!is_high && previous_was_high_) {
|
||||
if(wave_period_ >= 0.000764) push_wave(WaveType::Unrecognised);
|
||||
else if(wave_period_ >= 0.000604) push_wave(WaveType::Long);
|
||||
|
@ -126,7 +126,7 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
|
||||
indicates a high to low transition, inspects the time since the last transition, to produce
|
||||
a long, medium, short or unrecognised wave period.
|
||||
*/
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse) override;
|
||||
bool previous_was_high_ = false;
|
||||
float wave_period_ = 0.0f;
|
||||
|
||||
@ -134,7 +134,7 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
|
||||
Per the contract with Analyser::Static::TapeParser; produces any of a word marker, an end-of-block marker,
|
||||
a zero, a one or a lead-in symbol based on the currently captured waves.
|
||||
*/
|
||||
void inspect_waves(const std::vector<WaveType> &waves);
|
||||
void inspect_waves(const std::vector<WaveType> &waves) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
constexpr float maximum_medium_length = 0.000728f;
|
||||
constexpr float maximum_long_length = 0.001456f;
|
||||
|
||||
bool wave_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
const bool wave_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(!wave_was_high_ && wave_is_high != wave_was_high_) {
|
||||
if(cycle_length_ < maximum_short_length) push_wave(WaveType::Short);
|
||||
else if(cycle_length_ < maximum_medium_length) push_wave(WaveType::Medium);
|
||||
|
@ -32,8 +32,8 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
|
||||
bool sync_and_get_encoding_speed(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
||||
|
||||
private:
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
||||
void inspect_waves(const std::vector<WaveType> &waves);
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse) override;
|
||||
void inspect_waves(const std::vector<WaveType> &waves) override;
|
||||
|
||||
enum DetectionMode {
|
||||
FastData,
|
||||
|
@ -15,8 +15,8 @@ Parser::Parser() : pulse_was_high_(false), pulse_time_(0) {}
|
||||
void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
// If this is anything other than a transition from low to high, just add it to the
|
||||
// count of time.
|
||||
bool pulse_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
bool pulse_did_change = pulse_is_high != pulse_was_high_;
|
||||
const bool pulse_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
const bool pulse_did_change = pulse_is_high != pulse_was_high_;
|
||||
pulse_was_high_ = pulse_is_high;
|
||||
if(!pulse_did_change || !pulse_is_high) {
|
||||
pulse_time_ += pulse.length;
|
||||
@ -31,7 +31,7 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
void Parser::post_pulse() {
|
||||
constexpr float expected_pulse_length = 300.0f / 1000000.0f;
|
||||
constexpr float expected_gap_length = 1300.0f / 1000000.0f;
|
||||
auto pulse_time = pulse_time_.get<float>();
|
||||
const auto pulse_time = pulse_time_.get<float>();
|
||||
|
||||
if(pulse_time > expected_gap_length * 1.25f) {
|
||||
push_wave(WaveType::LongGap);
|
||||
|
@ -50,10 +50,9 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
|
||||
Time pulse_time_;
|
||||
void post_pulse();
|
||||
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse);
|
||||
void mark_end();
|
||||
|
||||
void inspect_waves(const std::vector<WaveType> &waves);
|
||||
void process_pulse(const Storage::Tape::Tape::Pulse &pulse) override;
|
||||
void mark_end() override;
|
||||
void inspect_waves(const std::vector<WaveType> &waves) override;
|
||||
|
||||
std::shared_ptr<std::vector<uint8_t>> get_next_file_data(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user