From f3737201eda72e51730a0762be98598fee08d86b Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 6 Mar 2026 16:06:56 +0100 Subject: Fix a cycling bug when shooting carelessly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When shooting like crazy and killing random enemies, after a while a cycling bug would appear which would make enemies to turn in weird directions, die unexpectedly, and other weird shenanigans. This comes back to commit 7c493ba3f338 ("Improve a bit the performance on enemy death"), which removed the saving/restoring of the value on the 'y' register. That being said, this register was actually being needed at least by Bullets::update(), so in certain situations this register might have a bad value (e.g. via the Explosions::create() call). Fixes: 7c493ba3f338 ("Improve a bit the performance on enemy death") Signed-off-by: Miquel Sabaté Solà --- src/enemies.s | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/enemies.s b/src/enemies.s index facb255..7097af5 100644 --- a/src/enemies.s +++ b/src/enemies.s @@ -613,7 +613,16 @@ .endproc ;; The enemy has been set to dust, remove it. + ;; + ;; NOTE: the 'x' register is modified, the 'y' register is _preserved_. .proc bite_the_dust + ;; This function might be called by loops which abuse index + ;; registers. Luckily that's not the case for the 'x' register, but at + ;; least the loop on Bullets::update() does heavy use of the 'y' + ;; register. Preserve it now on the stack. + tya + pha + ;; Invalidate this enemy. lda #$FF ldx Enemies::zp_pool_index @@ -634,6 +643,10 @@ ldx Enemies::zp_pool_index sta Enemies::zp_enemies_pool_base + 3, x + ;; Restore back the value for the 'y' register. + pla + tay + rts .endproc -- cgit v1.2.3