Nametable selection for NES PPU

614 Views Asked by At

I am writing an emulator for NES and I am trying to run Super Mario Bros. Everything runs fine, except for some screen flicker that happens when nametable 1 is used by the game.

If you are not aware, SMB has a constant score bar display at the top (around 31 scanlines) and rest of the screen below it scrolls horizontally. This score display sits only in Nametable 0 (and nametable 2 since the mapper uses Vertical mirroring).

The game sets the PPUCTRL to name table 0 at the start of the NMI and then waits for sprite 0 hit (which happens around line 30) and then sets the name table to 0 or 1 as required by the rest of the screen.

What is happening with my emulator that PPUCTRL is being set to an odd number even before the first scan line is rendered. As a result it displays the score bar from the right name tables and I get the flicker.

I confirmed the behavior with a standard emulator fceux. There too the PPUCTRL is set to a value that is odd. But there the emulator still draws from the left nametable.

Is my understanding of PPUCTRL not correct? Does the PPU always use the nametable 0 before a sprite 0 hit?

0

There are 0 best solutions below