Simultaneous DPCM and IRQ

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 8:31 am

Hello. I have a problem.
My Game Has to Play a loud "Checkpoint" Sound every time The player crosses the check point. The problem is that the DPCM is sort of Unpredictable when it fires an IRQ so it may mess up scanline dependent stuff like Water or parallax. Is there a way to tell when the DPCM Fires the Irq So I can Either not play that part of the sound or Cancel the scanline specifics when needed.

The Closes example I can get is Kirby's Adventure with the HUD and Samples.
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

User avatar
tokumaru
Posts: 11465
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Simultaneous DPCM and IRQ

Post by tokumaru » Tue Dec 03, 2019 9:09 am

Aren't DPCM IRQs optional? AFAIK you can just disable them.

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 9:27 am

I know that you CAN Disable them but the problem is WHEN do I need to disable.
Is there away to tell the difference between DPCM and a MMC3/5 counter?
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Simultaneous DPCM and IRQ

Post by tepples » Tue Dec 03, 2019 9:32 am

As described in "APU DMC" on the wiki, $4010 bit 7 controls whether or not the channel fires an IRQ after all the data is read. Were you using this IRQ for something in your program, such as playing several samples in succession? If not, you can just disable the IRQ.

Once you have disabled DMC IRQ, any other interference is probably the fault of DMC DMA pausing the CPU for up to 4 cycles when reading sample data, throwing off any 113.667-cycle timed loops.

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 9:42 am

No. I.. sort of Don't like micromanaging DPCM (Or PCM) in my songs.

Also It pauses the CPU for 4 Cycles?
I'm already at a time crunch for Logic. :(

Another thing is that The IRQ is More being used For Scanline specific stuff than samples.

The other question is can I detect when the data is going to be read? The game Uses an absurd amount of bank switching and I need to bankswitch the sample data into $C000 .
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

User avatar
dougeff
Posts: 2614
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Simultaneous DPCM and IRQ

Post by dougeff » Tue Dec 03, 2019 10:41 am

There would be no way to detect when DMC is reading. It would happen multiple times a frame, and can happen any time.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
rainwarrior
Posts: 7669
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simultaneous DPCM and IRQ

Post by rainwarrior » Tue Dec 03, 2019 11:14 am

IMAGICA wrote:
Tue Dec 03, 2019 9:42 am
Also It pauses the CPU for 4 Cycles?
I'm already at a time crunch for Logic. :(
At the highest samplerate that amounts to less than 250 cycles per frame, so overall it's relatively small amount of time lost.
IMAGICA wrote:
Tue Dec 03, 2019 9:42 am
The game Uses an absurd amount of bank switching and I need to bankswitch the sample data into $C000 .
The sample data bank should not be switched at any time while it's playing. The $C000 bank in this case should be dedicated to samples only, and switched when a new sample starts.
Last edited by rainwarrior on Tue Dec 03, 2019 11:50 am, edited 1 time in total.

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 11:38 am

rainwarrior wrote:
Tue Dec 03, 2019 11:14 am
The sample data bank should not be switched at any time while it's playing. The $C000 bank in this case should be dedicated to samples only, and switched when a new sample starts.
dougeff wrote:
Tue Dec 03, 2019 10:41 am
There would be no way to detect when DMC is reading. It would happen multiple times a frame, and can happen any time.
Ouch. Guess It's scrapped for now. Thank you
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

User avatar
rainwarrior
Posts: 7669
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simultaneous DPCM and IRQ

Post by rainwarrior » Tue Dec 03, 2019 11:49 am

Can you not use the bank at $A000 to do whatever banking you need? Why is there a specific need to swap $C000 and wanting to dance around the DPCM fetch timing? Maybe there's a different solution to whatever problem this wanted to be a solution for?

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 12:29 pm

rainwarrior wrote:
Tue Dec 03, 2019 11:49 am
Can you not use the bank at $A000 to do whatever banking you need? Why is there a specific need to swap $C000 and wanting to dance around the DPCM fetch timing? Maybe there's a different solution to whatever problem this wanted to be a solution for?
Here's the list of what does what:
Both:
$C000= "HUB Bank": This is where I configure the JSR to go to for things in the other banks and also the main IRQ/ NMI bank routines.
MMc3:
$8000-$A000 bank switch constantly for bullets sound and other functions, meaning it won't stay in place for a long time unless after a "Round/Act/Stage".

(I wish that I could Configure 8000 seperatly but reading the wiki says otherwise)

MMc5(The game It's used for):
$6000-$BFFF- Entire level map
$8000 Meta tile data (why it loads for a very long time)/Music Data bank
$A000 Same function as the $8000-$A000 bank in the MMC3 game
$E000 All accessible logic that is repeated in banks

I Literally don't have much time for a static Bank.

I could Swap $A000 for dpcm but i need a tme to swap for read AND that's may main logic bank.

Can I be more Efficient? I think that's now my question.
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

User avatar
Memblers
Site Admin
Posts: 3770
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Simultaneous DPCM and IRQ

Post by Memblers » Tue Dec 03, 2019 2:35 pm

What's the size of your DPCM sample(s)? There is always some static code, pretty much has to be for NMI/reset vectors at the very least. I would just bump it up against those, put it at $F800 or whatever is the highest start address it fits in. If you must swap out that bank, it's not a crime to simply duplicate the DPCM data in the multiple banks that are mapped there. :) Unless you are severely low on memory, or the samples are monstrously huge (in the latter case, you could consider a lower sample rate).

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Simultaneous DPCM and IRQ

Post by IMAGICA » Tue Dec 03, 2019 4:25 pm

Memblers wrote:
Tue Dec 03, 2019 2:35 pm
What's the size of your DPCM sample(s)? There is always some static code, pretty much has to be for NMI/reset vectors at the very least. I would just bump it up against those, put it at $F800 or whatever is the highest start address it fits in. If you must swap out that bank, it's not a crime to simply duplicate the DPCM data in the multiple banks that are mapped there. :) Unless you are severely low on memory, or the samples are monstrously huge (in the latter case, you could consider a lower sample rate).
Ok then. It might be a tight squeeze for 4 samples ("Checkpoint", If compressed correctly can be 417 bytes. If calculated correctly, all four planned sounds ("GO","Ready", "Finish" and "Checkpoint" ) can fit About silghtly under 2 kB), but it's doable. Now I just need to amplify them a bit and I am good to go.
This is Under $E000 by the way.
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]

Post Reply