News: 11 March 2016 - Forum Rules

Author Topic: Trying to find music in Castlevania III  (Read 2033 times)

SunGodPortal

  • Hero Member
  • *****
  • Posts: 2939
  • 2 + 2 = 5
    • View Profile
Trying to find music in Castlevania III
« on: February 25, 2016, 11:30:51 pm »
I'm trying to trace the location of the song data in Castlevania III so that I can document it for future editing purposes. I've went looking for things inside ROMs in the past and found them because I already had a general idea of what I was looking for (format-wise) or had Game Genie codes to help. I have only a basic understanding of how NES music is stored in general. The only thing I know to do is use some of the debugging functions in FCEUX (which I am new to).

I know that when a song starts, a value that corresponds to the current song is loaded into RAM locations $107-109 (as well as $10C if the song has percussion in it). I also know that the list of "song numbers" is located at $322D1 and are as follows: 4F 53 50 56 55 51 52 57 54 58 5B 5C 6A 5E 5F 63 60 64 6C 6B 66 67 62 68 69 65. Each of those bytes represents one song ie: 4F = Beginning, 53 = Clockwork, etc. I'm assuming that these numbers are used to reference the pointers for the song data but I'm not sure how to trace my way back to them. That list is as far as I've gotten in this venture.

I've tried setting a write breakpoint for the RAM addresses in question but when I go to look at what FCEUX spits out I'm not exactly sure what I should be looking for. I started studying 6502 ASM only just within the past two weeks. While I get the jist of what each individual instruction does I'm still kind of in the dark about what some of this stuff amounts to collectively.

Any advice?

EDIT: I should probably mention that once I DO find where the music is stored I should be able to handle the rest on my own. I need help figuring out how to get there though.

Also, those numbers I mentioned are also used in the NSF file (followed by a note from the dumper that says "that would be the song table"), but one or two are different. I did an experiment to change the numbers that didn't match up to the ones from the original ROM back to their original values. The songs played just fine until it got to some of the numbers that I changed. Is there any way that I can use this to my advantage to figure some of this out? If I can identify the music data in the NSF I should know what I'm looking for in the ROM, right?
« Last Edit: February 26, 2016, 12:03:05 am by SunGodPortal »
Cigarettes, ice-cream, figurines of the Virgin Mary...

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Trying to find music in Castlevania III
« Reply #1 on: February 26, 2016, 01:21:43 am »
I assume this is the US CV3 and not the Japanese AD?  I'm looking at the NSF from ZD [1].

I haven't actually tested this, so a lot of this is speculation and riddled with question marks:

It looks like the pointer table for "Beginning" is at 0x829B... with a rather unusual layout:

Code: [Select]
$829B:  8A 03 00 AC 87 01 7F 8A 02 75 8C 05 43 8E   <- beginning
$82A9:  8A 03 00 BE 8F 01 84 91 02 1C 93 05 A4 94   <- whatever track comes after that

This is a bankswitching NSF, so maybe the first two bytes are telling it which bank to swap to (bank 3?)

After that, the pointers seem to be in 3 byte groupings (00 AC 87 would be the first group)  Presumably the first byte is the channel ID???  I assume 00=pulse 1, 01=pulse 2, 02=tri, 05=percussion (maybe 03 and 04 were VRC6 channels that were removed in the US port???).  And the next 2 bytes would be the actual pointer.


That's as far as I'm willing to go tonight.

FWIW I made a tool many many many years ago to aid NSF rippers called SlickNSF [2] -- it basically is a minimalistic NSF player with tracing capabilites... so it's handy for music hacking as well.  It's what I used to find the above.




[1] http://www.zophar.net/music/nsf/castlevania-3-dracula-s-curse-[akumajou-densetsu].html
[2] http://slickproductions.org/slicknsf.php

SunGodPortal

  • Hero Member
  • *****
  • Posts: 2939
  • 2 + 2 = 5
    • View Profile
Re: Trying to find music in Castlevania III
« Reply #2 on: February 26, 2016, 03:32:42 am »
Yes, I am working with the US version.

I did a test by copy/pasting the data from one of the slots to the other and these do appear to be pointer tables for the song data. I've looked at every one now and noticed that about half start with $88 03 instead of $8A 03. Have any idea what that might indicate? I compared a few of them and at first I wondered if there would be a big difference in the pointers contained within but that didn't seem to be the case.

I find it interesting that there is enough data for 31 songs yet there appear to only be 28 songs in the Japanese or US NSF files. I'll be investigating that before I look into anything else. How awesome would it be if there were three tracks that have never been heard before outside of the development team?

The full set:
Code: [Select]
8A 03 00 5E 87 01 76 87 02 8D 87 05 9E 87
8A 03 00 AC 87 01 7F 8A 02 75 8C 05 43 8E
8A 03 00 BE 8F 01 84 91 02 1C 93 05 A4 94
8A 03 00 76 95 01 FD 96 02 68 98 05 6D 99
8A 03 00 03 9A 01 5B 9B 02 CD 9C 05 01 9E
8A 03 00 02 9E 01 E6 9F 02 47 A1 05 E2 A1
8A 03 00 E3 A1 01 35 A3 02 C6 A4 05 24 A6
8A 03 00 F2 A6 01 48 AA 02 C5 AC 05 AA AD
8A 03 00 3C AE 01 E0 AF 02 4D B1 05 01 B2
8A 03 00 CD B2 01 76 B3 02 0E B4 05 74 B4

88 03 00 C9 88 01 2F 8A 02 BD 8B 05 5B 8C
8A 03 00 3C AE 01 E0 AF 02 4D B1 05 01 B2
8A 03 00 E3 A1 01 35 A3 02 C6 A4 05 24 A6
88 03 00 13 8D 01 38 8E 02 E4 8E 05 8E 8F
88 03 00 26 90 01 2F 92 02 85 93 05 78 94
88 03 00 5F AC 01 9A AC 02 DE AC 05 0B AD
88 03 00 22 95 01 C6 97 02 A2 99 05 6E 9A
88 03 00 F3 9C 01 98 9E 02 22 A0 05 E5 A0
88 03 00 7D A1 01 03 A3 02 F7 A4 05 89 A5
88 03 00 58 A6 01 5D A6 02 62 A6 05 8F A5

88 03 00 67 A6 01 37 A7 02 78 A7 05 9B A7
88 03 00 5E 87 01 87 87 02 B5 87 05 E6 87
88 03 00 D2 9B 01 31 9C 02 75 9C 05 D3 9C
88 03 00 FF 87 01 52 88 02 80 88 05 A9 88
88 03 00 D8 A7 01 73 AA 02 C1 AB 05 5E AC
8A 03 00 A2 B7 01 C9 B7 02 18 B8 05 30 B8
88 03 00 AB AE 01 E7 AF 02 25 B1 05 B3 B1
8A 03 00 75 B4 01 EA B5 02 91 B6 05 49 B7
88 03 00 5F AC 01 9A AC 02 DE AC 05 0B AD
88 03 00 6A AD 01 4C AD 02 B5 AD 05 C3 AD

88 03 00 C4 AD 01 24 AE 02 6E AE 05 AA AE

My theory on the skipped numbers (03, 04): I'm guessing they are for the two extra squares available on the MMC5 and not related to the VRC6 since, IIRC this soundtrack was actually reprogrammed for the different configuration rather than simply adapted. The fact that they still have slots reserved for the unused squares of the MMC5 makes me wonder if I could still utilize them. I doubt I would be so lucky though (not that I would have space anyway). LOL

Thanks for the help. This will be a HUGE help.
Cigarettes, ice-cream, figurines of the Virgin Mary...

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Trying to find music in Castlevania III
« Reply #3 on: February 26, 2016, 11:03:11 am »
I did a test by copy/pasting the data from one of the slots to the other and these do appear to be pointer tables for the song data. I've looked at every one now and noticed that about half start with $88 03 instead of $8A 03. Have any idea what that might indicate?

I doubt I'll trace this any more so I really have no idea.

But if want a wild guess, maybe the $88/$8A is indicative of the bank, and $03 is how many melodic channels there are???  Again I'm pulling that out of my ass, I have no idea.

Quote
How awesome would it be if there were three tracks that have never been heard before outside of the development team?

Don't get your hopes up.  NSF Rippers are usually pretty good at finding those and pulling them out.




EDIT:

So it turns out a thing I was going to do today got cancelled, so I did more digging:

The $03 is the channel count-1.  In the music init routine, it gets loaded into $EA and is used as a downcounter for priming channels.  The counter ends when it goes negative rather than when it reaches 0, so a value of $03 means 4 channels are primed.


As for $88/$8A, it definitely looks to be bankswap related:

Code: [Select]
88C8   A5    LDA   EB          [8A]  8A 00 04  [N.I..]   FB   ; <- 8A value written to $EB
88CA   9D    STA   0195,X [0195=8A]  8A 00 04  [N.I..]   FB
88CD   84    STY   E2          [04]  8A 00 04  [N.I..]   FB
88CF   A0    LDY   #00               8A 00 00  [..IZ.]   FB
88D1   20    JSR   E1B5        [00]  8A 00 00  [..IZ.]   F9
E1B5   BD    LDA   0195,X [0195=8A]  8A 00 00  [N.I..]   F9
E1B8   20    JSR   E2E6        [00]  8A 00 00  [N.I..]   F7
E2E6   85    STA   21          [8A]  8A 00 00  [N.I..]   F7
E2E8   86    STX   00          [00]  8A 00 00  [N.I..]   F7
E2EA   48    PHA                     8A 00 00  [N.I..]   F6
E2EB   C9    CMP   #98               8A 00 00  [N.I..]   F6
E2ED   69    ADC   #00               8A 00 00  [N.I..]   F6
E2EF   29    AND   #03               02 00 00  [..I..]   F6
E2F1   AA    TAX                     02 02 00  [..I..]   F6
E2F2   BD    LDA   FFEC,X [FFEE=04]  04 02 00  [..I..]   F6
E2F5   8D    STA   5FF8        [04]  04 02 00  [..I..]   F6      ; <- 5FFx are NSF bankswap regs.  This code will not appear in the ROM, as the ROM
E2F8   BD    LDA   FFEF,X [FFF1=05]  05 02 00  [..I..]   F6  ; will be using MMC5 bankswap regs instead.
E2FB   8D    STA   5FF9        [05]  05 02 00  [..I..]   F6
E2FE   69    ADC   #01               06 02 00  [..I..]   F6
E300   8D    STA   5FFA        [06]  06 02 00  [..I..]   F6
E303   69    ADC   #01               07 02 00  [..I..]   F6
E305   8D    STA   5FFB        [07]  07 02 00  [..I..]   F6


So it turns out my wild guess was mostly correct!  Haw.
« Last Edit: February 26, 2016, 11:26:12 am by Disch »