Romhacking.net

Romhacking => Newcomer's Board => Topic started by: darcoza on November 06, 2020, 10:11:39 am

Title: Help w/ 6502 LDA $B1 instruction?
Post by: darcoza on November 06, 2020, 10:11:39 am
Hi! I'm trying to change which sprite is shown at a certain place on the screen for an NES game. I've tracked it down to the instruction that loads the sprite into the PPU, I can see that it goes somewhere and grabs the sprite location from somewhere using the LDA $B1 instruction, but for the life of me I cannot understand any of the explanations of this instruction to see if I can go find that location in the ROM file and change it to the sprite value that I want...

this is what the debugger says on the instruction:

00:AFC3:B1 2B     LDA ($2B),Y @ $B0B8 = #$60

I want to go find the location it pulled that #$60 from and change it to a different value like D4 which is currently blank so I can then draw in my own sprite. Can anyone explain how to calculate where that 60 is coming from?

Thanks!(https://drive.google.com/file/d/1-YXCnRt6VE-s9bnyq9qoYXXDmM8IYZHL/view?usp=sharing)
Title: Re: Help w/ 6502 LDA $B1 instruction?
Post by: Cyneprepou4uk on November 06, 2020, 05:26:01 pm
Debugger calculates the address for you and shows it after @, in your case it is $B0B8.

This addressing mode is called "post-indexed indirect". Indirect is when your final address is stored in 2 adjacent addresses in little-endian format. Indexed is adding value from an index register X or Y to the address. Post is adding index register after calculating indirect address.

LDA ($2B),Y = low byte at $002B, high byte at $002C. For example $002B = AB, $002C = 89. 89 & AB = $89AB. Then you add Y to this address to get $89AB-$8AAA range you can work with, which is 256 addresses in total. If Y = 05, then LDA ($2B),Y = $89AB + 05 = $89B0.
Title: Re: Help w/ 6502 LDA $B1 instruction?
Post by: darcoza on November 09, 2020, 03:38:02 pm
Thank you! I got it figured out!