aboutsummaryrefslogtreecommitdiff
path: root/src/score.s
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-25 22:40:48 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-25 22:40:48 +0100
commit63ef73de3bdd698ab250407354e24a6de7c9ef20 (patch)
tree5caa3f3a37ea32af6f0d4e0ae42ad3fa2b455c55 /src/score.s
parentccf320971efe9b11f7b7722b2ee2642a10303203 (diff)
downloadjetpac.nes-63ef73de3bdd.tar.gz
jetpac.nes-63ef73de3bdd.zip
Update scores on screen
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/score.s')
-rw-r--r--src/score.s72
1 files changed, 71 insertions, 1 deletions
diff --git a/src/score.s b/src/score.s
index ed36283..5b5c455 100644
--- a/src/score.s
+++ b/src/score.s
@@ -118,9 +118,79 @@
BCD_JUST_CARRY
- ;; TODO: set a flag about updating the score on the HUD.
+ ;;;
+ ;; And set the 'score' flag, signaling a need of updating the score.
+
+ lda Globals::zp_extra_flags
+ ora #$80
+ sta Globals::zp_extra_flags
+
+ rts
+ .endproc
+
+ ;; Update the score for both players. This might be a bit too much on single
+ ;; player mode but we have to show both scores on the title screen
+ ;; anyways. Hence, since we have all the time in the world anyways, we
+ ;; update both and avoid branching and stuff.
+ .proc nmi_update_scores
+ ;; The 'y' register will contain the right high byte for the PPU
+ ;; address. This is needed because scores are to be displayed on both
+ ;; the title and game screens.
+ lda PPU::zp_control
+ and #$02
+ tax
+ ldy hi_ppu_address, x
+
+ ;; Now we just put the numbers. The 'x' index has to go "backwards", and
+ ;; taking into account that both players live on the same buffer. The
+ ;; tile ID is basically the integer value + $10, which is the position
+ ;; of the '0' character on our tile set.
+
+ bit PPU::m_status
+ sty PPU::m_address
+ lda #$62
+ sta PPU::m_address
+
+ clc
+ ldx #(PLAYERS_BUFF_SIZE - 2)
+ @player1_loop:
+ lda Score::m_players, x
+ adc #$10
+ sta PPU::m_data
+
+ dex
+ dex
+ cpx #$FE
+ bne @player1_loop
+
+ ;; And the same for the second player.
+
+ bit PPU::m_status
+ sty PPU::m_address
+ lda #$78
+ sta PPU::m_address
+
+ clc
+ ldx #(PLAYERS_BUFF_SIZE - 1)
+ @player2_loop:
+ lda Score::m_players, x
+ adc #$10
+ sta PPU::m_data
+
+ dex
+ dex
+ cpx #$FF
+ bne @player2_loop
+
+ ;; Disable the 'score' flag.
+ lda Globals::zp_extra_flags
+ and #$3F
+ sta Globals::zp_extra_flags
rts
+
+ hi_ppu_address:
+ .byte $20, $00, $28, $00
.endproc
.endscope