From a2411d86a504adbc027a93c8bddb1ba0e0f447fd Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Sat, 28 Mar 2026 00:27:09 +0100 Subject: Fix overwrite issues when adding scores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The add_to_player() function relied on parameters to be passed on the 'Globals::zp_tmpX' variables, but that's just plain stupid. First, because these memory addresses are not meant for arguments; but most importantly, because callers actually needed some of these values before calling this function. Hence, everything went into chaos and sprites began to act wrongly in all sorts of random ways. Moreover, some of the callers also needed a guarantee on either the 'x' or the 'y' registers. Since this wasn't always feasible, we needed to store/load these registers' values case by case. All in all, now add_to_player() accepts only one argument via the 'y' register (which callers already knew it was going to be messed with). The value on 'y' has to be set via some helper constants. As a cherry on top, this not only fixes a nasty bug, but it also makes things more performant and with less code. Fixes: 63ef73de3bdd ("Update scores on screen") Signed-off-by: Miquel Sabaté Solà --- src/items.s | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/items.s') diff --git a/src/items.s b/src/items.s index 084bd1b..164d5b7 100644 --- a/src/items.s +++ b/src/items.s @@ -527,7 +527,9 @@ ;; game where the score was accounted on part/tank pickup, not ;; dropping. I find this more reliable and easier to code, and in the ;; end it's the same. + stx Globals::zp_tmp2 ADD_PART_FUEL_SCORE + ldx Globals::zp_tmp2 jmp @next @@ -946,8 +948,6 @@ ;; Collect an item as indexed by 'zp_pool_index'. This function assumes that ;; the item is already valid. - ;; - ;; NOTE: the 'y' register is preserved. .proc collect ldx Items::zp_pool_index @@ -975,7 +975,9 @@ sta Items::zp_pool_base, x ;; Account for this on the player's score. + stx Globals::zp_tmp2 ADD_ITEM_SCORE + ldx Globals::zp_tmp2 rts .endproc -- cgit v1.2.3