Replace Minecart macros with fns, add Minecart_SetDirectionX fns

This commit is contained in:
scawful
2024-12-09 19:11:51 -05:00
parent e4f000b891
commit aa220eb9c4

View File

@@ -118,9 +118,9 @@ Sprite_Minecart_Prep:
LDA.b #$01 : STA.w SprMiscF, X ; Set the auto-move flag LDA.b #$01 : STA.w SprMiscF, X ; Set the auto-move flag
+ +
LDA #$04 : STA.w SprNbrOAM, X ; Nbr Oam Entries LDA.b #$04 : STA.w SprNbrOAM, X ; Nbr Oam Entries
LDA #$40 : STA.w SprGfxProps, X ; Impervious props LDA.b #$40 : STA.w SprGfxProps, X ; Impervious props
LDA #$E0 : STA.w SprHitbox, X ; Persist outside camera LDA.b #$E0 : STA.w SprHitbox, X ; Persist outside camera
STZ.w SprDefl, X ; Sprite persist in dungeon STZ.w SprDefl, X ; Sprite persist in dungeon
STZ.w SprBump, X ; No bump damage STZ.w SprBump, X ; No bump damage
STZ.w SprTileDie, X ; Set interactive hitbox STZ.w SprTileDie, X ; Set interactive hitbox
@@ -153,38 +153,6 @@ Sprite_Minecart_Prep:
RTL RTL
} }
; =========================================================
macro HandlePlayerCamera()
LDA $22 : SEC : SBC $3F : STA $31
LDA $20 : SEC : SBC $3E : STA $30
PHX
JSL Link_HandleMovingAnimation_FullLongEntry
JSL HandleIndoorCameraAndDoors
JSL Link_CancelDash
PLX
endmacro
macro InitMovement()
LDA.b $22 : STA.b $3F
LDA.b $23 : STA.b $41
LDA.b $20 : STA.b $3E
LDA.b $21 : STA.b $40
endmacro
macro MoveCart()
JSR HandleTileDirections
JSR HandleDynamicSwitchTileDirections
LDA #$35 : STA $012E ; Cart SFX
endmacro
macro StopCart()
STZ.w $02F5
STZ.w SprYSpeed, X
STZ.w SprXSpeed, X
STZ.w !LinkInCart
endmacro
; ========================================================= ; =========================================================
; Handle the tossing of the cart ; Handle the tossing of the cart
; Changes the subtype of the cart to indicate the direction ; Changes the subtype of the cart to indicate the direction
@@ -346,7 +314,7 @@ Sprite_Minecart_Main:
Minecart_MoveNorth: Minecart_MoveNorth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%InitMovement() JSR InitMovement
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA.w SprYSpeed, X LDA.b #-!MinecartSpeed : STA.w SprYSpeed, X
JMP + JMP +
@@ -359,8 +327,7 @@ Sprite_Minecart_Main:
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() JSR HandlePlayerCameraAndMoveCart
%MoveCart()
RTS RTS
} }
@@ -369,7 +336,7 @@ Sprite_Minecart_Main:
Minecart_MoveEast: Minecart_MoveEast:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%InitMovement() JSR InitMovement
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA.w SprXSpeed, X LDA.b #!MinecartSpeed : STA.w SprXSpeed, X
JMP + JMP +
@@ -382,8 +349,7 @@ Sprite_Minecart_Main:
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() JSR HandlePlayerCameraAndMoveCart
%MoveCart()
RTS RTS
} }
@@ -392,7 +358,7 @@ Sprite_Minecart_Main:
Minecart_MoveSouth: Minecart_MoveSouth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%InitMovement() JSR InitMovement
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA.w SprYSpeed, X LDA.b #!MinecartSpeed : STA.w SprYSpeed, X
JMP + JMP +
@@ -405,8 +371,7 @@ Sprite_Minecart_Main:
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() JSR HandlePlayerCameraAndMoveCart
%MoveCart()
RTS RTS
} }
@@ -415,8 +380,7 @@ Sprite_Minecart_Main:
Minecart_MoveWest: Minecart_MoveWest:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%InitMovement() JSR InitMovement
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA.w SprXSpeed, X LDA.b #-!MinecartSpeed : STA.w SprXSpeed, X
JMP + JMP +
@@ -429,17 +393,15 @@ Sprite_Minecart_Main:
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() JSR HandlePlayerCameraAndMoveCart
%MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x06 ; 0x06
Minecart_Release: Minecart_Release:
{ {
%StopCart() JSR StopCart
LDA.w SprTimerD, X : BNE .not_ready LDA.w SprTimerD, X : BNE .not_ready
LDA #$40 : STA.w SprTimerA, X LDA #$40 : STA.w SprTimerA, X
LDA.w !SpriteDirection, X : CMP.b #$00 : BEQ .vert LDA.w !SpriteDirection, X : CMP.b #$00 : BEQ .vert
@@ -457,9 +419,74 @@ Sprite_Minecart_Main:
; ========================================================= ; =========================================================
HandlePlayerCameraAndMoveCart:
{
LDA $22 : SEC : SBC $3F : STA $31
LDA $20 : SEC : SBC $3E : STA $30
PHX
JSL Link_HandleMovingAnimation_FullLongEntry
JSL HandleIndoorCameraAndDoors
JSL Link_CancelDash
PLX
JSR HandleTileDirections
JSR HandleDynamicSwitchTileDirections
LDA #$35 : STA $012E ; Cart SFX
RTS
}
StopCart:
{
STZ.w $02F5
STZ.w SprYSpeed, X
STZ.w SprXSpeed, X
STZ.w !LinkInCart
RTS
}
InitMovement:
{
LDA.b $22 : STA.b $3F
LDA.b $23 : STA.b $41
LDA.b $20 : STA.b $3E
LDA.b $21 : STA.b $40
RTS
}
Minecart_SetDirectionNorth:
{
LDA.b #North : STA.w SprSubtype, X : STZ.w !MinecartDirection
LDA.b #Up : STA !SpriteDirection, X
RTS
}
Minecart_SetDirectionEast:
{
LDA.b #East : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Right : STA !SpriteDirection, X
RTS
}
Minecart_SetDirectionSouth:
{
LDA.b #South : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Down : STA.w !SpriteDirection, X
RTS
}
Minecart_SetDirectionWest:
{
LDA.b #West : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Left : STA.w !SpriteDirection, X
RTS
}
; =========================================================
; A = $0FA5
CheckForOutOfBounds: CheckForOutOfBounds:
{ {
LDA $0FA5
CMP.b #$02 : BNE .not_out_of_bounds CMP.b #$02 : BNE .not_out_of_bounds
; If the tile is out of bounds, release the cart ; If the tile is out of bounds, release the cart
LDA #$40 : STA.w SprTimerD, X LDA #$40 : STA.w SprTimerD, X
@@ -476,38 +503,34 @@ CheckForStopTiles:
CMP.b #$B8 : BEQ .stop_south CMP.b #$B8 : BEQ .stop_south
CMP.b #$B9 : BEQ .stop_west CMP.b #$B9 : BEQ .stop_west
CMP.b #$BA : BEQ .stop_east CMP.b #$BA : BEQ .stop_east
JMP + RTS
.stop_north .stop_north
; Set the new direction to north and flip the cart's orientation JSR Minecart_SetDirectionSouth
LDA.b #South : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Down : STA !SpriteDirection, X
JMP .go_vert JMP .go_vert
.stop_south .stop_south
; Set the new direction to south and flip the cart's orientation JSR Minecart_SetDirectionNorth
LDA.b #North : STA.w SprSubtype, X : STZ.w !MinecartDirection
LDA.b #Up : STA !SpriteDirection, X
.go_vert .go_vert
%SetTimerA($40) %SetTimerA($40)
%StopCart() JSR StopCart
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
JSL Link_ResetProperties_A JSL Link_ResetProperties_A
RTS RTS
.stop_east .stop_east
; Set the new direction to east and flip the cart's orientation JSR Minecart_SetDirectionWest
LDA.b #West : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Left : STA !SpriteDirection, X
JMP .go_horiz JMP .go_horiz
.stop_west .stop_west
; Set the new direction to west and flip the cart's orientation JSR Minecart_SetDirectionEast
LDA.b #East : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA.b #Right : STA !SpriteDirection, X
.go_horiz .go_horiz
%SetTimerA($40) %SetTimerA($40)
%StopCart() JSR StopCart
%GotoAction(0) ; Minecart_WaitHoriz %GotoAction(0) ; Minecart_WaitHoriz
JSL Link_ResetProperties_A JSL Link_ResetProperties_A
+
RTS RTS
} }
@@ -537,29 +560,29 @@ CheckForCornerTiles:
JMP .done JMP .done
.move_north .move_north
LDA #$00 : STA.w SprSubtype, X : STA !MinecartDirection JSR Minecart_SetDirectionNorth
STA !SpriteDirection, X
%GotoAction(2) ; Minecart_MoveNorth %GotoAction(2) ; Minecart_MoveNorth
LDA.w SprX, X : AND #$F8 : STA.w SprX, X LDA.w SprX, X : AND #$F8 : STA.w SprX, X
JMP .done JMP .done
.move_east .move_east
LDA #$01 : STA.w SprSubtype, X : STA !MinecartDirection JSR Minecart_SetDirectionEast
STA !MinecartDirection
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
LDA.w SprY, X : AND #$F8 : STA.w SprY, X LDA.w SprY, X : AND #$F8 : STA.w SprY, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
JMP .done JMP .done
.move_south .move_south
LDA #$02 : STA.w SprSubtype, X : STA !MinecartDirection JSR Minecart_SetDirectionSouth
LDA #$01 : STA !SpriteDirection, X
%GotoAction(4) ; Minecart_MoveSouth %GotoAction(4) ; Minecart_MoveSouth
LDA.w SprX, X : AND #$F8 : STA.w SprX, X LDA.w SprX, X : AND #$F8 : STA.w SprX, X
JMP .done JMP .done
.move_west .move_west
LDA #$03 : STA.w SprSubtype, X : STA !MinecartDirection JSR Minecart_SetDirectionWest
LDA #$02 : STA !SpriteDirection, X
LDA.w SprY, X : AND #$F8 : STA.w SprY, X LDA.w SprY, X : AND #$F8 : STA.w SprY, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
.done .done
CLC CLC
RTS RTS
@@ -628,6 +651,7 @@ HandleTileDirections:
; 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
LDA.w $0FA5
JSR CheckForOutOfBounds JSR CheckForOutOfBounds
JSR CheckForStopTiles JSR CheckForStopTiles
JSR CheckForCornerTiles : BCC .done JSR CheckForCornerTiles : BCC .done
@@ -660,25 +684,21 @@ HandleDynamicSwitchTileDirections:
.east_or_west .east_or_west
LDA.w SwitchRam : BNE .go_west LDA.w SwitchRam : BNE .go_west
LDA #$01 : STA.w SprSubtype, X : STA.w !MinecartDirection JSR Minecart_SetDirectionEast
LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
RTS RTS
.go_west .go_west
LDA #$03 : STA.w SprSubtype, X : STA.w !MinecartDirection JSR Minecart_SetDirectionWest
LDA #$02 : STA !SpriteDirection, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
RTS RTS
.north_or_south .north_or_south
LDA.w SwitchRam : BNE .go_south LDA.w SwitchRam : BNE .go_south
LDA #$00 : STA.w SprSubtype, X : STA.w !MinecartDirection JSR Minecart_SetDirectionNorth
STA !SpriteDirection, X
%GotoAction(2) ; Minecart_MoveNorth %GotoAction(2) ; Minecart_MoveNorth
RTS RTS
.go_south .go_south
LDA #$02 : STA.w SprSubtype, X : STA.w !MinecartDirection JSR Minecart_SetDirectionSouth
LDA #$01 : STA !SpriteDirection, X
%GotoAction(4) ; Minecart_MoveSouth %GotoAction(4) ; Minecart_MoveSouth
RTS RTS
} }
@@ -731,33 +751,25 @@ CheckForPlayerInput:
.can_input .can_input
LDY !SpriteDirection, X LDY !SpriteDirection, X
LDA $F0 : AND .d_pad_press, Y : STA $00 : AND.b #$08 : BEQ .not_pressing_up LDA $F0 : AND .d_pad_press, Y : STA $00 : AND.b #$08 : BEQ .not_pressing_up
LDA.b #$00 : STA !SpriteDirection, X ; Moving Up JSR Minecart_SetDirectionNorth
LDA.b #North : STA !MinecartDirection
STA.w SprSubtype, X
%GotoAction(2) ; Minecart_MoveNorth %GotoAction(2) ; Minecart_MoveNorth
BRA .return BRA .return
.not_pressing_up .not_pressing_up
LDA.b $00 : AND.b #$04 : BEQ .not_pressing_down LDA.b $00 : AND.b #$04 : BEQ .not_pressing_down
LDA.b #$01 : STA !SpriteDirection, X JSR Minecart_SetDirectionSouth
LDA.b #South : STA !MinecartDirection
STA.w SprSubtype, X
%GotoAction(4) ; Minecart_MoveSouth %GotoAction(4) ; Minecart_MoveSouth
BRA .return BRA .return
.not_pressing_down .not_pressing_down
LDA.b $00 : AND.b #$02 : BEQ .not_pressing_left LDA.b $00 : AND.b #$02 : BEQ .not_pressing_left
LDA.b #$02 : STA !SpriteDirection, X JSR Minecart_SetDirectionWest
LDA.b #West : STA !MinecartDirection
STA.w SprSubtype, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
BRA .return BRA .return
.not_pressing_left .not_pressing_left
LDA.b $00 : AND.b #$01 : BEQ .return LDA.b $00 : AND.b #$01 : BEQ .return
LDA.b #$03 : STA !SpriteDirection, X JSR Minecart_SetDirectionEast
LDA.b #East : STA !MinecartDirection
STA.w SprSubtype, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
.return .return
.cant_input .cant_input