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

Author Topic: NES Game sprite graphics routines  (Read 895 times)

Nalwonk

  • Newbie
  • *
  • Posts: 4
    • View Profile
NES Game sprite graphics routines
« on: April 10, 2020, 05:36:07 am »
Is there a simple trick to tracking down the graphics routines of sprites in NES games? 

FAST6191

  • Hero Member
  • *****
  • Posts: 2765
    • View Profile
Re: NES Game sprite graphics routines
« Reply #1 on: April 10, 2020, 10:23:59 am »
Same as any system really, give or take some systems maybe using another name for the memory handling sprites/objects.

Watch the OAM ( https://wiki.nesdev.com/w/index.php/PPU_OAM ), figure out what aspect of it is handling your desired sprite(s) -- your sprite viewer in the emulator might even tell you. Set a break on write to that section. Now you found at least one part of it (there might be others for later boss behaviours but it should be fairly obvious (or at least easy enough to figure out) when you scroll back up or step on forward where the IF ELSE type arrangement lands for that one.

If you have collisions separate to the sprites in your chosen game (hitboxes on the NES are a bit of a fun one compared to later systems) make sure to also handle those if you are changing things.

Disch

  • Hero Member
  • *****
  • Posts: 2813
  • NES Junkie
    • View Profile
Re: NES Game sprite graphics routines
« Reply #2 on: April 10, 2020, 10:29:23 am »
(FAST6191 lived up to his name and beat me to the punch, but I'll give my reply anyway.  ^^)

My usual approach is just to use the ASM sledgehammer.


Take a look at RAM to see if you can spot the page used for OAM data.  It will be exactly $100 bytes, and the entire block of it will [usually] be "rolling".  Most games either put it at the $0200 page or the $0700 page.  And large blocks of it will probably have $F8 or $FF every 4th byte.

If you are unsure or are unable to spot it visually, you can put a write breakpoint on $4014.  The game is likely writing that reg every frame, and the value written is the OAM data page number.  IE:  if the game is writing $02, then the OAM data is the $0200 page.

Then just put write breakpoints on bytes to that range and back-trace the code from there.  Note that games generally do not modify the actual OAM in the PPU directly so watching the real OAM in the PPU won't do you much good.  They will modify that $0200/$0700 page in RAM, and then the $4014 write copies the entire page to OAM in one big chunk.

Each sprite has 4 bytes of data:  Y position, tile graphic to use, flags/attributes, and X position.  Details can be found here:
https://wiki.nesdev.com/w/index.php/PPU_OAM


Depending on the game, it might be a laborious process, but it will always eventually get you there.   :thumbsup:

Nalwonk

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: NES Game sprite graphics routines
« Reply #3 on: April 14, 2020, 04:53:37 am »
Thanks, that helped a lot.  It was in $0200, and then I just tracked the writes to that area with the tile number I was looking for.  Kept jumping to different slots which was a bit of a pain in the butt, but I got it all worked out.