;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;This code will measure the displacement distance (signed) ;;of the sprite. The purpose is so that when making moving ;;platforms, you can have an x or y speed not multiple of ;;+/- #$10 without the need of lookup tables to move the player ;;relative with it. It does this by subtracting its final ;;position from its current position and using that value ;;to add it to the player's position. ;; ;;NOTE: If you plan to have the player spawn ON a platform when ;;the level loads, I recommend also using this subroutine since ;;the freeram does not clear automatically, causing the player ;;to "teleport". ;; ;;Output (when routine is done): ;; ;;$00 = [2 bytes], X position displacement ;;$02 = [2 bytes], Y position displacement ;; ;; !TableSize = 12 ;;^Max amount of sprites processed in decimal. 12 for ;;regular ROM, 22 for SA-1. This is also the table size ;;in bytes. ;; !Freeram_SavedXPosL = $7F8327 !Freeram_SavedXPosH = $7FC7BD !Freeram_SavedYPosL = $7FC7D3 !Freeram_SavedYPosH = $7FC7E9 ;;^Their size depends on !TableSize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MeasureDisplacement: LDA !Freeram_SavedXPosH,x ;\Store previous X position into $00 XBA ;| LDA !Freeram_SavedXPosL,x ;| REP #$20 ;| STA $00 ;| SEP #$20 ;/ LDA $14E0,x ;\Load current X position into A XBA ;| LDA $E4,x ;/ REP #$20 ;\final position subtract by inital SEC ;|position = displacement stored in $00 SBC $00 ;|its signed, so if it moves left, STA $00 ;|its gunna be negative. SEP #$20 ;/ LDA !Freeram_SavedYPosH,x ;\Store previous Y position into $02 XBA ;| LDA !Freeram_SavedYPosL,x ;| REP #$20 ;| STA $02 ;| SEP #$20 ;/ LDA $14D4,x ;\Load current Y position into A XBA ;| LDA $D8,x ;/ REP #$20 ;\final position subtract by inital SEC ;|position = displacement stored in $02 SBC $02 ;|its signed, so if it moves up, STA $02 ;|its gunna be negative. SEP #$20 ;/ ;This is so that if the sprite moves again for the 3rd frame. LDA $E4,x ;\update for next X position displacement STA !Freeram_SavedXPosL,x ;| LDA $14E0 ;| STA !Freeram_SavedXPosH,x ;/ LDA $D8,x ;\update for next Y position displacement STA !Freeram_SavedYPosL,x ;| LDA $14D4,x ;| STA !Freeram_SavedYPosH,x ;/ RTS