Page 1 of 1

Implement proper frame skipping

Posted: Sun Sep 30, 2018 11:22 pm
by babai
Hello guys, so like every other person on the planet I've also developed my own NES emu. It's browser based & cycle accurate so it needs a good CPU to maintain full speed. To run in weaker CPUs, I've tried to implement frame skipping in the following way:

Code: Select all

1. After a certain no. of frames, check if we have fallen behind
2. If true, skip a frame
3. When we are skipping, all the ppu does is update vblank flags, clear sprite0 and overflow flags, implement the pre-render line clock skipping on odd frames and generate NMIs. It doesn't do X/Y scrolling, or sprite evaluation, or rendering.
The problem is in some games like Megaman II I see the screen jumping in some scenes and when megaman takes those ladders to go up/down a screen, the screen jumps as if nametables are not being switched. This doesn't happen in normal scrolling scenarios, i.e the entire world of super mario is okay.
I'm thinking it might due to sprite0 hit not being set, so I tried to set sprite hit in the skipped frame in the same scanline/cycle the last frame had. But it's still not working

So my question is, are their any good frame skipping strategies where I don't need to do much work in the ppu but still be accurate enough? Thanks.

Re: Implement proper frame skipping

Posted: Mon Oct 01, 2018 2:03 am
by babai
Okay, I solved the screen jumping issue, this is due to incorrectly ending the skipped frame. But keeping this aside, I think my strategy is not accurate at all. Copying sprite 0 hit from previous frame can either cause an excess hit, and not copying it can cause a hit to miss.

Re: Implement proper frame skipping

Posted: Mon Oct 01, 2018 3:22 am
by Sumez
I don't think skipping frames should result in skipping PPU emulation. That's always going to cause inaccuracies in some games (I'd probably use Battletoads as a "worst case" example).
Skipping frames should just skip the emulator's own rendering code.

Re: Implement proper frame skipping

Posted: Mon Oct 01, 2018 3:44 am
by babai
I calculate sprite 0 hit, during my rendering code, after the background and attribute shift registers have shifted, and all sprites for current X position have been examined. Then I just calculate the color value and push to an off screen buffer, which is not that cpu intensive. So If I do all these calculations then there is not point of frame skipping anyways.

Re: Implement proper frame skipping

Posted: Mon Oct 01, 2018 7:12 am
by tepples
Do any games with nametable-triggered CHR bank switches (Punch-Out!!, Fire Emblem/FC Wars, Oeka Kids, FFVII) use sprite 0 hit? Those could be even tougher special cases than Battle(toads| Kid| City| Chess).