DMC / Controller Confusion

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
DMC / Controller Confusion
by on (#71094)
Oh no, I'm a n00b again!

There's a bug that's been in my game since I first implemented the sound engine, that I've decided it's time to squash it. The bug is like this: The 'right' button of the controller is being 'pushed' by the sound engine some how. Not constantly, but for just 1 frame every few seconds or so. I've actually narrowed it down to my DMC routine.

If I comment out the below code the bug is gone:
Code:
LDA #$0F

STA $4015  ; stop DMC if it's currently playing



LDA #$1F

STA $4015  ; and restart it

Is this not something I should be doing every time I start a new DMC sample? I notice the $4015 is just one byte lower that the controller 1 port.

I'm really stumped, any ideas?

by on (#71095)
There's a known bug where if you use dpcm the controller gets an extra clock sometimes. The way to fix it is to have your controller read several times and pick "best two out of three" .

by on (#71096)
Jeroen wrote:
There's a known bug where if you use dpcm the controller gets an extra clock sometimes. The way to fix it is to have your controller read several times and pick "best two out of three" .


Oh!!! So it's not a bug that I introduced?! lol. Is that a bug in NEStopia, or a bug that exists on the NES's hardware?

by on (#71100)
You got that while testing in Nestopia? This bug was found recently on real hardware, but AFAIK it shouldn't happen in Nestopia, because I don't think the emulator has been updated since that was discovered... In fact, I'm not aware of any emulators implementing that behavior. So, unless I'm wrong, there's still a chance that the problem was caused by an error on your part.

Whatever the reason is though, if you are playing DPCM samples while reading the controllers, you should be prepared to deal with unintentional reads, which will screw up your button data. Some games keep reading the joypad until 2 consecutive reads match, others only try a few times, and if they don't match the previous frame's data is used. I believe the wiki has a DPCM-proof controller reading function somewhere, look for it.

Note that this bug also affects the reading of PPU data through register $2007. For that case, I'm not aware of any solution.

by on (#71101)
tokumaru wrote:
You got that while testing in Nestopia?

Yes.

Does it have anything to do with this update in Nestopia v1.40?
"DMC DMA read conflicts. Info from blargg and bunnyboy."


Great, thanks for the info. I think it is enough for me to fix my issue.

by on (#71114)
Yeah it is implemented in Nestopia. Also occured when D-Pad hero was first released.

Blargg posted a what claims to be a fool proof routine in this thread: http://nesdev.com/bbs/viewtopic.php?t=4124. I don't think any of the commercial games were that scientific about it, though. :)

by on (#71123)
thefox wrote:
Yeah it is implemented in Nestopia. Also occured when D-Pad hero was first released.

Cool, Nestopia is awesome.

thefox wrote:
Blargg posted a what claims to be a fool proof routine in this thread: http://nesdev.com/bbs/viewtopic.php?t=4124. I don't think any of the commercial games were that scientific about it, though. :)

Cool, thanks!