From 13f7aa40635a37989e47707f40ab61984b328fcb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 24 Jul 2017 21:48:34 -0400 Subject: [PATCH] The TIA is now a `ClockReceiver`. --- Machines/Atari2600/Bus.hpp | 2 +- Machines/Atari2600/TIA.cpp | 11 ++++++----- Machines/Atari2600/TIA.hpp | 8 ++++---- OSBindings/Mac/Clock SignalTests/TIATests.mm | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Machines/Atari2600/Bus.hpp b/Machines/Atari2600/Bus.hpp index 0de25f9fa..76beb3796 100644 --- a/Machines/Atari2600/Bus.hpp +++ b/Machines/Atari2600/Bus.hpp @@ -48,7 +48,7 @@ class Bus { // video backlog accumulation counter unsigned int cycles_since_video_update_; inline void update_video() { - tia_->run_for_cycles((int)cycles_since_video_update_); + tia_->run_for(Cycles((int)cycles_since_video_update_)); cycles_since_video_update_ = 0; } diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index 0e5630e9b..aedbb6bcf 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -165,13 +165,14 @@ void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) { /* speaker_->set_input_rate((float)(get_clock_rate() / 38.0));*/ } -void TIA::run_for_cycles(int number_of_cycles) -{ +void TIA::run_for(const Cycles &cycles) { + int number_of_cycles = cycles.as_int(); + // if part way through a line, definitely perform a partial, at most up to the end of the line if(horizontal_counter_) { - int cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_); - output_for_cycles(cycles); - number_of_cycles -= cycles; + int output_cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_); + output_for_cycles(output_cycles); + number_of_cycles -= output_cycles; } // output full lines for as long as possible diff --git a/Machines/Atari2600/TIA.hpp b/Machines/Atari2600/TIA.hpp index 73438c9a5..ddf6aea17 100644 --- a/Machines/Atari2600/TIA.hpp +++ b/Machines/Atari2600/TIA.hpp @@ -11,10 +11,11 @@ #include #include "../CRTMachine.hpp" +#include "../../Components/ClockReceiver.hpp" namespace Atari2600 { -class TIA { +class TIA: public ClockReceiver { public: TIA(); // The supplied hook is for unit testing only; if instantiated with a line_end_function then it will @@ -27,10 +28,9 @@ class TIA { }; /*! - Advances the TIA by @c number_of_cycles cycles. Any queued setters take effect in the - first cycle performed. + Advances the TIA by @c cycles. Any queued setters take effect in the first cycle performed. */ - void run_for_cycles(int number_of_cycles); + void run_for(const Cycles &cycles); void set_output_mode(OutputMode output_mode); void set_sync(bool sync); diff --git a/OSBindings/Mac/Clock SignalTests/TIATests.mm b/OSBindings/Mac/Clock SignalTests/TIATests.mm index 5ebaee5fe..bda993fce 100644 --- a/OSBindings/Mac/Clock SignalTests/TIATests.mm +++ b/OSBindings/Mac/Clock SignalTests/TIATests.mm @@ -47,7 +47,7 @@ static void receive_line(uint8_t *next_line) _tia->set_playfield(0, 0x10); _tia->set_playfield(1, 0xf0); _tia->set_playfield(2, 0x0e); - _tia->run_for_cycles(228); + _tia->run_for(Cycles(228)); XCTAssert(line != nullptr, @"228 cycles should have ended the line"); @@ -70,7 +70,7 @@ static void receive_line(uint8_t *next_line) _tia->set_playfield(1, 0xf0); _tia->set_playfield(2, 0x0e); - _tia->run_for_cycles(228); + _tia->run_for(Cycles(228)); XCTAssert(line != nullptr, @"228 cycles should have ended the line"); uint8_t expected_line[] = { @@ -90,7 +90,7 @@ static void receive_line(uint8_t *next_line) _tia->set_player_graphic(0, 0xff); _tia->set_player_position(0); - _tia->run_for_cycles(228); + _tia->run_for(Cycles(228)); uint8_t first_expected_line[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -103,7 +103,7 @@ static void receive_line(uint8_t *next_line) XCTAssert(!memcmp(first_expected_line, line, sizeof(first_expected_line))); line = nullptr; - _tia->run_for_cycles(228); + _tia->run_for(Cycles(228)); uint8_t second_expected_line[] = { 0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,