0ldsk00l / nestopia

Cross-platform Nestopia emulator core with a GUI
http://0ldsk00l.ca/nestopia
GNU General Public License v2.0
701 stars 168 forks source link

DMC DMA read corruption working incorrectly #308

Open Fiskbit opened 5 years ago

Fiskbit commented 5 years ago

DMC DMA read corruption occurs in Nestopia UE on even cycles when it should occur on odd cycles. I'd like to use even-cycle joypad reads to avoid having to spend cycles reading joypads 2 or more times, as discussed here: https://forums.nesdev.com/viewtopic.php?f=2&t=14319. This issue can be tested with dma_sync_test; version 1, with separate even-cycle and odd-cycle versions, can be found on the first page of that thread, while v2 (with just even-cycle) is on page 2 and on the Nesdev "Emulator tests" page. The tests display a black screen until a right input is observed, turning the screen white. The v1 even-cycle and v2 tests are expected to not turn white until the user presses right, while the v1 odd-cycle test is expected to show a white screen almost immediately. While other emulators I've tested that emulate this corruption (Mesen 0.9.7, puNES 0.100, Nintendulator 0.975) match expected behavior, Nestopia UE's behavior is inverted, indicating the cycle alignment is wrong. I've tested on versions 1.47 and 1.49.

Fiskbit commented 5 years ago

Given the environments in which Nestopia runs, I expect old versions with this bug to be floating around for quite some time and I'd like to still be able to support them. Unfortunately, this problem is difficult to detect directly, so I've identified a separate accuracy test that is currently failed by Nestopia but is passed by Mesen, puNES, and Nintendulator: cpu_dummy_writes/cpu_dummy_writes_ppumem. Specifically, Nestopia does not emulate PPU open bus behavior correctly across 4 writes to $2004. By writing #$7F to $2004 four times and comparing against the value read from $2000 each time, Nestopia can be identified among this pool of emulators by one failed comparison. This test is easy and reliable.

I ask that you fix this PPU open bus issue at the same time as the DMC read corruption issue so I can use this to reliably identify whether I need to wait an extra cycle in my input routine to maintain compatibility with older versions of Nestopia. My hope is that there are not other emulators of any note that both correctly handle DMC read corruption and have this same open bus issue (I'm not aware of any).

carmiker commented 1 year ago

I believe I have fixed this problem in the upstream repository now. Some other details regarding DMC DMA are not quite perfect yet, but the odd/even cycle problem is at least fixed, and it was a simple and obvious fix in hindsight. The next tagged release should be able to close this issue.