diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-06 16:14:17 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-06 16:14:17 +0100 |
| commit | 3302f760f1461bc4582c99ee2e4ed0ccc1d5b186 (patch) | |
| tree | 8a9808677dc972c1115f6d6a75cab86a6651992a | |
| parent | 695d225256ed129ce55eb2dfde9de33d3d5f3af9 (diff) | |
| download | jetpac.nes-3302f760f1461bc4582c99ee2e4ed0ccc1d5b186.tar.gz jetpac.nes-3302f760f1461bc4582c99ee2e4ed0ccc1d5b186.zip | |
Don't toggle pause from a holded button
If you just holded the Select or Start buttons, it would be forever
toggling pause/unpause, which is an unexpected behavior.
Fix this by saving which value from the joypad was previously read. With
this, whenever the pause timer reaches zero, we can check whether either
button is still pressed, and avoid toggling if that is the case.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | .nasm/memory.txt | 1 | ||||
| -rw-r--r-- | include/joypad.s | 5 | ||||
| -rw-r--r-- | src/driver.s | 9 |
3 files changed, 13 insertions, 2 deletions
diff --git a/.nasm/memory.txt b/.nasm/memory.txt index c47526d..95b5ea9 100644 --- a/.nasm/memory.txt +++ b/.nasm/memory.txt @@ -11,6 +11,7 @@ $0A: zp_rand $10: zp_displayed $11: zp_timer $20: zp_flags +$21: zp_prev $22: zp_buttons1 $23: zp_buttons2 $24: zp_level diff --git a/include/joypad.s b/include/joypad.s index f7268e8..cc15d02 100644 --- a/include/joypad.s +++ b/include/joypad.s @@ -13,6 +13,9 @@ m_joypad1 = $4016 ;; m_joypad2 = $4017 + ;; The previous reading from the latest read controller. + zp_prev = $21 + ;; After running a `read_*` function these two variables will contain the ;; given result. zp_buttons1 = $22 @@ -68,5 +71,7 @@ ;; Shortcut for reading the joypad from the first player safely. .macro READ_JOYPAD1 ldx #$00 + lda Joypad::zp_buttons1 + sta Joypad::zp_prev jsr Joypad::read_x .endmacro diff --git a/src/driver.s b/src/driver.s index c4bd8e7..2b61e17 100644 --- a/src/driver.s +++ b/src/driver.s @@ -173,8 +173,13 @@ lda zp_pause_timer bne @skip_pause_handling - ;; The timer is zero and the player asked to pause, let's reset the - ;; timer. + ;; The timer reached zero, but is the player actually just holding the + ;; button? If so ignore it until it unholds it. + eor Joypad::zp_prev + and #(Joypad::BUTTON_START | Joypad::BUTTON_SELECT) + bne @skip_pause_handling + + ;; Let's reset the timer. lda #PAUSE_TIMER_VALUE sta zp_pause_timer |
