1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-27 17:29:38 +00:00

I think unit testing this thing is the only way forwards. Started adding appropriate hooks.

This commit is contained in:
Thomas Harte 2017-02-12 19:55:02 -05:00
parent 600bdc9af7
commit 25776de59d
2 changed files with 16 additions and 6 deletions

View File

@ -132,6 +132,11 @@ TIA::TIA() :
collision_buffer_.resize(160); collision_buffer_.resize(160);
} }
TIA::TIA(std::function<void(uint8_t *output_buffer)> line_end_function) : TIA()
{
line_end_function_ = line_end_function;
}
void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode)
{ {
// this is the NTSC phase offset function; see below for PAL // 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(!output_cursor)
{ {
if(line_end_function_) line_end_function_(collision_buffer_.data());
memset(collision_buffer_.data(), 0, 160); // sizeof(collision_buffer_) memset(collision_buffer_.data(), 0, 160); // sizeof(collision_buffer_)
horizontal_blank_extend_ = false; 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) if(position < 16 && player.copy_flags&1)
{ {
next_copy = 16; next_copy = 16;
} } else if(position < 32 && player.copy_flags&2)
else
if(position < 32 && player.copy_flags&2)
{ {
next_copy = 32; next_copy = 32;
} } else if(position < 64 && player.copy_flags&4)
else
if(position < 64 && player.copy_flags&4)
{ {
next_copy = 64; next_copy = 64;
} }

View File

@ -19,6 +19,11 @@ class TIA {
TIA(); 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<void(uint8_t *output_buffer)> line_end_function);
enum class OutputMode { enum class OutputMode {
NTSC, PAL NTSC, PAL
}; };
@ -74,6 +79,7 @@ class TIA {
private: private:
std::shared_ptr<Outputs::CRT::CRT> crt_; std::shared_ptr<Outputs::CRT::CRT> crt_;
std::function<void(uint8_t *output_buffer)> line_end_function_;
// the master counter; counts from 0 to 228 with all visible pixels being in the final 160 // the master counter; counts from 0 to 228 with all visible pixels being in the final 160
int horizontal_counter_; int horizontal_counter_;
@ -138,6 +144,8 @@ class TIA {
int pixel_position; int pixel_position;
int output_delay; int output_delay;
bool graphic_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]; } player_[2];
// missile state // missile state