From 1a74e6a1856673072a61abd0861759901bc2d939 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 10 Mar 2025 22:52:15 +0100 Subject: Bring code style to better standards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Be more careful on everything and try to follow along style.nes from my repository. This might change in the future, but it's in a much better state now. Signed-off-by: Miquel Sabaté Solà --- space/src/states/player.s | 160 +++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 80 deletions(-) (limited to 'space/src/states/player.s') diff --git a/space/src/states/player.s b/space/src/states/player.s index e03f54c..59dc9c7 100644 --- a/space/src/states/player.s +++ b/space/src/states/player.s @@ -6,54 +6,54 @@ ;;; .scope Player ;; Unsigned screen coordinates on the X axis. - m_screen_x = $30 + zp_screen_x = $30 ;; Unsigned screen coordinates on the Y axis. - m_screen_y = $31 + zp_screen_y = $31 ;; The actual velocity on the X coordinates. This is a signed fixed point ;; 4.4 (high nibble: pixels; low: subpixels). - m_velocity_x = $32 + zp_velocity_x = $32 ;; The actual velocity on the Y coordinates. This is a signed fixed point ;; 4.4 (high nibble: pixels; low: subpixels). - m_velocity_y = $33 + zp_velocity_y = $33 ;; The target velocity on the X coordinates. This is a signed fixed point ;; 4.4 (high nibble: pixels; low: subpixels). - m_target_velocity_x = $34 + zp_target_velocity_x = $34 ;; The target velocity on the Y coordinates. This is a signed fixed point ;; 4.4 (high nibble: pixels; low: subpixels). - m_target_velocity_y = $35 + zp_target_velocity_y = $35 ;; Computed position on the X coordinates at the subpixel level. This is a ;; signed fixed point 12.4. NOTE: two bytes! - m_position_x = $36 + zp_position_x = $36 ;; Computed position on the X coordinates at the subpixel level. This is a ;; signed fixed point 12.4. NOTE: two bytes! - m_position_y = $38 + zp_position_y = $38 ;; Initializes the player by initializing its internal data and loading some ;; values of the sprite itself. .proc init ;; Initialize position + subpixel. lda #$B0 - sta m_position_y + sta zp_position_y lda #$00 - sta m_position_y + 1 + sta zp_position_y + 1 lda #$7A - sta m_position_x + sta zp_position_x lda #$F0 - sta m_position_x + 1 + sta zp_position_x + 1 ;; Initialize velocity. lda #0 - sta m_velocity_x - sta m_velocity_y - sta m_target_velocity_x - sta m_target_velocity_y + sta zp_velocity_x + sta zp_velocity_y + sta zp_target_velocity_x + sta zp_target_velocity_y rts .endproc @@ -90,7 +90,7 @@ and Joypad::m_buttons1 beq @target_check_left lda positive_velocity, x - sta m_target_velocity_x + sta zp_target_velocity_x jmp @target_check_up @target_check_left: ;; Similar to before: if it was not pressed, then set the target @@ -100,13 +100,13 @@ and Joypad::m_buttons1 beq @target_no_x lda negative_velocity, x - sta m_target_velocity_x + sta zp_target_velocity_x jmp @target_check_up @target_no_x: ;; None of the buttons on the X-axis were pressed. Set the target ;; velocity to 0. lda #0 - sta m_target_velocity_x + sta zp_target_velocity_x @target_check_up: ;; Same as before but we return early if it was pressed, otherwise ;; we go into the arrow-down check. @@ -114,7 +114,7 @@ and Joypad::m_buttons1 beq @target_check_down lda negative_velocity, x - sta m_target_velocity_y + sta zp_target_velocity_y rts @target_check_down: ;; If down was not pressed, go to the "no_y" case, otherwise return @@ -123,13 +123,13 @@ and Joypad::m_buttons1 beq @target_no_y lda positive_velocity, x - sta m_target_velocity_y + sta zp_target_velocity_y rts @target_no_y: ;; None of the buttons on the Y-axis were pressed. Set the target ;; velocity to 0. lda #0 - sta m_target_velocity_y + sta zp_target_velocity_y rts positive_velocity: .byte $18, $28 @@ -141,81 +141,81 @@ ;; velocity on each case. Note that the velocity is simply increased by ;; one. A more detailed code could be more nuanced than this. .proc accelerate - lda m_velocity_x + lda zp_velocity_x sec - sbc m_target_velocity_x + sbc zp_target_velocity_x bne @accelerate_x_check_greater jmp @accelerate_y @accelerate_x_check_greater: bmi @accelerate_x_check_lesser - dec m_velocity_x + dec zp_velocity_x jmp @accelerate_y @accelerate_x_check_lesser: - inc m_velocity_x + inc zp_velocity_x @accelerate_y: - lda m_velocity_y + lda zp_velocity_y sec - sbc m_target_velocity_y + sbc zp_target_velocity_y bne @accelerate_y_check_greater rts @accelerate_y_check_greater: bmi @accelerate_y_check_lesser - dec m_velocity_y + dec zp_velocity_y rts @accelerate_y_check_lesser: - inc m_velocity_y + inc zp_velocity_y rts .endproc ;; Apply the currently computed velocity to the position at subpixel ;; level. .proc apply_velocity - lda m_velocity_x + lda zp_velocity_x bmi @apply_negative_velocity_x clc - adc m_position_x - sta m_position_x + adc zp_position_x + sta zp_position_x lda #0 ;NOTE: adding possible carry! - adc m_position_x + 1 - sta m_position_x + 1 + adc zp_position_x + 1 + sta zp_position_x + 1 jmp @apply_velocity_y @apply_negative_velocity_x: lda #0 sec - sbc m_velocity_x + sbc zp_velocity_x sta $00 - lda m_position_x + lda zp_position_x sec sbc $00 - sta m_position_x - lda m_position_x + 1 + sta zp_position_x + lda zp_position_x + 1 sbc #0 - sta m_position_x + 1 + sta zp_position_x + 1 @apply_velocity_y: - lda m_velocity_y + lda zp_velocity_y bmi @apply_negative_velocity_y clc - adc m_position_y - sta m_position_y + adc zp_position_y + sta zp_position_y lda #0 - adc m_position_y + 1 - sta m_position_y + 1 + adc zp_position_y + 1 + sta zp_position_y + 1 rts @apply_negative_velocity_y: lda #0 sec - sbc m_velocity_y + sbc zp_velocity_y sta $00 - lda m_position_y + lda zp_position_y sec sbc $00 - sta m_position_y - lda m_position_y + 1 + sta zp_position_y + lda zp_position_y + 1 sbc #0 - sta m_position_y + 1 + sta zp_position_y + 1 rts .endproc @@ -229,9 +229,9 @@ ;; Translate the X position at subpixel level to actual screen coordinates. .proc position_to_coordinates_x ;; Convert the fixed point position coordinate into screen coordinates - lda m_position_x + lda zp_position_x sta $00 - lda m_position_x + 1 + lda zp_position_x + 1 sta $01 lsr $01 ror $00 @@ -243,9 +243,9 @@ ror $00 ; Assume that everything is fine and save the sprite position lda $00 - sta m_screen_x + sta zp_screen_x - lda m_velocity_x + lda zp_velocity_x bmi @position_from_negative_velocity lda $01 @@ -256,33 +256,33 @@ rts @bound_upper_x: lda #$EF - sta m_screen_x + sta zp_screen_x lda #$0E - sta m_position_x + 1 + sta zp_position_x + 1 lda #$F0 - sta m_position_x + sta zp_position_x lda #0 - sta m_velocity_x + sta zp_velocity_x rts @position_from_negative_velocity: - lda m_position_x + 1 + lda zp_position_x + 1 bmi @bound_lower_x rts @bound_lower_x: lda #0 - sta m_position_x - sta m_position_x + 1 - sta m_screen_x - sta m_velocity_x + sta zp_position_x + sta zp_position_x + 1 + sta zp_screen_x + sta zp_velocity_x rts .endproc ;; Translate the Y position at subpixel level to actual screen coordinates. .proc position_to_coordinates_y ;; Convert the fixed point position coordinate into screen coordinates - lda m_position_y + lda zp_position_y sta $00 - lda m_position_y + 1 + lda zp_position_y + 1 sta $01 lsr $01 ror $00 @@ -294,9 +294,9 @@ ror $00 ; Assume that everything is fine and save the sprite position lda $00 - sta m_screen_y + sta zp_screen_y - lda m_velocity_y + lda zp_velocity_y bmi @position_from_negative_velocity_y lda $01 @@ -307,24 +307,24 @@ rts @bound_upper_y: lda #$EF - sta m_screen_y + sta zp_screen_y lda #$0E - sta m_position_y + 1 + sta zp_position_y + 1 lda #$F0 - sta m_position_y + sta zp_position_y lda #0 - sta m_velocity_y + sta zp_velocity_y rts @position_from_negative_velocity_y: - lda m_position_y + 1 + lda zp_position_y + 1 bmi @bound_lower_y rts @bound_lower_y: lda #0 - sta m_position_y - sta m_position_y + 1 - sta m_screen_y - sta m_velocity_y + sta zp_position_y + sta zp_position_y + 1 + sta zp_screen_y + sta zp_velocity_y rts .endproc .endscope @@ -335,12 +335,12 @@ ;; internal data stored in $30-$3F. .proc update ;; Update Y position. - lda m_screen_y + lda zp_screen_y sta $200 sta $204 ;; Update X position. - lda m_screen_x + lda zp_screen_x sta $203 clc adc #8 @@ -348,9 +348,9 @@ ;; If we have a target velocity, then we will show some fire, ;; otherwise we keep the basic ship. - lda m_target_velocity_x + lda zp_target_velocity_x bne @fire - lda m_target_velocity_y + lda zp_target_velocity_y bne @fire lda #0 jmp @sprite_set -- cgit v1.2.3