From 3b20d862f0befc74cd184cbdf346f13c9c63c05c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 9 Feb 2017 20:53:42 -0500 Subject: [PATCH] Made an initial attempt to mark sprite positions. But without hmove implemented, they're all over the place. --- Machines/Atari2600/TIA.cpp | 31 ++++++++++++++++++++++++++++++- Machines/Atari2600/TIA.hpp | 21 +++++++++++---------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index f999285db..0094a1dfc 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -304,7 +304,7 @@ void TIA::set_player_delay(int player, bool delay) void TIA::set_player_position(int player) { - player_[player].position = ((horizontal_counter_ - first_pixel_cycle) + 6)%160; + player_[player].position = 0; } void TIA::set_player_motion(int player, uint8_t motion) @@ -395,6 +395,8 @@ void TIA::output_for_cycles(int number_of_cycles) // accumulate an OR'd version of the output into the collision buffer draw_playfield(output_cursor, horizontal_counter_); + draw_player(player_[0], CollisionType::Player0, output_cursor, horizontal_counter_); + draw_player(player_[1], CollisionType::Player1, output_cursor, horizontal_counter_); // convert to television signals @@ -568,3 +570,30 @@ void TIA::draw_playfield(int start, int end) aligned_position += 4; } } + +#pragma mark - Player output + +void TIA::draw_player(Player &player, CollisionType identity, int start, int end) +{ + // don't do anything if this window ends too early + if(end < first_pixel_cycle + (horizontal_blank_extend_ ? 8 : 0)) return; + + int length = end - start; + + // check for initial trigger; player.position is guaranteed to be less than 160 so this is easy + if(player.position + length >= 160) + { + int trigger_position = 160 - player.position; + + int terminus = std::min(160, trigger_position+8); + while(trigger_position < terminus) + { + collision_buffer_[trigger_position] |= (uint8_t)identity; + trigger_position++; + } + } + + // update position counter + player.position = (player.position + end - start) % 160; + +} diff --git a/Machines/Atari2600/TIA.hpp b/Machines/Atari2600/TIA.hpp index a7c310475..db1850d58 100644 --- a/Machines/Atari2600/TIA.hpp +++ b/Machines/Atari2600/TIA.hpp @@ -75,16 +75,6 @@ class TIA { private: std::shared_ptr crt_; - // drawing methods - inline void output_for_cycles(int number_of_cycles); - inline void output_line(); - - inline void draw_playfield(int start, int end); - - int pixels_start_location_; - uint8_t *pixel_target_; - inline void output_pixels(int start, int end); - // the master counter; counts from 0 to 228 with all visible pixels being in the final 160 int horizontal_counter_; @@ -156,6 +146,17 @@ class TIA { // movement bool horizontal_blank_extend_; + + // drawing methods and state + inline void output_for_cycles(int number_of_cycles); + inline void output_line(); + + inline void draw_playfield(int start, int end); + inline void draw_player(Player &player, CollisionType identity, int start, int end); + + int pixels_start_location_; + uint8_t *pixel_target_; + inline void output_pixels(int start, int end); }; }