SNES Console Initialization and Core Functions. More...
Go to the source code of this file.
Functions | |
| void | consoleInit (void) |
| Initialize SNES hardware. | |
| void | fadeIn (u8 speed) |
| Fade the screen from black (0) up to full brightness (15). | |
| void | fadeOut (u8 speed) |
| Fade the screen from full brightness (15) down to black (0). | |
| u8 | getBrightness (void) |
| Get current brightness. | |
| u16 | getFrameCount (void) |
| Get frame counter. | |
| u8 | isInVBlank (void) |
| Check if currently in VBlank. | |
| u8 | isPAL (void) |
| Check if PAL system. | |
| void | resetFrameCount (void) |
| Reset frame counter. | |
| u16 | rngNext (void) |
| Next pseudo-random 16-bit number. | |
| void | rngSeed (u16 seed) |
| Seed the generator (the srand() of 0.x, removed 2026-10-05). | |
| void | setBrightness (u8 brightness) |
| Set screen brightness. | |
| void | setScreenOff (void) |
| Disable screen display (blank). | |
| void | setScreenOn (void) |
| Enable screen display. | |
| void | WaitForVBlank (void) |
| Wait for next VBlank period. | |
SNES Console Initialization and Core Functions.
Provides functions for initializing SNES hardware and core functionality like VBlank synchronization.
Originally from: PVSnesLib (https://github.com/alekmaul/pvsneslib) Author: Alekmaul License: zlib (compatible with MIT) Modifications:
| void consoleInit | ( | void | ) |
Initialize SNES hardware.
Must be called at the start of your program. What it does, exactly:
It does not clear work RAM or set up the CPU (crt0 did that before main), and it loads no palette — this list claimed all three until 2026-09-20.
After calling, screen is blanked (black). Call setScreenOn() to enable display after you've set up your graphics.
| void fadeIn | ( | u8 | speed | ) |
| void fadeOut | ( | u8 | speed | ) |
Fade the screen from full brightness (15) down to black (0).
Steps INIDISP brightness from 15 → 0, waiting speed VBlank frames between each step. Final state: setBrightness(0) (visually black, screen still rendering). Combine with setScreenOff() afterwards if you want to also enter force-blank for safe VRAM updates.
At 60 fps (NTSC):
| speed | VBlank frames to wait between each brightness step. speed=0 waits for nothing: all 16 steps are written in one burst, i.e. an instant cut, not a fade. |
| u8 getBrightness | ( | void | ) |
Get current brightness.
|
inline |
Get frame counter.
Returns the number of VBlanks since initialization. Wraps at 65535.
Inlined for zero-call-overhead access (just a 16-bit load).
| u8 isInVBlank | ( | void | ) |
Check if currently in VBlank.
| u8 isPAL | ( | void | ) |
| void resetFrameCount | ( | void | ) |
Reset frame counter.
Sets frame counter to 0. Useful for timing game events.
| u16 rngNext | ( | void | ) |
Next pseudo-random 16-bit number.
A 16-bit linear feedback shift register (x^16 + x^14 + x^13 + x^11 + 1). Named rand() until 2026-09-22 (that name was removed on 2026-10-05) — a libc name for a function that is not the libc one (no RAND_MAX, 1-65535, a u16), which collides the day any C library code is linked.
| void rngSeed | ( | u16 | seed | ) |
Seed the generator (the srand() of 0.x, removed 2026-10-05).
consoleInit() seeds it from the H/V counters; reseed from a player action (rngSeed(getFrameCount()) on START) for a different game each run.
| seed | Initial seed value; 0 is replaced by a fixed non-zero state |
| void setBrightness | ( | u8 | brightness | ) |
Set screen brightness.
| brightness | Brightness level (0-15, 0=black, 15=full) |
The mistake survives testing: a small transfer written this way lands inside VBlank and is correct every time, while a multi-KB one has its tail dropped during active display. Use setScreenOff() / setScreenOn() around any upload that is not comfortably inside the VBlank budget — see dmaCopyVram().
| void setScreenOff | ( | void | ) |
Disable screen display (blank).
Turns off the display. Use during major VRAM updates that can't complete during VBlank.
| void setScreenOn | ( | void | ) |
Enable screen display.
Turns on the display after initialization or a screen blank, at the LAST brightness set (15 after consoleInit). After fadeOut() that level is 0, so the screen stays black until fadeIn() or setBrightness() — which is what the fade example below relies on. (Documented as "full brightness" until 2026-09-20.)
| void WaitForVBlank | ( | void | ) |
Wait for next VBlank period.
Blocks until the PPU enters Vertical Blank. This is essential for:
Call once per frame in your main loop.
The capital W is deliberate: the name is PVSnesLib's, kept so a port needs no edit. It is the only function of the library not in camelCase.