OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Basics — ppuReset(): the next screen starts from a clean PPU. More...

#include <snes.h>

Macros

#define SCREEN_A_FRAMES   120
 How long screen A stays, in frames (two seconds at 60 Hz).

Functions

int main (void)
 Entry point: screen A for two seconds, ppuReset(), screen B.
void screen_a_setup (void)
 Screen A: text on BG3 of Mode 1, and every other PPU register changed on purpose.
void screen_b_setup (void)
 Screen B: set up exactly like a first screen.

Detailed Description

Basics — ppuReset(): the next screen starts from a clean PPU.

A game is a chain of screens: title, game, game over, title again. Each one sets the PPU registers it needs, and every register it does not set keeps the value the previous screen left. consoleInit() rewrites only a few of them; ppuReset() rewrites all of them, to their power-on value.

Screen A changes nearly every PPU register: the BG mode (Mode 1, text on BG3), the sprite size and tile base, the map and tile bases of the four layers, the scrolls, main and sub screen, a window, color math (a tint), mosaic, the Mode 7 matrix, SETINI, the brightness, and an HDMA wave on BG3. Two seconds later the program calls ppuReset() and sets up screen B the way any first screen is set up. Screen B shows no trace of screen A. Remove the ppuReset() call and screen B inherits the scroll of BG1 and the tint.

SNES Concepts
  • The PPU registers are write-only and keep their value until written: a screen inherits every register the previous one set and it did not
  • ppuReset() writes them all back to the values crt0 writes at boot, and puts the library's shadows (scrolls, mosaic, color math, windows, Mode 7, HDMA) back with them
  • It leaves VRAM, CGRAM, the audio and NMITIMEN alone: the next screen still loads its own tiles, maps and palettes
What to Observe
  • Screen A, two seconds: a waving, tinted, blocky text on a blue backdrop
  • Screen B: plain white text on green, in place, no wave, no tint
Modules Used
console, dma, text, background, sprite, colormath, mosaic, window, mode7, hdma, ppu_reset
See also
console.h (ppuReset), testing/manifests/basics_ppu_reset.toml

Macro Definition Documentation

◆ SCREEN_A_FRAMES

#define SCREEN_A_FRAMES   120

How long screen A stays, in frames (two seconds at 60 Hz).

Function Documentation

◆ main()

int main ( void )

Entry point: screen A for two seconds, ppuReset(), screen B.

Returns
Never returns (infinite loop).

◆ screen_a_setup()

void screen_a_setup ( void )

Screen A: text on BG3 of Mode 1, and every other PPU register changed on purpose.

The visible part is the text (BG3), its scroll, the tint, the mosaic and the wave. The rest (BG1, BG2, BG4, OBJSEL, the window, the sub screen, Mode 7, SETINI) is invisible here and changed so that ppuReset() has something to undo; the manifest reads it back from the PPU.

◆ screen_b_setup()

void screen_b_setup ( void )

Screen B: set up exactly like a first screen.

Nothing here undoes screen A: ppuReset() did. The manifest reads the PPU at the first instruction of this function, right after ppuReset(), and finds the values it reads at main().