From 5177cdfd63ab82dbf49b51210c20773df60186d0 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 6 Jan 2025 17:51:54 -0500 Subject: [PATCH] Update sprite functions, remove Sprite_BounceOffWall --- Core/sprite_functions.asm | 253 ++++++++++++++-------------------- Core/sprite_macros.asm | 74 +++------- Sprites/Enemies/puffstool.asm | 1 - Sprites/NPCs/piratian.asm | 1 - 4 files changed, 118 insertions(+), 211 deletions(-) diff --git a/Core/sprite_functions.asm b/Core/sprite_functions.asm index cbf5633..7af4a91 100644 --- a/Core/sprite_functions.asm +++ b/Core/sprite_functions.asm @@ -1,9 +1,9 @@ ; ========================================================= ; return carry set if active +; Deactivates the sprite in certain situations Sprite_CheckActive: { - ; Deactivates the sprite in certain situations LDA.w SprState, X : CMP.b #$09 : BNE .inactive LDA.w SprFreeze : BNE .inactive LDA $11 : BNE .inactive @@ -18,47 +18,34 @@ Sprite_CheckActive: } ; ========================================================= -; make the sprite move X axis Sprite_MoveHoriz: { LDA.w SprXSpeed, X : BEQ .no_velocity - ASL : ASL : ASL : ASL - CLC : ADC.w SprXRound, X : STA.w SprXRound, X - + ASL #4 : CLC : ADC.w SprXRound, X : STA.w SprXRound, X LDY.b #$00 LDA.w SprXSpeed, X - PHP : LSR : LSR : LSR : LSR : PLP - BPL ++ - - ORA.b #$F0 - DEY - - ++ ADC.w SprX, X : STA.w SprX, X + PHP : LSR #4 : PLP : BPL ++ + ORA.b #$F0 + DEY + ++ + ADC.w SprX, X : STA.w SprX, X TYA : ADC.w SprXH, X : STA.w SprXH, X - .no_velocity RTL } -; ========================================================= -; make the sprite move both directions (also height) - Sprite_MoveXyz: JSL Sprite_MoveAltitude Sprite_Move: JSL Sprite_MoveHoriz ; no RTL, just continue into Sprite_MoveVert -; ========================================================= -; make the sprite move Y axis - Sprite_MoveVert: { LDA.w SprYSpeed, X : BEQ .no_velocity ASL : ASL : ASL : ASL - CLC : ADC.w SprYRound,X : STA.w SprYRound,X - + CLC : ADC.w SprYRound, X : STA.w SprYRound, X LDY.b #$00 LDA.w SprYSpeed, X PHP : LSR : LSR : LSR : LSR : PLP @@ -67,34 +54,26 @@ Sprite_MoveVert: ORA.b #$F0 DEY - ++ ADC.w SprY,X : STA.w SprY,X - TYA : ADC.w SprYH,X : STA.w SprYH,X + ++ ADC.w SprY, X : STA.w SprY, X + TYA : ADC.w SprYH, X : STA.w SprYH, X .no_velocity RTL } -; ========================================================= -; make the sprite move Z axis (height) - Sprite_MoveZ: Sprite_MoveAltitude: { - LDA.w SprTimerF, X : ASL : ASL : ASL : ASL + LDA.w SprTimerF, X : ASL #4 CLC : ADC.w SprHeightS, X : STA.w SprHeightS, X - - LDA.w SprTimerF, X : PHP - LSR : LSR : LSR : LSR - PLP : BPL .positive + LDA.w SprTimerF, X : PHP : LSR #4 : PLP : BPL .positive ORA.b #$F0 .positive - ADC.w SprHeight,X : STA.w SprHeight,X - + ADC.w SprHeight, X : STA.w SprHeight, X RTL } ; ========================================================= -; make the sprite bounce toward player ; movement, collision are handled by this function ; $09 = speed, $08 = max height ( e.g. height:20 = vitreous) @@ -138,41 +117,26 @@ Sprite_BounceFromTileCollision: { JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++ LDA.w SprXSpeed, X : EOR.b #$FF : INC : STA.w SprXSpeed, X - - ++ LDA.w SprCollision, X : AND.b #$0C : BEQ ++ - LDA.w SprYSpeed, X : EOR.b #$FF : INC : STA.w SprYSpeed, X - - ++ RTL -} - -; ========================================================= - -Sprite_BounceOffWall: - LDA.w SprCollision, X : AND.b #$03 : BEQ .no_horizontal_collision - JSL Sprite_InvertSpeed_X - .no_horizontal_collision - LDA.w SprCollision, X : AND.b #$0C : BEQ .no_vertical_collision - JSL Sprite_InvertSpeed_Y - .no_vertical_collision + ++ + LDA.w SprCollision, X : AND.b #$0C : BEQ ++ + LDA.w SprYSpeed, X : EOR.b #$FF : INC : STA.w SprYSpeed, X + ++ RTL - -; ========================================================= +} Sprite_InvertSpeed_XY: JSL Sprite_InvertSpeed_Y Sprite_InvertSpeed_X: LDA.w SprXSpeed, X - EOR.b #$FF - INC A + EOR.b #$FF : INC A STA.w SprXSpeed, X RTL Sprite_InvertSpeed_Y: - LDA.w SprYSpeed,X - EOR.b #$FF - INC A - STA.w SprYSpeed,X + LDA.w SprYSpeed, X + EOR.b #$FF : INC A + STA.w SprYSpeed, X RTL ; ========================================================= @@ -651,89 +615,78 @@ Sprite_ApplySpeedTowardsPlayerXOrY: { JSL Sprite_IsBelowPlayer : BEQ .player_below ;playerAbove - REP #$20 ; if link.y is 6 above sprite.y it is considered below LDA.w SprCachedY : SEC : SBC $20 : CLC : ADC.w #$0006 : STA $01 ;delta Y SEP #$20 - JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right1 + JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_right1 ;player_to_the_Left - REP #$20 - LDA.w SprCachedX : SEC : SBC $22 ; delta X - - CMP $01 : BCS .XGreaterThanY1 + REP #$20 ; delta X + LDA.w SprCachedX : SEC : SBC $22 : CMP $01 : BCS .XGreaterThanY1 ;YGreaterThanX SEP #$20 LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed STZ.w SprXSpeed RTL - .XGreaterThanY1 - SEP #$20 - LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed - STZ.w SprYSpeed - RTL - - .player_to_the_Right1 - REP #$20 - LDA $22 : SEC : SBC.w SprCachedX ; delta X - - CMP $01 : BCS .XGreaterThanY2 - ;YGreaterThanX - SEP #$20 - LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed - STZ.w SprXSpeed - RTL - - .XGreaterThanY2 - SEP #$20 - LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed - STZ.w SprYSpeed - RTL + SEP #$20 + LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed + STZ.w SprYSpeed + RTL + .player_to_the_right1 + REP #$20 ; delta X + LDA $22 : SEC : SBC.w SprCachedX : CMP $01 : BCS .XGreaterThanY2 + ;YGreaterThanX + SEP #$20 + LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed + STZ.w SprXSpeed + RTL + .XGreaterThanY2 + SEP #$20 + LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed + STZ.w SprYSpeed + RTL .player_below - REP #$20 - ; if link.y is 6 above sprite.y it is considered below - LDA $20 : SEC : SBC.w SprCachedY : CLC : ADC.w #$0006 : STA $01 ; delta Y - SEP #$20 + REP #$20 + ; if link.y is 6 above sprite.y it is considered below + LDA $20 : SEC : SBC.w SprCachedY : CLC : ADC.w #$0006 : STA $01 ; delta Y + SEP #$20 - JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right2 - ;player_to_the_Left - REP #$20 - LDA.w SprCachedX : SEC : SBC $22 ; delta X + JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right2 + ;player_to_the_Left + REP #$20 + LDA.w SprCachedX : SEC : SBC $22 ; delta X - CMP $01 : BCS .XGreaterThanY3 - ;YGreaterThanX - SEP #$20 - LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed - STZ.w SprXSpeed - RTL + CMP $01 : BCS .XGreaterThanY3 + ;YGreaterThanX + SEP #$20 + LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed + STZ.w SprXSpeed + RTL - .XGreaterThanY3 - SEP #$20 - LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed - STZ.w SprYSpeed - RTL + .XGreaterThanY3 + SEP #$20 + LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed + STZ.w SprYSpeed + RTL + .player_to_the_Right2 + REP #$20 ; delta X + LDA $22 : SEC : SBC.w SprCachedX : CMP $01 : BCS .XGreaterThanY4 + ;YGreaterThanX + SEP #$20 + LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed + STZ.w SprXSpeed + RTL - .player_to_the_Right2 - REP #$20 - LDA $22 : SEC : SBC.w SprCachedX ; delta X - - CMP $01 : BCS .XGreaterThanY4 - ;YGreaterThanX - SEP #$20 - LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed - STZ.w SprXSpeed - RTL - - .XGreaterThanY4 - SEP #$20 - LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed - STZ.w SprYSpeed - RTL + .XGreaterThanY4 + SEP #$20 + LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed + STZ.w SprYSpeed + RTL } ; ========================================================= @@ -744,16 +697,16 @@ GetDistance8bit_Long: LDA.w POSY : STA $03 LDA.w SprX, X : STA $04 LDA.w SprY, X : STA $05 - LDA $04 : SEC : SBC $02 : BPL + + LDA $04 : SEC : SBC $02 : BPL + EOR.b #$FF : INC + - STA $00 ; Distance X (ABS) + STA $00 ; Distance X (ABS) - LDA $05 : SEC : SBC $03 : BPL + + LDA $05 : SEC : SBC $03 : BPL + EOR.b #$FF : INC + ; Add it back to X Distance - CLC : ADC $00 : STA $00 ; distance total X, Y (ABS) + CLC : ADC $00 : STA $00 ; distance total X, Y (ABS) RTL } @@ -762,7 +715,6 @@ GetDistance8bit_Long: Sprite_CheckIfRecoiling: { PHB : PHK : PLB - LDA.w $0EA0, X : BEQ .exit AND.b #$7F : BEQ .recoil_over LDA.w SprYSpeed, X @@ -775,57 +727,54 @@ Sprite_CheckIfRecoiling: LDA.w SprXRecoil, X : CLC : ADC.b #$20 : CMP.b #$40 : BCS .no_adjust LDA.w SprYRecoil, X : CLC : ADC.b #$20 : CMP.b #$40 : BCC .still_recoiling .no_adjust - LDA.b #$90 : STA.w $0EA0,X + LDA.b #$90 : STA.w $0EA0, X .still_recoiling - LDA.w $0EA0,X : BMI .no_movement + LDA.w $0EA0, X : BMI .no_movement LSR A LSR A TAY - LDA.b $1A : AND.w .masks,Y : BNE .no_movement + LDA.b $1A : AND.w .masks, Y : BNE .no_movement + LDA.w SprYRecoil, X : STA.w SprYSpeed, X + LDA.w SprXRecoil, X : STA.w SprXSpeed, X + LDA.w SprBump, X : BMI .handle_movement - LDA.w SprYRecoil, X : STA.w SprYSpeed,X + JSL Sprite_CheckTileCollision_long - LDA.w SprXRecoil, X : STA.w SprXSpeed,X + LDA.w $0E70, X : AND.b #$0F : BEQ .handle_movement - LDA.w SprBump, X : BMI .handle_movement + .stop_horizontal_movement + CMP.b #$04 : BCS .stop_vertical_movement - JSL Sprite_CheckTileCollision_long + STZ.w SprXRecoil, X + STZ.w SprXSpeed, X - LDA.w $0E70, X : AND.b #$0F : BEQ .handle_movement + BRA .movement_stopped - .stop_horizontal_movement - CMP.b #$04 : BCS .stop_vertical_movement + .stop_vertical_movement + STZ.w SprYRecoil, X + STZ.w SprYSpeed, X - STZ.w SprXRecoil,X - STZ.w SprXSpeed,X + .movement_stopped + BRA .no_movement - BRA .movement_stopped - - .stop_vertical_movement - STZ.w SprYRecoil,X - STZ.w SprYSpeed,X - - .movement_stopped - BRA .no_movement - - .handle_movement - JSL Sprite_Move + .handle_movement + JSL Sprite_Move .no_movement PLA - STA.w SprXSpeed,X + STA.w SprXSpeed, X PLA - STA.w SprYSpeed,X + STA.w SprYSpeed, X .exit PLB RTL .recoil_over - STZ.w $0EA0,X + STZ.w $0EA0, X PLB RTL diff --git a/Core/sprite_macros.asm b/Core/sprite_macros.asm index ce219b0..38cc90c 100644 --- a/Core/sprite_macros.asm +++ b/Core/sprite_macros.asm @@ -56,6 +56,14 @@ macro sta_x(...) %loop(STA.w, ..., X) endmacro +macro mode16() + REP #$30 +endmacro + +macro mode8() + SEP #$30 +endmacro + macro accum16() REP #$20 endmacro @@ -91,26 +99,6 @@ macro JumpTable(index, ...) endwhile endmacro -macro SetMode(bit_mode) - if == "16bit" - REP #$30 - elseif == "8bit" - SEP #$30 - endif -endmacro - -macro ScopedMode(bit_mode, body) - if == "16bit" - %SetMode("16bit") - - %SetMode("8bit") - elseif == "8bit" - %SetMode("8bit") - - %SetMode("16bit") - endif -endmacro - macro SpriteJumpTable(...) LDA.w SprAction, X JSL JumpTableLocal @@ -123,41 +111,32 @@ macro SpriteJumpTable(...) endmacro macro SetFlag(flag_addr, bit_pos) - LDA.b flag_addr - ORA.b #(1 << bit_pos) - STA.b flag_addr + LDA.b flag_addr : ORA.b #(1 << bit_pos) : STA.b flag_addr endmacro macro ClearFlag(flag_addr, bit_pos) - LDA.b flag_addr - AND.b #~(1 << bit_pos) - STA.b flag_addr + LDA.b flag_addr : AND.b #~(1 << bit_pos) : STA.b flag_addr endmacro macro ToggleFlag(flag_addr, bit_pos) - LDA.b flag_addr - EOR.b #(1 << bit_pos) - STA.b flag_addr + LDA.b flag_addr : EOR.b #(1 << bit_pos) : STA.b flag_addr endmacro macro CheckFlag(flag_addr, bit_pos, set_label, clear_label) - LDA.b flag_addr - AND.b #(1 << bit_pos) - BEQ clear_label - BRA set_label + LDA.b flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label + BRA set_label endmacro macro CheckFlagLong(flag_addr, bit_pos, set_label, clear_label) - LDA.l flag_addr - AND.b #(1 << bit_pos) - BEQ clear_label - BRA set_label + LDA.l flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label + BRA set_label endmacro ; Increase the sprite frame every (frames_wait) frames ; reset to (frame_start) when reaching (frame_end) ; This is using SprTimerB macro PlayAnimation(frame_start, frame_end, frame_wait) +{ LDA.w SprTimerB, X : BNE + LDA.w SprFrame, X : INC : STA.w SprFrame, X CMP.b #+1 : BCC .noframereset @@ -165,6 +144,7 @@ macro PlayAnimation(frame_start, frame_end, frame_wait) .noframereset LDA.b # : STA.w SprTimerB, X + +} endmacro macro PlayAnimBackwards(frame_start, frame_end, frame_wait) @@ -183,7 +163,6 @@ macro StartOnFrame(frame) + endmacro - ; Show message if the player is facing toward sprite and pressing A ; Return Carry Set if message is displayed ; can use BCC .label <> .label to see if message have been displayed @@ -254,16 +233,6 @@ macro AllowPlayerMovement() STZ.w $02E4 endmacro -; Enter 16bit mode -macro Set16bitmode() - REP #$30 -endmacro - -; Enter 8bit mode -macro Set8bitmode() - SEP #$30 -endmacro - ; This is a 16 bit will load A with current rupee count ; to use with instructions CMP and BCC/BCS macro GetPlayerRupees() @@ -282,47 +251,38 @@ macro SetSpriteSpeedX(speed) LDA.b # : STA.w SprXSpeed, x endmacro -; Will play a sound SFX 1 See Zelda_3_RAM.log for more informations macro PlaySFX1(sfxid) LDA.b # : STA $012E endmacro -; Will play a sound SFX 2 See Zelda_3_RAM.log for more informations macro PlaySFX2(sfxid) LDA.b # : STA $012F endmacro -; Will play a music See Zelda_3_RAM.log for more informations macro PlayMusic(musicid) LDA.b # : STA $012C endmacro -; Will set the timer A to wait (length) amount of frames macro SetTimerA(length) LDA.b # : STA.w SprTimerA, X endmacro -; Will set the timer B to wait (length) amount of frames macro SetTimerB(length) LDA.b # : STA.w SprTimerB, X endmacro -; Will set the timer C to wait (length) amount of frames macro SetTimerC(length) LDA.b # : STA.w SprTimerC, X endmacro -; Will set the timer D to wait (length) amount of frames macro SetTimerD(length) LDA.b # : STA.w SprTimerD, X endmacro -; Will set the timer E to wait (length) amount of frames macro SetTimerE(length) LDA.b # : STA.w SprTimerE, X endmacro -; Will set the timer F to wait (length) amount of frames macro SetTimerF(length) LDA.b # : STA.w SprTimerF, X endmacro diff --git a/Sprites/Enemies/puffstool.asm b/Sprites/Enemies/puffstool.asm index 84f9ac0..0480807 100644 --- a/Sprites/Enemies/puffstool.asm +++ b/Sprites/Enemies/puffstool.asm @@ -78,7 +78,6 @@ Sprite_Puffstool_Main: + JSL Sprite_MoveXyz JSL Sprite_BounceFromTileCollision - JSL Sprite_BounceOffWall JSL Sprite_DamageFlash_Long JSL ThrownSprite_TileAndSpriteInteraction_long JSL Sprite_CheckIfRecoiling diff --git a/Sprites/NPCs/piratian.asm b/Sprites/NPCs/piratian.asm index 2d6e180..ec209d9 100644 --- a/Sprites/NPCs/piratian.asm +++ b/Sprites/NPCs/piratian.asm @@ -115,7 +115,6 @@ Sprite_Piratian_Move: JSL Sprite_MoveXyz JSL Sprite_BounceFromTileCollision - JSL Sprite_BounceOffWall JSL Sprite_DamageFlash_Long JSL ThrownSprite_TileAndSpriteInteraction_long