Easier APU documentation?

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

The code from the Wiki works fine for me (testing on a PAL NES at the moment). I do notice that your code plays a very quiet noise either way, maybe that's the problem.
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

blargg wrote:The code from the Wiki works fine for me (testing on a PAL NES at the moment). I do notice that your code plays a very quiet noise either way, maybe that's the problem.
Odd. It plays full volume here. Definitely not a volume issue.

*shrugs* I'm baffled.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Can you show the complete code that you're using? Maybe the error is elsewhere. I just verified it on an NTSC NES as well, with the code running at reset.
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

Just stripped it all down to this;

Code: Select all

reset:
	sei
	ldx #$FF
	txs
	lda #$00
	sta PPU0
	sta PPU1
	
        jsr init_APU

mainLoop:
	jmp mainLoop
	
nmi:	rti
irq:  rti

init_APU:
	
	lda #$00
	sta $4015
	
	ldx #$00
@a:	lda @apu_regs,x
	sta $4000,x
	inx
	cpx #$18
	bne @a

	lda #$0F
	sta $4015
	
	lda #%00111111
	sta $400c
	lda #$01
	sta $400e
	;sta $400f
	rts

@apu_regs:	
        .BYTE $30,$08,$00,$00
	.BYTE $30,$08,$00,$00
	.BYTE $80,$00,$00,$00
	.BYTE $30,$00,$00,$00
	.BYTE $00,$00,$00,$00
	.BYTE $00,$0F,$00,$40
	
Which produces no sound until you put the 'sta $400f' line back in.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Here's the problem; your init_apu routine is different than the one on the wiki:

Code: Select all

init_apu:
        lda #$00   ; should be $0F
        sta $4015
I've added a note to the Wiki as to not altering the init routine in any way. Using the above was preventing the length counters from being loaded properly by the loop.
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

That's very odd.

I originally had the init routine from the wiki, verbatim, and I wasn't getting any noise output unless I wrote something to $400F at the time of writing the frequency register ($0E).

So then I added the lines to write $00 to $4015 before the loop and $0F after the loop, just clutching at straws really. It didn't seem to have any effect.

Now I've restored the init back to the wiki version, removed the extra write to $400f and it's now working.

*shrugs* Ghosts in the machine maybe....
User avatar
MetalSlime
Posts: 186
Joined: Tue Aug 19, 2008 11:01 pm
Location: Japan

Post by MetalSlime »

tokumaru wrote: From what I've read so far, the Nerdy Nights sound tutorial is pretty straightforward and tells exactly what you have to do to get things going without much trouble, along with simple register descriptions. Assuming it's accurate, I guess it's a really good intro to sound programming.
Thanks! I wrote those tutorials to help people learn how to program the APU. The tech docs are great but dense. A lot of new homebrewers were coming in and posting ROMs of their games in progress, but they were all silent. I had just figured the APU out so I wanted to help out.

BTW, if anyone wants to host or copy/paste the Nerdy Nights sound tutorials somewhere in the nesdev wiki, you have my blessing. The more accessible they are to nes homebrewers the better.
MetalSlime runs away.
Post Reply