Skip to content

Commit

Permalink
Ensure tape ending != infinite loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHarte committed Jan 30, 2025
1 parent 0ff6a0b commit 6cb3bba
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions Machines/Commodore/Plus4/Plus4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class SerialPort: public Serial::Port {
class ConcreteMachine:
public Activity::Source,
public BusController,
public ClockingHint::Observer,
public Configurable::Device,
public CPU::MOS6502::BusHandler,
public MachineTypes::AudioProducer,
Expand Down Expand Up @@ -223,6 +224,7 @@ class ConcreteMachine:
}

tape_player_ = std::make_unique<Storage::Tape::BinaryTapePlayer>(clock);
tape_player_->set_clocking_hint_observer(this);

joysticks_.emplace_back(std::make_unique<Joystick>());
joysticks_.emplace_back(std::make_unique<Joystick>());
Expand Down Expand Up @@ -712,12 +714,12 @@ class ConcreteMachine:
bool allow_fast_tape_hack_ = false; // TODO: implement fast-tape hack.
bool use_fast_tape_hack_ = false;
void set_use_fast_tape() {
use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_player_->motor_control() && rom_is_paged_;
use_fast_tape_hack_ =
allow_fast_tape_hack_ && tape_player_->motor_control() && rom_is_paged_ && !tape_player_->is_at_end();
}
void update_tape_motor() {
const auto output = io_output_ | ~io_direction_;
tape_player_->set_motor_control(play_button_ && (~output & 0x08));
set_use_fast_tape();
}
void advance_timers_and_tape(const Cycles length) {
timers_subcycles_ += length;
Expand Down Expand Up @@ -753,8 +755,9 @@ class ConcreteMachine:
//
// Time advancement.
//
const auto advance_cycles = [&](int cycles) {
const auto advance_cycles = [&](int cycles) -> bool {
advance_timers_and_tape(video_.cycle_length(false) * cycles);
return !use_fast_tape_hack_;
};

//
Expand Down Expand Up @@ -851,15 +854,19 @@ class ConcreteMachine:
ldimm(a, 0x10);
do {
bit(io_input());
advance_cycles(7);
if(advance_cycles(7)) {
return;
}
} while(eq());

//rwth ;it's high...now wait till it's low
// bit port
// bne rwth ; caught the edge
do {
bit(io_input());
advance_cycles(7);
if(advance_cycles(7)) {
return;
}
} while(ne());


Expand Down Expand Up @@ -899,7 +906,9 @@ class ConcreteMachine:
do {
ldimm(a, io_input());
cmp(io_input());
advance_cycles(11);
if(advance_cycles(11)) {
return;
}
} while(ne());
andimm(0x10);
} while(ne());
Expand All @@ -919,7 +928,9 @@ class ConcreteMachine:
//wata ; wait for ta to timeout
ldimm(a, 0x10);
do {
advance_cycles(13);
if(advance_cycles(13)) {
return;
}

// bit port ; kuldge, kludge, kludge !!! <<><>>
// bne rshort ; kuldge, kludge, kludge !!! <<><>>
Expand All @@ -940,7 +951,9 @@ class ConcreteMachine:
//
//casdb2
do {
advance_cycles(11);
if(advance_cycles(11)) {
return;
}

// lda port
// cmp port
Expand Down Expand Up @@ -970,7 +983,9 @@ class ConcreteMachine:
//; now do the dipole sample #2
ldimm(a, 0x40);
do {
advance_cycles(7);
if(advance_cycles(7)) {
return;
}
bit(interrupts_.status());
} while(eq());

Expand All @@ -980,7 +995,9 @@ class ConcreteMachine:
// cmp port
// bne casdb3
do {
advance_cycles(11);
if(advance_cycles(11)) {
return;
}
ldimm(a, io_input());
cmp(io_input());
} while(ne());
Expand Down Expand Up @@ -1017,7 +1034,9 @@ class ConcreteMachine:
// bit tedirq
// beq wata2 ; check z-cell is low
do {
advance_cycles(7);
if(advance_cycles(7)) {
return;
}
bit(interrupts_.status());
} while(eq());

Expand All @@ -1026,7 +1045,9 @@ class ConcreteMachine:
// cmp port
// bne casdb4
do {
advance_cycles(7);
if(advance_cycles(7)) {
return;
}
ldimm(a, io_input());
cmp(io_input());
} while(ne());
Expand Down Expand Up @@ -1063,6 +1084,11 @@ class ConcreteMachine:
}
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;

// MARK: - ClockingHint::Observer.
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference) override {
set_use_fast_tape();
}

// MARK: - Confidence.
Analyser::Dynamic::ConfidenceCounter confidence_;
float get_confidence() final { return confidence_.get_confidence(); }
Expand Down

0 comments on commit 6cb3bba

Please sign in to comment.