diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index 984500b6b..855975d8f 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -132,6 +132,11 @@ TIA::TIA() : collision_buffer_.resize(160); } +TIA::TIA(std::function line_end_function) : TIA() +{ + line_end_function_ = line_end_function; +} + void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) { // this is the NTSC phase offset function; see below for PAL @@ -402,6 +407,7 @@ void TIA::output_for_cycles(int number_of_cycles) if(!output_cursor) { + if(line_end_function_) line_end_function_(collision_buffer_.data()); memset(collision_buffer_.data(), 0, 160); // sizeof(collision_buffer_) horizontal_blank_extend_ = false; } @@ -660,14 +666,10 @@ void TIA::draw_player(Player &player, CollisionType collision_identity, const in if(position < 16 && player.copy_flags&1) { next_copy = 16; - } - else - if(position < 32 && player.copy_flags&2) + } else if(position < 32 && player.copy_flags&2) { next_copy = 32; - } - else - if(position < 64 && player.copy_flags&4) + } else if(position < 64 && player.copy_flags&4) { next_copy = 64; } diff --git a/Machines/Atari2600/TIA.hpp b/Machines/Atari2600/TIA.hpp index 495c8431e..dde5e06dd 100644 --- a/Machines/Atari2600/TIA.hpp +++ b/Machines/Atari2600/TIA.hpp @@ -19,6 +19,11 @@ class TIA { TIA(); ~TIA(); + // The supplied hook is for unit testing only; if instantiated with a line_end_function then it will + // be called with the latest collision buffer upon the conclusion of each line. What's a collision + // buffer? It's an implementation detail. If you're not writing a unit test, leave it alone. + TIA(std::function line_end_function); + enum class OutputMode { NTSC, PAL }; @@ -74,6 +79,7 @@ class TIA { private: std::shared_ptr crt_; + std::function line_end_function_; // the master counter; counts from 0 to 228 with all visible pixels being in the final 160 int horizontal_counter_; @@ -138,6 +144,8 @@ class TIA { int pixel_position; int output_delay; bool graphic_delay; + + Player() : size(0), copy_flags(0), graphic{0, 0}, reverse_mask(false), pixel_position(32), output_delay(0), graphic_delay(false) {} } player_[2]; // missile state