mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-23 20:29:42 +00:00
'Tape' has joined the new underscore orthodoxy.
This commit is contained in:
parent
0dc2aa6454
commit
3f7f2c6117
@ -12,7 +12,7 @@ using namespace Storage::Tape::Acorn;
|
||||
|
||||
Parser::Parser() :
|
||||
::Storage::Tape::Parser<WaveType, SymbolType>(),
|
||||
_crc(0x1021, 0x0000) {}
|
||||
crc_(0x1021, 0x0000) {}
|
||||
|
||||
int Parser::get_next_bit(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||
{
|
||||
@ -38,7 +38,7 @@ int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||
set_error_flag();
|
||||
return -1;
|
||||
}
|
||||
_crc.add((uint8_t)value);
|
||||
crc_.add((uint8_t)value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -56,8 +56,8 @@ int Parser::get_next_word(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||
return result;
|
||||
}
|
||||
|
||||
void Parser::reset_crc() { _crc.reset(); }
|
||||
uint16_t Parser::get_crc() { return _crc.get_value(); }
|
||||
void Parser::reset_crc() { crc_.reset(); }
|
||||
uint16_t Parser::get_crc() { return crc_.get_value(); }
|
||||
|
||||
void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ class Parser: public Storage::Tape::Parser<WaveType, SymbolType> {
|
||||
private:
|
||||
void process_pulse(Storage::Tape::Tape::Pulse pulse);
|
||||
void inspect_waves(const std::vector<WaveType> &waves);
|
||||
NumberTheory::CRC16 _crc;
|
||||
NumberTheory::CRC16 crc_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ using namespace Storage::Tape::Commodore;
|
||||
|
||||
Parser::Parser() :
|
||||
Storage::Tape::Parser<WaveType, SymbolType>(),
|
||||
_wave_period(0.0f),
|
||||
_previous_was_high(false),
|
||||
_parity_byte(0) {}
|
||||
wave_period_(0.0f),
|
||||
previous_was_high_(false),
|
||||
parity_byte_(0) {}
|
||||
|
||||
/*!
|
||||
Advances to the next block on the tape, treating it as a header, then consumes, parses, and returns it.
|
||||
@ -193,9 +193,9 @@ void Parser::expect_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, uint8
|
||||
if(next_byte != value) set_error_flag();
|
||||
}
|
||||
|
||||
void Parser::reset_parity_byte() { _parity_byte = 0; }
|
||||
uint8_t Parser::get_parity_byte() { return _parity_byte; }
|
||||
void Parser::add_parity_byte(uint8_t byte) { _parity_byte ^= byte; }
|
||||
void Parser::reset_parity_byte() { parity_byte_ = 0; }
|
||||
uint8_t Parser::get_parity_byte() { return parity_byte_; }
|
||||
void Parser::add_parity_byte(uint8_t byte) { parity_byte_ ^= byte; }
|
||||
|
||||
/*!
|
||||
Proceeds to the next word marker then returns the result of @c get_next_byte_contents.
|
||||
@ -255,19 +255,19 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||
// medium: 262µs => 0.000524s cycle
|
||||
// long: 342µs => 0.000684s cycle
|
||||
bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(!is_high && _previous_was_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);
|
||||
else if(_wave_period >= 0.000444) push_wave(WaveType::Medium);
|
||||
else if(_wave_period >= 0.000284) push_wave(WaveType::Short);
|
||||
if(wave_period_ >= 0.000764) push_wave(WaveType::Unrecognised);
|
||||
else if(wave_period_ >= 0.000604) push_wave(WaveType::Long);
|
||||
else if(wave_period_ >= 0.000444) push_wave(WaveType::Medium);
|
||||
else if(wave_period_ >= 0.000284) push_wave(WaveType::Short);
|
||||
else push_wave(WaveType::Unrecognised);
|
||||
|
||||
_wave_period = 0.0f;
|
||||
wave_period_ = 0.0f;
|
||||
}
|
||||
|
||||
_wave_period += pulse.length.get_float();
|
||||
_previous_was_high = is_high;
|
||||
wave_period_ += pulse.length.get_float();
|
||||
previous_was_high_ = is_high;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -94,7 +94,7 @@ class Parser: public Storage::Tape::Parser<WaveType, SymbolType> {
|
||||
*/
|
||||
void expect_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, uint8_t value);
|
||||
|
||||
uint8_t _parity_byte;
|
||||
uint8_t parity_byte_;
|
||||
void reset_parity_byte();
|
||||
uint8_t get_parity_byte();
|
||||
void add_parity_byte(uint8_t byte);
|
||||
@ -122,8 +122,8 @@ class Parser: public Storage::Tape::Parser<WaveType, SymbolType> {
|
||||
a long, medium, short or unrecognised wave period.
|
||||
*/
|
||||
void process_pulse(Storage::Tape::Tape::Pulse pulse);
|
||||
bool _previous_was_high;
|
||||
float _wave_period;
|
||||
bool previous_was_high_;
|
||||
float wave_period_;
|
||||
|
||||
/*!
|
||||
Per the contract with StaticAnalyser::TapeParser; produces any of a word marker, an end-of-block marker,
|
||||
|
@ -12,8 +12,8 @@ using namespace Storage::Tape::Oric;
|
||||
|
||||
int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, bool use_fast_encoding)
|
||||
{
|
||||
_detection_mode = use_fast_encoding ? FastZero : SlowZero;
|
||||
_cycle_length = 0.0f;
|
||||
detection_mode_ = use_fast_encoding ? FastZero : SlowZero;
|
||||
cycle_length_ = 0.0f;
|
||||
|
||||
int result = 0;
|
||||
int bit_count = 0;
|
||||
@ -21,7 +21,7 @@ int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, bool
|
||||
{
|
||||
SymbolType symbol = get_next_symbol(tape);
|
||||
if(!bit_count && symbol != SymbolType::Zero) continue;
|
||||
_detection_mode = use_fast_encoding ? FastData : SlowData;
|
||||
detection_mode_ = use_fast_encoding ? FastData : SlowData;
|
||||
result |= ((symbol == SymbolType::One) ? 1 : 0) << bit_count;
|
||||
bit_count++;
|
||||
}
|
||||
@ -31,7 +31,7 @@ int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, bool
|
||||
|
||||
bool Parser::sync_and_get_encoding_speed(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||
{
|
||||
_detection_mode = Sync;
|
||||
detection_mode_ = Sync;
|
||||
while(!tape->is_at_end())
|
||||
{
|
||||
SymbolType symbol = get_next_symbol(tape);
|
||||
@ -52,22 +52,22 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||
const float maximum_long_length = 0.001456f;
|
||||
|
||||
bool wave_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(!_wave_was_high && wave_is_high != _wave_was_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);
|
||||
else if(_cycle_length < maximum_long_length) push_wave(WaveType::Long);
|
||||
if(cycle_length_ < maximum_short_length) push_wave(WaveType::Short);
|
||||
else if(cycle_length_ < maximum_medium_length) push_wave(WaveType::Medium);
|
||||
else if(cycle_length_ < maximum_long_length) push_wave(WaveType::Long);
|
||||
else push_wave(WaveType::Unrecognised);
|
||||
|
||||
_cycle_length = 0.0f;
|
||||
cycle_length_ = 0.0f;
|
||||
}
|
||||
_wave_was_high = wave_is_high;
|
||||
_cycle_length += pulse.length.get_float();
|
||||
wave_was_high_ = wave_is_high;
|
||||
cycle_length_ += pulse.length.get_float();
|
||||
}
|
||||
|
||||
void Parser::inspect_waves(const std::vector<WaveType> &waves)
|
||||
{
|
||||
switch(_detection_mode)
|
||||
switch(detection_mode_)
|
||||
{
|
||||
case FastZero:
|
||||
if(waves.empty()) return;
|
||||
|
@ -41,9 +41,9 @@ class Parser: public Storage::Tape::Parser<WaveType, SymbolType> {
|
||||
FastZero,
|
||||
SlowZero,
|
||||
Sync
|
||||
} _detection_mode;
|
||||
bool _wave_was_high;
|
||||
float _cycle_length;
|
||||
} detection_mode_;
|
||||
bool wave_was_high_;
|
||||
float cycle_length_;
|
||||
|
||||
struct Pattern
|
||||
{
|
||||
|
@ -21,23 +21,23 @@ TapePlayer::TapePlayer(unsigned int input_clock_rate) :
|
||||
|
||||
void Storage::Tape::Tape::seek(Time &seek_time)
|
||||
{
|
||||
_current_time.set_zero();
|
||||
_next_time.set_zero();
|
||||
while(_next_time < seek_time) get_next_pulse();
|
||||
current_time_.set_zero();
|
||||
next_time_.set_zero();
|
||||
while(next_time_ < seek_time) get_next_pulse();
|
||||
}
|
||||
|
||||
void Storage::Tape::Tape::reset()
|
||||
{
|
||||
_current_time.set_zero();
|
||||
_next_time.set_zero();
|
||||
current_time_.set_zero();
|
||||
next_time_.set_zero();
|
||||
virtual_reset();
|
||||
}
|
||||
|
||||
Tape::Pulse Tape::get_next_pulse()
|
||||
{
|
||||
Tape::Pulse pulse = virtual_get_next_pulse();
|
||||
_current_time = _next_time;
|
||||
_next_time += pulse.length;
|
||||
current_time_ = next_time_;
|
||||
next_time_ += pulse.length;
|
||||
return pulse;
|
||||
}
|
||||
|
||||
@ -45,34 +45,34 @@ Tape::Pulse Tape::get_next_pulse()
|
||||
|
||||
void TapePlayer::set_tape(std::shared_ptr<Storage::Tape::Tape> tape)
|
||||
{
|
||||
_tape = tape;
|
||||
tape_ = tape;
|
||||
reset_timer();
|
||||
get_next_pulse();
|
||||
}
|
||||
|
||||
std::shared_ptr<Storage::Tape::Tape> TapePlayer::get_tape()
|
||||
{
|
||||
return _tape;
|
||||
return tape_;
|
||||
}
|
||||
|
||||
bool TapePlayer::has_tape()
|
||||
{
|
||||
return (bool)_tape;
|
||||
return (bool)tape_;
|
||||
}
|
||||
|
||||
void TapePlayer::get_next_pulse()
|
||||
{
|
||||
// get the new pulse
|
||||
if(_tape)
|
||||
_current_pulse = _tape->get_next_pulse();
|
||||
if(tape_)
|
||||
current_pulse_ = tape_->get_next_pulse();
|
||||
else
|
||||
{
|
||||
_current_pulse.length.length = 1;
|
||||
_current_pulse.length.clock_rate = 1;
|
||||
_current_pulse.type = Tape::Pulse::Zero;
|
||||
current_pulse_.length.length = 1;
|
||||
current_pulse_.length.clock_rate = 1;
|
||||
current_pulse_.type = Tape::Pulse::Zero;
|
||||
}
|
||||
|
||||
set_next_event_time_interval(_current_pulse.length);
|
||||
set_next_event_time_interval(current_pulse_.length);
|
||||
}
|
||||
|
||||
void TapePlayer::run_for_cycles(int number_of_cycles)
|
||||
@ -90,19 +90,19 @@ void TapePlayer::run_for_input_pulse()
|
||||
|
||||
void TapePlayer::process_next_event()
|
||||
{
|
||||
process_input_pulse(_current_pulse);
|
||||
process_input_pulse(current_pulse_);
|
||||
get_next_pulse();
|
||||
}
|
||||
|
||||
#pragma mark - Binary Player
|
||||
|
||||
BinaryTapePlayer::BinaryTapePlayer(unsigned int input_clock_rate) :
|
||||
TapePlayer(input_clock_rate), _motor_is_running(false)
|
||||
TapePlayer(input_clock_rate), motor_is_running_(false)
|
||||
{}
|
||||
|
||||
void BinaryTapePlayer::set_motor_control(bool enabled)
|
||||
{
|
||||
_motor_is_running = enabled;
|
||||
motor_is_running_ = enabled;
|
||||
}
|
||||
|
||||
void BinaryTapePlayer::set_tape_output(bool set)
|
||||
@ -112,26 +112,26 @@ void BinaryTapePlayer::set_tape_output(bool set)
|
||||
|
||||
bool BinaryTapePlayer::get_input()
|
||||
{
|
||||
return _input_level;
|
||||
return input_level_;
|
||||
}
|
||||
|
||||
void BinaryTapePlayer::run_for_cycles(int number_of_cycles)
|
||||
{
|
||||
if(_motor_is_running) TapePlayer::run_for_cycles(number_of_cycles);
|
||||
if(motor_is_running_) TapePlayer::run_for_cycles(number_of_cycles);
|
||||
}
|
||||
|
||||
void BinaryTapePlayer::set_delegate(Delegate *delegate)
|
||||
{
|
||||
_delegate = delegate;
|
||||
delegate_ = delegate;
|
||||
}
|
||||
|
||||
void BinaryTapePlayer::process_input_pulse(Storage::Tape::Tape::Pulse pulse)
|
||||
{
|
||||
bool new_input_level = pulse.type == Tape::Pulse::Low;
|
||||
if(_input_level != new_input_level)
|
||||
if(input_level_ != new_input_level)
|
||||
{
|
||||
_input_level = new_input_level;
|
||||
if(_delegate) _delegate->tape_did_change_input(this);
|
||||
input_level_ = new_input_level;
|
||||
if(delegate_) delegate_->tape_did_change_input(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,13 +53,13 @@ class Tape {
|
||||
virtual bool is_at_end() = 0;
|
||||
|
||||
/// @returns the amount of time preceeding the most recently-returned pulse.
|
||||
virtual Time get_current_time() { return _current_time; }
|
||||
virtual Time get_current_time() { return current_time_; }
|
||||
|
||||
/// Advances or reverses the tape to the last time before or at @c time from which a pulse starts.
|
||||
virtual void seek(Time &time);
|
||||
|
||||
private:
|
||||
Time _current_time, _next_time;
|
||||
Time current_time_, next_time_;
|
||||
|
||||
virtual Pulse virtual_get_next_pulse() = 0;
|
||||
virtual void virtual_reset() = 0;
|
||||
@ -90,8 +90,8 @@ class TapePlayer: public TimedEventLoop {
|
||||
private:
|
||||
inline void get_next_pulse();
|
||||
|
||||
std::shared_ptr<Storage::Tape::Tape> _tape;
|
||||
Tape::Pulse _current_pulse;
|
||||
std::shared_ptr<Storage::Tape::Tape> tape_;
|
||||
Tape::Pulse current_pulse_;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -118,10 +118,10 @@ class BinaryTapePlayer: public TapePlayer {
|
||||
void set_delegate(Delegate *delegate);
|
||||
|
||||
protected:
|
||||
Delegate *_delegate;
|
||||
Delegate *delegate_;
|
||||
virtual void process_input_pulse(Storage::Tape::Tape::Pulse pulse);
|
||||
bool _input_level;
|
||||
bool _motor_is_running;
|
||||
bool input_level_;
|
||||
bool motor_is_running_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user