Simple 50hz Conversion romhack (TMNT 3:Manhattan project)

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
User avatar
TR3KT
Posts: 40
Joined: Sat Oct 01, 2016 2:20 am
Location: Australia, the land of British 50hz and obscure sports games.

Simple 50hz Conversion romhack (TMNT 3:Manhattan project)

Post by TR3KT »

Hi, i'm new to the world of Famitracker and Hex editing. I've done lots of research with no answer to my question. How do you convert a NTSC only game's music file (TMNT 3 was never released in europe) to increase the pitch and tempo of the music so that it runs properly on a PAL console? What hex value(s) to you have to edit for that game specifically? I'd like to hear from someone with the knowledge of the game's music engine.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by tepples »

The level of detail of an explanation that you would find most useful depends on your level of familiarity with 6502 assembly language. How familiar are you with it?
User avatar
TR3KT
Posts: 40
Joined: Sat Oct 01, 2016 2:20 am
Location: Australia, the land of British 50hz and obscure sports games.

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by TR3KT »

I have little knowledge of 6502. i know it has something to do with tracking hex data when performing a certain action in the rom or something, but i can't figure the layout of it.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by rainwarrior »

Adjusting the tempo: Relatively easy. Just add a counter that runs the play routine twice on every fifth frame (converts 60 to 50 fps).

Adjusting the pitch: usually this involves finding a table of note frequencies somewhere in the ROM and replacing it. The table might be 12 entries long (one octave, which is shifted to get values for other octaves) or it might be more like 60 or 100 entries long, depending on the engine. It also might be a table of 16-bit values, or two tables of 8-bit values (the high and low separately).

It's not normally important to adjust pitch unless the game uses tuned DPCM sounds (e.g. playing chords or bassline on DPCM samples). Everything else maintains proper relative pitch with everything else, so despite sounding lower all of the musical relationships will be intact. So: high probability you don't need to adjust pitch (only a handful of games use tuned samples).
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by tepples »

rainwarrior wrote:It's not normally important to adjust pitch unless the game uses tuned DPCM sounds (e.g. playing chords or bassline on DPCM samples). Everything else maintains proper relative pitch with everything else, so despite sounding lower all of the musical relationships will be intact. So: high probability you don't need to adjust pitch (only a handful of games use tuned samples).
In particular, I don't think Probotector/Contra uses tuned DPCM, but Super C does. So do Bee 52 and later Sunsoft games. For anything that doesn't, you can just add one semitone to the pitch value from the music engine to get approximately correct pitch.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by rainwarrior »

tepples wrote:you can just add one semitone to the pitch value from the music engine to get approximately correct pitch.
Well that's an interesting approach, but I'm not sure where this approximation would be a desirable solution over replacing the pitch table?

If you can find the spot in the engine that fetches a note number, the pitch table value will usually be the very next thing that is fetched, i.e. if you've found one, you should be able to find the other with very little additional effort.

Replacing the pitch table will give you more accurate control of the pitch retuning, and won't require finding a place to insert new code.
User avatar
TR3KT
Posts: 40
Joined: Sat Oct 01, 2016 2:20 am
Location: Australia, the land of British 50hz and obscure sports games.

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by TR3KT »

I am so thankful for all the replies sent my way, i think i am pointed in the right direction but i have some more questions. Rainwarrior you said that you could set a counter within the rom itself to fix the tempo but as i said before i have little knowledge of 6502. Can you explain how to set up such a thing?
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by rainwarrior »

If it's an NSF:

1. Find an empty location in RAM for your counter. Often stuff at the end of RAM is open, like $7FF. (Put a read/write breakpoint on it in FCEUX and see if/when it gets hit.)

2. Find where PLAY points to in the ROM. (In FCEUX you can simply type PLAY into the breakpoint field and it auto-complete it to set a breakpoint for you.)

3. Find empty space somewhere near PLAY where you can put your counter code. The code might look like this:

Code: Select all

inc counter ; counter = $7FF ?
lda counter
cmp #5
bcc :+ ; if counter >= 5 call PLAY an extra time and reset counter
jsr play ; play = address of PLAY routine
lda #0
sta counter
:
jmp play
You can insert assembly code directly into the ROM in FCEUX by left-clicking on the vertical strip to the left of the disassembly pane in the debugger.

4. Finally, edit the NSF header to replace the PLAY address with this routine you just created.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by rainwarrior »

Though, there may be a simpler solution. You said "runs properly on a PAL console". How are you running a modified ROM on the console?

If you have a PowerPak, an NSF will play at the speed specified by its header, independently of the system's video rate. The pitch will be lower on PAL than NTSC but the playback rate is driven by a separate timer that will keep it at the original rate.

So, you might just be able to play the NSF on a PowerPak and have it already run at 60 Hz, if that's what the NSF has specified in its header. (If it doesn't, see the NSF file format and replace the 2 byte PAL speed in the NSF with 60 Hz.)

Doing that is probably much easier than trying to modify the ROM, if you have a PowerPak already, anyway.
User avatar
TR3KT
Posts: 40
Joined: Sat Oct 01, 2016 2:20 am
Location: Australia, the land of British 50hz and obscure sports games.

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by TR3KT »

I am running the rom on a PAL-A system with an everdrive n8, not powerpak
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple 50hz Conversion romhack (TMNT 3:Manhattan project

Post by rainwarrior »

Hmm, well unless the Everdrive N8 gets updated with an NSF player I guess you'll have to hack the ROM.

Looking at the NSF version might help you find the music code in the game ROM though, it will normally be at the same address as PLAY (or called quickly by a small stub PLAY routine), so it could give you a good idea where to start looking. Once you find the music code, sort of the same steps as before, but it might be a little trickier than trying to hack just an NSF.
User avatar
TR3KT
Posts: 40
Joined: Sat Oct 01, 2016 2:20 am
Location: Australia, the land of British 50hz and obscure sports games.

Re: rainwarrior

Post by TR3KT »

Thank you for your full explanation, i am starting work on it right away. This hack won't just fix the music for PAL, i also wish to fix some visual bugs occuring in the game due to resolution problems.
Post Reply