From 5a192edf13f16ceec49f69d9c1430ba81008f95d Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 13 Feb 2025 09:18:40 -0500 Subject: [PATCH] Move UpdateCachedCoords, RoundCoords to sprite_functions --- Core/sprite_functions.asm | 21 +++++++++++++++++++++ Sprites/Objects/minecart.asm | 34 ++-------------------------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Core/sprite_functions.asm b/Core/sprite_functions.asm index 3415b53..5222472 100644 --- a/Core/sprite_functions.asm +++ b/Core/sprite_functions.asm @@ -138,6 +138,27 @@ Sprite_InvertSpeed_Y: STA.w SprYSpeed, X RTL +UpdateCachedCoords: +{ + LDA.w SprY, X : STA.w SprCachedY+0 + LDA.w SprX, X : STA.w SprCachedX+0 + LDA.w SprYH, X : STA.w SprCachedY+1 + LDA.w SprXH, X : STA.w SprCachedX+1 + RTS +} + +RoundCoords: +{ + ; Clamp the Y coord to the nearest multiple of 8. + LDA.b $00 : CLC : ADC.b #$04 : AND.b #$F8 : STA.b $00 : STA.w SprY, X + + ; Clamp the X coord to the nearest multiple of 8. + LDA.b $02 : CLC : ADC.b #$04 : AND.b #$F8 : STA.b $02 : STA.w SprX, X + + JSR UpdateCachedCoords + RTS +} + ; ========================================================= Sprite_SelectNewDirection: diff --git a/Sprites/Objects/minecart.asm b/Sprites/Objects/minecart.asm index 56b3ee1..03daa1c 100644 --- a/Sprites/Objects/minecart.asm +++ b/Sprites/Objects/minecart.asm @@ -91,7 +91,7 @@ Right = $03 ; it in the same place upon returning to that room. ; There is a total possibility of 0x20 different subtypes that can be set. -; Therefore there can be a total of 0x20 different tracks. +; Therefore there can be a total of 0x20 different tracks. ; This value is used to keep track of which room the minecart was left ; in. Currently #$00 is reserved to keep track of new tracks that have @@ -154,10 +154,8 @@ Right = $03 Sprite_Minecart_Long: { PHB : PHK : PLB - JSR Sprite_Minecart_DrawTop ; Draw behind Link JSR Sprite_Minecart_DrawBottom ; Draw in front of Link - JSL Sprite_CheckActive : BCC .SpriteIsNotActive JSR Sprite_Minecart_Main .SpriteIsNotActive @@ -188,7 +186,7 @@ Sprite_Minecart_Prep: BRA .killMinecart .notInCart .notSameTrack - + REP #$20 ; Check if the track has already been initialized. If not we need to ; tell the game where the cart on the track starts @@ -275,7 +273,6 @@ Sprite_Minecart_Prep: .active2 STZ.w SprTimerB, X - LDA.w SprMiscB, X : CMP.b #$00 : BEQ .north CMP.b #$01 : BEQ .east CMP.b #$02 : BEQ .south @@ -1116,33 +1113,6 @@ CheckForTrackTiles: ; ========================================================= -; NOTE TO SCAWFUL: This function could really go in a generic sprite -; functions file but I'll leave that up to you. -UpdateCachedCoords: -{ - LDA.w SprY, X : STA.w SprCachedY+0 - LDA.w SprX, X : STA.w SprCachedX+0 - LDA.w SprYH, X : STA.w SprCachedY+1 - LDA.w SprXH, X : STA.w SprCachedX+1 - - RTS -} - -; NOTE TO SCAWFUL: This function could really go in a generic sprite -; functions file but I'll leave that up to you. -RoundCoords: -{ - ; Clamp the Y coord to the nearest multiple of 8. - LDA.b $00 : CLC : ADC.b #$04 : AND.b #$F8 : STA.b $00 : STA.w SprY, X - - ; Clamp the X coord to the nearest multiple of 8. - LDA.b $02 : CLC : ADC.b #$04 : AND.b #$F8 : STA.b $02 : STA.w SprX, X - - JSR UpdateCachedCoords - - RTS -} - ; $04 = sprite index of sprite ID $B0 ; SEC if sprite is present. CheckTrackSpritePresence: