News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Help w/ 6502 LDA $B1 instruction?  (Read 451 times)

darcoza

  • Jr. Member
  • **
  • Posts: 6
    • View Profile
Help w/ 6502 LDA $B1 instruction?
« 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!

Cyneprepou4uk

  • Hero Member
  • *****
  • Posts: 573
  • I am the baldest romhacker
    • View Profile
Re: Help w/ 6502 LDA $B1 instruction?
« Reply #1 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.
« Last Edit: November 12, 2020, 12:23:59 am by Cyneprepou4uk »
iromhacker.ru - NES ROM hacking tutorials for beginners. Please use Google Translate browser extension

darcoza

  • Jr. Member
  • **
  • Posts: 6
    • View Profile
Re: Help w/ 6502 LDA $B1 instruction?
« Reply #2 on: November 09, 2020, 03:38:02 pm »
Thank you! I got it figured out!