This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Need help with MMC5 PCM

Need help with MMC5 PCM
by on (#108550)
I have some questions regarding the PCM when it deals with the MMC5.

Ive been working on a major overhaul of The Legend of Zelda. I converted the rom from MMC1 to MMC5.

Zelda uses $4010 & $4011 for the PCM sfx located at $C000-$FFFF.

The sfx are Link's flying sword, dungeon doors, boss sfx.

Ive had to use the beginning of $C000, for alot of asm to take place within the hard wired bank. In doing this, Link's flying sword sfx has been overwritten, about 40% of it.

I tried reading up on the PCM within the MMC5. Id like to know the following.

1. Can I just use $5010-$5011 as the only way to play the PCM sfx?
2. It says MMC5's PCM read the raw data from $8000-$BFFF, so, does that mean it reads it within the same bank as the sound engine? Do I/can I, define any bank for where I want the PCM to be read from?
3. The original APU PCM pointers, that load where the specific sfx starts, and how far to read, are those included in MMC5, or do those original APU registers need to stay there?

I appreciate any assistance. Ive never messed with the actual asm to a sound engine, ive rewritten music though.

Thanks for reading.

-infidelity
Re: Need help with MMC5 PCM
by on (#108551)
MMC5 sound won't work on the US NES, but will still work on emulators which support it. MMC5 PCM is not a DMC channel like the NES has, instead it outputs raw 8-bit samples that are written there.
In MMC5 read mode, any read from 8000-BFFF will change the sound wave, this includes CPU instruction fetches. So executing code at 8000-BFFF will change the sound wave too. The MMC5 won't automatically generate 8000-BFFF fetches at a regular interval, so it won't automatically play the sound for you.

So you're best off finding a different place to store your code, or hacking the game to use a switchable bank at C000-FFFF so it can switch between multiple sets of samples.
Re: Need help with MMC5 PCM
by on (#108554)
So you are saying the hard wired bank $C000-$FFFF can be swapped?
Re: Need help with MMC5 PCM
by on (#108557)
infidelity wrote:
So you are saying the hard wired bank $C000-$FFFF can be swapped?

By definition, a "hard-wired" bank cannot be swapped - what he's suggesting is that you use a mapper where $C000-$FFFF (or at least $C000-$DFFF) is not hard-wired so that you can swap new banks into it. Incidentally, the MMC3 works quite nicely for this (assuming you don't mind having $8000-$9FFF hardwired instead), and it's a lot easier to get an MMC3 to put in a physical cartridge (or find a donor cartridge) than an MMC5.
Re: Need help with MMC5 PCM
by on (#108559)
I originaly did use mmc3, but needed my prg to be set to 64x16kb, and the only way I could get my prg that maxed was to upgrade to mmc5. If there was a way for me to have stayed in mmc3, with the extra prg space I needed, I wouldve.

My 4000 byte banks go all the way to $100000
Re: Need help with MMC5 PCM
by on (#108560)
If you're using the MMC5, though, then none of the banks are actually hardwired...
Re: Need help with MMC5 PCM
by on (#108562)
I dont understand. Ive always been under the impression, that $C000-$FFF was the hw bank, regardless of whatever mapper. I apologize for not knowing otherwise.

But I believe ive found my answer, im pretty much screwed, because I need my code that I have in $C000 to stay there.

Thanks for all the info and insight everyone. :-)
Re: Need help with MMC5 PCM
by on (#108572)
So duplicate the code in the new bank.
Re: Need help with MMC5 PCM
by on (#108576)
Duplicate it to where?

Certain functions will only work for me within $C000-$FFFF, particularly custom bankswap routines. Like if im in bank 04 and need to get into bank 30, I wiuld have to first load 30 jsr to the hw bank, perform my bankswap routine to bank 30, then when im done in there, I rts back to the hw bank, and rhen I have to bankswap back to bank 04 with a jmp to the address right after the lda 30. I tried doing bankswaps from within 04 to 30, but it never wirked, caused crasges, etc.

I cant put the cide in exram, cause $5C00-$5FFF is being used specificly for Link's movements fir hookshot, pegasus shoed.

And I cant swap my sram cause the game heavily uses sram to run the game, si when I try to swap out all the sram, it xrashes.

So im screwed. I may just remove some of the pcm sfx that I can live without, and relocate Links flying sword pcm sfx to that area.
Re: Need help with MMC5 PCM
by on (#108578)
Make a jump table and put code in RAM. If you can't do something, you have to start programming different/better. If it's a hack I'd understand, but if you're coding something, there's no reason it can't be done otherwise.
Re: Need help with MMC5 PCM
by on (#108604)
3gengames wrote:
If it's a hack I'd understand


This is a hack of the Legend of Zelda, not his own source code, so it's not trivial. That said, if you look at the wiki documentation on MMC5, there is no fixed bank. You can duplicate the "fixed" bank (we'll call it "primary") to another bank (which we can call "secondary"). In the "secondary" bank replace whatever data you can with your PCM data. Then you can swap between them seamlessly, loading up whichever bank has the data you need.
Re: Need help with MMC5 PCM
by on (#108611)
infidelity wrote:
So im screwed. I may just remove some of the pcm sfx that I can live without, and relocate Links flying sword pcm sfx to that area.


If your sounds are actually PCM you can put them anywhere, but I think you mean DPCM don't you? The MMC5 PCM channel doesn't actually do DPCM like the APU. Also, if you are doing PCM (and not DPCM) the APU is as pretty much equally capable of doing PCM as the MMC5 so it's not really worth using the MMC5's version. (It's not well supported in emulators anyway.)
Re: Need help with MMC5 PCM
by on (#108640)
Yes I think im misphrasing. The sounds are DPCM, cause they cant be played anywhere else in the rom, only $C000-$FFF.

@snarfblam, I will definitly check out that wiki document. I purposely set aside 5, 4000 byte prg banks, for when the time comes for new asm.
Re: Need help with MMC5 PCM
by on (#108766)
Dwedit wrote:
MMC5 sound won't work on the US NES, but will still work on emulators which support it. MMC5 PCM is not a DMC channel like the NES has, instead it outputs raw 8-bit samples that are written there.
In MMC5 read mode, any read from 8000-BFFF will change the sound wave, this includes CPU instruction fetches. So executing code at 8000-BFFF will change the sound wave too. The MMC5 won't automatically generate 8000-BFFF fetches at a regular interval, so it won't automatically play the sound for you.
What exactly is the point of this? I suppose that, together with IRQ, it might be used to play back samples at a higher sample rate if it is not doing anything else, but if it is longer than 256 then you will need the code to increment the 16-bit address. Or you might use hacks to make the CPU instructions to make music, or just use that feature only for the IRQ when reading zero from that area, which would even more hack.
Re: Need help with MMC5 PCM
by on (#108772)
From what the patent describes, it was meant to be used along with an interrupt timer (probably external from the MMC5 itself) so your interrupt routine could be 4 cycles shorter (i.e. just read the value from RAM and skip the write to $5011), but said interrupt routine would also have to read $5010 to see if it had read the last byte (which makes it rather useless, since doing "BIT $5010 ; BMI done" takes just as long as "STA $5011 ; BEQ done" and also requires an additional "CLI" at the top of the IRQ routine to make it re-entrant, so overall it's slower than doing it manually).

MMC5 PCM's "read mode" would really only be useful in a system that has proper support for DMA, and that system is not the NES.
Re: Need help with MMC5 PCM
by on (#108775)
Well, aside from the interrupt feature, it can still save a store in a straight playback loop. Though, a sample loop shouldn't be shorter than ~40 cycles anyway (44kHz), and is probably much longer since ROM space is at a premium. ~200 cycle (8kHz) sample loops are probably more common. One store cut out of a 200 cycle loop doesn't seem like much of a savings, does it.

Here are two things the MMC5 PCM can do that the APU can't:

1. 8-bit instead of 7-bit PCM playback.

2. Able to use APU DPCM at the same time as PCM.

I don't think either of these are particularly compelling reasons to use it. In practice it was used only in one game, which could easily have used the APU instead (i.e. voice clips that halt gameplay, and they still sound like poop anyway).
Re: Need help with MMC5 PCM
by on (#108800)
Just wanted to say, with the help of kuja killer, we were able to swap out $C000-FFFF, and I made it so links flying sword dpcm is loaded from the new bank, while the other dpcms are still able to be loaded from the original bank.