Update sprite functions, remove Sprite_BounceOffWall

This commit is contained in:
scawful
2025-01-06 17:51:54 -05:00
parent 1b9ce3e0fb
commit 5177cdfd63
4 changed files with 118 additions and 211 deletions

View File

@@ -1,9 +1,9 @@
; ========================================================= ; =========================================================
; return carry set if active ; return carry set if active
; Deactivates the sprite in certain situations
Sprite_CheckActive: Sprite_CheckActive:
{ {
; Deactivates the sprite in certain situations
LDA.w SprState, X : CMP.b #$09 : BNE .inactive LDA.w SprState, X : CMP.b #$09 : BNE .inactive
LDA.w SprFreeze : BNE .inactive LDA.w SprFreeze : BNE .inactive
LDA $11 : BNE .inactive LDA $11 : BNE .inactive
@@ -18,47 +18,34 @@ Sprite_CheckActive:
} }
; ========================================================= ; =========================================================
; make the sprite move X axis
Sprite_MoveHoriz: Sprite_MoveHoriz:
{ {
LDA.w SprXSpeed, X : BEQ .no_velocity LDA.w SprXSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL ASL #4 : CLC : ADC.w SprXRound, X : STA.w SprXRound, X
CLC : ADC.w SprXRound, X : STA.w SprXRound, X
LDY.b #$00 LDY.b #$00
LDA.w SprXSpeed, X LDA.w SprXSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP PHP : LSR #4 : PLP : BPL ++
BPL ++ ORA.b #$F0
DEY
ORA.b #$F0 ++
DEY ADC.w SprX, X : STA.w SprX, X
++ ADC.w SprX, X : STA.w SprX, X
TYA : ADC.w SprXH, X : STA.w SprXH, X TYA : ADC.w SprXH, X : STA.w SprXH, X
.no_velocity .no_velocity
RTL RTL
} }
; =========================================================
; make the sprite move both directions (also height)
Sprite_MoveXyz: Sprite_MoveXyz:
JSL Sprite_MoveAltitude JSL Sprite_MoveAltitude
Sprite_Move: Sprite_Move:
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
; no RTL, just continue into Sprite_MoveVert ; no RTL, just continue into Sprite_MoveVert
; =========================================================
; make the sprite move Y axis
Sprite_MoveVert: Sprite_MoveVert:
{ {
LDA.w SprYSpeed, X : BEQ .no_velocity LDA.w SprYSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL 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 LDY.b #$00
LDA.w SprYSpeed, X LDA.w SprYSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP PHP : LSR : LSR : LSR : LSR : PLP
@@ -67,34 +54,26 @@ Sprite_MoveVert:
ORA.b #$F0 ORA.b #$F0
DEY DEY
++ ADC.w SprY,X : STA.w SprY,X ++ ADC.w SprY, X : STA.w SprY, X
TYA : ADC.w SprYH,X : STA.w SprYH,X TYA : ADC.w SprYH, X : STA.w SprYH, X
.no_velocity .no_velocity
RTL RTL
} }
; =========================================================
; make the sprite move Z axis (height)
Sprite_MoveZ: Sprite_MoveZ:
Sprite_MoveAltitude: 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 CLC : ADC.w SprHeightS, X : STA.w SprHeightS, X
LDA.w SprTimerF, X : PHP : LSR #4 : PLP : BPL .positive
LDA.w SprTimerF, X : PHP
LSR : LSR : LSR : LSR
PLP : BPL .positive
ORA.b #$F0 ORA.b #$F0
.positive .positive
ADC.w SprHeight,X : STA.w SprHeight,X ADC.w SprHeight, X : STA.w SprHeight, X
RTL RTL
} }
; ========================================================= ; =========================================================
; make the sprite bounce toward player
; movement, collision are handled by this function ; movement, collision are handled by this function
; $09 = speed, $08 = max height ( e.g. height:20 = vitreous) ; $09 = speed, $08 = max height ( e.g. height:20 = vitreous)
@@ -138,41 +117,26 @@ Sprite_BounceFromTileCollision:
{ {
JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++ JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++
LDA.w SprXSpeed, X : EOR.b #$FF : INC : STA.w SprXSpeed, X LDA.w SprXSpeed, X : EOR.b #$FF : INC : STA.w SprXSpeed, X
++
++ LDA.w SprCollision, X : AND.b #$0C : BEQ ++ LDA.w SprCollision, X : AND.b #$0C : BEQ ++
LDA.w SprYSpeed, X : EOR.b #$FF : INC : STA.w SprYSpeed, X 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
RTL RTL
}
; =========================================================
Sprite_InvertSpeed_XY: Sprite_InvertSpeed_XY:
JSL Sprite_InvertSpeed_Y JSL Sprite_InvertSpeed_Y
Sprite_InvertSpeed_X: Sprite_InvertSpeed_X:
LDA.w SprXSpeed, X LDA.w SprXSpeed, X
EOR.b #$FF EOR.b #$FF : INC A
INC A
STA.w SprXSpeed, X STA.w SprXSpeed, X
RTL RTL
Sprite_InvertSpeed_Y: Sprite_InvertSpeed_Y:
LDA.w SprYSpeed,X LDA.w SprYSpeed, X
EOR.b #$FF EOR.b #$FF : INC A
INC A STA.w SprYSpeed, X
STA.w SprYSpeed,X
RTL RTL
; ========================================================= ; =========================================================
@@ -651,89 +615,78 @@ Sprite_ApplySpeedTowardsPlayerXOrY:
{ {
JSL Sprite_IsBelowPlayer : BEQ .player_below JSL Sprite_IsBelowPlayer : BEQ .player_below
;playerAbove ;playerAbove
REP #$20 REP #$20
; if link.y is 6 above sprite.y it is considered below ; 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 LDA.w SprCachedY : SEC : SBC $20 : CLC : ADC.w #$0006 : STA $01 ;delta Y
SEP #$20 SEP #$20
JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right1 JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_right1
;player_to_the_Left ;player_to_the_Left
REP #$20 REP #$20 ; delta X
LDA.w SprCachedX : SEC : SBC $22 ; delta X LDA.w SprCachedX : SEC : SBC $22 : CMP $01 : BCS .XGreaterThanY1
CMP $01 : BCS .XGreaterThanY1
;YGreaterThanX ;YGreaterThanX
SEP #$20 SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed
STZ.w SprXSpeed STZ.w SprXSpeed
RTL RTL
.XGreaterThanY1 .XGreaterThanY1
SEP #$20 SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed
STZ.w SprYSpeed STZ.w SprYSpeed
RTL 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
.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 .player_below
REP #$20 REP #$20
; if link.y is 6 above sprite.y it is considered below ; 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 LDA $20 : SEC : SBC.w SprCachedY : CLC : ADC.w #$0006 : STA $01 ; delta Y
SEP #$20 SEP #$20
JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right2 JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right2
;player_to_the_Left ;player_to_the_Left
REP #$20 REP #$20
LDA.w SprCachedX : SEC : SBC $22 ; delta X LDA.w SprCachedX : SEC : SBC $22 ; delta X
CMP $01 : BCS .XGreaterThanY3 CMP $01 : BCS .XGreaterThanY3
;YGreaterThanX ;YGreaterThanX
SEP #$20 SEP #$20
LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed
STZ.w SprXSpeed STZ.w SprXSpeed
RTL RTL
.XGreaterThanY3 .XGreaterThanY3
SEP #$20 SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed
STZ.w SprYSpeed STZ.w SprYSpeed
RTL 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 .XGreaterThanY4
REP #$20 SEP #$20
LDA $22 : SEC : SBC.w SprCachedX ; delta X LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed
STZ.w SprYSpeed
CMP $01 : BCS .XGreaterThanY4 RTL
;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
} }
; ========================================================= ; =========================================================
@@ -744,16 +697,16 @@ GetDistance8bit_Long:
LDA.w POSY : STA $03 LDA.w POSY : STA $03
LDA.w SprX, X : STA $04 LDA.w SprX, X : STA $04
LDA.w SprY, X : STA $05 LDA.w SprY, X : STA $05
LDA $04 : SEC : SBC $02 : BPL + LDA $04 : SEC : SBC $02 : BPL +
EOR.b #$FF : INC 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 EOR.b #$FF : INC
+ +
; Add it back to X Distance ; 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 RTL
} }
@@ -762,7 +715,6 @@ GetDistance8bit_Long:
Sprite_CheckIfRecoiling: Sprite_CheckIfRecoiling:
{ {
PHB : PHK : PLB PHB : PHK : PLB
LDA.w $0EA0, X : BEQ .exit LDA.w $0EA0, X : BEQ .exit
AND.b #$7F : BEQ .recoil_over AND.b #$7F : BEQ .recoil_over
LDA.w SprYSpeed, X 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 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 LDA.w SprYRecoil, X : CLC : ADC.b #$20 : CMP.b #$40 : BCC .still_recoiling
.no_adjust .no_adjust
LDA.b #$90 : STA.w $0EA0,X LDA.b #$90 : STA.w $0EA0, X
.still_recoiling .still_recoiling
LDA.w $0EA0,X : BMI .no_movement LDA.w $0EA0, X : BMI .no_movement
LSR A LSR A
LSR A LSR A
TAY 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 .stop_vertical_movement
CMP.b #$04 : BCS .stop_vertical_movement STZ.w SprYRecoil, X
STZ.w SprYSpeed, X
STZ.w SprXRecoil,X .movement_stopped
STZ.w SprXSpeed,X BRA .no_movement
BRA .movement_stopped .handle_movement
JSL Sprite_Move
.stop_vertical_movement
STZ.w SprYRecoil,X
STZ.w SprYSpeed,X
.movement_stopped
BRA .no_movement
.handle_movement
JSL Sprite_Move
.no_movement .no_movement
PLA PLA
STA.w SprXSpeed,X STA.w SprXSpeed, X
PLA PLA
STA.w SprYSpeed,X STA.w SprYSpeed, X
.exit .exit
PLB PLB
RTL RTL
.recoil_over .recoil_over
STZ.w $0EA0,X STZ.w $0EA0, X
PLB PLB
RTL RTL

View File

@@ -56,6 +56,14 @@ macro sta_x(...)
%loop(STA.w, ..., X) %loop(STA.w, ..., X)
endmacro endmacro
macro mode16()
REP #$30
endmacro
macro mode8()
SEP #$30
endmacro
macro accum16() macro accum16()
REP #$20 REP #$20
endmacro endmacro
@@ -91,26 +99,6 @@ macro JumpTable(index, ...)
endwhile endwhile
endmacro endmacro
macro SetMode(bit_mode)
if <bit_mode> == "16bit"
REP #$30
elseif <bit_mode> == "8bit"
SEP #$30
endif
endmacro
macro ScopedMode(bit_mode, body)
if <bit_mode> == "16bit"
%SetMode("16bit")
<body>
%SetMode("8bit")
elseif <bit_mode> == "8bit"
%SetMode("8bit")
<body>
%SetMode("16bit")
endif
endmacro
macro SpriteJumpTable(...) macro SpriteJumpTable(...)
LDA.w SprAction, X LDA.w SprAction, X
JSL JumpTableLocal JSL JumpTableLocal
@@ -123,41 +111,32 @@ macro SpriteJumpTable(...)
endmacro endmacro
macro SetFlag(flag_addr, bit_pos) macro SetFlag(flag_addr, bit_pos)
LDA.b flag_addr LDA.b flag_addr : ORA.b #(1 << bit_pos) : STA.b flag_addr
ORA.b #(1 << bit_pos)
STA.b flag_addr
endmacro endmacro
macro ClearFlag(flag_addr, bit_pos) macro ClearFlag(flag_addr, bit_pos)
LDA.b flag_addr LDA.b flag_addr : AND.b #~(1 << bit_pos) : STA.b flag_addr
AND.b #~(1 << bit_pos)
STA.b flag_addr
endmacro endmacro
macro ToggleFlag(flag_addr, bit_pos) macro ToggleFlag(flag_addr, bit_pos)
LDA.b flag_addr LDA.b flag_addr : EOR.b #(1 << bit_pos) : STA.b flag_addr
EOR.b #(1 << bit_pos)
STA.b flag_addr
endmacro endmacro
macro CheckFlag(flag_addr, bit_pos, set_label, clear_label) macro CheckFlag(flag_addr, bit_pos, set_label, clear_label)
LDA.b flag_addr LDA.b flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label
AND.b #(1 << bit_pos) BRA set_label
BEQ clear_label
BRA set_label
endmacro endmacro
macro CheckFlagLong(flag_addr, bit_pos, set_label, clear_label) macro CheckFlagLong(flag_addr, bit_pos, set_label, clear_label)
LDA.l flag_addr LDA.l flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label
AND.b #(1 << bit_pos) BRA set_label
BEQ clear_label
BRA set_label
endmacro endmacro
; Increase the sprite frame every (frames_wait) frames ; Increase the sprite frame every (frames_wait) frames
; reset to (frame_start) when reaching (frame_end) ; reset to (frame_start) when reaching (frame_end)
; This is using SprTimerB ; This is using SprTimerB
macro PlayAnimation(frame_start, frame_end, frame_wait) macro PlayAnimation(frame_start, frame_end, frame_wait)
{
LDA.w SprTimerB, X : BNE + LDA.w SprTimerB, X : BNE +
LDA.w SprFrame, X : INC : STA.w SprFrame, X LDA.w SprFrame, X : INC : STA.w SprFrame, X
CMP.b #<frame_end>+1 : BCC .noframereset CMP.b #<frame_end>+1 : BCC .noframereset
@@ -165,6 +144,7 @@ macro PlayAnimation(frame_start, frame_end, frame_wait)
.noframereset .noframereset
LDA.b #<frame_wait> : STA.w SprTimerB, X LDA.b #<frame_wait> : STA.w SprTimerB, X
+ +
}
endmacro endmacro
macro PlayAnimBackwards(frame_start, frame_end, frame_wait) macro PlayAnimBackwards(frame_start, frame_end, frame_wait)
@@ -183,7 +163,6 @@ macro StartOnFrame(frame)
+ +
endmacro endmacro
; Show message if the player is facing toward sprite and pressing A ; Show message if the player is facing toward sprite and pressing A
; Return Carry Set if message is displayed ; Return Carry Set if message is displayed
; can use BCC .label <> .label to see if message have been displayed ; can use BCC .label <> .label to see if message have been displayed
@@ -254,16 +233,6 @@ macro AllowPlayerMovement()
STZ.w $02E4 STZ.w $02E4
endmacro 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 ; This is a 16 bit will load A with current rupee count
; to use with instructions CMP and BCC/BCS ; to use with instructions CMP and BCC/BCS
macro GetPlayerRupees() macro GetPlayerRupees()
@@ -282,47 +251,38 @@ macro SetSpriteSpeedX(speed)
LDA.b #<speed> : STA.w SprXSpeed, x LDA.b #<speed> : STA.w SprXSpeed, x
endmacro endmacro
; Will play a sound SFX 1 See Zelda_3_RAM.log for more informations
macro PlaySFX1(sfxid) macro PlaySFX1(sfxid)
LDA.b #<sfxid> : STA $012E LDA.b #<sfxid> : STA $012E
endmacro endmacro
; Will play a sound SFX 2 See Zelda_3_RAM.log for more informations
macro PlaySFX2(sfxid) macro PlaySFX2(sfxid)
LDA.b #<sfxid> : STA $012F LDA.b #<sfxid> : STA $012F
endmacro endmacro
; Will play a music See Zelda_3_RAM.log for more informations
macro PlayMusic(musicid) macro PlayMusic(musicid)
LDA.b #<musicid> : STA $012C LDA.b #<musicid> : STA $012C
endmacro endmacro
; Will set the timer A to wait (length) amount of frames
macro SetTimerA(length) macro SetTimerA(length)
LDA.b #<length> : STA.w SprTimerA, X LDA.b #<length> : STA.w SprTimerA, X
endmacro endmacro
; Will set the timer B to wait (length) amount of frames
macro SetTimerB(length) macro SetTimerB(length)
LDA.b #<length> : STA.w SprTimerB, X LDA.b #<length> : STA.w SprTimerB, X
endmacro endmacro
; Will set the timer C to wait (length) amount of frames
macro SetTimerC(length) macro SetTimerC(length)
LDA.b #<length> : STA.w SprTimerC, X LDA.b #<length> : STA.w SprTimerC, X
endmacro endmacro
; Will set the timer D to wait (length) amount of frames
macro SetTimerD(length) macro SetTimerD(length)
LDA.b #<length> : STA.w SprTimerD, X LDA.b #<length> : STA.w SprTimerD, X
endmacro endmacro
; Will set the timer E to wait (length) amount of frames
macro SetTimerE(length) macro SetTimerE(length)
LDA.b #<length> : STA.w SprTimerE, X LDA.b #<length> : STA.w SprTimerE, X
endmacro endmacro
; Will set the timer F to wait (length) amount of frames
macro SetTimerF(length) macro SetTimerF(length)
LDA.b #<length> : STA.w SprTimerF, X LDA.b #<length> : STA.w SprTimerF, X
endmacro endmacro

View File

@@ -78,7 +78,6 @@ Sprite_Puffstool_Main:
+ +
JSL Sprite_MoveXyz JSL Sprite_MoveXyz
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSL Sprite_BounceOffWall
JSL Sprite_DamageFlash_Long JSL Sprite_DamageFlash_Long
JSL ThrownSprite_TileAndSpriteInteraction_long JSL ThrownSprite_TileAndSpriteInteraction_long
JSL Sprite_CheckIfRecoiling JSL Sprite_CheckIfRecoiling

View File

@@ -115,7 +115,6 @@ Sprite_Piratian_Move:
JSL Sprite_MoveXyz JSL Sprite_MoveXyz
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSL Sprite_BounceOffWall
JSL Sprite_DamageFlash_Long JSL Sprite_DamageFlash_Long
JSL ThrownSprite_TileAndSpriteInteraction_long JSL ThrownSprite_TileAndSpriteInteraction_long