new sprite function lib cleanup

This commit is contained in:
scawful
2024-06-27 19:04:02 -04:00
parent 99cf2085ac
commit ce0b6772cc

View File

@@ -1,17 +1,13 @@
; ========================================================= ; =========================================================
;Long function, return Carry Set if Active ; return carry set if active
Sprite_CheckActive: Sprite_CheckActive:
{ {
; Deactivates the sprite in certain situations ; Deactivates the sprite in certain situations
LDA $0DD0, X : CMP.b #$09 : BNE .inactive LDA $0DD0, X : CMP.b #$09 : BNE .inactive
LDA $0FC1 : BNE .inactive LDA $0FC1 : BNE .inactive
LDA $11 : BNE .inactive LDA $11 : BNE .inactive
LDA $0CAA, X : BMI .active LDA $0CAA, X : BMI .active
LDA $0F00, X : BEQ .active LDA $0F00, X : BEQ .active
.inactive .inactive
@@ -28,20 +24,20 @@ Sprite_CheckActive:
Sprite_MoveHoriz: Sprite_MoveHoriz:
{ {
LDA.w $0D50, X : BEQ .no_velocity LDA.w SprXSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL ASL : ASL : ASL : ASL
CLC : ADC.w $0D70,X : STA.w $0D70,X CLC : ADC.w $0D70, X : STA.w $0D70, X
LDY.b #$00 LDY.b #$00
LDA.w $0D50, X LDA.w SprXSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP PHP : LSR : LSR : LSR : LSR : PLP
BPL ++ BPL ++
ORA.b #$F0 ORA.b #$F0
DEY DEY
++ ADC.w $0D10,X : STA.w $0D10,X ++ ADC.w $0D10, X : STA.w $0D10, X
TYA : ADC.w $0D30,X : STA.w $0D30,X TYA : ADC.w $0D30, X : STA.w $0D30, X
.no_velocity .no_velocity
RTL RTL
@@ -61,12 +57,12 @@ Sprite_Move:
Sprite_MoveVert: Sprite_MoveVert:
{ {
LDA.w $0D40, X : BEQ .no_velocity LDA.w SprYSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL ASL : ASL : ASL : ASL
CLC : ADC.w $0D60,X : STA.w $0D60,X CLC : ADC.w $0D60,X : STA.w $0D60,X
LDY.b #$00 LDY.b #$00
LDA.w $0D40, X LDA.w SprYSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP PHP : LSR : LSR : LSR : LSR : PLP
BPL ++ BPL ++
@@ -87,14 +83,12 @@ Sprite_MoveZ:
Sprite_MoveAltitude: Sprite_MoveAltitude:
{ {
LDA.w $0F80, X : ASL : ASL : ASL : ASL LDA.w $0F80, X : ASL : ASL : ASL : ASL
CLC : ADC.w $0F90,X : STA.w $0F90,X CLC : ADC.w $0F90, X : STA.w $0F90, X
LDA.w $0F80, X : PHP LDA.w $0F80, X : PHP
LSR : LSR : LSR : LSR LSR : LSR : LSR : LSR
PLP : BPL .positive PLP : BPL .positive
ORA.b #$F0 ORA.b #$F0
.positive .positive
ADC.w $0F70,X : STA.w $0F70,X ADC.w $0F70,X : STA.w $0F70,X
@@ -160,8 +154,8 @@ Sprite_FloatTowardPlayer:
Sprite_FloatAwayFromPlayer: Sprite_FloatAwayFromPlayer:
{ {
LDA $0D50, X : EOR.b #$FF : INC : STA $0D50, X LDA SprXSpeed, X : EOR.b #$FF : INC : STA SprXSpeed, X
LDA $0D40, X : EOR.b #$FF : INC : STA $0D40, X LDA SprYSpeed, X : EOR.b #$FF : INC : STA SprYSpeed, X
JSL Sprite_MoveAltitude JSL Sprite_MoveAltitude
@@ -171,14 +165,20 @@ Sprite_FloatAwayFromPlayer:
Sprite_BounceFromTileCollision: Sprite_BounceFromTileCollision:
{ {
JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++ JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++
LDA.w $0D50,X : EOR.b #$FF : INC : STA.w $0D50,X LDA.w SprXSpeed, X : EOR.b #$FF : INC : STA.w SprXSpeed, X
INC.w $0ED0, X INC.w $0ED0, X
++ LDA.w $0E70, X : AND.b #$0C : BEQ ++ ++ LDA.w $0E70, X : AND.b #$0C : BEQ ++
LDA.w $0D40,X : EOR.b #$FF : INC : STA.w $0D40,X LDA.w SprYSpeed, X : EOR.b #$FF : INC : STA.w SprYSpeed, X
INC.w $0ED0, X INC.w $0ED0, X
++ RTL ++ RTL
}
Sprite_ProjectSpeedRandomly:
{
} }
; ========================================================= ; =========================================================
@@ -254,13 +254,11 @@ DragPlayer:
Intro_Dungeon_Main: Intro_Dungeon_Main:
{ {
;test to see if we are at a place where a guardian is present LDA $0E20 : CMP.b #$92 : BNE .not_sprite_body_boss
LDA $0E20 : CMP.b #$92 : BNE .notGuardian LDA $0E30 : BEQ .not_sprite_body_boss
LDA $0E30 : BEQ .notGuardian
LDA $1C : AND.b #$FE : STA $1C ;turn off BG2 (Body) LDA $1C : AND.b #$FE : STA $1C ;turn off BG2 (Body)
;free ram used to check if the sprite ran this frame, if 0, it didn't run ; free ram used to check if the sprite ran this frame, if 0, it didn't run
LDA.b SpriteRanCheck : BEQ .didNotRun LDA.b SpriteRanCheck : BEQ .didNotRun
LDA $1C : ORA.b #$01 : STA $1C ;turn on BG2 (Body) LDA $1C : ORA.b #$01 : STA $1C ;turn on BG2 (Body)
@@ -268,7 +266,7 @@ Intro_Dungeon_Main:
STZ.b SpriteRanCheck STZ.b SpriteRanCheck
.notGuardian .not_sprite_body_boss
REP #$21 : LDA.w DungeonMainCheck : BNE .intro ;<- load that free ram you are using if it's not zero then we're doing intro thing REP #$21 : LDA.w DungeonMainCheck : BNE .intro ;<- load that free ram you are using if it's not zero then we're doing intro thing
LDA $E2 : RTL ;return to normal intro LDA $E2 : RTL ;return to normal intro
@@ -301,10 +299,10 @@ MoveCamera:
ADC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera down by 1 ADC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera down by 1
BRA .dontMoveY BRA .dontMoveY
.CameraBelowPointY .CameraBelowPointY
SEC : SBC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera up by 1 SEC : SBC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera up by 1
.dontMoveY .dontMoveY
;move the camera right or left until a point is reached ;move the camera right or left until a point is reached
LDA $E2 : CMP.w $02 : BEQ .dontMoveX ;if equals that point, dont move x LDA $E2 : CMP.w $02 : BEQ .dontMoveX ;if equals that point, dont move x
@@ -314,10 +312,10 @@ MoveCamera:
ADC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera right by 1 ADC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera right by 1
BRA .dontMoveX BRA .dontMoveX
.CameraBelowPointX .CameraBelowPointX
SEC : SBC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera left by 1 SEC : SBC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera left by 1
.dontMoveX .dontMoveX
;if link is outside of a certain range of the camera, make him dissapear so he doesnt appear on the other side ;if link is outside of a certain range of the camera, make him dissapear so he doesnt appear on the other side
LDA $20 : SEC : SBC $E8 : CMP.w #$00E0 : BCS .MakeLinkInvisible LDA $20 : SEC : SBC $E8 : CMP.w #$00E0 : BCS .MakeLinkInvisible
@@ -327,7 +325,7 @@ MoveCamera:
LDA.b #$00 : STA $4B ;make link visible LDA.b #$00 : STA $4B ;make link visible
RTS RTS
.MakeLinkInvisible .MakeLinkInvisible
SEP #$20 SEP #$20
LDA.b #$0C : STA $4B ;make link invisible LDA.b #$0C : STA $4B ;make link invisible
@@ -453,61 +451,35 @@ Link_SetupHitBox:
Sprite_SetupHitBox: Sprite_SetupHitBox:
{
PHB : PHK : PLB PHB : PHK : PLB
LDA.w $0F70, X LDA.w $0F70, X : BMI .too_high
BMI .too_high
PHY PHY
LDA.w $0F60, X : AND.b #$1F : TAY
LDA.w $0D10, X : CLC : ADC.w .offset_x_low, Y : STA.b $04
LDA.w $0F60, X LDA.w $0D30, X : ADC.w .offset_x_high, Y : STA.b $0A
AND.b #$1F
TAY
LDA.w $0D10, X LDA.w $0D00, X : CLC : ADC.w .offset_y_low, Y
CLC
ADC.w .offset_x_low, Y
STA.b $04
LDA.w $0D30, X
ADC.w .offset_x_high, Y
STA.b $0A
LDA.w $0D00, X
CLC
ADC.w .offset_y_low, Y
PHP PHP
SEC SEC : SBC.w $0F70, X : STA.b $05
SBC.w $0F70, X LDA.w $0D20, X : SBC.b #$00
STA.b $05
LDA.w $0D20, X
SBC.b #$00
PLP PLP
ADC.w .offset_y_high, Y ADC.w .offset_y_high, Y : STA.b $0B
STA.b $0B
LDA.w .width, Y
STA.b $06
LDA.w .height, Y
STA.b $07
LDA.w .width, Y : STA.b $06
LDA.w .height, Y : STA.b $07
PLY PLY
PLB PLB
RTL RTL
; ---------------------------------------------------------
.too_high
LDA.b #$80
STA.b $0A
.too_high
LDA.b #$80 : STA.b $0A
PLB PLB
RTL RTL
.offset_x_low .offset_x_low
@@ -729,7 +701,9 @@ Sprite_SetupHitBox:
db 48 ; 0x1D db 48 ; 0x1D
db 8 ; 0x1E db 8 ; 0x1E
db 12 ; 0x1F db 12 ; 0x1F
}
; =========================================================
Sprite_ApplySpeedTowardsPlayerXOrY_Long: Sprite_ApplySpeedTowardsPlayerXOrY_Long:
{ {