NSF ripper Guide Level 15


Level 0   Level 1   Level 2   Level 3   Level 4  

Level 5   Level 6   Level 7   Level 8   Level 9

Level 10   Level 11   Level 12   Level 13   Level 14

Level 15   Level 16   Level 17   Level 18   Level 19

Level 20


LEVEL 15 Nintendo - Backgammon FDS

Now comes the time to learn how to rip NSF's from FDS disks. FDS (Famicom Disk System) is a NES add-on that uses disks. Lucky for us emulation people, many disks have been dumped so that we may play them. The FDS uses the 6502 instruction set, all of the NES specific address registers, in addition you have the registers that are concerned with disk loading and the operation of the unit itself. The great thing about the FDS system is that in addition to the NES APU, you have one FDS expansion sound channel. Many FDS games use this expansion sound channel, but not all will use this channel, be aware of this and browse the code to know for a fact.

The first thing that I am going to do is paste verbatim from a document by Disch, a list of sound registers for the FDS sound expansion channel. You can read the document by Disch and other FDS documents as reference if you do not know much about the FDS. The register list is as follows.


4040h..407Fh - Wave RAM - 64 x 6bit sample data (Read/Write)

Writes to these registers are ignored unless Write Mode is turned on (see register 4089h).



4089h - Wave RAM Control (Write Only)  Bit7    Wave Write Mode (1=Stop Sound output & Allow to write to Wave RAM)

  Bit6-2  Not used

  Bit1-0  Master Volume   (0-3 = 100%,66%,50%,40% = 30/30,20/30,15/30,12/30)





4082h - Wave RAM Sample Rate LSB (Write Only)  Bit7-0  Lower 8 bits of the main unit's frequency (upper 4 bits in 4083h)



4083h - Wave RAM Sample Rate MSB and Control (Write Only)  Bit7    Main Unit disable  (0=Enable, 1=Disable Sound Output)

  Bit6    Envelope disable   (0=Normal, 1=Disable Volume/Sweep Envelopes)

  Bit5-4  Not used

  Bit3-0  Upper 4 bits of the main unit's frequency



Main Unit / Sample Rate: (per entry of the 64-entry wave ram)   F = 1.79MHz * (Freq + Mod) / 65536

   Mod = Frequency change based on the Modulation unit



If the 12bit frequency is zero, the Main unit is disabled (channel silent).



408Ah - Envelope Base Frequency (Write Only)  Bit7-0  Envelope Base Frequency, Fbase=1.79MHz/8/N



Fbase used by 4080h and 4084h. Volume/Sweep Envelope are disabled if N=0.



4080h - Volume Envelope (Write Only)  Bit7    Volume Envelope Mode      (0=Volume Envelope, 1=Fixed Volume)

  Bit6    Volume Envelope Direction (When enabled / at specified rate)

           0=Decrease Volume by 1 (only if Volume>00h)

           1=Increase Volume by 1 (only if Volume<20h)

  Bit5-0  When Bit7=1: Volume Level (0-20h=Muted-Loudest, 21h-3Fh=Same as 20h)

  Bit5-0  When Bit7=0: Volume Envelope Rate, F=Fbase/(N+1)
The volume level can be set to 00h-3Fh by write with Bit7=1, this level is also used as initial volume when switching to envelope mode by setting Bit7=0.

In decrease mode, initial values 21h-3Fh are resulting delayed decrease; volume stays at maximum level until the value gets smaller than 20h.

4084h - Sweep Envelope (Write Only)  Bit7    Sweep Envelope Disable (1=Disable)

  Bit6    Sweep Envelope Mode    (0=Decrease, 1=Increase sweep gain)

  Bit5-0  When Bit7=1: Sweep Gain

  Bit5-0  When Bit7=0: Sweep Envelope Rate, F=Fbase/(N+1)





4085h - Sweep Bias (Write Only)  Bit7    Not used

  Bit6-0  Sweep Bias (signed 7bit; -40h..+3Fh)
Sweep Bias is a used by the Modulation unit in calculating frequency bend. Sweep Bias negative: Modulation unit will be bending frequency down. Sweep Bias positive: Modulation unit will be bending frequency up. Any write to Sweep Bias register resets Modulation Unit's address to zero. This address is used by the Modulation Unit when looking up entries written to the Modulation table (via $4088).
4086h - Modulation Frequency LSB (Write Only)  Bit7-0  Lower 8bit of 12bit Modulation frequency



4087h - Modulation Frequency MSB (Write Only)  Bit7    Modulation Enable/Disable (0=Enable, 1=Disable)

  Bit6-4  Not used

  Bit3-0  Upper 4bit of 12bit Modulation frequency



Modulation Unit: Modulation Rate (per entry of the 64-entry modulation table)   F = 1.79MHz * ModFreq / 65536



If the 12bit frequency is zero, the Modulation unit is disabled.



4088h - Modulation Table (Write Only)  Bit7-3  Not used

  Bit2-0  Modulation input
Writing to this register puts the value written at the END of the modulation table **twice**, and shifts each entry already in the table 2 places to the front. The first 2 entries of the Modulation table are shifted out and lost. old, old <-- ModTable_0 <-- ModTable_1 <-- ... <-- ModTable_63 <-- new, new
4090h - Current Volume Gain Level (6bit) (Read Only)



4092h - Current Sweep Gain Level (6bit) (Read Only)



4023h - 2C33 I/O Control Port  Bit0  Disk I/O   (0=Disable, 1=Enable)

  Bit1  Sound      (0=Disable, 1=Enable)





FDS Sound by Disch, Release 1, 07/14/2004, based on info from Nori.

Read this list and become familiar with the FDS sound registers, when you see any of these registers in a disassembly of one of the files in a disk, chances are that this game could be using FDS sound.


Now is the time to learn how to rip a NSF from a FDS game. We can use two methods to rip this NSF, one of them is dumping the active contents of memory in Nesten or FECU, and debug until you find the Play and Init address calls. However, we are not going to extract the NSF from the game in this way. The reason is because the skills you learn here will help you become accustomed to ripping NSFs from a disk that uses both sides of the disk and/or a game that uses two disks that use both sides of each disk. For now, you'll learn how to rip from a FDS game that uses only one side of one disk. A little history about this NSF rip that I done back in 08-03-2004. I had dumped this game using an emulator and the debugger, and now I will show you the new method of ripping this game. This method will also produce a much smaller and compact file for play.

The first thing that we are going to do is use FDS Explorer. FDS Explorer is a utility that enables you to browse the contents of a disk, on both sides and all of the disks of a given game. You can view the hex and disassembly of each file that you wish to look at.

File # ID File Name Address Size Type
0
0
KYODAKU-
$2800
224
NT
1
0
SOUND
$C300
7417
PRG
2
0
BG-MAIN
$6000
18816
PRG
3
1
CP
$A980
4736
PRG
4
0
VECTOR
$DFFA
6
PRG
5
16
BG-DEMO
$A980
6528
PRG
6
32
BG-FINAL
$A980
1664
PRG
7
1
BG-CHR10
$BE00
1280
PRG
8
0
BG-CHR11
$0200
512
PRG
9
0
BG-CHR12
$0600
512
PRG
10
1
BG-CHR00
$0000
8192
CHR
11
17
BG-CHR20
$1B00
1280
CHR
12
33
BG-CHR30
$1400
1536
CHR

Using FDS Explorer, you can see that the FDS game Backgammon has many files on the A side of the disk. Your job is to figure out which file(s) contain the sound driver and then extract them. Usually this task can be a frustrating and tedious job to do, especially when you have to piece together the files and integrate them into one NSF file using code that you have to write. The task for making an NSF from Backgammon is about the easiest I've ever seen in my life.

The boot ID is 15 for this game. Any file that has a boot ID of equal to or less than the game will be loaded at bootup, always keep that in mind in every FDS game that you attempt to rip the NSF from. The file called SOUND has a boot ID of 0, is a PRG (Program RAM) section of the disk and has the starting address at $C300, file size 7417. Click on this file and view the hex and the disassembly from this program, carefully look at the code to determine if this is in fact the file that contains your sound driver. After examining the file, it is in fact the entire sound driver. Extract the file called SOUND into your NSF project folder as a .bin and then slap a NSF header on it. Set a load address of $C300, since that's the start of the music driver (and the file) and then you'll need to debug for the play and init addresses respectively, is an easy task for this game. Make sure that you set the sound expansion chip for FDS in the NSF header, the setting will be 04 in hex if you're wondering. What you have now is a compact sized file, that plays excellent FDS sound.