Add comments and update formatting

This commit is contained in:
scawful
2024-03-30 09:43:58 -04:00
parent e0a20a98cd
commit 58dd5aab1f

View File

@@ -92,17 +92,15 @@ Sprite_Minecart_Prep:
; If link is in a cart, then draw the dummy cart ; If link is in a cart, then draw the dummy cart
LDA !LinkInCart : BNE .dummy_continue LDA !LinkInCart : BNE .dummy_continue
.clear_cart ; .clear_cart
STZ.w $0DD0, X ; Otherwise, clear the sprite STZ.w $0DD0, X ; Otherwise, clear the sprite
PLB PLB
RTL RTL
.continue .continue
; Unused dummy cart code ; 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
.dummy_continue .dummy_continue
LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X
@@ -141,7 +139,6 @@ Sprite_Minecart_Prep:
%GotoAction(0) ; Minecart_WaitHoriz %GotoAction(0) ; Minecart_WaitHoriz
.done .done
PLB PLB
RTL RTL
} }
@@ -238,7 +235,6 @@ Sprite_Minecart_Main:
.lifting .lifting
%HandleLiftAndToss() %HandleLiftAndToss()
RTS RTS
} }
@@ -255,8 +251,7 @@ Sprite_Minecart_Main:
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 ; Set Link in cart flag
LDA #$01 : STA !LinkInCart
; Check if the cart is facing north or south ; Check if the cart is facing north or south
LDA SprSubtype, X : BEQ .opposite_direction LDA SprSubtype, X : BEQ .opposite_direction
@@ -384,12 +379,19 @@ Sprite_Minecart_Main:
} }
} }
; =========================================================================== ; =========================================================
; The purpose of this routine is to determine the direction
; the sprite is facing and then adjust the X and Y positions
; of the tile interaction lookup based on that direction.
; If implemented correctly this would make sure the sprite
; stays centered on the tracks when it makes corner turns.
; Currently, depending on where the tile is placed the
; cart may make a turn too early and appear to be off center.
SetTileLookupPosBasedOnDirection: SetTileLookupPosBasedOnDirection:
{ {
; Based on the direction of the Minecart, adjust the lookup position ; Based on the direction of the Minecart, adjust the
; to be in front of the sprite ; lookup position 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
@@ -423,6 +425,8 @@ SetTileLookupPosBasedOnDirection:
RTS RTS
} }
; =========================================================
print "HandleTileDirections ", pc print "HandleTileDirections ", pc
HandleTileDirections: HandleTileDirections:
{ {
@@ -587,8 +591,10 @@ HandleTileDirections:
; db $BE ; + any direction ; db $BE ; + any direction
} }
; =========================================================
; Clamp the sprite position to a 16x16 grid ; Clamp the sprite position to a 16x16 grid
; Slows the game down if you run it too often :( ; Slows the game down if you run it too often :(
ClampSpritePositionToGrid: ClampSpritePositionToGrid:
{ {
; Check if SprX is already a multiple of 16 ; Check if SprX is already a multiple of 16
@@ -602,6 +608,10 @@ ClampSpritePositionToGrid:
RTS RTS
} }
; =========================================================
; Check for the switch_track sprite and move based on the
; state of that sprite.
HandleDynamicSwitchTileDirections: HandleDynamicSwitchTileDirections:
{ {
; Find out if the sprite $B0 is in the room ; Find out if the sprite $B0 is in the room
@@ -620,9 +630,7 @@ HandleDynamicSwitchTileDirections:
CMP.b #$02 : BEQ .north_or_south CMP.b #$02 : BEQ .north_or_south
.east_or_west .east_or_west
LDA SwitchRam : BNE .go_west LDA SwitchRam : BNE .go_west
LDA #$01 : STA SprSubtype, X LDA #$01 : STA SprSubtype, X
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
@@ -651,7 +659,9 @@ HandleDynamicSwitchTileDirections:
RTS RTS
} }
; =========================================================
; $00 = flag indicating presence of sprite ID $B0 ; $00 = flag indicating presence of sprite ID $B0
CheckSpritePresence: CheckSpritePresence:
{ {
PHX PHX
@@ -752,6 +762,7 @@ DragPlayer:
; db -1, 0, 0, 0, -1, 0, -1, 0 ; db -1, 0, 0, 0, -1, 0, -1, 0
} }
; =========================================================
CheckForPlayerInput: CheckForPlayerInput:
{ {
@@ -775,43 +786,29 @@ CheckForPlayerInput:
LDA $0FA5 : CLC : CMP.b #$B6 : BNE .cant_input LDA $0FA5 : CLC : CMP.b #$B6 : BNE .cant_input
; Check for input from the user (u,d,l,r) ; Check for input from the user (u,d,l,r)
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 LDA.b #$00 : STA !SpriteDirection, X ; Moving Up
STA SprSubtype, X STA SprSubtype, X
%GotoAction(2) ; Minecart_MoveNorth %GotoAction(2) ; Minecart_MoveNorth
BRA .return BRA .return
.not_pressing_up: .not_pressing_up:
LDA $00 : AND.b #$04 : BEQ .not_pressing_down LDA $00 : AND.b #$04 : BEQ .not_pressing_down
LDA.b #$01 : STA !SpriteDirection, X LDA.b #$01 : STA !SpriteDirection, X
LDA #$02 : STA SprSubtype, X LDA #$02 : STA SprSubtype, X
%GotoAction(4) ; Minecart_MoveSouth %GotoAction(4) ; Minecart_MoveSouth
BRA .return BRA .return
.not_pressing_down .not_pressing_down
LDA $00 : AND.b #$02 : BEQ .not_pressing_left LDA $00 : AND.b #$02 : BEQ .not_pressing_left
LDA.b #$02 : STA !SpriteDirection, X LDA.b #$02 : STA !SpriteDirection, X
LDA #$03 : STA SprSubtype, X LDA #$03 : STA SprSubtype, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
BRA .return BRA .return
.not_pressing_left .not_pressing_left
LDA $00 : AND.b #$01 : BEQ .always LDA $00 : AND.b #$01 : BEQ .always
LDA.b #$03 : STA !SpriteDirection, X LDA.b #$03 : STA !SpriteDirection, X
STA SprSubtype, X STA SprSubtype, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
@@ -819,12 +816,9 @@ CheckForPlayerInput:
.always .always
; LDA !SpriteDirection, X : CMP.b #$03 : BNE .not_going_right ; LDA !SpriteDirection, X : CMP.b #$03 : BNE .not_going_right
; ; Default heading in reaction to this tile is going up. ; ; Default heading in reaction to this tile is going up.
; ; LDA.b #$00 : STA !SpriteDirection, X ; ; LDA.b #$00 : STA !SpriteDirection, X
; .not_going_right ; .not_going_right
; ;STZ $0D80, X ; ;STZ $0D80, X
.return .return
@@ -836,26 +830,31 @@ CheckForPlayerInput:
db $0B, $07, $0E, $0D db $0B, $07, $0E, $0D
} }
; =========================================================
; Sets carry if player is overlapping the sprite
; Clear carry if player is outside the bounds
CheckIfPlayerIsOn: CheckIfPlayerIsOn:
{ {
REP #$20 REP #$20
LDA $22 : CLC : ADC #$0009 : CMP $0FD8 : BCC .OutsideLeft LDA $22 : CLC : ADC #$0009 : CMP $0FD8 : BCC .left
LDA $22 : SEC : SBC #$0009 : CMP $0FD8 : BCS .OutsideRight LDA $22 : SEC : SBC #$0009 : CMP $0FD8 : BCS .right
LDA $20 : CLC : ADC #$0012 : CMP $0FDA : BCC .OutsideUp LDA $20 : CLC : ADC #$0012 : CMP $0FDA : BCC .up
LDA $20 : SEC : SBC #$0012 : CMP $0FDA : BCS .OutsideDown LDA $20 : SEC : SBC #$0012 : CMP $0FDA : BCS .down
SEP #$21 : RTS ; Return with carry set SEP #$21 : RTS ; Return with carry set
.OutsideLeft .left
.OutsideRight .right
.OutsideDown .up
.OutsideUp .down
SEP #$20 SEP #$20
CLC : RTS ; Return with carry cleared CLC : RTS ; Return with carry cleared
} }
; ========================================================= ; =========================================================
; Draw the portion of the cart which is behind the player
Sprite_Minecart_DrawTop: Sprite_Minecart_DrawTop:
{ {
@@ -945,6 +944,8 @@ Sprite_Minecart_DrawTop:
db $02, $02 db $02, $02
} }
; =========================================================
; Draw the portion of the cart which is in front of the player
Sprite_Minecart_DrawBottom: Sprite_Minecart_DrawBottom:
{ {