1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-22 19:31:27 +00:00

Fixed failure to set a delegate, slowed tape speed if operating in RAM.

This commit is contained in:
Thomas Harte 2016-01-23 11:42:14 -05:00
parent 43a7d1b7ae
commit 949c33774a
2 changed files with 31 additions and 27 deletions

View File

@ -35,6 +35,7 @@ Machine::Machine() :
memset(_roms[c], 0xff, 16384); memset(_roms[c], 0xff, 16384);
_speaker.set_input_rate(125000); _speaker.set_input_rate(125000);
_tape.set_delegate(this);
} }
Machine::~Machine() Machine::~Machine()
@ -290,7 +291,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
break; break;
} }
_tape.run_for_cycle(); _tape.run_for_cycles(cycles);
return cycles; return cycles;
} }
@ -657,38 +658,41 @@ inline void Tape::clear_interrupts(uint8_t interrupts)
} }
} }
inline void Tape::run_for_cycle() inline void Tape::run_for_cycles(unsigned int number_of_cycles)
{ {
if(_is_running && _tape != nullptr) if(_is_running && _tape != nullptr)
{ {
_time_into_pulse += (unsigned int)_pulse_stepper->step(); while(number_of_cycles--)
if(_time_into_pulse == _current_pulse.length.length)
{ {
get_next_tape_pulse(); _time_into_pulse += (unsigned int)_pulse_stepper->step();
if(_time_into_pulse == _current_pulse.length.length)
_crossings[0] = _crossings[1];
_crossings[1] = _crossings[2];
_crossings[2] = _crossings[3];
_crossings[3] = Tape::Unrecognised;
if(_current_pulse.type != Storage::Tape::Pulse::Zero)
{ {
float pulse_length = (float)_current_pulse.length.length / (float)_current_pulse.length.clock_rate; get_next_tape_pulse();
if(pulse_length > 0.4 / 2400.0 && pulse_length < 0.6 / 2400.0) _crossings[3] = Tape::Short;
if(pulse_length > 0.4 / 1200.0 && pulse_length < 0.6 / 1200.0) _crossings[3] = Tape::Long;
}
if(_crossings[0] == Tape::Long && _crossings[1] == Tape::Long) _crossings[0] = _crossings[1];
{ _crossings[1] = _crossings[2];
push_tape_bit(0); _crossings[2] = _crossings[3];
_crossings[1] = Tape::Unrecognised;
} _crossings[3] = Tape::Unrecognised;
else if(_current_pulse.type != Storage::Tape::Pulse::Zero)
{
if(_crossings[0] == Tape::Short && _crossings[1] == Tape::Short && _crossings[2] == Tape::Short && _crossings[3] == Tape::Short)
{ {
push_tape_bit(1); float pulse_length = (float)_current_pulse.length.length / (float)_current_pulse.length.clock_rate;
_crossings[3] = Tape::Unrecognised; if(pulse_length > 0.4 / 2400.0 && pulse_length < 0.6 / 2400.0) _crossings[3] = Tape::Short;
if(pulse_length > 0.4 / 1200.0 && pulse_length < 0.6 / 1200.0) _crossings[3] = Tape::Long;
}
if(_crossings[0] == Tape::Long && _crossings[1] == Tape::Long)
{
push_tape_bit(0);
_crossings[1] = Tape::Unrecognised;
}
else
{
if(_crossings[0] == Tape::Short && _crossings[1] == Tape::Short && _crossings[2] == Tape::Short && _crossings[3] == Tape::Short)
{
push_tape_bit(1);
_crossings[3] = Tape::Unrecognised;
}
} }
} }
} }

View File

@ -74,7 +74,7 @@ class Tape {
}; };
inline void set_delegate(Delegate *delegate) { _delegate = delegate; } inline void set_delegate(Delegate *delegate) { _delegate = delegate; }
inline void run_for_cycle(); inline void run_for_cycles(unsigned int number_of_cycles);
void set_is_running(bool is_running) { _is_running = is_running; } void set_is_running(bool is_running) { _is_running = is_running; }