From f3c2c0ffa9abaaa737ef41a0a4720518ce75f775 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 30 Mar 2023 19:11:00 -0400 Subject: [PATCH] Synchronise fetch and draw sprite buffer usage. --- Components/9918/Implementation/9918.cpp | 9 +++++++-- Components/9918/Implementation/LineBuffer.hpp | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index dca9ac02c..54002dd45 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -131,8 +131,11 @@ void Base::posit_sprite(int sprite_number, int sprite_position, uin // Evaluation of visibility of sprite 0 is always the first step in // populating a sprite buffer; so use it to uncork a new one. if(!sprite_number) { + fetch_line_buffer_->fetched_sprites = true; + advance(fetch_sprite_buffer_); fetch_sprite_buffer_->reset_sprite_collection(); + fetch_sprite_buffer_->sprite_terminator = mode_timing_.sprite_terminator(fetch_line_buffer_->screen_mode); } if(!(status_ & StatusSpriteOverflow)) { @@ -359,7 +362,7 @@ void TMS9918::run_for(const HalfCycles cycles) { this->fetch_line_buffer_->next_border_column = Timing::CyclesPerLine; this->fetch_line_buffer_->pixel_count = 256; this->fetch_line_buffer_->screen_mode = this->screen_mode_; -// mode_timing_.sprite_terminator(buffer.screen_mode); + this->fetch_line_buffer_->fetched_sprites = false; this->mode_timing_.maximum_visible_sprites = 4; switch(this->screen_mode_) { case ScreenMode::Text: @@ -598,8 +601,10 @@ void TMS9918::run_for(const HalfCycles cycles) { // ------------- this->output_pointer_.column = end_column; if(end_column == Timing::CyclesPerLine) { + if(this->draw_line_buffer_->fetched_sprites) { + this->advance(this->draw_sprite_buffer_); + } this->advance(this->draw_line_buffer_); - this->advance(this->draw_sprite_buffer_); } } diff --git a/Components/9918/Implementation/LineBuffer.hpp b/Components/9918/Implementation/LineBuffer.hpp index 0af99d6d5..6d9c9b71b 100644 --- a/Components/9918/Implementation/LineBuffer.hpp +++ b/Components/9918/Implementation/LineBuffer.hpp @@ -22,6 +22,7 @@ struct LineBuffer { FetchMode fetch_mode = FetchMode::Text; ScreenMode screen_mode = ScreenMode::Text; VerticalState vertical_state = VerticalState::Blank; + bool fetched_sprites = false; // Holds the horizontal scroll position to apply to this line; // of those VDPs currently implemented, affects the Master System only.