diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-25 23:44:29 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-27 10:48:53 +0100 |
| commit | 63939a5c86c5678347f41f877e562b58236782df (patch) | |
| tree | c8330923330524c02083f1465db9a04e24d60ac4 /src | |
| parent | 63ef73de3bdd698ab250407354e24a6de7c9ef20 (diff) | |
| download | jetpac.nes-63939a5c86c5678347f41f877e562b58236782df.tar.gz jetpac.nes-63939a5c86c5678347f41f877e562b58236782df.zip | |
Save the high score after game over
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/driver.s | 2 | ||||
| -rw-r--r-- | src/jetpac.s | 8 | ||||
| -rw-r--r-- | src/score.s | 96 |
3 files changed, 102 insertions, 4 deletions
diff --git a/src/driver.s b/src/driver.s index a9a2fbd..8915868 100644 --- a/src/driver.s +++ b/src/driver.s @@ -139,7 +139,7 @@ sta Globals::zp_flags ;; And the scores should be updated on the game screen as well. - lda #$80 + lda #$C0 sta Globals::zp_extra_flags rts diff --git a/src/jetpac.s b/src/jetpac.s index a50ba6a..7734491 100644 --- a/src/jetpac.s +++ b/src/jetpac.s @@ -124,11 +124,9 @@ @init: ;; Force the scores to appear. - lda #$80 + lda #$C0 sta Globals::zp_extra_flags - ;; TODO: update high score (see zp_extra_flags) - ;; Disable the PPU and zero out variables which shadow PPU registers. lda #0 sta PPU::m_mask @@ -264,6 +262,10 @@ pla beq @main_game_loop + ;; If we have a new high score, save it now before initializing scores + ;; again. + jsr Score::save_hi_score + ;; We will skip the initialization of the assets so to avoid writing into ;; the first nametable when it's just fine. That being said, we still need ;; to prepare palettes for the title screen. Do it now before starting over. diff --git a/src/score.s b/src/score.s index 5b5c455..b1b00a2 100644 --- a/src/score.s +++ b/src/score.s @@ -128,6 +128,79 @@ rts .endproc + ;; Save the score of either of the two players if any of them are higher + ;; than the high score we have right now. + .proc save_hi_score + ;;; + ;; Check player 1. + + ldx #(PLAYERS_BUFF_SIZE - 2) + ldy #5 + + @player1_loop: + lda Score::m_hi, y + cmp Score::m_players, x + bcc @save_player1 + dex + dex + dey + cpy #$FF + bne @player1_loop + + ;; No dice! If we are in multiplayer mode, then check player 2, + ;; otherwise just quit. + bit Globals::zp_multiplayer + bpl @end + + ;;; + ;; Check player 2. + + ldx #(PLAYERS_BUFF_SIZE - 1) + ldy #5 + + @player2_loop: + lda Score::m_hi, y + cmp Score::m_players, x + bcc @save_player2 + dex + dex + dey + cpy #$FF + bne @player2_loop + + ;; Not player 2 either. Just quit. + rts + + ;;; + ;; One of the players actually achieved a high score. Let's save it. + + @save_player1: + ldx #0 + beq @save + @save_player2: + ldx #1 + + @save: + ldy #0 + @save_loop: + lda Score::m_players, x + sta Score::m_hi, y + + inx + inx + iny + cpy #6 + bne @save_loop + + ;; And set the 'high' bit so this change is reflected on screen. + lda Globals::zp_extra_flags + ora #$40 + sta Globals::zp_extra_flags + + @end: + 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 @@ -182,6 +255,29 @@ cpx #$FF bne @player2_loop + ;; Then do the high score if requested. + + lda Globals::zp_extra_flags + and #$40 + beq @unset + + bit PPU::m_status + sty PPU::m_address + lda #$6D + sta PPU::m_address + + clc + ldx #5 + @hi_loop: + lda Score::m_hi, x + adc #$10 + sta PPU::m_data + + dex + cpx #$FF + bne @hi_loop + + @unset: ;; Disable the 'score' flag. lda Globals::zp_extra_flags and #$3F |
