Language…
7 users online: Bensalot, Cappaque, Golden Yoshi, gui, MorrieTheMagpie, pakkie, Zavok - Guests: 105 - Bots: 192
Users: 55,618 (2,425 active)
Latest user: CrazilyNutty

[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
Code
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
PHB : PHK : PLB
;... code that uses the tables ...
PLB


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).