NSF ripper Guide Level 17


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 17 Takara - Transformers The Head Masters FDS

Now we step up in difficulty, again we are going to rip a NSF from a FDS game called Transformers - The Head Masters. Here is where my insistance about ripping from the disk becoming useful, because you'll more than likely never be able to rip the NSF from this game without browsing the contents of the disk. What I am going to do is use emulator dumping in combination with disk browsing to rip this game. Load up Nesten or FCEU MOD with the game Transformers - The Head Masters and debug for the sound registers in the usual way and then dump $8000 - $FFFF, or $C000 - $FFFF in FCEU MOD. After you have dumped the contents of memory, disassemble the bank and debug for the play and init address calls respectively. You'll find them at C000(load)/C061(init)/C057(play) respectively, in addition a bootstrap at $C034, tune switching address $28. Write some init code and you'll find that you have a bunch of sound effects and one tune on side A of the disk. If you do the same for side B, you'll get about the same thing, a different tune and some sound effects. So it's time to browse both sides of the disk.

SIDE A

File # ID File Name Address Size Type
0
0
KYODAKU-
$2800
224
NT
1
6
SPRITE
$0000
2144
CHR
2
7
*FIX*
$1000
4080
CHR
3
8
PROG.001
$6200
16384
PRG
4
9
PROG.002
$A200
10496
PRG
5
11
*TITLE*
$D280
2480
PRG
6
12
JMP-TBL
$DFE0
32
PRG
7
38
*LASTMP*
$C580
6720
PRG
8
38
PLLASTCG
$0980
1152
CHR
9
38
*LASTCG*
$1700
1408
CHR
10
48
*END-PRO
$D280
2560
PRG
11
48
*ENDSCG
$0980
320
CHR
12
48
*ENDFCG
$1700
960
CHR

Wow, we have a lot of files here, and no file that specifically says sound. The more you look at this pile the worse it looks and you'll find out soon enough and then the work load gets worse on SIDE B of the disk. This disk has a Boot ID of 15 like the others. Files 0 - 6 are loaded up at bootup, that is the first clue to locating the files that you need, the next one is that if you debugged and dumped active memory from one of the emulators then you'll know the address range of the sound driver code is located from $C034 - $C455. Check each file, the one that has sound driver code is File # 4. PROG.002, address $A200, size 10496, PRG RAM. You'll get no sound from this file, I debugged the file and come to find out, it's missing the sequence data. So I decided to debug the disk again to locate the missing sequence data. Set a write breakpoint range $4000 - $4004 in FCEUD. Click run a few times if you have to, to figure out where the sequence data is located at. It is known already that the sequence data is not located in the $A000 - $CAFF range.


$C18B:0A        ASL

$C18C:AA        TAX

$C18D:B1 32     LDA ($32),Y @ $D724 = #$B4

$C18F:9D 00 40  STA $4000,X @ $4000 = #$FF

$C192:E0 07     CPX #$07

$C194:B0 06     BCS $C19C

$C196:C8        INY

$C197:B1 32     LDA ($32),Y @ $D724 = #$B4

$C199:9D 01 40  STA $4001,X @ $4001 = #$FF

$C19C:68        PLA

$C19D:AA        TAX

$C19E:C8        INY

$C19F:60        RTS

I have snapped the debugger a few times and wound up in the range of $D5xx - $D8xx, I believe this is where the sequence data is located at. Let's take a look at the FDS file list again and note all of the files that could contain this address range and possibly the sequence data. They are as follows.

One way to find out without playing through the entire game is to replace the known sequence data with one of the files on the disk. I have a feeling that we are already playing TITLE, on the title screen of the game, so we can try the file *END-PRO, address $D280 which seems more likely to contain the sequence data than the other file *LASTMP*, later on we will find out this file contains music as well.

Take the emulator dump and trim off off $8000 - $BFFF if you haven't done so already, or dumped it from $C000 - $FFFF. Next you'll extract the file *END-PRO from the disk into your NSF project folder. The starting address of this file is $D200, so in order to test this file, trim off $D200 - $FFFF from your emulator dump and then append this file, you'll find out that a different tune plays, so this file is good, save it. You can then trim that file off that you appended to your emulator dump and replace it with the file *TITLE*, sure enough you hear the familiar title screen music once again. In the file *LASTMP*, go to address $D200 and copy and paste that address and the remainder of the file and append to your once again trimmed emulator dump, again another tune, so that's three tunes on this side of the disk. We need to tally up the results of SIDE B of the disk before we decide upon a strategy of ripping this game. Dealing with the fact that all three tunes' sequence data is located at the same address location, this could be a problem. Onward we go.

SIDE B

File # ID File Name Address Size Type
0
16
PL_CGSET
$C680
1408
PRG
1
32
*RESMAP*
$CB00
5312
PRG
2
32
ENEMYCGE
$0980
1664
CHR
3
32
**RESCG*
$1700
1632
CHR
4
33
*BONUS *
$C580
896
PRG
5
33
*REMMAP*
$D280
3392
PRG
6
33
**REMCG*
$1700
944
CHR
7
34
*RSSMAP*
$CB00
5312
PRG
8
34
ENEMYCGS
$0980
1664
CHR
9
34
**RSSCG*
$1700
1120
CHR
10
35
*BONUS *
$C580
896
PRG
11
35
*RSMMAP*
$D280
3392
PRG
12
35
**RSMCG*
$1700
656
CHR
13
36
*RJSMAP*
$CB00
5312
PRG
14
36
ENEMYCGJ
$0980
1664
CHR
15
36
**RJSCG*
$1700
1440
CHR
16
37
*BONUS *
$C580
896
PRG
17
37
*RJMMAP*
$D280
896
PRG
18
37
**RJMCG*
$1700
944
CHR
19
64
NAMEPRO
$D600
1792
PRG
20
65
NAMEDATA
$0700
128
PRG

We have a total of 21 files on SIDE B of the disk, nearly twice as much as SIDE A, but not quite. Even though we have more files to deal with, the structure of the data is not too much different, nor are the file names. It's easier to deduce which files are the sequence data, because any file that contains the address range $D280 will be the files that we extract, you can test those files out, as we had for SIDE A. Here are the files to extract from this side of the disk.

That's 6 music files on SIDE B, adding the 3 from SIDE A, that makes 9 tunes in total. I'm currious as to the files that are at $CB00, what is the data used for, before the verified sequence data, let's check it out. I have just verified that the data is not part of the sound driver, this fact may help us complete the NSF a little easier. You can also set a read breakpoint for the address range $CB00 - $D27F and check it out yourself, do this once you reach the level on SIDE B.

First of all, let's trim those files that start at $CB00, then we will calculate how much space these files will take in total. We have 9 files that are betweeen 2.5K and 3.31K, 3 of those files are duplicate songs, so we'll not use three files. Now we are going to set up the banks on the NSF, using the emulator dump, padd the last bank until it's reached it's last byte, $DFFF. The next thing that you want to do is add a bank that will be $E000 - $EFFF, insert 1000h in padding, 00's or FF's. You're going to use this bank for your code, the rest of the NSF does not have enough space for code and data indexes. Now you will set your NSF bankswitch header bytes up as follows, 00,00,00,00,00,01,02,00. 00,01,02 is what you're concerned with since you're using banks $C000, $D000 and $E000. Now you're ready to padd the 6 files and convert them into banks. Again in this level we are using a NSF paging optimization trick. In the next level is how we will deal with straight forward bankswitching according to the spec.

Since you trimmed your files earlier on, they should be clean as possible and ready to convert into banks. You have 6 banks, some of them are of the same size. For example, *TITLE * has a starting address of $D280, you want to make this file start at $D000. Simply add 280h to the beginning of the file with a hex editor of your choice, at the end of the file you'll have to use a calculator on some of them, this one I believe you only add 40h in bytes. Do this with each file and append them on to the end, one at a time. When you're done, you should have a file size of about 32896 with the NSF header prepended, that's assuming that you added 6 - 4K banks.

Now it's time to write some init code in the $E000 bank, my code is right at the beginning. What makes this rip kind of tricky is that sequence data for each of the 6 tunes starts at $D280, and they are of the same tune number which is 10h. Here is how I'm going to handle it.


PHA

LDA #$80

STA $4017

JSR $C034                 ; Bootstrap code

PLA

LDA $bankswitch_index,X

STA $5FFD                 ; Switch the bank in the $D000 - $DFFF range

LDA $tune_index,X

STA $28

JMP $C057                 ; Jump to main init



bankswitch_index: .db 03070604010501010101010101010101010101010101010101010101010101010101010101010101



tune_index: .db 1010101010100102030405060708090A0B0C0D0E

The code looks pretty simple, however there is more here than what meets the eye. As I said before, all of the tunes and not the sound effects have an index number of 10h, as you can see with six 10h's in a row, normally you would never see this in a normal NSF rip. The bankswitching corresponds to the tune index, if you change the first six bankswitch index bytes, that is how you order the tunes and how the banks are loaded at the same time, remember one tune per file that we converted to a bank. The rest of the 01's are to make sure the $D000 - $DFFF bank stays loaded while the sound effects play. Make sure that you set the header for FDS sound, indeed this rip has expansion sound. Enjoy listening to the music after doing this tedious job.