Frequency Registers Help

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Frequency Registers Help
by on (#141069)
I have been compiling information for NES sound drivers, mainly their frequency registers, for contribution over at VGMPF. Sometimes, I can find the frequency register data in the game's ROM, but other times, I can't find it. My question is, are the frequency registers somehow compressed in the ROM or are they coded differently? For example, frequency 357 would be 35 07 instead of 57 03. I'm kind of new to this and don't know much about NES programming in general.

I was also looking at Nick Eastridge's sound engine used in his earlier games (Paperboy, Mad Max, etc.) and found that some notes have two different frequencies. Not just for the triangle channel, but for the square channels as well. I wonder what's up with that. Thanks for your time.
Re: Frequency Registers Help
by on (#141075)
The value sent to the frequency register is the result of arbitrary calculations.

Usually we're trying to approximate a twelfth-root-of-two scale, and since the NES can't really calculate that on the fly, part of the calculation usually uses a lookup table.

Here are some common ways to do things:

1. Use a 12 note table, and bit shifting to select an octave (dividing by two raises the pitch by an octave)?

2. Use a table with one entry for every note?

3. Allow detune, vibrato, slide, or other pitch effects to modify the pitch looked up from the table?

The lookup table will typically be 16 bit (2 byte) values. The might sometimes be stored in pairs of bytes (big or little endian is arbitrary; the CPU only sees 8 bits at a time so the order is up to the programmer), or more likely there will be two tables, one for MSB and one for LSB, because this tends to look up more efficiently on the NES.
Re: Frequency Registers Help
by on (#141076)
I'm not sure what you mean by 'tables'. Again, I don't know much about the NES and 6502 though I've been trying to learn.

I also notice some games list some (but not all) of the frequency registers.
Re: Frequency Registers Help
by on (#141077)
A table, in this context, is just a list of values. An array.
Re: Frequency Registers Help
by on (#141078)
Oh okay.

I looked at some of these games, and I don't see anything that resembles the frequencies, but I think they should be in there or else, I wouldn't know how the music plays.
Re: Frequency Registers Help
by on (#141079)
Create a trace log, and put a breakpoint on the writes to the pitch register. When you find it, work backwards through the assembly trace to find where the value came from. Ultimately you'll find the tables used.
Re: Frequency Registers Help
by on (#141080)
I'm not sure how to do that. I know how to open the trace logger, and I think setting the breakpoints can be done in the debugger, but I'm not too familiar with that stuff.
Re: Frequency Registers Help
by on (#141082)
Well, start by reading this, I suppose: http://www.fceux.com/web/help/fceux.html?Debugger.html