From 63ef73de3bdd698ab250407354e24a6de7c9ef20 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 25 Mar 2026 22:40:48 +0100 Subject: Update scores on screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- src/score.s | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'src/score.s') 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 -- cgit v1.2.3