Overclocking In An SNES Emulator

The bsnes emulator has a new overclocking mode to eliminate slowdowns in SNES games while keeping the gameplay speed accurate. We’re emulating old SNES hardware on modern machines that are vastly more powerful. Eliminating slowdowns should be trivial, right? For an emulator such as bsnes, which is written to achieve essentially pixel-perfect accuracy when emulating, the problem is decidedly non-trivial. Stick around to learn why.

The Super Nintendo was an impressive system, for its time — mostly. The SNES framerate is locked to 60 FPS, which is a bit surprising considering the NTSC standard was only 30 FPS. NTSC calls for 30 frames per second, but those are interlaced frames. 30 times a second the even scanlines are updated, and 30 times a second the odd scanlines are updated. So 60 times a second, half of the screen is updated, alternating between the even and odd lines.

At the top of each frame the equivalent of half a scanline marks whether the rest of the frame is even or odd scanlines. In order to produce a clean 60 FPS, the SNES didn’t interlace, and just always wrote to the same 240 scanlines. This is also why retro consoles can look so terrible on modern monitors. The blank scanlines were hidden by the analog fuzziness of CRT TVs.

The SNES primary processor runs all the game logic and updates the graphics 60 times per second, finishing each frame’s calculations before the TV began writing that frame to the screen. Games were generally carefully written to make sure each frame’s processing would finish within that 16 millisecond window.

Most games have a few scenarios where lots of things are happening at once, and the processor just can’t keep up with the framerate. In this case, the game begins to lag. Since the framerate is hard synced to 60fps, the previous frame is simply shown again, and the game is paused for that frame while processing finishes.

The bsnes solution is a clever one. Virtual scanlines are added, but the audio and video emulation is paused. This allows the whole process to happen very rapidly, and yet continue to sync with the normal 60 FPS. Below is the Gradius III demo, showing off the results.

Header image: Sandos (CC BY-SA 3.0).

10 thoughts on “Overclocking In An SNES Emulator

  1. Basically, there is a way to output non-interlaced video on traditional CRT? Wow, I have no idea! How is the 240p decided then? I think I have seen different game consoles of the same generation having different number of vertical resolutions.

    1. 240p is more of a hack within the 480i spec. In 480i, the odd-line field is drawn as normal: the first line begins at the beginning of the vertical trace. However, the even-line field is drawn with a slight delay to let the vertical trace fall below the already-drawn odd lines.

      240p gets rid of this delay on even fields, forcing the CRT to always draw odd lines and never draw even lines. Hence, a 240p60 progressive image. Since 240p isn’t exactly an official spec, many modern monitors mistake it for 480i and attempt to either deinterlace it (which is terrible since it’s not interlaced in the first place) or draw every other frame on odd/even lines like a 480i signal. Either way: not a great look. Line doublers like the Open Source Scan Converter can properly detect 240p and will handle it correctly, outputting a line-doubled HDMI/DVI signal.

  2. Hopefully this can be applied to the Saturn which has a much more complex series of processors and clocks (including two main cpus )

    It’s something I’ve asked for for yabuse more than once but there was little interest (and I was far from capable of implementing something like this).

    I did get it working sometime ago on an early mega drive / genesis emulator with improvements in fluidity of frames but audio suffered and I put lag became much more complex.

  3. Interlaced video is “automatic” when you’re working with a CRT. When the hsync rate is an integer multiple of the vsync rate, you get progressive video. When it’s ±1/2, you get interlaced video.

    There’s fanciness (“serration sync”) around massaging the composite sync signal so that vsync can start halfway through hsync every other retrace.

  4. *a SNES, not an.
    An is only used when the next word starts with a vowel sound. Normally you have an excuse with acronyms cause they can be pronounced 2 ways. SNES or super Nintendo entertainment system. Neither start with a vowel sound

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.