From 2f140cfb7ea73e631fce086327bcb3a674758b0e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 1 Apr 2025 16:23:34 +0200 Subject: player: First PAL implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The steps by which a player increases its current velocity to reach the target one has been adapted on PAL, so every five frames it takes an extra step compared to NTSC. This at least brings PAL to grow its values at the same rate as NTSC. Signed-off-by: Miquel Sabaté Solà --- src/driver.s | 32 ++++++++++++++++++++++++++++++++ src/jetpac.s | 6 ++++++ src/player.s | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- src/vectors.s | 5 +++++ 4 files changed, 91 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/driver.s b/src/driver.s index bb0303f..00e807c 100644 --- a/src/driver.s +++ b/src/driver.s @@ -9,6 +9,11 @@ zp_player_timer = $30 PLAYER_TIMER_VALUE = HZ * 2 + .ifdef PAL + ;; Frame counter which resets every 5 frames. + zp_pal_counter = $31 + .endif + ;; Switch from the title screen to the main street. Note that this function ;; is to be called with the PPU disabled. If that's not the case, then it ;; will set the proper values to disable it on the next `nmi` call and set @@ -75,4 +80,31 @@ @game: JAL Player::update .endproc + + .ifdef PAL + ;; All the code that is needed to fix some values for PAL machines. + .proc pal_handler + ;; Check if 5 frames have passed since last counter reset. + lda Driver::zp_pal_counter + cmp #4 + beq @do_handle + + ;; Nope! Reset the player's step on PAL and increase the counter. + lda #1 + sta Player::zp_step_on_pal + inc Driver::zp_pal_counter + bne @end + + @do_handle: + ;; Increase the step just for this frame and reset the counter. + lda Player::zp_step_on_pal + clc + adc #2 + sta Player::zp_step_on_pal + lda #0 + sta Driver::zp_pal_counter + @end: + rts + .endproc + .endif .endscope diff --git a/src/jetpac.s b/src/jetpac.s index 184374e..65b5d11 100644 --- a/src/jetpac.s +++ b/src/jetpac.s @@ -52,6 +52,12 @@ ;; Initialize the assets for the game. jsr Assets::init + ;; Initialize some PAL-specific constants. + .ifdef PAL + lda #0 + sta Driver::zp_pal_counter + .endif + ;; We shadow the PPU control register in memory. Depending on the `make` ;; target we might need to switch directly to the main game. Otherwise we go ;; into the title as expected. diff --git a/src/player.s b/src/player.s index 55245f6..9cb73f3 100644 --- a/src/player.s +++ b/src/player.s @@ -100,6 +100,14 @@ ;; Simple counter for the walking animation. zp_walk_counter = $51 + .ifdef PAL + ;; The increment/decrement to be applied to the velocity on a PAL + ;; system. This value is updated on `driver.s` on each frame. + ;; + ;; NOTE: only used on PAL. + zp_step_on_pal = $52 + .endif + ;; How many animations are there for walking? WALK_ANIMATION_NR = 3 @@ -113,6 +121,12 @@ lda #%01000100 sta zp_state + ;; Set the step to be applied on PAL. + .ifdef PAL + lda #1 + sta zp_step_on_pal + .endif + ;; Reset velocity and walking counter. lda #0 sta zp_target_velocity_y @@ -236,13 +250,27 @@ sbc Globals::zp_tmp0 beq @apply_velocity - ;; Increase or decrease depending on what we have now. - ;; TODO: inc/dec might not quite cut it in NTSC vs PAL + ;; Increase or decrease depending on what we have now. Note that how + ;; this is done depends on whether we are on NTSC or PAL. bmi @down - dec zp_velocity_y + .ifdef PAL + lda zp_velocity_y + sec + sbc zp_step_on_pal + sta zp_velocity_y + .else + dec zp_velocity_y + .endif jmp @apply_velocity @down: - inc zp_velocity_y + .ifdef PAL + lda zp_velocity_y + clc + adc zp_step_on_pal + sta zp_velocity_y + .else + inc zp_velocity_y + .endif jmp @apply_velocity @blast_off: @@ -334,17 +362,30 @@ ;; and we just subtract the current velocity and see if we either have ;; to accelerate or decelerate to reach that, and we do that with steps. @apply_acceleration: - ;; TODO: as with vertical motion, mind NTSC vs PAL sta Globals::zp_tmp0 lda zp_velocity_x sec sbc Globals::zp_tmp0 beq @apply_velocity bmi @accelerate_left - dec zp_velocity_x + .ifdef PAL + lda zp_velocity_x + sec + sbc zp_step_on_pal + sta zp_velocity_x + .else + dec zp_velocity_x + .endif jmp @apply_velocity @accelerate_left: - inc zp_velocity_x + .ifdef PAL + lda zp_velocity_x + clc + adc zp_step_on_pal + sta zp_velocity_x + .else + inc zp_velocity_x + .endif ;; With the final velocity already at hand, update the position with it. @apply_velocity: diff --git a/src/vectors.s b/src/vectors.s index f4c515c..f9aa31d 100644 --- a/src/vectors.s +++ b/src/vectors.s @@ -85,6 +85,11 @@ lda #$02 sta OAM::DMA + ;; PAL-specific code + .ifdef PAL + jsr Driver::pal_handler + .endif + ;; TODO: some actions here will depend on the status of the game... ;; Decrease title timer. -- cgit v1.2.3