Skip to content
Techniques & Technology

Frameskipping and Interpolation

Running the logic slower than the screen

When a C64 game runs out of raster time, it can render less often than it thinks (frameskipping) or think less often than it renders, filling the gaps with linear interpolation. Cadaver set out both in his Rant 9 and shipped the second in Metal Warrior 4.

commodore-64programmingoptimisationarchitecture

A C64 game that scrolls most of the screen, multiplexes a crowd of sprites and runs any kind of AI can run out of raster time, and the honest symptom is slowdown: the whole game runs slower, and so does the player. Cadaver’s Rant 9 is a survey of what a game can do instead, given one condition — that the code that advances the world (movement, AI, collision) can be separated from the code that shows it (scrolling, sprite sorting, VIC register writes).

Fast facts

  • Frameskipping: render less often than the logic runs. Count the frames since the last render and run the logic that many times before drawing again. Motion gets jerkier; speed stays right.
  • Interpolation: run the logic less often than the screen refreshes — every second or fourth frame — and move sprites along a straight line between old and new positions on the frames in between.
  • Cost of interpolation: input lag proportional to the logic interval, and every layer needs its own copy of the sprite data so the frames do not step on one another.
  • Named uses: Metal Warrior 4 (Cadaver, 2001 onwards); Gauntlet III and Myth update sprites at a lower rate than they scroll, without the in-between frames; The Last Ninja 2 takes visibly bigger steps in heavy scenes, which Cadaver reads as frameskipping.

Frameskipping

Frameskipping is the pattern PC games and demos used when rendering cost more than logic. The logic keeps its fixed step; the renderer draws when it can and the logic catches up by running for however many frames were missed. On the C64 Cadaver expects it to pay in 3D and isometric bitmap games, and wherever sprites are masked against the background, as in the Last Ninja games. It cannot help when the logic itself is the slow part.

Interpolation

Interpolation reverses the ratio. The full movement and logic pass runs on every second or fourth frame; between passes the sprites are advanced along the line from their previous position to their new one, which is much cheaper than moving them properly. Scrolling, sprite sorting and the raster interrupts still run at 50 Hz, so the screen stays smooth. Cadaver dates his own realisation of the idea to the end of 2001 and does not know of an earlier C64 game that showed the in-between frames.

The plain form keeps everything in the main program and alternates two kinds of frame: a full logic frame (storing every sprite’s old position first), then an interpolation frame, then round again. The bottleneck is still the logic frame — if it overruns, the whole cycle slips.

Re-entrant interrupts

The stronger form treats the machine as three layers that can interrupt each other:

  1. Movement and logic, in the main program, triggered every two or four frames. It touches no VIC registers and does no scrolling.
  2. Frame update, run from the interrupts: interpolation, scrolling, sprite sorting.
  3. Low-level raster interrupts: screen splits, putting multiplexed sprites on screen, music and sound.

The top-of-screen and bottom-of-screen interrupts each finish with dec $d019 / cli / jmp frameupdate, so the frame update runs as an interruptible tail of either one while the raster interrupts keep firing underneath. An execution counter stops it re-entering itself, and every interrupt has to save its registers on the stack rather than in fixed zero-page locations, because nesting will happen. The frame update keeps its own state about what to do next and exits whenever nothing useful is possible — a colour-RAM update, for instance, only makes sense after the bottom interrupt, where it cannot be seen.

What it felt like

The second Metal Warrior 4 preview ran the logic every fourth frame at 50 Hz. Cadaver worried the controls would feel laggy and had two testers, CreaMD and Pixman, confirm they did not — then wrote, of the finished game, that “4-frame interpolation feels indeed quite lagged”. The full game uses the simpler main-program interpolation, because it did not need more and the re-entrant version’s memory cost was too high.

See also

Not yet fact-checked. This entry was drafted by an AI and nobody has verified it. The dates, figures and technical details may be wrong. Use it to find your bearings, then confirm anything that matters against a primary source.