This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

DMC - errant button presses **SOLVED**

DMC - errant button presses **SOLVED**
by on (#163585)
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:
_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?
Re: DMC - errant button presses
by on (#163586)
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.
Re: DMC - errant button presses
by on (#163587)
The games are pausing randomly (START) when DMC sounds play. And occasionally Select. I'm not sure if R is or not.
Re: DMC - errant button presses
by on (#163589)
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.
Re: DMC - errant button presses
by on (#163596)
Do random pauses occur while holding Up?
Re: DMC - errant button presses
by on (#163598)
Not holding UP, but if I tap UP repeatedly, it goes into Pause mode, as if START was pressed.
Re: DMC - errant button presses
by on (#163599)
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.
Re: DMC - errant button presses
by on (#163600)
Spotted an error: if the test fails at the end, you jmp to GetInput3 but don't restrobe the controllers.
Re: DMC - errant button presses
by on (#163601)
Aha, that could be it. Thanks.

I'll test it later tonight.
Re: DMC - errant button presses
by on (#163621)
That was it. Thanks rainwarrior. I can now confirm that my game is hardware compliant.

This is what it looks like now...

Code:
_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.