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

Author Topic: Castlevania nes palette swapping  (Read 308 times)

Revility

  • Newbie
  • *
  • Posts: 4
    • View Profile
Castlevania nes palette swapping
« on: October 25, 2017, 06:19:27 pm »
I did a forum search and seen a topic on palette swapping and read the links in the topic... it was very informative. Yet it is still greek to me.  I've had no issues figuring out how to replace sprites, tiles, or search for a pallet to replace colors in it.  However I am still fairly new to hex editing so understanding how to change the pallet a sprite uses to another is a bit confusing.

I am not sure where to find the info in a hex editor for which sprite uses what palette and also figure out how exactly to find what number a sprite is in order to begin the process of finding that info in the rom.

Any help would be greatly appreciated.

Dr. Floppy

  • Restricted Access
  • Hero Member
  • *
  • Posts: 978
  • Make America GREAT Again!
    • View Profile
    • BaddestHacks.net
Re: Castlevania nes palette swapping
« Reply #1 on: October 27, 2017, 08:21:56 pm »
NES games arrange sprite data in a buffer zone, usually at $200-2FF. If it isn't there, it'll be at $300, $400, $500, $600 or $700. Experience will enable you to identify this visually during routine gameplay; for now, you can confirm the sprite buffer location by searching for the snippet "8D-14-40". The byte directly prior to that is the high byte of the RAM Page used as a Sprite Buffer. Thus,

A9-02-8D-14-40 means the Sprite Buffer is at $200-2FF.

A9-03-8D-14-40 means the Sprite Buffer is at $300-3FF.

A9-07-8D-14-40 means the Sprite Buffer is at $700-7FF.


Within this region, sprites are defined in four-byte "YTAX" chunks. The first byte is the vertical position onscreen (values higher than #EF are too low to be seen). The second byte is the Sprite Tile#. The third byte is the assigned sprite palette, whether or not it's flipped horizontally and/or vertically, and if it should be placed behind non-godtone backgrounds. The fourth byte is the sprite's horizontal position onscreen.


You can begin tracking down sprite palette assignments by setting Write Breakpoints to the respective Attribute byte of a given sprite's YTAX (Y-pos, Tile#, Attributes, X-pos) chunk. For example, if the sprite is defined at $220-223, set a write breakpoint to $222 and backtrace it from there.



Bits of Attribute Byte = VHBx xxPP

V = Flip Vertically?
H = Flip Horizontally?
B = Put Behind non-godtone Backgrounds (SMB3 where Mario drops down behind large white blocks, but is still "in front" of the dark blue sky)
xxx = unused
PP = Sprite Palette assignment

Revility

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Castlevania nes palette swapping
« Reply #2 on: October 30, 2017, 02:03:07 pm »
So for example if I want to find the big candle stands when the game starts up, I ran the "8D-14-40" search in the ram and seen it pointing to the 200's...  in there I seen 55 & 56 seem to be the ones for candle stand's 2 frame sprite animation.  Its from here things start to get fuzzy for me.

I set a write break point from there and ran the debugger which spit out a bunch of code on the left panel... it's in there I'll find the attributes to trace back into the rom?

Dr. Floppy

  • Restricted Access
  • Hero Member
  • *
  • Posts: 978
  • Make America GREAT Again!
    • View Profile
    • BaddestHacks.net
Re: Castlevania nes palette swapping
« Reply #3 on: October 31, 2017, 09:51:49 pm »
If you're referring to the 2-frame fire animation seen on the very first screen of Level 1, it would be #97 and #99.

NES games can select from two sprite modes: normal, and "tall". With the former, each sprite defined in the $200-2FF (or wherever) buffer zone invokes an 8x8-pixel tile from sprite data in PPU Memory.

With "tall" sprites, each sprite is effectively two regular, consecutive 8x8 tiles stacked vertically (even# on top). Assigning an odd Tile# to the $200-2FF buffer region results in data being pulled from the BG region of PPU Memory.


Thus, the values of #97 and #99 are pulling Tiles 96/97, and 98/99 from the Background tilesheet and using them to create the animated fire sprites.




Revility

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Castlevania nes palette swapping
« Reply #4 on: November 02, 2017, 11:23:30 am »
That really helped and I think I figured it out!  Seems like I was over thinking this.  Need to test it out more, but so far it is working great.  Huge thanks!!! :thumbsup:

November 02, 2017, 05:10:16 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
That worked quite well for changing various items.  How does the tile/sprite numbering work for larger sprites such as enemies who are 16 wide and divided into 2 parts for the torso and legs? The zombie/ghoul, player and skeletons as an examples.
« Last Edit: November 02, 2017, 05:10:16 pm by Revility »