DMC / Controller Confusion

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

DMC / Controller Confusion

Post by cartlemmy »

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: Select all

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?
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen »

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" .
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

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?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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.
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

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.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Post by thefox »

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. :)
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

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!
Post Reply