Update sprite macros for draw code, add new macros

This commit is contained in:
scawful
2024-12-19 09:44:08 -05:00
parent 548379f95a
commit 2a996a69e5
7 changed files with 179 additions and 310 deletions

View File

@@ -1,47 +1,57 @@
; Write Sprite Properties in the rom MACRO ; Write Sprite Properties in the rom MACRO
macro Set_Sprite_Properties(SprPrep, SprMain) macro Set_Sprite_Properties(SprPrep, SprMain)
{
pushpc ; Save writing Position for the sprite
org $0DB080+!SPRID ; Oam Harmless ($0E40)
db ((!Harmless<<7)|(!HVelocity<<6)|!NbrTiles)
pushpc ; Save writing Position for the sprite org $0DB173+!SPRID ; Sprite HP ($0E50)
org $0DB080+!SPRID ; Oam Harmless ($0E40) db !Health
db ((!Harmless<<7)|(!HVelocity<<6)|!NbrTiles)
org $0DB173+!SPRID ; Sprite HP ($0E50) org $0DB266+!SPRID ; Sprite Damage ($0CD2)
db !Health db !Damage
org $0DB266+!SPRID ; Sprite Damage ($0CD2) org $0DB359+!SPRID ; Sprite Data ($0E60 / $0F50)
db !Damage db ((!DeathAnimation<<7)|(!ImperviousAll<<6)|(!SmallShadow<<5)|(!Shadow<<4)|(!Palette<<1))
org $0DB359+!SPRID ; Sprite Data ($0E60 / $0F50) org $0DB44C+!SPRID ; Sprite Hitbox ($0F60)
db ((!DeathAnimation<<7)|(!ImperviousAll<<6)|(!SmallShadow<<5)|(!Shadow<<4)|(!Palette<<1)) db ((!CollisionLayer<<7)|(!Statis<<6)|(!Persist<<5)|(!Hitbox))
org $0DB44C+!SPRID ; Sprite Hitbox ($0F60) org $0DB53F+!SPRID ; Sprite Fall ($0B6B)
db ((!CollisionLayer<<7)|(!Statis<<6)|(!Persist<<5)|(!Hitbox)) db ((!DeflectArrow<<3)|(!Boss<<1)|!CanFall)
org $0DB53F+!SPRID ; Sprite Fall ($0B6B) org $0DB632+!SPRID ; Sprite Prize ($0BE0)
db ((!DeflectArrow<<3)|(!Boss<<1)|!CanFall) db ((!Interaction<<7)|(!WaterSprite<<6)|(!Blockable<<5)|(!Sound<<4)|!Prize)
org $0DB632+!SPRID ; Sprite Prize ($0BE0) org $0DB725+!SPRID ; Sprite ($0CAA)
db ((!Interaction<<7)|(!WaterSprite<<6)|(!Blockable<<5)|(!Sound<<4)|!Prize) db ($40|(!Statue<<5)|(!DeflectProjectiles<<4)|(!ImpervSwordHammer<<2)|(!ImperviousArrow<<1))
org $0DB725+!SPRID ; Sprite ($0CAA) org $069283+(!SPRID*2) ; Vanilla Sprite Main Pointer
db ($40|(!Statue<<5)|(!DeflectProjectiles<<4)|(!ImpervSwordHammer<<2)|(!ImperviousArrow<<1)) dw NewMainSprFunction
org $069283+(!SPRID*2) ; Vanilla Sprite Main Pointer org $06865B+(!SPRID*2) ; Vanilla Sprite Prep Pointer
dw NewMainSprFunction dw NewSprPrepFunction
org $06865B+(!SPRID*2) ; Vanilla Sprite Prep Pointer org NewSprRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer
dw NewSprPrepFunction dl <SprMain>
org NewSprRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer
dl <SprMain>
org NewSprPrepRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer
dl <SprPrep>
pullpc ; Get back the writing position for the sprite
org NewSprPrepRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer
dl <SprPrep>
pullpc ; Get back the writing position for the sprite
}
endmacro
macro loop(body, ...)
!x #= 0
while !x < sizeof(...)
!x #= !x+1
endwhile
endmacro
macro sta(...)
%loop(STA, ...)
endmacro endmacro
; Go to the action specified ID can be Hex or Decimal
macro GotoAction(action) macro GotoAction(action)
LDA.b #<action> : STA.w SprAction, X LDA.b #<action> : STA.w SprAction, X
endmacro endmacro
@@ -70,12 +80,14 @@ macro SetMode(bit_mode)
endmacro endmacro
macro ScopedMode(bit_mode, body) macro ScopedMode(bit_mode, body)
SetMode bit_mode
body
if <bit_mode> == "16bit" if <bit_mode> == "16bit"
SetMode "8bit" %SetMode("16bit")
<body>
%SetMode("8bit")
elseif <bit_mode> == "8bit" elseif <bit_mode> == "8bit"
SetMode "16bit" %SetMode("8bit")
<body>
%SetMode("16bit")
endif endif
endmacro endmacro
@@ -307,3 +319,44 @@ macro SetupDistanceFromSprite()
LDA.w SprY, X : STA $05 LDA.w SprY, X : STA $05
endmacro endmacro
macro DrawSprite()
{
JSL Sprite_PrepOamCoord
JSL Sprite_OAM_AllocateDeferToPlayer
LDA.w SprGfx, X : CLC : ADC.w SprFrame, X : TAY
LDA.w .start_index, Y : STA $06
LDA.w SprFlash, X : STA $08
PHX
LDX .nbr_of_tiles, Y ; amount of tiles -1
LDY.b #$00
.nextTile
PHX ; Save current Tile Index?
TXA : CLC : ADC $06 ; Add Animation Index Offset
PHA ; Keep the value with animation index offset?
ASL A : TAX
REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y
AND.w #$0100 : STA $0E
INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100
SEP #$20
BCC .on_screen_y
; Put the sprite out of the way
LDA.b #$F0 : STA ($90), Y : STA $0E
.on_screen_y
PLX ; Pullback Animation Index Offset (without the *2 not 16bit anymore)
INY
LDA .chr, X : STA ($90), Y
INY
LDA .properties, X : ORA $08 : STA ($90), Y
PHY
TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY
PLX : DEX : BPL .nextTile
PLX
RTS
}
endmacro

View File

@@ -110,7 +110,6 @@ Sprite_BusinessScrub_Main:
JSL Sprite_IsBelowPlayer : TYA JSL Sprite_IsBelowPlayer : TYA
CMP #$00 : BNE .is_below_player CMP #$00 : BNE .is_below_player
; Check if the player is too close ; Check if the player is too close
%SetupDistanceFromSprite()
JSL GetDistance8bit_Long : CMP.b #$24 : BCC .too_close JSL GetDistance8bit_Long : CMP.b #$24 : BCC .too_close
; The player is below the scrub, so it should pop up ; The player is below the scrub, so it should pop up
LDA #$20 : STA.w SprTimerA, X LDA #$20 : STA.w SprTimerA, X
@@ -138,7 +137,6 @@ Sprite_BusinessScrub_Main:
INC.w SprAction, X INC.w SprAction, X
.not_done .not_done
%SetupDistanceFromSprite()
JSL GetDistance8bit_Long : CMP #$18 : BCS .not_too_close JSL GetDistance8bit_Long : CMP #$18 : BCS .not_too_close
%GotoAction(0) %GotoAction(0)
.not_too_close .not_too_close

View File

@@ -74,16 +74,12 @@ Sprite_HelmetChuchu_Prep:
Sprite_HelmetChuchu_Main: Sprite_HelmetChuchu_Main:
{ {
JSL Sprite_DamageFlash_Long JSL Sprite_DamageFlash_Long
%SpriteJumpTable(GreenChuchu_Helmet,
LDA.w SprAction, X GreenChuchu_NoHelmet,
JSL UseImplicitRegIndexedLocalJumpTable RedChuchu_Masked,
RedChuchu_NoMask,
dw GreenChuchu_Helmet HelmetSubtype,
dw GreenChuchu_NoHelmet MaskSubtype)
dw RedChuchu_Masked
dw RedChuchu_NoMask
dw HelmetSubtype
dw MaskSubtype
GreenChuchu_Helmet: GreenChuchu_Helmet:
{ {

View File

@@ -283,7 +283,6 @@ Sprite_WaterOctorok_Attack:
RTS RTS
+ +
%SetupDistanceFromSprite()
JSL GetDistance8bit_Long JSL GetDistance8bit_Long
CMP.b #$40 CMP.b #$40
BCC .not_close_enough ; LD < 64 BCC .not_close_enough ; LD < 64

View File

@@ -3,7 +3,7 @@
; ========================================================= ; =========================================================
!SPRID = Sprite_PolsVoice !SPRID = Sprite_PolsVoice
!NbrTiles = 02 ; Number of tiles used in a frame !NbrTiles = 03 ; Number of tiles used in a frame
!Harmless = 00 ; 00 = Sprite is Harmful, 01 = Sprite is Harmless !Harmless = 00 ; 00 = Sprite is Harmful, 01 = Sprite is Harmless
!HVelocity = 00 ; Is your sprite going super fast? put 01 if it is !HVelocity = 00 ; Is your sprite going super fast? put 01 if it is
!Health = 10 ; Number of Health the sprite have !Health = 10 ; Number of Health the sprite have
@@ -78,7 +78,6 @@ Sprite_PolsVoice_Main:
JSL Sprite_BounceFromTileCollision JSL Sprite_BounceFromTileCollision
JSL Sprite_DamageFlash_Long JSL Sprite_DamageFlash_Long
%DoDamageToPlayerSameLayerOnContact() %DoDamageToPlayerSameLayerOnContact()
JSL GetRandomInt : AND #$3F : BNE .not_done JSL GetRandomInt : AND #$3F : BNE .not_done
@@ -133,63 +132,7 @@ Sprite_PolsVoice_Main:
Sprite_PolsVoice_Draw: Sprite_PolsVoice_Draw:
{ {
JSL Sprite_PrepOamCoord %DrawSprite()
JSL Sprite_OAM_AllocateDeferToPlayer
LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame
LDA .start_index, Y : STA $06
LDA.w SprFlash, X : STA $08
PHX
LDX .nbr_of_tiles, Y ;amount of tiles -1
LDY.b #$00
.nextTile
PHX ; Save current Tile Index?
TXA : CLC : ADC $06 ; Add Animation Index Offset
PHA ; Keep the value with animation index offset?
ASL A : TAX
REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y
AND.w #$0100 : STA $0E
INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100
SEP #$20
BCC .on_screen_y
LDA.b #$F0 : STA ($90), Y ;Put the sprite out of the way
STA $0E
.on_screen_y
PLX ; Pullback Animation Index Offset (without the *2 not 16bit anymore)
INY
LDA .chr, X : STA ($90), Y
INY
LDA .properties, X : ORA $08 : STA ($90), Y
PHY
TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY
PLX : DEX : BPL .nextTile
PLX
RTS
; =======================================================
.start_index .start_index
db $00, $01, $02, $03, $04 db $00, $01, $02, $03, $04

View File

@@ -63,13 +63,9 @@ Sprite_Puffstool_Prep:
Sprite_Puffstool_Main: Sprite_Puffstool_Main:
{ {
LDA.w SprAction, X %SpriteJumpTable(Puffstool_Walking,
JSL UseImplicitRegIndexedLocalJumpTable Puffstool_Stunned,
Puffstool_Spores)
dw Puffstool_Walking
dw Puffstool_Stunned
dw Puffstool_Spores
Puffstool_Walking: Puffstool_Walking:
{ {
@@ -140,20 +136,14 @@ Puffstool_SpawnSpores:
LDA.b #$0C ; SFX2.0C LDA.b #$0C ; SFX2.0C
JSL $0DBB7C ; SpriteSFX_QueueSFX2WithPan JSL $0DBB7C ; SpriteSFX_QueueSFX2WithPan
LDA.b #$03 LDA.b #$03 : STA.b $0D
STA.b $0D
.nth_child .nth_child
LDA.b #$B1 ; SPRITE 10 LDA.b #$B1 : JSL Sprite_SpawnDynamically : BMI .no_space
JSL Sprite_SpawnDynamically
BMI .no_space
JSL Sprite_SetSpawnedCoordinates JSL Sprite_SetSpawnedCoordinates
PHX PHX
LDX.b $0D LDX.b $0D
LDA.w .speed_x, X : STA.w SprXSpeed, Y LDA.w .speed_x, X : STA.w SprXSpeed, Y
LDA.w .speed_y, X : STA.w SprYSpeed, Y LDA.w .speed_y, X : STA.w SprYSpeed, Y
LDA.b #$20 : STA.w $0F80, Y LDA.b #$20 : STA.w $0F80, Y
@@ -163,7 +153,6 @@ Puffstool_SpawnSpores:
LDA.b #$02 : STA.w SprAction, Y LDA.b #$02 : STA.w SprAction, Y
PLX PLX
.no_space .no_space
DEC.b $0D DEC.b $0D
BPL .nth_child BPL .nth_child
@@ -180,56 +169,7 @@ Puffstool_SpawnSpores:
Sprite_Puffstool_Draw: Sprite_Puffstool_Draw:
{ {
JSL Sprite_PrepOamCoord %DrawSprite()
JSL Sprite_OAM_AllocateDeferToPlayer
LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame
LDA .start_index, Y : STA $06
LDA.w SprFlash, X : STA $08 ; Palette damage flash
PHX
LDX .nbr_of_tiles, Y ;amount of tiles -1
LDY.b #$00
.nextTile
PHX ; Save current Tile Index?
TXA : CLC : ADC $06 ; Add Animation Index Offset
PHA ; Keep the value with animation index offset?
ASL A : TAX
REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y
AND.w #$0100 : STA $0E
INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100
SEP #$20
BCC .on_screen_y
LDA.b #$F0 : STA ($90), Y ;Put the sprite out of the way
STA $0E
.on_screen_y
PLX ; Pullback Animation Index Offset (without the *2 not 16bit anymore)
INY
LDA .chr, X : STA ($90), Y
INY
LDA .properties, X : ORA $08 : STA ($90), Y
PHY
TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY
PLX : DEX : BPL .nextTile
PLX
RTS
; =========================================================
.start_index .start_index
db $00, $02, $04, $06, $08, $0A, $0C, $0E, $0F, $10, $11, $12 db $00, $02, $04, $06, $08, $0A, $0C, $0E, $0F, $10, $11, $12

View File

@@ -47,7 +47,6 @@ Sprite_ThunderGhost_Long:
RTL RTL
} }
Sprite_ThunderGhost_Prep: Sprite_ThunderGhost_Prep:
{ {
PHB : PHK : PLB PHB : PHK : PLB
@@ -66,14 +65,11 @@ Sprite_ThunderGhost_Prep:
Sprite_ThunderGhost_Main: Sprite_ThunderGhost_Main:
{ {
LDA.w SprAction, X %SpriteJumpTable(ThunderGhostFaceForward,
JSL UseImplicitRegIndexedLocalJumpTable ThunderGhostLeft,
ThunderGhostRight,
dw ThunderGhostFaceForward CastThunderLeft,
dw ThunderGhostLeft CastThunderRight)
dw ThunderGhostRight
dw CastThunderLeft
dw CastThunderRight
ThunderGhostFaceForward: ThunderGhostFaceForward:
{ {
@@ -124,7 +120,6 @@ Sprite_ThunderGhost_Main:
} }
} }
Sprite_ThunderGhost_Move: Sprite_ThunderGhost_Move:
{ {
JSL Sprite_Move JSL Sprite_Move
@@ -215,63 +210,8 @@ SpawnLightningAttack:
Sprite_ThunderGhost_Draw: Sprite_ThunderGhost_Draw:
{ {
JSL Sprite_PrepOamCoord %DrawSprite()
JSL Sprite_OAM_AllocateDeferToPlayer
LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame
LDA .start_index, Y : STA $06
LDA.w SprFlash, X : STA $08
PHX
LDX .nbr_of_tiles, Y ;amount of tiles -1
LDY.b #$00
.nextTile
PHX ; Save current Tile Index?
TXA : CLC : ADC $06 ; Add Animation Index Offset
PHA ; Keep the value with animation index offset?
ASL A : TAX
REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y
AND.w #$0100 : STA $0E
INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100
SEP #$20
BCC .on_screen_y
LDA.b #$F0 : STA ($90), Y ;Put the sprite out of the way
STA $0E
.on_screen_y
PLX ; Pullback Animation Index Offset (without the *2 not 16bit anymore)
INY
LDA .chr, X : STA ($90), Y
INY
LDA .properties, X : ORA $08 : STA ($90), Y
PHY
TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY
PLX : DEX : BPL .nextTile
PLX
RTS
; =======================================================
.start_index .start_index
db $00, $03, $06, $09, $0C, $0F, $12, $15 db $00, $03, $06, $09, $0C, $0F, $12, $15
.nbr_of_tiles .nbr_of_tiles