Sorry for not getting back to this one sooner. I just finished my code that plays DMC samples when pressing 'A'. 'Left' and 'Right' Lets you choose a different sample. All the selections caused by button presses seems to be working, but the first time I play a sample I hear a 'pop' sound and after that nothing if I try again.
Here is whats in my main loop (and few lines before it):
Code:
LDA #%00010000
STA APUStatus
MainLoop:
LDA joy_1_frame
AND #%00000001
CMP #%00000001
BNE SkipA
LDA #$01
STA DMCTrigger
SkipA:
LDA joy_1_frame
AND #%01000000
CMP #%01000000
BNE SkipLeft
LDA DMCSample
SEC
SBC #$01
CMP #$FF
BNE SkipUnderflow
LDA #$00
SkipUnderflow:
STA DMCSample
SkipLeft:
LDA joy_1_frame
AND #%10000000
CMP #%10000000
BNE SkipRight
LDA DMCSample
CLC
ADC #$01
CMP #$06
BNE SkipOverflow
LDA #$05
SkipOverflow:
STA DMCSample
SkipRight:
LDA #$01
STA sleeping
MainSleep:
LDX sleeping
CPX #$00
BNE MainSleep
JMP MainLoop
Here is my DMC code (in NMI):
Code:
DMCPlay:
LDX DMCTrigger
CPX #$01
BNE SkipDMC
LDY DMCSample
LDA DPCMFreq, y
STA DMCFreq
LDA DPCMLoad, y
STA DMCLoad
LDA DPCMAddr, y
STA DMCAddr
LDA DPCMLength, y
STA DMCLength
LDX #$00
STX DMCTrigger
SkipDMC:
...
Here are the lookup tables:
Code:
DPCMFreq:
.db $0F,$0F,$0F,$0F,$0F,$0F
DPCMLoad:
.db $3C,$40,$40,$3C,$40,$30
DPCMAddr:
.db $00,$24,$1E,$04,$11,$2C
DPCMLength:
.db $10,$20,$18,$34,$34,$1C
And here is the .incbins:
Code:
.bank 3
.org $C000
.incbin "Recca_$C000.dmc"
.org $C100
.incbin "Recca_$C100.dmc"
.org $C440
.incbin "Recca_$C440.dmc"
.org $C780
.incbin "Recca_$C780.dmc"
.org $C900
.incbin "Recca_$C900.dmc"
.org $CB00
.incbin "Recca_$CB00.dmc"
The samples and lookup table values are from Recca (didn't include the pitched down samples) to make it easier for me to at least get things working.