Need help with MMC5 PCM

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Need help with MMC5 PCM

Post by infidelity »

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
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Need help with MMC5 PCM

Post by Dwedit »

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.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need help with MMC5 PCM

Post by infidelity »

So you are saying the hard wired bank $C000-$FFFF can be swapped?
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Need help with MMC5 PCM

Post by Quietust »

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.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need help with MMC5 PCM

Post by infidelity »

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
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Need help with MMC5 PCM

Post by Quietust »

If you're using the MMC5, though, then none of the banks are actually hardwired...
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need help with MMC5 PCM

Post by infidelity »

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. :-)
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Need help with MMC5 PCM

Post by Dwedit »

So duplicate the code in the new bank.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need help with MMC5 PCM

Post by infidelity »

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.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Re: Need help with MMC5 PCM

Post by 3gengames »

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.
snarfblam
Posts: 143
Joined: Fri May 13, 2011 7:36 pm

Re: Need help with MMC5 PCM

Post by snarfblam »

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.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Need help with MMC5 PCM

Post by rainwarrior »

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.)
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need help with MMC5 PCM

Post by infidelity »

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.
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: Need help with MMC5 PCM

Post by zzo38 »

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.
(Free Hero Mesh - FOSS puzzle game engine)
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Need help with MMC5 PCM

Post by Quietust »

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.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Post Reply