cleanup sprite functions and macros

This commit is contained in:
scawful
2024-07-07 11:00:28 -04:00
parent 9e739c8891
commit 1f2bb46559
2 changed files with 226 additions and 222 deletions

View File

@@ -307,181 +307,6 @@ Sprite_Damage_Flash:
; =========================================================
Intro_Dungeon_Main:
{
LDA $0E20 : CMP.b #$92 : BNE .not_sprite_body_boss
LDA $0E30 : BEQ .not_sprite_body_boss
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
LDA.b SpriteRanCheck : BEQ .didNotRun
LDA $1C : ORA.b #$01 : STA $1C ;turn on BG2 (Body)
.didNotRun
STZ.b SpriteRanCheck
.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
LDA $E2 : RTL ;return to normal intro
.intro
PLA ;Pop 2byte from stack
;skip all the BGs codes
SEP #$20
PLA ;Pop 1 byte from the stack
JSL $07F0AC ; $3F0AC IN ROM. Handle the sprites of pushed blocks.
JSL $068328 ;Sprite_Main
JSL $0DA18E ;PlayerOam_Main
JSL $0DDB75 ;HUD.RefillLogicLong
JML $0AFD0C ;FloorIndicator ; $57D0C IN ROM. Handles HUD floor indicator
}
; =========================================================
;uses $00 as the Y coordinate and $02 as the X
MoveCamera:
{
REP #$20
;move the camera up or down until a point is reached
LDA $E8 : CMP $00 : BEQ .dontMoveY ;if equals that point, dont move y
BCS .CameraBelowPointY
;CameraAbovePoint
ADC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera down by 1
BRA .dontMoveY
.CameraBelowPointY
SEC : SBC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera up by 1
.dontMoveY
;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
BCS .CameraBelowPointX ;left
;CameraAbovePoint ;right
ADC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera right by 1
BRA .dontMoveX
.CameraBelowPointX
SEC : SBC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera left by 1
.dontMoveX
;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 $22 : SEC : SBC $E2 : CMP.w #$00E0 : BCS .MakeLinkInvisible
SEP #$20
LDA.b #$00 : STA $4B ;make link visible
RTS
.MakeLinkInvisible
SEP #$20
LDA.b #$0C : STA $4B ;make link invisible
RTS
}
; =========================================================
MovieEffectTimer = $7EF500 ;0x01
;these need to be the same as the next set
;used to do the HDMA
MovieEffectArray = $F900 ;0x0F
MovieEffectBank = $7E
;used to set the actual values
MovieEffect0 = $7EF900 ;0x01
MovieEffect1 = $7EF901 ;0x01
MovieEffect2 = $7EF902 ;0x01
MovieEffect3 = $7EF903 ;0x01
MovieEffect4 = $7EF904 ;0x01
MovieEffect5 = $7EF905 ;0x01
MovieEffect6 = $7EF906 ;0x01
MovieEffect7 = $7EF907 ;0x01
MovieEffect8 = $7EF908 ;0x01
MovieEffect9 = $7EF909 ;0x01
MovieEffectA = $7EF90A ;0x01
MovieEffectB = $7EF90B ;0x01
MovieEffectC = $7EF90C ;0x01
MovieEffectD = $7EF90D ;0x01
MovieEffectE = $7EF90E ;0x01
SetupMovieEffect:
{
;setup HDMA RAM
;Top Dark Row
LDA.b #$01 : STA.l MovieEffect0
LDA.b #$00 : STA.l MovieEffect1
;Top Dark Row Buffer
LDA.b #$1F : STA.l MovieEffect2
LDA.b #$0F : STA.l MovieEffect3
;Middle Unaffected Area
LDA.b #$50 : STA.l MovieEffect4
LDA.b #$0F : STA.l MovieEffect5
LDA.b #$50 : STA.l MovieEffect6
LDA.b #$0F : STA.l MovieEffect7
;Bottom Drak Row Buffer
LDA.b #$1F : STA.l MovieEffect8
LDA.b #$0F : STA.l MovieEffect9
;Bottom Dark Row
LDA.b #$01 : STA.l MovieEffectA
LDA.b #$00 : STA.l MovieEffectB
;Below screen
LDA.b #$20 : STA.l MovieEffectC
LDA.b #$0F : STA.l MovieEffectD
;End
LDA.b #$00 : STA.l MovieEffectE
;start timer
LDA.b #$01 : STA.l MovieEffectTimer
RTS
}
; =========================================================
MovieEffect:
{
REP #$20
LDX #$00 : STX $4350 ;Set the transfer mode into 1 byte to 1 register
LDX #$00 : STX $4351 ;Set register to 00 ($21 00)
LDA.w #MovieEffectArray : STA $4352 ;set address of the hdma table
LDX.b #MovieEffectBank : STX $4354 ;set the bank of HDMA table
SEP #$20
LDA.b #$20 : STA $9B ;Do the HDMA instead of $420C
; LDA $9B : ORA #$20 : STA $9B
; LDA.b #$02 : STA $13 ;controls the brightness of the screen
RTS
HDMATable: ;values cannot go above 80 or it will read as continuous mode
db $20, $00 ;for $20 line set screen brightness to 0
db $50, $0F ;for $A0 line set screen brightness to 15 full
db $50, $0F ;for $A0 line set screen brightness to 15 full
db $3F, $00 ;for $20 line set screen brightness to 0
db $00 ;end the HDMA
}
Link_CheckNewY_ButtonPress_Long:
{
BIT.b $3A : BVS .fail
@@ -495,6 +320,8 @@ Link_CheckNewY_ButtonPress_Long:
RTL
}
; =========================================================
Link_SetupHitBox:
{
LDA.b #$08 : STA $02 : STA $03
@@ -872,3 +699,180 @@ GetDistance8bit_Long:
CLC : ADC $00 : STA $00 ; distance total X, Y (ABS)
RTL
}
; =========================================================
Intro_Dungeon_Main:
{
LDA $0E20 : CMP.b #$92 : BNE .not_sprite_body_boss
LDA $0E30 : BEQ .not_sprite_body_boss
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
LDA.b SpriteRanCheck : BEQ .didNotRun
LDA $1C : ORA.b #$01 : STA $1C ;turn on BG2 (Body)
.didNotRun
STZ.b SpriteRanCheck
.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
LDA $E2 : RTL ;return to normal intro
.intro
PLA ;Pop 2byte from stack
;skip all the BGs codes
SEP #$20
PLA ;Pop 1 byte from the stack
JSL $07F0AC ; $3F0AC IN ROM. Handle the sprites of pushed blocks.
JSL $068328 ;Sprite_Main
JSL $0DA18E ;PlayerOam_Main
JSL $0DDB75 ;HUD.RefillLogicLong
JML $0AFD0C ;FloorIndicator ; $57D0C IN ROM. Handles HUD floor indicator
}
; =========================================================
;uses $00 as the Y coordinate and $02 as the X
MoveCamera:
{
REP #$20
;move the camera up or down until a point is reached
LDA $E8 : CMP $00 : BEQ .dontMoveY ;if equals that point, dont move y
BCS .CameraBelowPointY
;CameraAbovePoint
ADC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera down by 1
BRA .dontMoveY
.CameraBelowPointY
SEC : SBC.w #$0001 : STA $E8 : STA $E6 : STA $0122 : STA $0124 ;move the camera up by 1
.dontMoveY
;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
BCS .CameraBelowPointX ;left
;CameraAbovePoint ;right
ADC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera right by 1
BRA .dontMoveX
.CameraBelowPointX
SEC : SBC.w #$0001 : STA $E2 : STA $E0 : STA $011E : STA $0120 ;move the camera left by 1
.dontMoveX
;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 $22 : SEC : SBC $E2 : CMP.w #$00E0 : BCS .MakeLinkInvisible
SEP #$20
LDA.b #$00 : STA $4B ;make link visible
RTS
.MakeLinkInvisible
SEP #$20
LDA.b #$0C : STA $4B ;make link invisible
RTS
}
; =========================================================
MovieEffectTimer = $7EF500 ;0x01
;these need to be the same as the next set
;used to do the HDMA
MovieEffectArray = $F900 ;0x0F
MovieEffectBank = $7E
;used to set the actual values
MovieEffect0 = $7EF900 ;0x01
MovieEffect1 = $7EF901 ;0x01
MovieEffect2 = $7EF902 ;0x01
MovieEffect3 = $7EF903 ;0x01
MovieEffect4 = $7EF904 ;0x01
MovieEffect5 = $7EF905 ;0x01
MovieEffect6 = $7EF906 ;0x01
MovieEffect7 = $7EF907 ;0x01
MovieEffect8 = $7EF908 ;0x01
MovieEffect9 = $7EF909 ;0x01
MovieEffectA = $7EF90A ;0x01
MovieEffectB = $7EF90B ;0x01
MovieEffectC = $7EF90C ;0x01
MovieEffectD = $7EF90D ;0x01
MovieEffectE = $7EF90E ;0x01
SetupMovieEffect:
{
;setup HDMA RAM
;Top Dark Row
LDA.b #$01 : STA.l MovieEffect0
LDA.b #$00 : STA.l MovieEffect1
;Top Dark Row Buffer
LDA.b #$1F : STA.l MovieEffect2
LDA.b #$0F : STA.l MovieEffect3
;Middle Unaffected Area
LDA.b #$50 : STA.l MovieEffect4
LDA.b #$0F : STA.l MovieEffect5
LDA.b #$50 : STA.l MovieEffect6
LDA.b #$0F : STA.l MovieEffect7
;Bottom Drak Row Buffer
LDA.b #$1F : STA.l MovieEffect8
LDA.b #$0F : STA.l MovieEffect9
;Bottom Dark Row
LDA.b #$01 : STA.l MovieEffectA
LDA.b #$00 : STA.l MovieEffectB
;Below screen
LDA.b #$20 : STA.l MovieEffectC
LDA.b #$0F : STA.l MovieEffectD
;End
LDA.b #$00 : STA.l MovieEffectE
;start timer
LDA.b #$01 : STA.l MovieEffectTimer
RTS
}
; =========================================================
MovieEffect:
{
REP #$20
LDX #$00 : STX $4350 ;Set the transfer mode into 1 byte to 1 register
LDX #$00 : STX $4351 ;Set register to 00 ($21 00)
LDA.w #MovieEffectArray : STA $4352 ;set address of the hdma table
LDX.b #MovieEffectBank : STX $4354 ;set the bank of HDMA table
SEP #$20
LDA.b #$20 : STA $9B ;Do the HDMA instead of $420C
; LDA $9B : ORA #$20 : STA $9B
; LDA.b #$02 : STA $13 ;controls the brightness of the screen
RTS
HDMATable: ;values cannot go above 80 or it will read as continuous mode
db $20, $00 ;for $20 line set screen brightness to 0
db $50, $0F ;for $A0 line set screen brightness to 15 full
db $50, $0F ;for $A0 line set screen brightness to 15 full
db $3F, $00 ;for $20 line set screen brightness to 0
db $00 ;end the HDMA
}

View File

@@ -43,7 +43,7 @@ endmacro
; Go to the action specified ID can be Hex or Decimal
macro GotoAction(action)
LDA.b #<action> : STA.w SprAction, X
LDA.b #<action> : STA.w SprAction, X
endmacro
@@ -51,18 +51,18 @@ endmacro
; 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 #<frame_end>+1 : BCC .noframereset
LDA.b #<frame_start> : STA.w SprFrame, X
.noframereset
LDA.b #<frame_wait> : STA.w SprTimerB, X
+
LDA.w SprTimerB, X : BNE +
LDA.w SprFrame, X : INC : STA.w SprFrame, X : CMP.b #<frame_end>+1 : BCC .noframereset
LDA.b #<frame_start> : STA.w SprFrame, X
.noframereset
LDA.b #<frame_wait> : STA.w SprTimerB, X
+
endmacro
macro StartOnFrame(frame)
LDA.w SprFrame, x : CMP.b #<frame> : BCS +
LDA.w SprFrame, x : CMP.b #<frame> : BCS +
LDA.b #<frame> : STA.w SprFrame, x
+
+
endmacro
@@ -76,143 +76,143 @@ macro ShowSolicitedMessage(message_id)
endmacro
macro ShowMessageOnContact(message_id)
LDY.b #(<message_id>)>>8
LDA.b #<message_id>
JSL $05E1F0 ; Sprite_ShowMessageOnContact
LDY.b #(<message_id>)>>8
LDA.b #<message_id>
JSL $05E1F0 ; Sprite_ShowMessageOnContact
endmacro
; Show message no matter what (should not be used without code condition)
macro ShowUnconditionalMessage(message_id)
LDY.b #(<message_id>)>>8
LDA.b #<message_id>
JSL Sprite_ShowMessageUnconditional
LDY.b #(<message_id>)>>8
LDA.b #<message_id>
JSL Sprite_ShowMessageUnconditional
endmacro
; Make the sprite move towards the player at a speed of (speed)
macro MoveTowardPlayer(speed)
LDA.b #<speed>
JSL Sprite_ApplySpeedTowardsPlayer
JSL Sprite_MoveLong
LDA.b #<speed>
JSL Sprite_ApplySpeedTowardsPlayer
JSL Sprite_MoveLong
endmacro
; Prevent the player from passing through sprite hitbox
macro PlayerCantPassThrough()
JSL Sprite_PlayerCantPassThrough
JSL Sprite_PlayerCantPassThrough
endmacro
; Do damage to player on contact if sprite is on same layer as player
macro DoDamageToPlayerSameLayerOnContact()
JSL Sprite_CheckDamageToPlayerSameLayer
JSL Sprite_CheckDamageToPlayerSameLayer
endmacro
; Set harmless flag, 0 = harmful, 1 = harmless
macro SetHarmless(value)
LDA.w SprNbrOAM, X
AND #$7F
if <value> != 0
ORA.b #(<value>)<<7
endif
STA.w SprNbrOAM, X
LDA.w SprNbrOAM, X
AND #$7F
if <value> != 0
ORA.b #(<value>)<<7
endif
STA.w SprNbrOAM, X
endmacro
; Set Room Flag (Chest 6)
; Do not use if you have more than 5 chests or a small key under a pot
; in that room unless you want it to be already opened/taken
macro SetRoomFlag(value)
if <value> != 0
if <value> != 0
LDA $0403 : ORA #$20 : STA $0403
else
else
LDA $0403 : AND #$DF : STA $0403
endif
endif
endmacro
; Will prevent the player from moving or opening his menu
macro PreventPlayerMovement()
LDA #$01 : STA $02E4
LDA #$01 : STA $02E4
endmacro
; Will allow the player to move or open his menu
macro AllowPlayerMovement()
STZ.w $02E4
STZ.w $02E4
endmacro
; Enter 16bit mode
macro Set16bitmode()
REP #$30
REP #$30
endmacro
; Enter 8bit mode
macro Set8bitmode()
SEP #$30
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()
LDA $7EF360
LDA $7EF360
endmacro
; Set the velocity Y of the sprite at (speed) value
; this require the use of the function JSL Sprite_MoveLong
macro SetSpriteSpeedY(speed)
LDA.b #<speed> : STA.w SprYSpeed, x
LDA.b #<speed> : STA.w SprYSpeed, x
endmacro
; Set the velocity X of the sprite at (speed) value
; this require the use of the function JSL Sprite_MoveLong
macro SetSpriteSpeedX(speed)
LDA.b #<speed> : STA.w SprXSpeed, x
LDA.b #<speed> : STA.w SprXSpeed, x
endmacro
; Will play a sound SFX 1 See Zelda_3_RAM.log for more informations
macro PlaySFX1(sfxid)
LDA.b #<sfxid> : STA $012E
LDA.b #<sfxid> : STA $012E
endmacro
; Will play a sound SFX 2 See Zelda_3_RAM.log for more informations
macro PlaySFX2(sfxid)
LDA.b #<sfxid> : STA $012F
LDA.b #<sfxid> : STA $012F
endmacro
; Will play a music See Zelda_3_RAM.log for more informations
macro PlayMusic(musicid)
LDA.b #<musicid> : STA $012C
LDA.b #<musicid> : STA $012C
endmacro
; Will set the timer A to wait (length) amount of frames
macro SetTimerA(length)
LDA.b #<length> : STA.w SprTimerA, X
LDA.b #<length> : STA.w SprTimerA, X
endmacro
; Will set the timer B to wait (length) amount of frames
macro SetTimerB(length)
LDA.b #<length> : STA.w SprTimerB, X
LDA.b #<length> : STA.w SprTimerB, X
endmacro
; Will set the timer C to wait (length) amount of frames
macro SetTimerC(length)
LDA.b #<length> : STA.w SprTimerC, X
LDA.b #<length> : STA.w SprTimerC, X
endmacro
; Will set the timer D to wait (length) amount of frames
macro SetTimerD(length)
LDA.b #<length> : STA.w SprTimerD, X
LDA.b #<length> : STA.w SprTimerD, X
endmacro
; Will set the timer E to wait (length) amount of frames
macro SetTimerE(length)
LDA.b #<length> : STA.w SprTimerE, X
LDA.b #<length> : STA.w SprTimerE, X
endmacro
; Will set the timer F to wait (length) amount of frames
macro SetTimerF(length)
LDA.b #<length> : STA.w SprTimerF, X
LDA.b #<length> : STA.w SprTimerF, X
endmacro
macro NextAction()
INC $0D80, X
INC $0D80, X
endmacro
macro GetTilePos(x, y)
LDX.w #((<y>*$80)+(<x>*$02))
LDX.w #((<y>*$80)+(<x>*$02))
endmacro