Donkey Kong running improperly on my emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
zeno84
Posts: 2
Joined: Thu Aug 23, 2018 7:10 pm

Donkey Kong running improperly on my emulator

Post by zeno84 »

Hello. I am new here, and I have been working on my NES emulator for the past month or so and am at the point where I can render donkey kong, and it'll play the opening animation.

The problem is that the opening animation does not run properly. Mario will grab the hammer, and run up to the first barrel, hit it, and then the animation will stop right there.

I tried inspecting the loop it's caught in, but I can't detect where it's supposed to escape.

Has anyone else run into anything like this? What was the resolution?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Donkey Kong running improperly on my emulator

Post by Dwedit »

Sounds like a bad CPU, so try to pass all the tests that would indicate that the operations are doing what they should be doing.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Donkey Kong running improperly on my emulator

Post by koitsu »

https://wiki.nesdev.com/w/index.php/Emulator_tests

You will need to read in great detail any documentation that each of these tests/suites comes with. They generally are not "generic magic smoke" that "just does magical things" to test your emulator.
zeno84
Posts: 2
Joined: Thu Aug 23, 2018 7:10 pm

Re: Donkey Kong running improperly on my emulator

Post by zeno84 »

Okay, maybe you guys can answer a somewhat related question for me:

I use a catch-up model where the processor execute X number of cycles, and then hands off execution to the PPU for X*3 PPU dots. Is this a correct way to approach this?

The Catch-Up article on NESDEV seems to suggest that doing one cycle and then three dots is fine. It also goes into detail about some sort of predictive model of execution which I hadn't even considered.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Donkey Kong running improperly on my emulator

Post by Sour »

Nowadays the typical approach used by most emulators is to run the PPU for 3 ticks each time the CPU does a read or write operation. Since every CPU cycle implies a memory read or write, this keeps both components in sync. This does mean that you need to implement dummy read/writes properly first, which might be a bit of a pain when starting off.

If you don't want to bother with dummy read/writes right away, the simplest alternative is to run 1 full CPU instruction (which take anything between 2 to 7-ish? CPU cycles), and then run the PPU (for 6-21 cycles accordingly). This way you can use a lookup table that determines how many cycles a specific instruction uses, etc. This won't give perfect "accuracy" when it comes to some raster effects, etc. but it will work nicely for the vast majority of games.

Unless you are specifically aiming to make a super fast emulator, trying to predict the execution when it comes to the PPU is probably not worth the effort. There are so many different mappers that have hard-to-predict interactions with the PPU that doing so is a lot of extra code/effort (not to mention a source of potential bugs)

Predicting the APU on the other hand is relatively easy, and worth the effort for the extra performance it gives.
Post Reply