From a4774997249f6198d41bd5e636697f9cd493c1db Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 7 Feb 2017 22:14:45 -0500 Subject: [PATCH] Got a bit more explicit with range returned by `get_cycles_until_horizontal_blank` and hence attempted a more thorough (/correct) version of WSYNC. --- Machines/Atari2600/Atari2600.cpp | 11 ++++++----- Machines/Atari2600/TIA.cpp | 2 +- Machines/Atari2600/TIA.hpp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 7f7f70ea6..26b1a6c7d 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -54,14 +54,15 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // leap to the end of ready only once ready is signalled — because on a 6502 ready doesn't take // effect until the next read; therefore it isn't safe to assume that signalling ready immediately // skips to the end of the line. - if(operation == CPU6502::BusOperation::Ready) { + if(operation == CPU6502::BusOperation::Ready) cycles_run_for = (unsigned int)tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_); - set_ready_line(false); - } cycles_since_speaker_update_ += cycles_run_for; cycles_since_video_update_ += cycles_run_for; + if(!tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_)) + set_ready_line(false); + if(operation != CPU6502::BusOperation::Ready) { // check for a paging access @@ -134,8 +135,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x01: update_video(); tia_->set_blank(!!(*value & 0x02)); break; case 0x02: - set_ready_line(true); - // TODO: if(horizontal_timer_) + if(tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_)) + set_ready_line(true); break; case 0x03: update_video(); tia_->reset_horizontal_counter(); break; // TODO: audio will now be out of synchronisation — fix diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index e2c9efc10..d24b205f7 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -212,7 +212,7 @@ void TIA::reset_horizontal_counter() int TIA::get_cycles_until_horizontal_blank(unsigned int from_offset) { - return 4 + (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line); + return (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line) % cycles_per_line; } void TIA::set_background_colour(uint8_t colour) diff --git a/Machines/Atari2600/TIA.hpp b/Machines/Atari2600/TIA.hpp index 599585ddb..ceda0c412 100644 --- a/Machines/Atari2600/TIA.hpp +++ b/Machines/Atari2600/TIA.hpp @@ -34,6 +34,10 @@ class TIA { void set_blank(bool blank); void reset_horizontal_counter(); // Reset is delayed by four cycles. + /*! + @returns the number of cycles between (current TIA time) + from_offset to the current or + next horizontal blanking period. Returns numbers in the range [0, 227]. + */ int get_cycles_until_horizontal_blank(unsigned int from_offset); void set_background_colour(uint8_t colour);