Move minecart ram, macros, update formatting and comments

This commit is contained in:
scawful
2024-03-28 20:10:33 -04:00
parent 53561eab31
commit 3324a13fb2

View File

@@ -38,25 +38,6 @@
; Link is in cart ; Link is in cart
!LinkInCart = $35 !LinkInCart = $35
Sprite_Minecart_Long:
{
PHB : PHK : PLB
JSR Sprite_Minecart_DrawTop ; Draws the top half behind Link
JSR Sprite_Minecart_DrawBottom ; Draw the bottom half in front of Link
JSL Sprite_CheckActive ; Check if game is not paused
BCC .SpriteIsNotActive ; Skip Main code is sprite is innactive
JSR Sprite_Minecart_Main ; Call the main sprite code
.SpriteIsNotActive
PLB ; Get back the databank we stored previously
RTL ; Go back to original code
}
; =========================================================
!MinecartSpeed = 20 !MinecartSpeed = 20
!DoubleSpeed = 30 !DoubleSpeed = 30
@@ -81,6 +62,26 @@ Sprite_Minecart_Long:
; l - lifting object ; l - lifting object
!LinkCarryOrToss = $0309 !LinkCarryOrToss = $0309
; =========================================================
Sprite_Minecart_Long:
{
PHB : PHK : PLB
JSR Sprite_Minecart_DrawTop ; Draws the top half behind Link
JSR Sprite_Minecart_DrawBottom ; Draw the bottom half in front of Link
JSL Sprite_CheckActive ; Check if game is not paused
BCC .SpriteIsNotActive ; Skip Main code is sprite is innactive
JSR Sprite_Minecart_Main ; Call the main sprite code
.SpriteIsNotActive
PLB ; Get back the databank we stored previously
RTL ; Go back to original code
}
; =========================================================
Sprite_Minecart_Prep: Sprite_Minecart_Prep:
{ {
PHB : PHK : PLB PHB : PHK : PLB
@@ -98,6 +99,7 @@ Sprite_Minecart_Prep:
.continue .continue
; Unused dummy cart code
; LDA.w !LinkInCart : AND.b #$FF : BEQ .dummy_continue ; LDA.w !LinkInCart : AND.b #$FF : BEQ .dummy_continue
; JMP .clear_cart ; JMP .clear_cart
@@ -132,7 +134,6 @@ Sprite_Minecart_Prep:
JMP .done JMP .done
.south .south
LDA #$02 : STA !MinecartDirection LDA #$02 : STA !MinecartDirection
; LDA SprX, X : CLC : ADC.b #$01 : STA SprX, X
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
JMP .done JMP .done
.west .west
@@ -172,6 +173,13 @@ macro MoveCart()
LDA #$35 : STA $012E ; Cart SFX LDA #$35 : STA $012E ; Cart SFX
endmacro endmacro
macro StopCart()
STZ $02F5
STZ.w SprYSpeed, X
STZ.w SprXSpeed, X
STZ.w !LinkInCart
endmacro
macro HandleLiftAndToss() macro HandleLiftAndToss()
LDA.w !LinkCarryOrToss : AND #$02 : BNE .not_tossing LDA.w !LinkCarryOrToss : AND #$02 : BNE .not_tossing
; Velocities for cart tossing ; Velocities for cart tossing
@@ -239,34 +247,33 @@ Sprite_Minecart_Main:
; 0x01 ; 0x01
Minecart_WaitVert: Minecart_WaitVert:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
LDA SprTimerA, X : BNE .not_ready LDA SprTimerA, X : BNE .not_ready
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
JSR CheckIfPlayerIsOn : BCC .not_ready JSR CheckIfPlayerIsOn : BCC .not_ready
JSL Player_HaltDashAttack ; Stop the player from dashing JSL Player_HaltDashAttack ; Stop the player from dashing
LDA #$02 : STA $02F5 ; Somaria platform and moving LDA #$02 : STA $02F5 ; Somaria platform and moving
LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos
LDA #$01 : STA !LinkInCart LDA #$01 : STA !LinkInCart
; Check if the cart is facing north or south
LDA SprSubtype, X : BEQ .opposite_direction
STA.w !MinecartDirection
LDA #$01 : STA $0DE0, X
%GotoAction(4) ; Minecart_MoveSouth
RTS
.opposite_direction ; Check if the cart is facing north or south
STA.w !MinecartDirection LDA SprSubtype, X : BEQ .opposite_direction
LDA #$00 : STA $0DE0, X STA.w !MinecartDirection
%GotoAction(2) ; Minecart_MoveNorth LDA #$01 : STA $0DE0, X
%GotoAction(4) ; Minecart_MoveSouth
RTS
.opposite_direction
STA.w !MinecartDirection
LDA #$00 : STA $0DE0, X
%GotoAction(2) ; Minecart_MoveNorth
.not_ready .not_ready
.lifting .lifting
%HandleLiftAndToss() %HandleLiftAndToss()
RTS RTS
} }
@@ -274,101 +281,95 @@ Sprite_Minecart_Main:
; 0x02 ; 0x02
Minecart_MoveNorth: Minecart_MoveNorth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA SprYSpeed, X LDA.b #-!MinecartSpeed : STA SprYSpeed, X
JMP .continue JMP .continue
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA SprYSpeed, X LDA.b #-!DoubleSpeed : STA SprYSpeed, X
.continue .continue
JSL Sprite_MoveVert JSL Sprite_MoveVert
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSR DragPlayer JSR DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x03 ; 0x03
Minecart_MoveEast: Minecart_MoveEast:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA $0D50, X LDA.b #!MinecartSpeed : STA $0D50, X
JMP .continue JMP .continue
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA $0D50, X LDA.b #!DoubleSpeed : STA $0D50, X
.continue .continue
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSR DragPlayer JSR DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x04 ; 0x04
Minecart_MoveSouth: Minecart_MoveSouth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA SprYSpeed, X LDA.b #!MinecartSpeed : STA SprYSpeed, X
JMP .continue JMP .continue
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA SprYSpeed, X LDA.b #!DoubleSpeed : STA SprYSpeed, X
.continue .continue
JSL Sprite_MoveVert JSL Sprite_MoveVert
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSR DragPlayer JSR DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x05 ; 0x05
Minecart_MoveWest: Minecart_MoveWest:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA $0D50, X LDA.b #-!MinecartSpeed : STA $0D50, X
JMP .continue JMP .continue
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA $0D50, X LDA.b #-!DoubleSpeed : STA $0D50, X
.continue .continue
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSR DragPlayer JSR DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
macro StopCart()
STZ $02F5
STZ.w SprYSpeed, X
STZ.w SprXSpeed, X
STZ.w !LinkInCart
endmacro
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x06 ; 0x06
@@ -390,7 +391,6 @@ SetTileLookupPosBasedOnDirection:
{ {
; Based on the direction of the Minecart, adjust the lookup position ; Based on the direction of the Minecart, adjust the lookup position
; to be in front of the sprite ; to be in front of the sprite
LDA.w !MinecartDirection : CMP.b #$00 : BEQ .north LDA.w !MinecartDirection : CMP.b #$00 : BEQ .north
CMP.b #$01 : BEQ .east CMP.b #$01 : BEQ .east
CMP.b #$02 : BEQ .south CMP.b #$02 : BEQ .south
@@ -421,7 +421,7 @@ SetTileLookupPosBasedOnDirection:
LDA.w SprY, X : STA $0FDA LDA.w SprY, X : STA $0FDA
LDA.w SprYH, X : STA $0FDB LDA.w SprYH, X : STA $0FDB
RTS RTS
} }
print "HandleTileDirections ", pc print "HandleTileDirections ", pc
@@ -531,8 +531,7 @@ HandleTileDirections:
} }
.check_direction .check_direction
LDA SprSubtype, X LDA SprSubtype, X : BNE .not_zero
BNE .not_zero
.not_zero .not_zero
ASL #2 ; Multiply by 4 (shifting left by 2 bits) to offset rows in the lookup table ASL #2 ; Multiply by 4 (shifting left by 2 bits) to offset rows in the lookup table
@@ -595,13 +594,12 @@ ClampSpritePositionToGrid:
{ {
; Check if SprX is already a multiple of 16 ; Check if SprX is already a multiple of 16
LDA.w SprX, X : AND #$0F : BEQ .x_aligned LDA.w SprX, X : AND #$0F : BEQ .x_aligned
LDA.w SprX, X : LSR : ASL : STA.w SprX, X LDA.w SprX, X : LSR : ASL : STA.w SprX, X
.x_aligned .x_aligned
; Check if SprY is already a multiple of 16 ; Check if SprY is already a multiple of 16
LDA.w SprY, X : AND #$0F : BEQ .y_aligned LDA.w SprY, X : AND #$0F : BEQ .y_aligned
LDA.w SprY, X : LSR : ASL : STA.w SprY, X LDA.w SprY, X : LSR : ASL : STA.w SprY, X
.y_aligned .y_aligned
RTS RTS
} }
@@ -651,7 +649,6 @@ HandleDynamicSwitchTileDirections:
RTS RTS
.no_b0 .no_b0
RTS RTS
} }
@@ -660,9 +657,7 @@ CheckSpritePresence:
{ {
PHX PHX
CLC ; Assume sprite ID $B0 is not present CLC ; Assume sprite ID $B0 is not present
LDX.b #$10 LDX.b #$10
.x_loop .x_loop
DEX DEX
@@ -747,6 +742,7 @@ DragPlayer:
.drag_y_high .drag_y_high
db -1, 0, 0, 0 db -1, 0, 0, 0
; Alternate drag values provided by Zarby
; .drag_x_high ; .drag_x_high
; db 0, 0, -1, 0, -1 ; db 0, 0, -1, 0, -1
; .drag_x_low ; .drag_x_low
@@ -760,85 +756,85 @@ DragPlayer:
CheckForPlayerInput: CheckForPlayerInput:
{ {
LDA $5D : CMP #$02 : BEQ .release LDA $5D : CMP #$02 : BEQ .release
CMP #$06 : BNE .continue CMP #$06 : BNE .continue
.release .release
; Release player in recoil ; Release player in recoil
%GotoAction(6) ; Minecart_Release %GotoAction(6) ; Minecart_Release
RTS RTS
.continue .continue
; Setup Minecart position to look for tile IDs ; Setup Minecart position to look for tile IDs
LDA.w SprY, X : AND #$F8 : STA.b $00 : LDA.w SprYH, X : STA.b $01 LDA.w SprY, X : AND #$F8 : STA.b $00 : LDA.w SprYH, X : STA.b $01
LDA.w SprX, X : AND #$F8 : STA.b $02 : LDA.w SprXH, X : STA.b $03 LDA.w SprX, X : AND #$F8 : STA.b $02 : LDA.w SprXH, X : STA.b $03
; Fetch tile attributes based on current coordinates ; Fetch tile attributes based on current coordinates
LDA.b #$00 : JSL Sprite_GetTileAttr LDA.b #$00 : JSL Sprite_GetTileAttr
; Load the tile index
LDA $0FA5 : CLC : CMP.b #$B6 : BNE .cant_input
; Check for input from the user (u,d,l,r)
LDY $0DE0, X ; Load the tile index
LDA $0FA5 : CLC : CMP.b #$B6 : BNE .cant_input
LDA $F0 : AND .d_pad_press, Y : STA $00 : AND.b #$08 : BEQ .not_pressing_up
LDA.b #$00 : STA $0DE0, X ; Moving Up
STA SprSubtype, X
%GotoAction(2) ; Minecart_MoveNorth
BRA .return
.not_pressing_up: ; Check for input from the user (u,d,l,r)
LDY $0DE0, X
LDA $F0 : AND .d_pad_press, Y : STA $00 : AND.b #$08 : BEQ .not_pressing_up
LDA.b #$00 : STA $0DE0, X ; Moving Up
STA SprSubtype, X
%GotoAction(2) ; Minecart_MoveNorth
BRA .return
LDA $00 : AND.b #$04 : BEQ .not_pressing_down .not_pressing_up:
LDA.b #$01 : STA $0DE0, X
LDA #$02 : STA SprSubtype, X
%GotoAction(4) ; Minecart_MoveSouth
LDA $00 : AND.b #$04 : BEQ .not_pressing_down
BRA .return
LDA.b #$01 : STA $0DE0, X
LDA #$02 : STA SprSubtype, X
%GotoAction(4) ; Minecart_MoveSouth
.not_pressing_down
BRA .return
LDA $00 : AND.b #$02 : BEQ .not_pressing_left .not_pressing_down
LDA.b #$02 : STA $0DE0, X
LDA #$03 : STA SprSubtype, X
%GotoAction(5) ; Minecart_MoveWest
LDA $00 : AND.b #$02 : BEQ .not_pressing_left
BRA .return
LDA.b #$02 : STA $0DE0, X
LDA #$03 : STA SprSubtype, X
%GotoAction(5) ; Minecart_MoveWest
.not_pressing_left
BRA .return
LDA $00 : AND.b #$01 : BEQ .always .not_pressing_left
LDA.b #$03 : STA $0DE0, X
STA SprSubtype, X
%GotoAction(3) ; Minecart_MoveEast
.always LDA $00 : AND.b #$01 : BEQ .always
LDA.b #$03 : STA $0DE0, X
STA SprSubtype, X
%GotoAction(3) ; Minecart_MoveEast
; LDA $0DE0, X : CMP.b #$03 : BNE .not_going_right .always
; ; Default heading in reaction to this tile is going up.
; ; LDA.b #$00 : STA $0DE0, X
; .not_going_right ; LDA $0DE0, X : CMP.b #$03 : BNE .not_going_right
; ; Default heading in reaction to this tile is going up.
; ; LDA.b #$00 : STA $0DE0, X
; ;STZ $0D80, X ; .not_going_right
.return ; ;STZ $0D80, X
.cant_input
RTS
.d_pad_press .return
db $0B, $07, $0E, $0D
.cant_input
RTS
.d_pad_press
db $0B, $07, $0E, $0D
} }
CheckIfPlayerIsOn: CheckIfPlayerIsOn:
@@ -1006,6 +1002,9 @@ Sprite_Minecart_DrawBottom:
PLX PLX
; Debug box which draws in the location of the hitbox from
; the code in HandleTileDirections / SetTileLookupPosBasedOnDirection
; The latter of which is an experimental function
; { ; {
; LDA $0FD8 : STA $00 ; LDA $0FD8 : STA $00
; LDA $0FDA : STA $02 ; LDA $0FDA : STA $02