Implement proper frame skipping

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Implement proper frame skipping
by on (#226700)
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:
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
by on (#226703)
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
by on (#226707)
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
by on (#226709)
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
by on (#226718)
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).