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

Author Topic: Hacking music in a NES game  (Read 2190 times)

brainsingravy

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Hacking music in a NES game
« on: October 13, 2014, 06:08:24 pm »
I was wanting to do a music hack on Castlevania 3 (not akumajou densetsu). How do you locate the song in the rom file and how do you find out which numbers = certain notes. I know a little bit about hex editing but I'm new to it.

Dr. Floppy

  • Restricted Access
  • Hero Member
  • *
  • Posts: 970
  • Make America GREAT Again!
    • View Profile
    • BaddestHacks.net
Re: Hacking music in a NES game
« Reply #1 on: October 13, 2014, 06:29:07 pm »
Quote
How do you locate the song in the rom file and how do you find out which numbers = certain notes.

Set write breakpoints to $4006 and $4007. Those registers are reserved for the frequency emitted by the Pulse-2 channel (which is usually used for melody and overall song direction). If you backtrace from there, you'll find not only a key part of the game's music handler, but also the frequency lookup table which will allow you to determine precisely what byte-values correspond to what frequencies/notes.

You can use this table to decode the frequency arrays you're about to discover: http://wiki.nesdev.com/w/index.php/Pulse_Channel_frequency_chart

brainsingravy

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: Hacking music in a NES game
« Reply #2 on: October 13, 2014, 06:34:46 pm »
Thank you I don't know if this will solve it all for me but it really is a big piece of the puzzle.  :)

Bregalad

  • Hero Member
  • *****
  • Posts: 2755
    • View Profile
Re: Hacking music in a NES game
« Reply #3 on: October 14, 2014, 12:43:38 pm »
I think you should look at the post I made here, because after all, sound extraction and music hacking are almost the same : You'll need to figure the bytecode format used by the game first.

Dr. Floppy

  • Restricted Access
  • Hero Member
  • *
  • Posts: 970
  • Make America GREAT Again!
    • View Profile
    • BaddestHacks.net
Re: Hacking music in a NES game
« Reply #4 on: October 14, 2014, 05:06:34 pm »
Yeah, bytecodes are definitely key. With NES games, one thing I've noticed a LOT of games have in common is their use of "positive" values [#00-7F] as coded frequencies (tones, pitches, etc.) and the first line or two of "negative" values [#80-FF] as rhythmic duration markers.

For example, SMB1 and Zelda 1 both utilize the bytes #80-87 as rhythm markers. When the game engine encounters any of these bytes, it uses the low-nybble (right digit) as an offset into a lookup table to find out how many frames each of the next series of frequencies is supposed to last. (60 frames in 1 second.) It isn't out of the ordinary to see music data that looks like:

Code: [Select]
84-3E-86-3E-3E-84-29-86-3C-80-39
Note how the bytes starting with $8 all precede a byte or bytes characterized by smaller numbers. Being from the Midwest, it kinda reminds me of a cornfield after the first winter frost. Some dessicated stalks are still standing upright, but they're surrounded mostly by collapsed compatriots. Whenever I see a field of bytes in the 2x-3x-4x range, interspersed with 8x (and sometimes 9x) bytes, I have a sneaking suspicion that what I'm seeing just might be music data.


(Anyone who recognized the coded musical reference gets a  :cookie:.)

brainsingravy

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: Hacking music in a NES game
« Reply #5 on: October 14, 2014, 05:54:52 pm »
okay I will keep that in mind I'm not quite to a point of editing the music yet I'm working on graphics right now. I was just curious as to how one would edit the music.