;Perfect Sprite initial facing fix, By GreenHammerBro ;This uberasm code fixes a bug in smw that if you go to another (sub)level, ;the sprite's init facing in the next level will use mario's last x position ;in the previous level. ;Unlike Alcaro's patch, this one is guaranteed it will always work. ;Insert this code in "gamemode_init_14" (level mode init, not to be confused ;with regular gamemode 13 (level load, that is, runs multiple frames during ;fading)). if !SA1 ;Sa-1 stuff: !NumbOfSprSlots = 22 !SprTbl_E4 = $322C ;>Sprite x pos, lo byte !SprTbl_14E0 = $326E ;>Sprite x pos, hi byte !SprTbl_157C = $3334 ;>Sprite horiz facing 0 = R, 1 = L else ;Non-sa-1 stuff: !NumbOfSprSlots = 12 !SprTbl_E4 = $E4 ;>Sprite x pos, lo byte !SprTbl_14E0 = $14E0 ;>Sprite x pos, hi byte !SprTbl_157C = $157C ;>Sprite horiz facing 0 = R, 1 = L endif FixFacing: LDX.b #!NumbOfSprSlots-1 ;>Start loop. .SlotLoop STZ !SprTbl_157C,x ;>Starts out as going right. LDA !SprTbl_14E0,x ;\Transfer sprite high byte XBA ;/to high byte of A LDA !SprTbl_E4,x ;>Load the low byte position REP #$20 CMP $94 ;>Compare with the player's x position (low and high) SEP #$20 BMI .SprOnLeft ;>If sprite is left of player, leave $157C as zero ;SprOnLeft INC !SprTbl_157C,x ;>Otherwise, make $157C = 1 to go left. .SprOnLeft DEX ;>Next slot BPL .SlotLoop ;>If slot is 0 or positive, loop. RTS