diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-25 22:40:48 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-25 22:40:48 +0100 |
| commit | 63ef73de3bdd698ab250407354e24a6de7c9ef20 (patch) | |
| tree | 5caa3f3a37ea32af6f0d4e0ae42ad3fa2b455c55 | |
| parent | ccf320971efe9b11f7b7722b2ee2642a10303203 (diff) | |
| download | jetpac.nes-63ef73de3bdd.tar.gz jetpac.nes-63ef73de3bdd.zip | |
Update scores on screen
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | .nasm/memory.txt | 3 | ||||
| -rw-r--r-- | .nasm/segments.txt | 2 | ||||
| -rw-r--r-- | include/globals.s | 11 | ||||
| -rw-r--r-- | src/bullets.s | 3 | ||||
| -rw-r--r-- | src/driver.s | 4 | ||||
| -rw-r--r-- | src/interrupts.s | 6 | ||||
| -rw-r--r-- | src/items.s | 11 | ||||
| -rw-r--r-- | src/jetpac.s | 8 | ||||
| -rw-r--r-- | src/score.s | 72 |
9 files changed, 114 insertions, 6 deletions
diff --git a/.nasm/memory.txt b/.nasm/memory.txt index 7a2ccaa..b7a16bc 100644 --- a/.nasm/memory.txt +++ b/.nasm/memory.txt @@ -23,6 +23,7 @@ $22: zp_buttons $24: zp_level $25: zp_level_kind $26: zp_multiplayer +$27: zp_extra_flags $2E: zp_blink_status $2F: zp_blink_timer $30: zp_title_timer @@ -83,4 +84,4 @@ $4016: m_joypad $4017: m_frame_counter --- Summary (in bytes) --- -- Internal RAM: 437/2048 (21.34%) +- Internal RAM: 438/2048 (21.39%) diff --git a/.nasm/segments.txt b/.nasm/segments.txt index 486c2fa..eb919f2 100644 --- a/.nasm/segments.txt +++ b/.nasm/segments.txt @@ -1,4 +1,4 @@ - HEADER: 16/16 (100%) -- ROM0: 8864/32762 (27.06%) +- ROM0: 9005/32762 (27.49%) - ROMV: 6/6 (100%) - ROM2: 8192/8192 (100%) diff --git a/include/globals.s b/include/globals.s index 1861e07..a958778 100644 --- a/include/globals.s +++ b/include/globals.s @@ -56,4 +56,15 @@ ;; | 1 | player's 1 state | 0: over; 1: alive | ;; | 0 | active | 0: player 1; 1: player 2 | zp_multiplayer = $26 + + ;; Extra bitmap that was needed beyond the ones that we already have. Yeah, + ;; I know, bad planning from my side, but now it's a bit complex to untangle + ;; variables like 'Globals::zp_flags'. + ;; + ;; | Bit | Short name | Meaning | + ;; |-----+------------------+----------------------------------| + ;; | 7 | score | The score has been updated. | + ;; | 6 | high | The high score has been updated. | + ;; | 5-0 | - | Unused. | + zp_extra_flags = $27 .endscope diff --git a/src/bullets.s b/src/bullets.s index 3cc74b9..802edb7 100644 --- a/src/bullets.s +++ b/src/bullets.s @@ -297,8 +297,9 @@ jsr Enemies::collides beq @next_enemy_collision - ;; Yes! Kill the enemy and break the loop. + ;; Yes! Kill the enemy, keep the score and break the loop. jsr Enemies::bite_the_dust + ADD_ENEMY_SCORE jmp @save_bullet_move @next_enemy_collision: diff --git a/src/driver.s b/src/driver.s index 8e26fbe..a9a2fbd 100644 --- a/src/driver.s +++ b/src/driver.s @@ -138,6 +138,10 @@ and #%11111011 sta Globals::zp_flags + ;; And the scores should be updated on the game screen as well. + lda #$80 + sta Globals::zp_extra_flags + rts .endproc diff --git a/src/interrupts.s b/src/interrupts.s index 9c2cb45..7026223 100644 --- a/src/interrupts.s +++ b/src/interrupts.s @@ -27,6 +27,12 @@ lda #$02 sta OAM::m_dma + ;; Should scores be updated? + bit Globals::zp_extra_flags + bpl @check_pause + jsr Score::nmi_update_scores + +@check_pause: ;; Toggle pause message from the HUD. bit Driver::zp_flags bvc @increase_rand diff --git a/src/items.s b/src/items.s index 12f551f..084bd1b 100644 --- a/src/items.s +++ b/src/items.s @@ -521,6 +521,14 @@ lsr sta Items::zp_current_tiles + 1, x + ;; Account for this on the player's score. + ;; + ;; NOTE: this is in opposition as to how it was handled in the original + ;; 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. + ADD_PART_FUEL_SCORE + jmp @next ;;; @@ -966,7 +974,8 @@ lda #$FF sta Items::zp_pool_base, x - ;; TODO: score + ;; Account for this on the player's score. + ADD_ITEM_SCORE rts .endproc diff --git a/src/jetpac.s b/src/jetpac.s index b356192..a50ba6a 100644 --- a/src/jetpac.s +++ b/src/jetpac.s @@ -107,7 +107,7 @@ bpl @vblankwait2 ;; NOTE: palettes are not initialized here as it's going to be one of the - ;; first things done on `main` code. + ;; first things done in main(). __fallthrough__ main .endproc @@ -123,6 +123,12 @@ sta Score::m_hi + 5 @init: + ;; Force the scores to appear. + lda #$80 + 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 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 |
