PVSnesLib  3.4.0
Macros | Enumerations | Functions | Variables
video.h File Reference

contains the basic defnitions for controlling the video hardware. More...

#include <snes/snestypes.h>

Go to the source code of this file.

Macros

#define CGRAM_PALETTE   ((u8*)0x2122)
 Palette CGRAM Data Write (W) 1st Access: Lower 8 bits (even address) 2nd Access: Upper 7 bits (odd address) (upper 1bit = PPU2 open bus) More...
 
#define CM_DIRCOLOR   (1<<0)
 Color Math Control Register A & B bits.
 
#define M7_HFLIP   (1<<0)
 Mode7 screen H-Flip (0=Normal, 1=Flipped) flip 256x256 "screen".
 
#define M7_OUTTILE   (3<<6)
 Outside 128x128 tile area is filled by Tile 00h.
 
#define M7_OUTTRANS   (2<<6)
 Outside 128x128 tile area is Transparent.
 
#define M7_VFLIP   (1<<1)
 Mode7 screen V-Flip (0=Normal, 1=Flipped) flip 256x256 "screen".
 
#define M7_WRAP   (1<<6)
 Mode7 Wrap within 128x128 tile area.
 
#define PPU_50HZ   (1<<4)
 Frame Rate (PPU2.Pin30) (0=NTSC/60Hz, 1=PAL/50Hz)
 
#define REG_CGADD   (*(vuint8*)0x2121)
 Palette CGRAM Address (Color Generator Memory) (W) Color index (0..255). This is a WORD-address (2-byte steps), allowing to access 256 words (512 bytes). Writing to this register resets the 1st/2nd access flipflop (for 2122h/213Bh) to 1st access.
 
#define REG_CGADSUB   (*(vuint8*)0x2131)
 Color Math Control Register B (W) 7 Color Math Add/Subtract (0=Add; Main+Sub, 1=Subtract; Main-Sub) 6 Color Math "Div2" Half Result (0=No divide, 1=Divide result by 2) 5 Color Math when Main Screen = Backdrop (0=Off, 1=On) ;\ 4 Color Math when Main Screen = OBJ/Palette4..7 (0=Off, 1=On) ; OFF: Show. More...
 
#define REG_CGWSEL   (*(vuint8*)0x2130)
 Color Math Control Register A (W) 7-6 Force Main Screen Black (3=Always, 2=MathWindow, 1=NotMathWin, 0=Never) 5-4 Color Math Enable (0=Always, 1=MathWindow, 2=NotMathWin, 3=Never) 3-2 Not used 1 Sub Screen BG/OBJ Enable (0=No/Backdrop only, 1=Yes/Backdrop+BG+OBJ) 0 Direct Color (for 256-color BGs) (0=Use Palette, 1=Direct Color)
 
#define REG_COLDATA   (*(vuint8*)0x2132)
 Color Math Sub Screen Backdrop Color (W) This 8bit port allows to manipulate some (or all) bits of a 15bit RGB value. Examples: Black: write E0h (R,G,B=0), Cyan: write 20h (R=0) and DFh (G,B=1Fh). 7 Apply Blue (0=No change, 1=Apply Intensity as Blue) 6 Apply Green (0=No change, 1=Apply Intensity as Green) 5 Apply Red (0=No change, 1=Apply Intensity as Red) 4-0 Intensity (0..31)
 
#define REG_INIDISP   (*(vuint8*)0x2100)
 Display Control 1 (W) 7 Forced Blanking (0=Normal, 1=Screen Black) 6-4 Not used 3-0 Master Brightness (0=Screen Black, or N=1..15: Brightness*(N+1)/16) More...
 
#define REG_M7A   (*(vuint8*)0x211B)
 Rotation/Scaling Parameter A (and Maths 16bit operand) (W)
 
#define REG_M7B   (*(vuint8*)0x211C)
 Rotation/Scaling Parameter B (and Maths 16bit operand) (W)
 
#define REG_M7C   (*(vuint8*)0x211D)
 Rotation/Scaling Parameter C (W)
 
#define REG_M7D   (*(vuint8*)0x211E)
 Rotation/Scaling Parameter D (W)
 
#define REG_M7HOFS   (*(vuint8*)0x210D)
 BG1 Horizontal Scroll (X) (W)
 
#define REG_M7SEL   (*(vuint8*)0x211A)
 Rotation/Scaling Mode Settings (W) 7-6 Screen Over (see below) 5-2 Not used 1 Screen V-Flip (0=Normal, 1=Flipped) ; flip 256x256 "screen" 0 Screen H-Flip (0=Normal, 1=Flipped) ;. More...
 
#define REG_M7VOFS   (*(vuint8*)0x210E)
 BG1 Vertical Scroll (Y) (W)
 
#define REG_M7X   (*(vuint8*)0x211F)
 Rotation/Scaling Center Coordinate X (W)
 
#define REG_M7Y   (*(vuint8*)0x2120)
 Rotation/Scaling Center Coordinate Y (W)
 
#define REG_MPYH   (*(vuint8*) 0x2136)
 Signed Multiply Result (upper 8bit) (R)
 
#define REG_MPYL   (*(vuint8*) 0x2134)
 Signed Multiply Result (lower 8bit) (R)
 
#define REG_MPYM   (*(vuint8*) 0x2135)
 Signed Multiply Result (middle 8bit) (R)
 
#define REG_MPYMH   (*(vuint16*) 0x2135)
 Signed Multiply Result (middle +upper 8bit) (R)
 
#define REG_STAT77   (*(vuint8*)0x213E)
 PPU1 Status and Version Number (R) 7 OBJ Time overflow (0=Okay, 1=More than 8x34 OBJ pixels per scanline) 6 OBJ Range overflow (0=Okay, 1=More than 32 OBJs per scanline) 5 Master/Slave Mode (PPU1.Pin25) (0=Normal=Master) 4 Not used (PPU1 open bus) (same as last value read from PPU1) 3-0 PPU1 5C77 Version Number (only version 1 exists as far as I know) More...
 
#define REG_STAT78   (*(vuint8*)0x213F)
 PPU2 Status and Version Number (R) 7 Current Interlace-Frame (0=1st, 1=2nd Frame) 6 H/V-Counter/Lightgun/Joypad2.Pin6 Latch Flag (0=No, 1=New Data Latched) 5 Not used (PPU2 open bus) (same as last value read from PPU2) 4 Frame Rate (PPU2.Pin30) (0=NTSC/60Hz, 1=PAL/50Hz) 3-0 PPU2 5C78 Version Number (version 1..3 exist as far as I know)
 
#define REG_VMADDLH   (*(vuint16*)0x2116)
 VMADDL - VRAM Address (lower 8bit) (W) VMADDH - VRAM Address (upper 8bit) (W) More...
 
#define REG_VMAIN   (*(vuint8*)0x2115)
 VRAM Address Increment Mode (W) 7 Increment VRAM Address after accessing High/Low byte (0=Low, 1=High) 6-4 Not used 3-2 Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit) 1-0 Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128) More...
 
#define REG_VMDATAH   (*(vuint8*)0x2119)
 VRAM Data Write (upper 8bit) (W)
 
#define REG_VMDATAL   (*(vuint8*)0x2118)
 VRAM Data Write (lower 8bit) (W)
 
#define REG_VMDATALH   (*(vuint16*)0x2118)
 VRAM Data Write (lower and upper 8bit) (W)
 
#define RGB8(r, g, b)   (((r)>>3)|(((g)>>3)<<5)|(((b)>>3)<<10))
 Macro to convert 5 bits or 8 bits r g b components into a single 15 bit RGB triplet.
 
#define setPalette(palette, paletteEntry, paletteSize)   dmaCopyCGram(palette, paletteEntry, paletteSize)
 Change a palette in CGRAM. More...
 
#define setPaletteColor(paletteEntry, paletteColor)   REG_CGADD = paletteEntry; *CGRAM_PALETTE = (paletteColor) & 0xFF; *CGRAM_PALETTE = (paletteColor)>>8;
 Change a color palette in CGRAM. More...
 

Enumerations

enum  VideoControl {
  DSP_FORCEVBL = BIT(7), VRAM_INCLOW = (0 << 7) , VRAM_ADRTR_0B = (0 << 2), VRAM_ADRTR_8B = (1 << 2),
  VRAM_ADRTR_9B = (2 << 2), VRAM_ADRTR_10B = (3 << 2), VRAM_ADRSTINC_1 = (0 << 0), VRAM_ADRSTINC_32 = (1 << 0),
  VRAM_ADRSTINC_128 = (2 << 0), VRAM_ADRSTINC_128 = (2 << 0)
}
 Bit defines for the video control registers. More...
 

Functions

void getPalette (u8 paletteEntry, u8 paletteSize, u16 *paletteColors)
 Get a palette from CGRAM. More...
 
void getPaletteColor (u8 paletteEntry, u16 *paletteColor)
 Get a color palette from CGRAM. More...
 
void setBrightness (u8 level)
 sets the screens brightness. More...
 
void setColorEffect (u8 colorMathA, u8 colorMathB)
 Do addition or other color effects. More...
 
void setColorIntensity (u8 colorApply, u8 intensity)
 Change intensity for transparency. More...
 
void setFadeEffect (u8 mode)
 Do a fadein or fadeout effect. More...
 
void setMode (u8 mode, u8 size)
 Set the SNES hardware to operate in new display mode. More...
 
void setMode7 (u8 mode)
 Put screen in mode 7 with generic init. More...
 
void setMode7Angle (u8 angle)
 Changle angle view in mode 7 without changing matrix. More...
 
void setMode7MoveForwardBack (u8 z8)
 Changle perspective view forward/backward in mode 7 without changing matrix. More...
 
void setMode7MoveLeftRight (u8 z8)
 Changle perspective view left/right in mode 7 without changing matrix. More...
 
void setMode7Rot (u8 angle)
 Changle angle view in mode 7 with matrix transformation. More...
 
void setMosaicEffect (u8 mode, u8 bgNumbers)
 Do a mosaic in or out effect. More...
 
void setScreenOn (void)
 Put screen On.
 

Variables

u8 videoMode
 Current value of REG_TM.
 
u8 videoModeSub
 Current value of REG_TS.
 

Detailed Description

contains the basic defnitions for controlling the video hardware.

Macro Definition Documentation

◆ CGRAM_PALETTE

#define CGRAM_PALETTE   ((u8*)0x2122)

Palette CGRAM Data Write (W) 1st Access: Lower 8 bits (even address) 2nd Access: Upper 7 bits (odd address) (upper 1bit = PPU2 open bus)

Reads and Writes to EVEN and ODD byte-addresses work as follows: Write to EVEN address –> set Cgram_Lsb = Data ;memorize value Write to ODD address –> set WORD[addr-1] = Data*256 + Cgram_Lsb Read from ANY address –> return BYTE[addr]

The address is automatically incremented after every read or write access.

256-Color Palette Entries 15 Not used (should be zero) (read: PPU2 Open Bus) 14-10 Blue 9-5 Green 4-0 Red

Palette Indices 00h Main Backdrop color (used when all BG/OBJ pixels are transparent) 01h-FFh 256-color BG palette (when not using direct-color mode) 01h-7Fh 128-color BG palette (BG2 in Mode 7) 01h-7Fh Eight 16-color BG palettes 01h-1Fh Eight 4-color BG palettes (except BG2-4 in Mode 0) 21h-3Fh Eight 4-color BG palettes (BG2 in Mode 0 only) 41h-5Fh Eight 4-color BG palettes (BG3 in Mode 0 only) 61h-7Fh Eight 4-color BG palettes (BG4 in Mode 0 only) 81h-FFh Eight 16-color OBJ palettes (half of them with color-math disabled) N/A Sub Backdrop color (not in CGRAM, set via COLDATA, Port 2132h)

◆ REG_CGADSUB

#define REG_CGADSUB   (*(vuint8*)0x2131)

Color Math Control Register B (W) 7 Color Math Add/Subtract (0=Add; Main+Sub, 1=Subtract; Main-Sub) 6 Color Math "Div2" Half Result (0=No divide, 1=Divide result by 2) 5 Color Math when Main Screen = Backdrop (0=Off, 1=On) ;\ 4 Color Math when Main Screen = OBJ/Palette4..7 (0=Off, 1=On) ; OFF: Show.

  • Color Math when Main Screen = OBJ/Palette0..3 (Always=Off) ; Raw Main, 3 Color Math when Main Screen = BG4 (0=Off, 1=On) ; or 2 Color Math when Main Screen = BG3 (0=Off, 1=On) ; ON: Show 1 Color Math when Main Screen = BG2 (0=Off, 1=On) ; Main+/-Sub 0 Color Math when Main Screen = BG1 (0=Off, 1=On) ;/

◆ REG_INIDISP

#define REG_INIDISP   (*(vuint8*)0x2100)

Display Control 1 (W) 7 Forced Blanking (0=Normal, 1=Screen Black) 6-4 Not used 3-0 Master Brightness (0=Screen Black, or N=1..15: Brightness*(N+1)/16)

In Forced Blank, VRAM, OAM and CGRAM can be freely accessed (otherwise it's accessible only during Vblank). Even when in forced blank, the TV Set keeps receiving Vsync/Hsync signals (thus producing a stable black picture). And, the CPU keeps receiving Hblank/Vblank signals (so any enabled video NMIs, IRQs, HDMAs are kept generated).

Forced blank doesn't apply immediately... so one must wait whatever (maybe a scanline) before VRAM can be freely accessed... or is it only vice-versa: disabling forced blank doesn't apply immediately/shows garbage pixels?

◆ REG_M7SEL

#define REG_M7SEL   (*(vuint8*)0x211A)

Rotation/Scaling Mode Settings (W) 7-6 Screen Over (see below) 5-2 Not used 1 Screen V-Flip (0=Normal, 1=Flipped) ; flip 256x256 "screen" 0 Screen H-Flip (0=Normal, 1=Flipped) ;.

Screen Over (when exceeding the 128x128 tile BG Map size): 0=Wrap within 128x128 tile area 1=Wrap within 128x128 tile area (same as 0) 2=Outside 128x128 tile area is Transparent 3=Outside 128x128 tile area is filled by Tile 00h

◆ REG_STAT77

#define REG_STAT77   (*(vuint8*)0x213E)

PPU1 Status and Version Number (R) 7 OBJ Time overflow (0=Okay, 1=More than 8x34 OBJ pixels per scanline) 6 OBJ Range overflow (0=Okay, 1=More than 32 OBJs per scanline) 5 Master/Slave Mode (PPU1.Pin25) (0=Normal=Master) 4 Not used (PPU1 open bus) (same as last value read from PPU1) 3-0 PPU1 5C77 Version Number (only version 1 exists as far as I know)

The overflow flags are cleared at end of V-Blank, but NOT during forced blank! The overflow flags are set (regardless of OBJ enable/disable in 212Ch), at following times: Bit6 when V=OBJ.YLOC/H=OAM.INDEX*2, bit7 when V=OBJ.YLOC+1/H=0.

◆ REG_VMADDLH

#define REG_VMADDLH   (*(vuint16*)0x2116)

VMADDL - VRAM Address (lower 8bit) (W) VMADDH - VRAM Address (upper 8bit) (W)

VRAM Address for reading/writing. This is a WORD address (2-byte steps), the PPU could theoretically address up to 64K-words (128K-bytes), in practice, only 32K-words (64K-bytes) are installed in SNES consoles (VRAM address bit15 is not connected, so addresses 8000h-FFFFh are mirrors of 0-7FFFh). After reading/writing VRAM Data, the Word-address can be automatically incremented by 1,32,128 (depending on the Increment Mode in Port 2115h) (Note: the Address Translation feature is applied only "temporarily" upon memory accesses, it doesn't affect the value in Port 2116h-17h). Writing to 2116h/2117h does prefetch 16bit data from the new address (for later reading).

Examples:
games/likemario/LikeMario.c.

◆ REG_VMAIN

#define REG_VMAIN   (*(vuint8*)0x2115)

VRAM Address Increment Mode (W) 7 Increment VRAM Address after accessing High/Low byte (0=Low, 1=High) 6-4 Not used 3-2 Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit) 1-0 Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)

The address translation is intended for bitmap graphics (where one would have filled the BG Map by increasing Tile numbers), technically it does thrice left-rotate the lower 8, 9, or 10 bits of the Word-address: Translation Bitmap Type Port [2116h/17h] VRAM Word-Address 8bit rotate 4-color; 1 word/plane aaaaaaaaYYYxxxxx –> aaaaaaaaxxxxxYYY 9bit rotate 16-color; 2 words/plane aaaaaaaYYYxxxxxP –> aaaaaaaxxxxxPYYY 10bit rotate 256-color; 4 words/plane aaaaaaYYYxxxxxPP –> aaaaaaxxxxxPPYYY

Where "aaaaa" would be the normal address MSBs, "YYY" is the Y-index (within a 8x8 tile), "xxxxx" selects one of the 32 tiles per line, "PP" is the bit-plane index (for BGs with more than one Word per plane). For the intended result (writing rows of 256 pixels) the Translation should be combined with Increment Step=1. For Mode 7 bitmaps one could eventually combine step 32/128 with 8bit/10bit rotate:

8bit-rotate/step32 aaaaaaaaXXXxxYYY –> aaaaaaaaxxYYYXXX 10bit-rotate/step128 aaaaaaXXXxxxxYYY –> aaaaaaxxxxYYYXXX

Though the SNES can't access enought VRAM for fullscreen Mode 7 bitmaps. Step 32 (without translation) is useful for updating BG Map columns (eg. after horizontal scrolling).

Examples:
games/likemario/LikeMario.c.

◆ setPalette

setPalette (   palette,
  paletteEntry,
  paletteSize 
)    dmaCopyCGram(palette, paletteEntry, paletteSize)

Change a palette in CGRAM.

Parameters
paletteaddress of palette entry
paletteEntrypalette number (0..16 for 16 colors mode) of the begining of each colors
paletteSizesize of palette

◆ setPaletteColor

setPaletteColor (   paletteEntry,
  paletteColor 
)    REG_CGADD = paletteEntry; *CGRAM_PALETTE = (paletteColor) & 0xFF; *CGRAM_PALETTE = (paletteColor)>>8;

Change a color palette in CGRAM.

Parameters
paletteEntrypalette color numer (0..255)
paletteColorRGB5 color
Examples:
audio/music/Music.c, and audio/tada/Tada.c.

Enumeration Type Documentation

◆ VideoControl

Bit defines for the video control registers.

Enumerator
DSP_FORCEVBL 

Forced Blanking (0=Normal, 1=Screen Black)

VRAM_INCLOW 

Increment VRAM Address after accessing High/Low byte (0=Low, 1=High)

VRAM_ADRTR_0B 

Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)

VRAM_ADRTR_8B 

Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)

VRAM_ADRTR_9B 

Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)

VRAM_ADRTR_10B 

Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)

VRAM_ADRSTINC_1 

Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)

VRAM_ADRSTINC_32 

Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)

VRAM_ADRSTINC_128 

Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)

VRAM_ADRSTINC_128 

Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)

Function Documentation

◆ getPalette()

getPalette ( u8  paletteEntry,
u8  paletteSize,
u16 *  paletteColors 
)

Get a palette from CGRAM.

Parameters
paletteEntry1st entry in palette (0..255 for 16 colors mode)
paletteSizesize of palette to get
paletteColorsRGB5 color to save all values

◆ getPaletteColor()

getPaletteColor ( u8  paletteEntry,
u16 *  paletteColor 
)

Get a color palette from CGRAM.

Parameters
paletteEntrypalette color numer (0..255)
paletteColorRGB5 color to save value
Examples:
graphics/Palette/GetColors/GetColors.c.

◆ setBrightness()

setBrightness ( u8  level)

sets the screens brightness.

Parameters
level15 = full brightness, 0= black
Examples:
games/breakout/breakout.c, random/random.c, and scoring/scoring.c.

◆ setColorEffect()

setColorEffect ( u8  colorMathA,
u8  colorMathB 
)

Do addition or other color effects.

Parameters
colorMathAvalue for color math A register
colorMathBvalue for color math B register
Examples:
graphics/Effects/Transparency/Transparency.c.

◆ setColorIntensity()

setColorIntensity ( u8  colorApply,
u8  intensity 
)

Change intensity for transparency.

Parameters
colorApplywith component is affect (red, green, blue)
intensityvalue for intensity

◆ setFadeEffect()

setFadeEffect ( u8  mode)

Do a fadein or fadeout effect.

Parameters
mode(FADE_IN = black to complete light, FADE_OUT = light to black)
Examples:
graphics/Effects/MosaicShading/MosaicShading.c.

◆ setMode()

setMode ( u8  mode,
u8  size 
)

Set the SNES hardware to operate in new display mode.

Parameters
mode0..7 for available Snes display mode
sizeTile Size (8x8 or 16x16) of each BG in this mode (if available)

Mode BG1 BG2 BG3 BG4 0 4-color 4-color 4-color 4-color ;Normal 1 16-color 16-color 4-color - ;Normal 2 16-color 16-color (o.p.t) - ;Offset-per-tile 3 256-color 16-color - - ;Normal 4 256-color 4-color (o.p.t) - ;Offset-per-tile 5 16-color 4-color - - ;512-pix-hires 6 16-color - (o.p.t) - ;512-pix plus Offs-p-t 7 256-color EXTBG - - ;Rotation/Scaling

Examples:
audio/music/Music.c, audio/tada/Tada.c, debug/debug.c, games/breakout/breakout.c, games/likemario/LikeMario.c, graphics/Backgrounds/Mode0/Mode0.c, graphics/Backgrounds/Mode1/Mode1.c, graphics/Backgrounds/Mode1MixedScroll/Mode1MixedScroll.c, graphics/Backgrounds/Mode1Png/Mode1.c, graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c, graphics/Backgrounds/Mode3/Mode3.c, graphics/Effects/HDMAGradient/HDMAGradient.c, graphics/Effects/MosaicShading/MosaicShading.c, graphics/Effects/Transparency/Transparency.c, graphics/Palette/GetColors/GetColors.c, graphics/Sprites/AnimatedSprite/AnimatedSprite.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/SimpleSprite/SimpleSprite.c, hello_world/src/hello_world.c, input/input.c, maps/mapscroll/mapscroll.c, objects/moveobjects/moveobjects.c, random/random.c, scoring/scoring.c, sram/sram.c, and timer/timer.c.

◆ setMode7()

setMode7 ( u8  mode)

Put screen in mode 7 with generic init.

Parameters
modeRotation/Scaling Mode Settings (see REG_M7SEL)
Examples:
graphics/Backgrounds/Mode7/Mode7.c, and graphics/Backgrounds/Mode7Perspective/Mode7Perspective.c.

◆ setMode7Angle()

setMode7Angle ( u8  angle)

Changle angle view in mode 7 without changing matrix.

Parameters
angle: 0..255 value

◆ setMode7MoveForwardBack()

setMode7MoveForwardBack ( u8  z8)

Changle perspective view forward/backward in mode 7 without changing matrix.

Parameters
z8: 0..255 value

◆ setMode7MoveLeftRight()

setMode7MoveLeftRight ( u8  z8)

Changle perspective view left/right in mode 7 without changing matrix.

Parameters
z8: 0..255 value

◆ setMode7Rot()

setMode7Rot ( u8  angle)

Changle angle view in mode 7 with matrix transformation.

Parameters
angle: 0..255 value
Examples:
graphics/Backgrounds/Mode7/Mode7.c.

◆ setMosaicEffect()

setMosaicEffect ( u8  mode,
u8  bgNumbers 
)

Do a mosaic in or out effect.

Parameters
bgNumbers(MOSAIC_BG1 to MOSAIC_BG4 depending of which background to use for effect)
mode(MOSAIC_IN = normal to mosaic, MOSAIC_OUT = mosaic to normal)
Examples:
graphics/Effects/MosaicShading/MosaicShading.c.