35 users online: 1UPdudes, Abstract, Apple Boy, bandicoot, Big Brawler, Blizzard Buffalo, Carouco, CourtlyHades296, DKB95, Dumsmw,  Fernap, Fullcannon, Green, Hammerer, HmWhyNot, Housemeister, hugoballin, imamelia, Klug, Knight of Time, MrNapkino, racknae, RollingRigatonis, Ryrir, Scags, SF - The Dark Warrior, StarWolf3000, Stivi, SuperLuigiGaurdian4,  Telinc1, TheBourgyman, Tulip Time Scholarship Games, Wavee, wye, Yoshi Master - Guests: 180 - Bots: 198
Users: 64,347 (2,452 active)
Latest user: WouterBM

[Solved] Erroneous Sprite Displacement

Hey everyone,

I've been lurking for a long time, trying to learn ASM. Now is the first time I've genuinely been confused to the point where I don't think I can find any resources to help me about it.
I've been trying to make a relatively simple patch that makes it so that 1. you always throw a carried item in the direction you are holding on the d-pad (to remove spin-jump frame variance jank) and 2. if you are spinning and drop or up-throw an item, you throw it out from the center of mario, a la mario maker.
It all works, however, for some reason, part of my motified drop code doesn't properly work. The thing is, I basically copy-pasted the code from the the disassembly (from address $01A049, to be specific), so I don't know whats different and why it won't work.

What ends up happening is the item gets places a screen too early when facing right, and magically disappears when facing left. Even without the high-byte addition, the item drops ~32 pixels right of where its supposed to be.

Here's the code in question
DropLow:  db $F3, $0D ; Low-byte values, -13 and +13
DropHigh: db $FF, $00 ; High-byte values

LDA $D1        ; Get Mario's x-position
CLC            ; 
ADC DropLow,y  ; Add the relevant value
STA $E4,X      ; Set the carried sprite's x-position
LDA $D2        ; \
ADC DropHigh,y ; | Repeat for the high-byte
STA $14E0,X    ; /

Thank you in advance for anyone who helps!

Edit: Thank you guys! I guess I have to review addressing a little.
The problem with your code is that you aren't updating the data bank which causes the "ADC DropLow,y" to read from the address of DropLow but in a different bank

You can fix this by adding
;... code that uses the tables ...

which will update the data bank to the bank the code is currently running in.
The alternative is to transfer X to Y first and use that for the sprite tables so that you can use the X register for the tables and use long addressing (and obviously restore X).

My method has got the disadvantage that it takes a bit more space and is slower but the advantage is that the patch can be put in anywhere in the ROM and not just in the first 2MB (and change the "freecode" to "freedata", that's it).