Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 746

Help needed getting MMC5 PCM to work!

$
0
0
Hi, I know it isn't liked to use MMC5 for homebrew, but for the past year I've been making my game in it.

I am having a really hard time understanding how this works. I am quite sure I set up the IRQ wrong,
and I am even moreso worried about how the PCM is even supposed to be fed.

Here is my code, please keep in mind all of this is guess work, I don't even know how an IRQ runs.
The code to initiate the IRQ is also in the Main game loop and not in VBlank.

Code:

IRQ:  STA $0400  STX $0401  STY $0402AcknowledgeIRQ:  LDA $5204             ;Acknowledge IRQ  LDA #$80  STA $5010             ;PCM IRQ Enable  LDX #$20Repeat16:  LDA [SampleIndex], y  ;Index  STA $5011             ;PCM Write  INC SampleIndex  DEX  BNE Repeat16            ;16 cycle loopIncSampleIndex:  LDA SampleIndex         ;Increment Highbyte after 256          BNE IRQ2  INC SampleIndex+1  LDA SampleIndex+1       ;Loop Highbyte at $B000  CMP #$B0  BNE IRQ2  LDA #$A5                ;Return to $A500  STA SampleIndex+1  JMP IRQ2                ;Here just to show IRQScanlinecode closerIRQScanline:  .db $10,$20,$30,$40,$50,$60,$70,$80,$90,$B0,$D0,$EFIRQ2:  INC IRQScanlineUpdate  LDY IRQScanlineUpdate  CPY #$0E                  ;Loop after index to 0E  BNE IRQ3  LDA #$00  STA IRQScanlineUpdateIRQ3:  LDA IRQScanline, y  STA $5203           ;IRQ Counter  LDA #$80              STA $5204           ;Enable IRQ flag  LDA $0400  LDX $0401  LDY $0402  RTI
The game plays the sample but it is very noisy. The only thing that plays right is the volume, Everything else is a mess.

Here is a link to both PCM and original sample.
The sample is an 8-bit unsigned wav PCM 1000bytes approx

https://drive.google.com/drive/folders/ ... drive_link
Frequency spectrum of original sample
Image

NES Sample
Image

Here I'm showing that it appears that I am not able to set up the IRQ and sample feed loop well as the sampling happens
at horrible intervals
Image

The green dots (At left) are IRQ activations. The teal dots everywhere are PCM $5011 writes.
Often on the frame after there are absolutely no IRQ activations at all. (Likely just my code)
Image
This isn't a case of I've tried everything, but rather that I have no idea if I'm doing anything right.
My questions are.

1. How am I ->actually<- supposed to do the IRQ? The wiki says this

MMC5's DAC is changed either by writing a value to $5011 (in write mode) or reading a value from $8000-BFFF (in read mode). If you try to assign a value of $00, the DAC is not changed; an IRQ is generated instead. This could be used to read stream 8-bit PCM from ROM and terminate at $00.

And then this Psuedocode, which I honestly don't know how to translate or use practically

Code:

(On DAC write)    if(value=0)        irqTrip=1    else        irqTrip=0(On $5010 write)    irqEnable=value.bit7(On $5010 read)    value.bit7=(irqTrip AND irqEnable)    irqTrip=0Cart IRQ line=(irqTrip AND irqEnable)
2. Is my sample type correct?

I choose a wav of 8-bit PCM unsigned, (I also cut out the header in it)

3. How do I set the IRQ? Do I initialize it in Vblank? How often do I initialize it?


If anyone can help me, thank you so much. I don't have access to the only game that uses this Shin 4 Nin Uchi Mahjong.
But I definitely know people here have run the PCM just fine.

Statistics: Posted by YogiGame — Wed Feb 14, 2024 7:47 am — Replies 5 — Views 176



Viewing all articles
Browse latest Browse all 746

Trending Articles