diff --git a/Core/sprite_macros.asm b/Core/sprite_macros.asm index 34619b0..ce636e7 100644 --- a/Core/sprite_macros.asm +++ b/Core/sprite_macros.asm @@ -1,47 +1,57 @@ ; Write Sprite Properties in the rom MACRO 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 $0DB080+!SPRID ; Oam Harmless ($0E40) -db ((!Harmless<<7)|(!HVelocity<<6)|!NbrTiles) + org $0DB173+!SPRID ; Sprite HP ($0E50) + db !Health -org $0DB173+!SPRID ; Sprite HP ($0E50) -db !Health + org $0DB266+!SPRID ; Sprite Damage ($0CD2) + db !Damage -org $0DB266+!SPRID ; Sprite Damage ($0CD2) -db !Damage + org $0DB359+!SPRID ; Sprite Data ($0E60 / $0F50) + db ((!DeathAnimation<<7)|(!ImperviousAll<<6)|(!SmallShadow<<5)|(!Shadow<<4)|(!Palette<<1)) -org $0DB359+!SPRID ; Sprite Data ($0E60 / $0F50) -db ((!DeathAnimation<<7)|(!ImperviousAll<<6)|(!SmallShadow<<5)|(!Shadow<<4)|(!Palette<<1)) + org $0DB44C+!SPRID ; Sprite Hitbox ($0F60) + db ((!CollisionLayer<<7)|(!Statis<<6)|(!Persist<<5)|(!Hitbox)) -org $0DB44C+!SPRID ; Sprite Hitbox ($0F60) -db ((!CollisionLayer<<7)|(!Statis<<6)|(!Persist<<5)|(!Hitbox)) + org $0DB53F+!SPRID ; Sprite Fall ($0B6B) + db ((!DeflectArrow<<3)|(!Boss<<1)|!CanFall) -org $0DB53F+!SPRID ; Sprite Fall ($0B6B) -db ((!DeflectArrow<<3)|(!Boss<<1)|!CanFall) + org $0DB632+!SPRID ; Sprite Prize ($0BE0) + db ((!Interaction<<7)|(!WaterSprite<<6)|(!Blockable<<5)|(!Sound<<4)|!Prize) -org $0DB632+!SPRID ; Sprite Prize ($0BE0) -db ((!Interaction<<7)|(!WaterSprite<<6)|(!Blockable<<5)|(!Sound<<4)|!Prize) + org $0DB725+!SPRID ; Sprite ($0CAA) + db ($40|(!Statue<<5)|(!DeflectProjectiles<<4)|(!ImpervSwordHammer<<2)|(!ImperviousArrow<<1)) -org $0DB725+!SPRID ; Sprite ($0CAA) -db ($40|(!Statue<<5)|(!DeflectProjectiles<<4)|(!ImpervSwordHammer<<2)|(!ImperviousArrow<<1)) + org $069283+(!SPRID*2) ; Vanilla Sprite Main Pointer + dw NewMainSprFunction -org $069283+(!SPRID*2) ; Vanilla Sprite Main Pointer -dw NewMainSprFunction + org $06865B+(!SPRID*2) ; Vanilla Sprite Prep Pointer + dw NewSprPrepFunction -org $06865B+(!SPRID*2) ; Vanilla Sprite Prep Pointer -dw NewSprPrepFunction - -org NewSprRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer -dl - -org NewSprPrepRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer -dl -pullpc ; Get back the writing position for the sprite + org NewSprRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer + dl + org NewSprPrepRoutinesLong+(!SPRID*3) ; New Long Sprite Pointer + dl + 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 -; Go to the action specified ID can be Hex or Decimal macro GotoAction(action) LDA.b # : STA.w SprAction, X endmacro @@ -70,12 +80,14 @@ macro SetMode(bit_mode) endmacro macro ScopedMode(bit_mode, body) - SetMode bit_mode - body if == "16bit" - SetMode "8bit" + %SetMode("16bit") + + %SetMode("8bit") elseif == "8bit" - SetMode "16bit" + %SetMode("8bit") + + %SetMode("16bit") endif endmacro @@ -307,3 +319,44 @@ macro SetupDistanceFromSprite() LDA.w SprY, X : STA $05 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 + diff --git a/Sprites/Enemies/business_scrub.asm b/Sprites/Enemies/business_scrub.asm index 44bc6b0..1d3d2c8 100644 --- a/Sprites/Enemies/business_scrub.asm +++ b/Sprites/Enemies/business_scrub.asm @@ -110,7 +110,6 @@ Sprite_BusinessScrub_Main: JSL Sprite_IsBelowPlayer : TYA CMP #$00 : BNE .is_below_player ; Check if the player is too close - %SetupDistanceFromSprite() JSL GetDistance8bit_Long : CMP.b #$24 : BCC .too_close ; The player is below the scrub, so it should pop up LDA #$20 : STA.w SprTimerA, X @@ -138,7 +137,6 @@ Sprite_BusinessScrub_Main: INC.w SprAction, X .not_done - %SetupDistanceFromSprite() JSL GetDistance8bit_Long : CMP #$18 : BCS .not_too_close %GotoAction(0) .not_too_close diff --git a/Sprites/Enemies/helmet_chuchu.asm b/Sprites/Enemies/helmet_chuchu.asm index 313a212..c4b1905 100644 --- a/Sprites/Enemies/helmet_chuchu.asm +++ b/Sprites/Enemies/helmet_chuchu.asm @@ -74,16 +74,12 @@ Sprite_HelmetChuchu_Prep: Sprite_HelmetChuchu_Main: { JSL Sprite_DamageFlash_Long - - LDA.w SprAction, X - JSL UseImplicitRegIndexedLocalJumpTable - - dw GreenChuchu_Helmet - dw GreenChuchu_NoHelmet - dw RedChuchu_Masked - dw RedChuchu_NoMask - dw HelmetSubtype - dw MaskSubtype + %SpriteJumpTable(GreenChuchu_Helmet, + GreenChuchu_NoHelmet, + RedChuchu_Masked, + RedChuchu_NoMask, + HelmetSubtype, + MaskSubtype) GreenChuchu_Helmet: { diff --git a/Sprites/Enemies/octorok.asm b/Sprites/Enemies/octorok.asm index 203ded1..b83788c 100644 --- a/Sprites/Enemies/octorok.asm +++ b/Sprites/Enemies/octorok.asm @@ -283,7 +283,6 @@ Sprite_WaterOctorok_Attack: RTS + - %SetupDistanceFromSprite() JSL GetDistance8bit_Long CMP.b #$40 BCC .not_close_enough ; LD < 64 diff --git a/Sprites/Enemies/pols_voice.asm b/Sprites/Enemies/pols_voice.asm index 104e7b1..ea046e2 100644 --- a/Sprites/Enemies/pols_voice.asm +++ b/Sprites/Enemies/pols_voice.asm @@ -3,7 +3,7 @@ ; ========================================================= !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 !HVelocity = 00 ; Is your sprite going super fast? put 01 if it is !Health = 10 ; Number of Health the sprite have @@ -78,7 +78,6 @@ Sprite_PolsVoice_Main: JSL Sprite_BounceFromTileCollision JSL Sprite_DamageFlash_Long - %DoDamageToPlayerSameLayerOnContact() JSL GetRandomInt : AND #$3F : BNE .not_done @@ -133,63 +132,7 @@ Sprite_PolsVoice_Main: Sprite_PolsVoice_Draw: { - JSL Sprite_PrepOamCoord - 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 - - - ; ======================================================= + %DrawSprite() .start_index db $00, $01, $02, $03, $04 diff --git a/Sprites/Enemies/puffstool.asm b/Sprites/Enemies/puffstool.asm index 2c22572..84f9ac0 100644 --- a/Sprites/Enemies/puffstool.asm +++ b/Sprites/Enemies/puffstool.asm @@ -63,13 +63,9 @@ Sprite_Puffstool_Prep: Sprite_Puffstool_Main: { - LDA.w SprAction, X - JSL UseImplicitRegIndexedLocalJumpTable - - dw Puffstool_Walking - dw Puffstool_Stunned - - dw Puffstool_Spores + %SpriteJumpTable(Puffstool_Walking, + Puffstool_Stunned, + Puffstool_Spores) Puffstool_Walking: { @@ -140,30 +136,23 @@ Puffstool_SpawnSpores: LDA.b #$0C ; SFX2.0C JSL $0DBB7C ; SpriteSFX_QueueSFX2WithPan - LDA.b #$03 - STA.b $0D + LDA.b #$03 : STA.b $0D .nth_child - LDA.b #$B1 ; SPRITE 10 - JSL Sprite_SpawnDynamically - BMI .no_space + LDA.b #$B1 : JSL Sprite_SpawnDynamically : BMI .no_space + JSL Sprite_SetSpawnedCoordinates + PHX - JSL Sprite_SetSpawnedCoordinates - - PHX - - LDX.b $0D - - LDA.w .speed_x, X : STA.w SprXSpeed, Y - LDA.w .speed_y, X : STA.w SprYSpeed, Y - LDA.b #$20 : STA.w $0F80, Y - LDA.b #$FF : STA.w $0E80, Y - LDA.b #$40 : STA.w SprTimerC, Y - LDA.b #$01 : STA.w SprSubtype, Y - LDA.b #$02 : STA.w SprAction, Y - - PLX + LDX.b $0D + LDA.w .speed_x, X : STA.w SprXSpeed, Y + LDA.w .speed_y, X : STA.w SprYSpeed, Y + LDA.b #$20 : STA.w $0F80, Y + LDA.b #$FF : STA.w $0E80, Y + LDA.b #$40 : STA.w SprTimerC, Y + LDA.b #$01 : STA.w SprSubtype, Y + LDA.b #$02 : STA.w SprAction, Y + PLX .no_space DEC.b $0D BPL .nth_child @@ -180,124 +169,75 @@ Puffstool_SpawnSpores: Sprite_Puffstool_Draw: { - JSL Sprite_PrepOamCoord - 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 - - ; ========================================================= + %DrawSprite() .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 .nbr_of_tiles - db 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 + db 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 .x_offsets - dw 0, 0 - dw 0, 0 - dw 0, 0 - dw 0, 0 - dw 0, 0 - dw 0, 0 - dw 0, 0 - dw 0 - dw 0 - dw 0 - dw 0 - dw 4 + dw 0, 0 + dw 0, 0 + dw 0, 0 + dw 0, 0 + dw 0, 0 + dw 0, 0 + dw 0, 0 + dw 0 + dw 0 + dw 0 + dw 0 + dw 4 .y_offsets - dw -8, 0 - dw 0, -8 - dw 0, -8 - dw 0, -8 - dw 0, -8 - dw 0, -8 - dw 0, -8 - dw 0 - dw 0 - dw 0 - dw 0 - dw 4 + dw -8, 0 + dw 0, -8 + dw 0, -8 + dw 0, -8 + dw 0, -8 + dw 0, -8 + dw 0, -8 + dw 0 + dw 0 + dw 0 + dw 0 + dw 4 .chr - db $C0, $D0 - db $D2, $C2 - db $D4, $C4 - db $D2, $C2 - db $D0, $C0 - db $D2, $C2 - db $D4, $C4 - db $D6 - db $EA - db $C8 - db $E8 - db $F7 + db $C0, $D0 + db $D2, $C2 + db $D4, $C4 + db $D2, $C2 + db $D0, $C0 + db $D2, $C2 + db $D4, $C4 + db $D6 + db $EA + db $C8 + db $E8 + db $F7 .properties - db $33, $33 - db $33, $33 - db $33, $33 - db $33, $33 - db $33, $33 - db $73, $73 - db $73, $73 - db $3D - db $33 - db $33 - db $33 - db $33 + db $33, $33 + db $33, $33 + db $33, $33 + db $33, $33 + db $33, $33 + db $73, $73 + db $73, $73 + db $3D + db $33 + db $33 + db $33 + db $33 .sizes - db $02, $02 - db $02, $02 - db $02, $02 - db $02, $02 - db $02, $02 - db $02, $02 - db $02, $02 - db $02 - db $02 - db $02 - db $02 - db $00 + db $02, $02 + db $02, $02 + db $02, $02 + db $02, $02 + db $02, $02 + db $02, $02 + db $02, $02 + db $02 + db $02 + db $02 + db $02 + db $00 } diff --git a/Sprites/Enemies/thunder_ghost.asm b/Sprites/Enemies/thunder_ghost.asm index c5f0497..f8b2c3e 100644 --- a/Sprites/Enemies/thunder_ghost.asm +++ b/Sprites/Enemies/thunder_ghost.asm @@ -47,7 +47,6 @@ Sprite_ThunderGhost_Long: RTL } - Sprite_ThunderGhost_Prep: { PHB : PHK : PLB @@ -66,14 +65,11 @@ Sprite_ThunderGhost_Prep: Sprite_ThunderGhost_Main: { - LDA.w SprAction, X - JSL UseImplicitRegIndexedLocalJumpTable - - dw ThunderGhostFaceForward - dw ThunderGhostLeft - dw ThunderGhostRight - dw CastThunderLeft - dw CastThunderRight + %SpriteJumpTable(ThunderGhostFaceForward, + ThunderGhostLeft, + ThunderGhostRight, + CastThunderLeft, + CastThunderRight) ThunderGhostFaceForward: { @@ -124,7 +120,6 @@ Sprite_ThunderGhost_Main: } } - Sprite_ThunderGhost_Move: { JSL Sprite_Move @@ -215,63 +210,8 @@ SpawnLightningAttack: Sprite_ThunderGhost_Draw: { - JSL Sprite_PrepOamCoord - JSL Sprite_OAM_AllocateDeferToPlayer + %DrawSprite() - 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 db $00, $03, $06, $09, $0C, $0F, $12, $15 .nbr_of_tiles