DMC - errant button presses **SOLVED**

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

Post Reply
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

DMC - errant button presses **SOLVED**

Post by dougeff »

Hello all,

Yesterday I got a PowerPak, and I'm testing my games today...

Sadly, I'm getting errant button presses from DMC music corruption.

This is the code I've been working with...(and is the sample code on my blog, btw...)

Code: Select all

_Get_Input:
	lda _joypad1
	sta _joypad1old
	lda _joypad2
	sta _joypad2old
	
	ldx #$01	;strobe controller 1
	stx $4016
	dex
	stx $4016
	
	ldy #$08
GetInput2:		;get first read, store them as a test
	lda $4016
	and #$03
	cmp #$01
	rol _joypad1test
	lda $4017
	and #$03
	cmp #$01
	rol _joypad2test
	dey
	bne GetInput2
	
	ldx #$01	;restrobe strobe controller 1
	stx $4016
	dex
	stx $4016
	
	ldy #$08
GetInput3:		;read again, store them as joypads
	lda $4016
	and #$03
	cmp #$01
	rol _joypad1
	lda $4017
	and #$03
	cmp #$01
	rol _joypad2
	dey
	bne GetInput3
	
CompareInput:
	lda _joypad1
	cmp _joypad1test
	bne :+
	lda _joypad2
	cmp _joypad2test
	bne :+
	rts				;if same, done
	
:	lda _joypad1
	sta _joypad1test
	lda _joypad2
	sta _joypad2test
	ldy #$08
	jmp GetInput3	;if different, reread
I can't spot an error.

But, from blargg's sample code, (circuitously directed to from the wiki), he's reading the joypads 4 times, and I'm only reading 3 x. Could this be the source of the error?
Last edited by dougeff on Sun Jan 31, 2016 9:08 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: DMC - errant button presses

Post by tepples »

Usually if there's a DPCM glitch, the spurious press will be Right. Is that what you're seeing?

Would it be acceptable to read only twice and discard the reads (instead using the previous frame's presses) if they differ? Because the gamepad driver I use does that and has no problem with spurious presses.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: DMC - errant button presses

Post by dougeff »

The games are pausing randomly (START) when DMC sounds play. And occasionally Select. I'm not sure if R is or not.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: DMC - errant button presses

Post by dougeff »

Hmm. Maybe DMC is a 'red herring', because I'm pretty sure one of the problem games doesn't even use DMC samples.

I'm very confused/annoyed.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: DMC - errant button presses

Post by tepples »

Do random pauses occur while holding Up?
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: DMC - errant button presses

Post by dougeff »

Not holding UP, but if I tap UP repeatedly, it goes into Pause mode, as if START was pressed.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DMC - errant button presses

Post by rainwarrior »

You may want to do controllers individually, rather than reading them in parallel like that? I seem to recall notes from blargg that roughly 2 read loops of a single controller can fit between samples, but 3 read loops might not fit. (I might be misremembering though.)

Edit: probably isn't the problem here, though.
Last edited by rainwarrior on Sun Jan 31, 2016 5:39 pm, edited 2 times in total.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DMC - errant button presses

Post by rainwarrior »

Spotted an error: if the test fails at the end, you jmp to GetInput3 but don't restrobe the controllers.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: DMC - errant button presses

Post by dougeff »

Aha, that could be it. Thanks.

I'll test it later tonight.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: DMC - errant button presses

Post by dougeff »

That was it. Thanks rainwarrior. I can now confirm that my game is hardware compliant.

This is what it looks like now...

Code: Select all

_Get_Input:
	lda _joypad1
	sta _joypad1old
	lda _joypad2
	sta _joypad2old
	
	ldx #$01	;strobe controller 1
	stx $4016
	dex
	stx $4016
	
	ldy #$08
Get_Input2:		;get first read, store them as a test
	lda $4016
	and #$03
	cmp #$01
	rol _joypad1test
	lda $4017
	and #$03
	cmp #$01
	rol _joypad2test
	dey
	bne Get_Input2

GetInputFix:
	ldx #$01	;restrobe strobe controller 1
	stx $4016
	dex
	stx $4016
	
	ldy #$08
Get_Input3:		;read again, store them as joypads
	lda $4016
	and #$03
	cmp #$01
	rol _joypad1
	lda $4017
	and #$03
	cmp #$01
	rol _joypad2
	dey
	bne Get_Input3
	
CompareInput:
	lda _joypad1
	cmp _joypad1test
	bne :+
	lda _joypad2
	cmp _joypad2test
	bne :+
	rts				;if same, done
	
:	lda _joypad1
	sta _joypad1test
	lda _joypad2
	sta _joypad2test
	; ldy #$08
	jmp GetInputFix	;if different, reread
Give me a little time to redo the links to my game, thanks.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
aquasnake
Posts: 515
Joined: Fri Sep 13, 2019 11:22 pm

Re: DMC - errant button presses **SOLVED**

Post by aquasnake »

dmc/dma operation will hijack the rol bit instruction,i'v met the same trouble
User avatar
aquasnake
Posts: 515
Joined: Fri Sep 13, 2019 11:22 pm

Re: DMC - errant button presses

Post by aquasnake »

dougeff wrote: Sun Jan 31, 2016 5:29 pm Not holding UP, but if I tap UP repeatedly, it goes into Pause mode, as if START was pressed.
yes, the same phenomenon like mine:

JOY_UP becomes JOY_START
Post Reply