aboutsummaryrefslogtreecommitdiff
path: root/src/items.s
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-18 00:52:52 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-18 00:55:35 +0100
commite50190685001d5dc48703428b101ac5c39510de8 (patch)
tree3fe6ed61905011b0459d72cbc735d34ec29af2a1 /src/items.s
parentc961e1fed5d31f5f9b7c9cf016790c9612f85978 (diff)
downloadjetpac.nes-e50190685001d5dc48703428b101ac5c39510de8.tar.gz
jetpac.nes-e50190685001d5dc48703428b101ac5c39510de8.zip
Use specific variables for cached player's tile coordinates
Before this commit we were using the zp_argX variables, but this can go wrong, and more so considering other functions like background collision checking also use these variables. All in all, since we have plenty of RAM to spare, let's just allocate a new set of bytes just for that. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/items.s')
-rw-r--r--src/items.s19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/items.s b/src/items.s
index e90ae82..447b874 100644
--- a/src/items.s
+++ b/src/items.s
@@ -17,6 +17,13 @@
zp_player_screen_x = $45 ; asan:ignore
PLAYER_WAIST = $0C
+ ;; The tile coordinates are also cached during the update()
+ ;; function. Reserve them into their own memory regions to avoid surprises
+ ;; by using the 'Globals::zp_arg0' and 'Globals::zp_arg1' variables which
+ ;; are also being used by the background check.
+ zp_player_tile_y = $43
+ zp_player_tile_x = $48
+
;; Maximum amount of items allowed on screen at the same time.
POOL_CAPACITY = 3
@@ -341,14 +348,14 @@
lsr
lsr
lsr
- sta Globals::zp_arg0
+ sta Items::zp_player_tile_y
lda zp_player_screen_x
lsr
lsr
lsr
clc
adc #1
- sta Globals::zp_arg1
+ sta Items::zp_player_tile_x
@loop:
;; This index will be valid throughout the iteration so different
@@ -735,22 +742,22 @@
;; Check for the Y tile coordinate. If it's not the same on either the
;; upper or the bottom parts of the item, then it's a no.
- cmp Globals::zp_arg0
+ cmp Items::zp_player_tile_y
beq @check_x
clc
adc #1
- cmp Globals::zp_arg0
+ cmp Items::zp_player_tile_y
bne @no
@check_x:
;; If the Y tile coordinate checks out, let's narrow it down to the X
;; coordinate.
lda Items::zp_current_tiles + 1, x
- cmp Globals::zp_arg1
+ cmp Items::zp_player_tile_x
beq @yes
clc
adc #1
- cmp Globals::zp_arg1
+ cmp Items::zp_player_tile_x
bne @no
@yes: