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

SNES Video / PPU Functions. More...

#include <snes/types.h>

Go to the source code of this file.

Macros

#define BG3_MODE1_PRIORITY_HIGH   0x08
 
#define BG_MODE0   0
 
#define BG_MODE1   1
 
#define BG_MODE2   2
 
#define BG_MODE3   3
 
#define BG_MODE4   4
 
#define BG_MODE5   5
 
#define BG_MODE6   6
 
#define BG_MODE7   7
 
#define LAYER_BG1   0x01
 
#define LAYER_BG2   0x02
 
#define LAYER_BG3   0x04
 
#define LAYER_BG4   0x08
 
#define LAYER_OBJ   0x10
 
#define RGB(r, g, b)   (((b) << 10) | ((g) << 5) | (r))
 Create RGB color value.
 
#define RGB24(r, g, b)   RGB((r) >> 3, (g) >> 3, (b) >> 3)
 Convert 24-bit RGB to SNES format.
 
#define setColor(index, color)
 Set a single CGRAM color.
 
#define setMainScreen(layers)   (REG_TM = (u8)(layers))
 Enable layers on the main screen.
 
#define setSubScreen(layers)   (REG_TS = (u8)(layers))
 Enable layers on the sub screen.
 

Functions

void setMode (u8 mode, u8 flags)
 Set background mode.
 

Detailed Description

SNES Video / PPU Functions.

Low-level video functions for PPU control, palette management, and screen modes.

Author
OpenSNES Team
Todo:
Implement video functions

Macro Definition Documentation

◆ RGB

#define RGB (   r,
  g,
  b 
)    (((b) << 10) | ((g) << 5) | (r))

Create RGB color value.

Parameters
rRed (0-31)
gGreen (0-31)
bBlue (0-31)
Returns
15-bit BGR color

◆ RGB24

#define RGB24 (   r,
  g,
  b 
)    RGB((r) >> 3, (g) >> 3, (b) >> 3)

Convert 24-bit RGB to SNES format.

Parameters
rRed (0-255)
gGreen (0-255)
bBlue (0-255)
Returns
15-bit BGR color

◆ setColor

#define setColor (   index,
  color 
)
Value:
do { \
REG_CGADD = (u8)(index); \
REG_CGDATA = (u8)((color) & 0xFF); \
REG_CGDATA = (u8)(((color) >> 8) & 0xFF); \
} while(0)
static u16 color
Definition main.c:163
#define REG_CGADD
CGRAM address (W)
Definition registers.h:148
#define REG_CGDATA
CGRAM data write (W)
Definition registers.h:151
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:46

Set a single CGRAM color.

Writes a 15-bit BGR color to the specified palette index. Works during VBlank or force blank only.

Parameters
indexColor index (0-255)
color15-bit BGR color (use RGB() or RGB24() macros)
setColor(0, RGB(0, 0, 0)); // Color 0 = black
setColor(1, RGB(31, 31, 31)); // Color 1 = white
setColor(128, RGB(31, 0, 0)); // Sprite palette 0, color 0 = red
#define RGB(r, g, b)
Create RGB color value.
Definition video.h:76
#define setColor(index, color)
Set a single CGRAM color.
Definition video.h:156

◆ setMainScreen

#define setMainScreen (   layers)    (REG_TM = (u8)(layers))

Enable layers on the main screen.

Sets which layers are visible on the main screen (REG_TM $212C). Forgetting to call this (or set REG_TM directly) is the #1 cause of blank screens after consoleInit().

Parameters
layersOR'd combination of LAYER_BG1..LAYER_OBJ
setMainScreen(LAYER_BG1 | LAYER_OBJ); // Show BG1 + sprites
setMainScreen(LAYER_BG1 | LAYER_BG2); // Show BG1 + BG2
#define LAYER_BG1
Definition video.h:96
#define LAYER_BG2
Definition video.h:97
#define LAYER_OBJ
Definition video.h:100
#define setMainScreen(layers)
Enable layers on the main screen.
Definition video.h:121

◆ setSubScreen

#define setSubScreen (   layers)    (REG_TS = (u8)(layers))

Enable layers on the sub screen.

Sets which layers are visible on the sub screen (REG_TS $212D). The sub screen is used as the second operand for color math.

Parameters
layersOR'd combination of LAYER_BG1..LAYER_OBJ
setSubScreen(LAYER_BG2); // BG2 as color math source
#define setSubScreen(layers)
Enable layers on the sub screen.
Definition video.h:135

Function Documentation

◆ setMode()

void setMode ( u8  mode,
u8  flags 
)

Set background mode.

Parameters
modeBackground mode (BG_MODE0-BG_MODE7), optionally OR'd with priority flags

Mode overview:

  • 0: 4 BG layers, 4 colors each
  • 1: 2 BG 16-color, 1 BG 4-color (most common)
  • 7: Mode 7 rotation/scaling
Note
consoleInit() sets BG1 tilemap at VRAM $0400 and tile data at $0000. Use bgSetMapPtr() and bgSetGfxPtr() to customize after setMode().
// Mode 1 with BG3 having high priority (for HUD overlay)
#define BG_MODE1
Definition video.h:28
#define BG3_MODE1_PRIORITY_HIGH
Definition video.h:41
void setMode(u8 mode, u8 flags)
Set background mode.