Implement proper frame skipping

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
babai
Posts: 10
Joined: Thu Aug 03, 2017 7:15 am
Location: India

Implement proper frame skipping

Post by babai » Sun Sep 30, 2018 11:22 pm

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.

babai
Posts: 10
Joined: Thu Aug 03, 2017 7:15 am
Location: India

Re: Implement proper frame skipping

Post by babai » Mon Oct 01, 2018 2:03 am

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.

User avatar
Sumez
Posts: 909
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: Implement proper frame skipping

Post by Sumez » Mon Oct 01, 2018 3:22 am

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.

babai
Posts: 10
Joined: Thu Aug 03, 2017 7:15 am
Location: India

Re: Implement proper frame skipping

Post by babai » Mon Oct 01, 2018 3:44 am

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.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Implement proper frame skipping

Post by tepples » Mon Oct 01, 2018 7:12 am

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).

Post Reply