Loading...
Searching...
No Matches
system.h File Reference

SNES System Variables (crt0.asm exports) More...

#include <snes/types.h>

Go to the source code of this file.

Variables

volatile u16 frame_count
 Frame counter incremented every VBlank by the NMI handler.
 
volatile u8 oam_update_flag
 OAM DMA trigger flag.
 
u8 oamMemory []
 Hardware OAM buffer (544 bytes at $7E:0300)
 
volatile u8 vblank_flag
 VBlank flag (set by NMI handler each frame)
 

Detailed Description

SNES System Variables (crt0.asm exports)

Declares variables defined in crt0.asm that are commonly needed by game code. Including <snes.h> automatically includes this header.

Author
OpenSNES Team

Variable Documentation

◆ frame_count

volatile u16 frame_count
extern

Frame counter incremented every VBlank by the NMI handler.

Counts total frames since boot (including lag frames). Useful for timing, animation, and elapsed-time calculations.

Note
Defined in crt0.asm.

◆ oam_update_flag

volatile u8 oam_update_flag
extern

OAM DMA trigger flag.

Set to 1 to request OAM buffer DMA during the next VBlank. The NMI handler clears this after the transfer.

Note
Defined in crt0.asm. Automatically set by WaitForVBlank().

◆ oamMemory

u8 oamMemory[]
extern

Hardware OAM buffer (544 bytes at $7E:0300)

This buffer is DMA'd to OAM hardware during VBlank by the NMI handler when oam_update_flag is set.

Layout:

  • Bytes 0-511: 4 bytes per sprite (128 sprites)
    • offset+0: X position (low 8 bits)
    • offset+1: Y position
    • offset+2: Tile number (low 8 bits)
    • offset+3: Attributes (vhoopppc)
  • Bytes 512-543: 2 bits per sprite (X high bit, size select)
Note
Defined in crt0.asm. Used by oamSetFast()/oamSetXYFast() macros.

◆ vblank_flag

volatile u8 vblank_flag
extern

VBlank flag (set by NMI handler each frame)

Set to 1 by the NMI handler at the start of each VBlank. WaitForVBlank() polls this flag and clears it.

For manual VBlank timing after heavy computation, clear this flag before calling WaitForVBlank() to avoid using a stale flag:

vblank_flag = 0; // Clear stale flag
WaitForVBlank(); // Wait for next real VBlank
void WaitForVBlank(void)
Wait for next VBlank period.
volatile u8 vblank_flag
VBlank flag (set by NMI handler each frame)
Note
Defined in crt0.asm.