PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
background.h File Reference

snes background defines and functionality. More...

#include <snes/snestypes.h>
#include <snes/dma.h>
#include <snes/interrupt.h>
#include <snes/video.h>

Go to the source code of this file.

Macros

#define REG_BG12NBA   (*(vuint8 *)0x210B)
 BG Character Data Area Designation (W) 15-12 BG4 Tile Base Address (in 4K-word steps) 11-8 BG3 Tile Base Address (in 4K-word steps) 7-4 BG2 Tile Base Address (in 4K-word steps) 3-0 BG1 Tile Base Address (in 4K-word steps) More...
 
#define REG_BG1HOFS   (*(vuint8 *)0x210D)
 BG1 Horizontal Scroll (X) (W) and M7HOFS.
 
#define REG_BG1VOFS   (*(vuint8 *)0x210E)
 BG1 Vertical Scroll (Y) (W) and M7VOFS.
 
#define REG_BG2HOFS   (*(vuint8 *)0x210F)
 BG2 Horizontal Scroll (X) (W)
 
#define REG_BG2VOFS   (*(vuint8 *)0x2110)
 BG2 Vertical Scroll (Y) (W)
 
#define REG_BG3HOFS   (*(vuint8 *)0x2111)
 BG3 Horizontal Scroll (X) (W)
 
#define REG_BG3VOFS   (*(vuint8 *)0x2112)
 BG3 Vertical Scroll (Y) (W)
 
#define REG_BG4HOFS   (*(vuint8 *)0x2113)
 BG4 Horizontal Scroll (X) (W)
 
#define REG_BG4VOFS   (*(vuint8 *)0x2114)
 BG4 Vertical Scroll (Y) (W)
 
#define REG_BGMODE   (*(vuint8 *)0x2105)
 BG Mode and BG Character Size (W) 7 BG4 Tile Size (0=8x8, 1=16x16) ;(BgMode0..4: variable 8x8 or 16x16) 6 BG3 Tile Size (0=8x8, 1=16x16) ; (BgMode5: 8x8 acts as 16x8) 5 BG2 Tile Size (0=8x8, 1=16x16) ; (BgMode6: fixed 16x8?) 4 BG1 Tile Size (0=8x8, 1=16x16) ;/(BgMode7: fixed 8x8) 3 BG3 Priority in Mode 1 (0=Normal, 1=High) 2-0 BG Screen Mode (0..7 = see below) More...
 
#define REG_BGxHOFS   0x210D
 BGx Horizontal Scroll (X) (W) and M7HOFS.
 
#define REG_BGxVOFS   0x210E
 BGx Vertical Scroll (Y) (W) and M7VOFS.
 
#define REG_MOSAIC   (*(vuint8 *)0x2106)
 Mosaic Size and Mosaic Enable (W) Allows to divide the BG layer into NxN pixel blocks, in each block, the hardware picks the upper-left pixel of each block, and fills the whole block by the color - thus effectively reducing the screen resolution. More...
 
#define REG_TMW   (*(vuint8 *)0x212E)
 Window Area Main Screen Disable (W) 212Eh - TMW - Window Area Main Screen Disable (W) 212Fh - TSW - Window Area Sub Screen Disable (W) 7-5 Not used 4 OBJ (0=Enable, 1=Disable) ;"Disable" forcefully disables the layer 3 BG4 (0=Enable, 1=Disable) ; within the window area (otherwise it is 2 BG3 (0=Enable, 1=Disable) ; enabled or disabled as selected in the 1 BG2 (0=Enable, 1=Disable) ; master enable bits in port 212Ch/212Dh) 0 BG1 (0=Enable, 1=Disable) ;/. More...
 
#define REG_TS   (*(vuint8 *)0x212D)
 TM - Main Screen Designation (W) TS - Sub Screen Designation (W) More...
 
#define REG_W12SEL   (*(vuint8 *)0x2123)
 Window BG1/BG2 Mask Settings (W) 2123h - W12SEL - Window BG1/BG2 Mask Settings (W) 2124h - W34SEL - Window BG3/BG4 Mask Settings (W) 2125h - WOBJSEL - Window OBJ/MATH Mask Settings (W) Bit 2123h 2124h 2125h 7-6 BG2 BG4 MATH Window-2 Area (0..1=Disable, 1=Inside, 2=Outside) 5-4 BG2 BG4 MATH Window-1 Area (0..1=Disable, 1=Inside, 2=Outside) 3-2 BG1 BG3 OBJ Window-2 Area (0..1=Disable, 1=Inside, 2=Outside) 1-0 BG1 BG3 OBJ Window-1 Area (0..1=Disable, 1=Inside, 2=Outside)
 
#define REG_WBGLOG   (*(vuint8 *)0x212A)
 Window 1/2 Mask Logic (W) 212Ah/212Bh - WBGLOG/WOBJLOG - Window 1/2 Mask Logic (W) Bit 212Ah 212Bh 7-6 BG4 - Window 1/2 Mask Logic (0=OR, 1=AND, 2=XOR, 3=XNOR) 5-4 BG3 - Window 1/2 Mask Logic (0=OR, 1=AND, 2=XOR, 3=XNOR) 3-2 BG2 MATH Window 1/2 Mask Logic (0=OR, 1=AND, 2=XOR, 3=XNOR) 1-0 BG1 OBJ Window 1/2 Mask Logic (0=OR, 1=AND, 2=XOR, 3=XNOR) Allows to merge the Window 1 and 2 areas into a single "final" window area (which is then used by TMW, TSW, and CGWSEL). The OR/AND/XOR/XNOR logic is applied ONLY if BOTH window 1 and 2 are enabled (in WxxSEL registers). If only one window is enabled, then that window is used as is as "final" area. If both are disabled, then the "final" area will be empty. Note: "XNOR" means "1 XOR area1 XOR area2" (ie. the inverse of the normal XOR result).
 
#define REG_WH0   (*(vuint8 *)0x2126)
 Window 1 Left Position (X1) (W) 2126h - WH0 - Window 1 Left Position (X1) (W) 2127h - WH1 - Window 1 Right Position (X2) (W) 2128h - WH2 - Window 2 Left Position (X1) (W) 2129h - WH3 - Window 2 Right Position (X2) (W) 7-0 Window Position (00h..0FFh; 0=leftmost, 255=rightmost) More...
 
#define SC_BASE_SHIFT   2
 The shift to apply to map base when storing it in a tile map location register.
 
#define SC_TILE_BASE(base)   ((base) << SC_BASE_SHIFT)
 Macro to set the tile map address in tile map location.
 

Functions

void bgInitMapSet (u8 bgNumber, u8 *mapSource, u16 mapSize, u8 sizeMode, u16 address)
 Initializes a Map Set and loads it into SNES VRAM. More...
 
void bgInitMapTileSet7 (u8 *tileSource, u8 *mapSource, u8 *tilePalette, u16 tileSize, u16 address)
 Initializes a Tile & Map Set and Loads the Tile & Map GFX into VRAM for Mode 7. More...
 
void bgInitTileSet (u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 tileSize, u16 paletteSize, u16 colorMode, u16 address)
 Initializes a Tile Set and Loads the Tile GFX into VRAM. More...
 
void bgInitTileSetData (u8 bgNumber, u8 *tileSource, u16 tileSize, u16 address)
 Add some Tile Set and Loads the Tile GFX into VRAM. More...
 
void bgInitTileSetLz (u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 paletteSize, u16 colorMode, u16 address)
 Initializes a Tile Set and Loads the Tile GFX compressed with LZ algo into VRAM. More...
 
void bgSetDisable (u8 bgNumber)
 Disable a BG in the actual SNES mode. More...
 
void bgSetDisableSub (u8 bgNumber)
 Disable a BG from sub screen (translucent) in the actual SNES mode. More...
 
void bgSetEnable (u8 bgNumber)
 Enable a BG in the actual SNES mode. More...
 
void bgSetEnableSub (u8 bgNumber)
 Enable a BG from sub screen (translucent) in the actual SNES mode. More...
 
void bgSetGfxPtr (u8 bgNumber, u16 address)
 Definition of each background address. More...
 
void bgSetMapPtr (u8 bgNumber, u16 address, u8 mapSize)
 Change Background Map address. More...
 
void bgSetScroll (u8 bgNumber, u16 x, u16 y)
 Sets the scroll hardware to the specified location. More...
 
void bgSetWindowsRegions (u8 bgNumber, u8 winNumber, u8 xLeft, u8 xRight)
 Define a region on screen where map / sprite can be disable. More...
 

Variables

u16 bg1gfxaddr
 Definition of each background address.
 
u16 bg2gfxaddr
 Definition of each background address.
 
u16 bg3gfxaddr
 Definition of each background address.
 

Detailed Description

snes background defines and functionality.

Macro Definition Documentation

◆ REG_BG12NBA

#define REG_BG12NBA   (*(vuint8 *)0x210B)

BG Character Data Area Designation (W) 15-12 BG4 Tile Base Address (in 4K-word steps) 11-8 BG3 Tile Base Address (in 4K-word steps) 7-4 BG2 Tile Base Address (in 4K-word steps) 3-0 BG1 Tile Base Address (in 4K-word steps)

Ignored in Mode 7 (Base is always zero)

◆ REG_BGMODE

#define REG_BGMODE   (*(vuint8 *)0x2105)

BG Mode and BG Character Size (W) 7 BG4 Tile Size (0=8x8, 1=16x16) ;(BgMode0..4: variable 8x8 or 16x16) 6 BG3 Tile Size (0=8x8, 1=16x16) ; (BgMode5: 8x8 acts as 16x8) 5 BG2 Tile Size (0=8x8, 1=16x16) ; (BgMode6: fixed 16x8?) 4 BG1 Tile Size (0=8x8, 1=16x16) ;/(BgMode7: fixed 8x8) 3 BG3 Priority in Mode 1 (0=Normal, 1=High) 2-0 BG Screen Mode (0..7 = see below)

The BG Screen Modes are:

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

Mode 7 supports rotation/scaling and extbg (but doesn't support hv-flip). Mode 5/6 don't support screen addition/subtraction. CG Direct Select is support on BG1 of Mode 3/4, and on BG1/BG2? of Mode 7.

◆ REG_MOSAIC

#define REG_MOSAIC   (*(vuint8 *)0x2106)

Mosaic Size and Mosaic Enable (W) Allows to divide the BG layer into NxN pixel blocks, in each block, the hardware picks the upper-left pixel of each block, and fills the whole block by the color - thus effectively reducing the screen resolution.

7-4 Mosaic Size (0=Smallest/1x1, 0Fh=Largest/16x16) 3 BG4 Mosaic Enable (0=Off, 1=On) 2 BG3 Mosaic Enable (0=Off, 1=On) 1 BG2 Mosaic Enable (0=Off, 1=On) 0 BG1 Mosaic Enable (0=Off, 1=On)

Horizontally, the first block is always located on the left edge of the TV screen. Vertically, the first block is located on the top of the TV screen. When changing the mosaic size mid-frame, the hardware does first finish current block (using the old vertical size) before applying the new vertical size. Technically, vertical mosaic is implemented as so: subtract the vertical index (within the current block) from the vertical scroll register (BGnVOFS).

◆ REG_TMW

#define REG_TMW   (*(vuint8 *)0x212E)

Window Area Main Screen Disable (W) 212Eh - TMW - Window Area Main Screen Disable (W) 212Fh - TSW - Window Area Sub Screen Disable (W) 7-5 Not used 4 OBJ (0=Enable, 1=Disable) ;"Disable" forcefully disables the layer 3 BG4 (0=Enable, 1=Disable) ; within the window area (otherwise it is 2 BG3 (0=Enable, 1=Disable) ; enabled or disabled as selected in the 1 BG2 (0=Enable, 1=Disable) ; master enable bits in port 212Ch/212Dh) 0 BG1 (0=Enable, 1=Disable) ;/.

  • Backdrop (Always enabled) Allows to disable video layers within the window region.

◆ REG_TS

#define REG_TS   (*(vuint8 *)0x212D)

TM - Main Screen Designation (W) TS - Sub Screen Designation (W)

7-5 Not used 4 OBJ (0=Disable, 1=Enable) 3 BG4 (0=Disable, 1=Enable) 2 BG3 (0=Disable, 1=Enable) 1 BG2 (0=Disable, 1=Enable) 0 BG1 (0=Disable, 1=Enable)

  • Backdrop (Always enabled)

    Allows to enable/disable video layers. The Main screen is the "normal" display. The Sub screen is used only for Color Math and for 512-pixel Hires Mode.

◆ REG_WH0

#define REG_WH0   (*(vuint8 *)0x2126)

Window 1 Left Position (X1) (W) 2126h - WH0 - Window 1 Left Position (X1) (W) 2127h - WH1 - Window 1 Right Position (X2) (W) 2128h - WH2 - Window 2 Left Position (X1) (W) 2129h - WH3 - Window 2 Right Position (X2) (W) 7-0 Window Position (00h..0FFh; 0=leftmost, 255=rightmost)

Specifies the horizontal boundaries of the windows. Note that there are no vertical boundaries (these could be implemented by manipulating the window registers via IRQ and/or HDMA). The "inside-window" region extends from X1 to X2 (that, including the X1 and X2 coordinates), so the window width is X2-X1+1. If the width is zero (or negative), then the "inside-window" becomes empty, and the whole screen will be treated "outside-window".

Function Documentation

◆ bgInitMapSet()

◆ bgInitMapTileSet7()

void bgInitMapTileSet7 ( u8 *  tileSource,
u8 *  mapSource,
u8 *  tilePalette,
u16  tileSize,
u16  address 
)

Initializes a Tile & Map Set and Loads the Tile & Map GFX into VRAM for Mode 7.

Parameters
tileSourceaddress of tile graphics entry
mapSourceaddress of map entry
tilePaletteaddress of palette entry
tileSizesize of tile graphics
addressaddress of tile graphics (4K aligned)
Examples
graphics/Backgrounds/Mode7/Mode7.c, and graphics/Backgrounds/Mode7Perspective/Mode7Perspective.c.

◆ bgInitTileSet()

void bgInitTileSet ( u8  bgNumber,
u8 *  tileSource,
u8 *  tilePalette,
u8  paletteEntry,
u16  tileSize,
u16  paletteSize,
u16  colorMode,
u16  address 
)

Initializes a Tile Set and Loads the Tile GFX into VRAM.

Parameters
bgNumberbackground number (0 to 3)
tileSourceaddress of tile graphics entry
tilePaletteaddress of palette entry
paletteEntrypalette number (0..16 for 16 colors mode) of the beginning of each colors
tileSizesize of tile graphics
paletteSizesize of palette
colorModeused for correct palette entry (BG_4COLORS0, BG_16COLORS, BG_256COLORS)
addressaddress of tile graphics (4K aligned)
Examples
games/likemario/LikeMario.c, graphics/Backgrounds/Mode0/Mode0.c, graphics/Backgrounds/Mode1/Mode1.c, graphics/Backgrounds/Mode1BG3HighPriority/Mode1BG3HighPriority.c, graphics/Backgrounds/Mode1ContinuosScroll/Mode1ContinuosScroll.c, graphics/Backgrounds/Mode1MixedScroll/Mode1MixedScroll.c, graphics/Backgrounds/Mode1Png/Mode1.c, graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c, graphics/Backgrounds/Mode3/Mode3.c, graphics/Backgrounds/Mode5/Mode5.c, graphics/Backgrounds/Mode7Perspective/Mode7Perspective.c, graphics/Effects/Fading/Fading.c, graphics/Effects/GradientColors/GradientColors.c, graphics/Effects/HDMAGradient/HDMAGradient.c, graphics/Effects/MosaicShading/MosaicShading.c, graphics/Effects/ParallaxScrolling/ParallaxScrolling.c, graphics/Effects/Transparency/Transparency.c, graphics/Effects/TransparentWindow/src/main.c, graphics/Effects/Waves/Waves.c, graphics/Effects/Window/Window.c, graphics/Palette/GetColors/GetColors.c, graphics/Sprites/DynamicEngineMetaSprite/DynamicEngineMetaSprite.c, graphics/Sprites/DynamicEngineSprite/DynamicEngineSprite.c, input/mouse/mouse.c, input/superscope/superscope.c, maps/mapscroll/mapscroll.c, maps/tiled/tiled.c, objects/mapandobjects/mapandobjects.c, and objects/nogravityobject/nogravityobjects.c.

◆ bgInitTileSetData()

void bgInitTileSetData ( u8  bgNumber,
u8 *  tileSource,
u16  tileSize,
u16  address 
)

Add some Tile Set and Loads the Tile GFX into VRAM.

Parameters
bgNumberbackground number (0 to 3, 0xff to not change gfx pointer)
tileSourceaddress of tile graphics entry
tileSizesize of tile graphics
addressaddress of tile graphics (4K aligned)

◆ bgInitTileSetLz()

void bgInitTileSetLz ( u8  bgNumber,
u8 *  tileSource,
u8 *  tilePalette,
u8  paletteEntry,
u16  paletteSize,
u16  colorMode,
u16  address 
)

Initializes a Tile Set and Loads the Tile GFX compressed with LZ algo into VRAM.

Parameters
bgNumberbackground number (0 to 3)
tileSourceaddress of tile graphics entry compressed with LZ algo
tilePaletteaddress of palette entry
paletteEntrypalette number (0..16 for 16 colors mode) of the beginning of each colors
paletteSizesize of palette
colorModeused for correct palette entry (BG_4COLORS0, BG_16COLORS, BG_256COLORS)
addressaddress of tile graphics (4K aligned)
Examples
graphics/Backgrounds/Mode1LZ77/Mode1LZ77.c.

◆ bgSetDisable()

void bgSetDisable ( u8  bgNumber)

Disable a BG in the actual SNES mode.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)
Examples
audio/effects/effects.c, audio/effectsandmusic/effectsandmusic.c, audio/music/Music.c, audio/musicGreaterThan32k/musicGreaterThan32k.c, audio/tada/Tada.c, breakpoints/src/breakpoints.c, debug/debug.c, games/breakout/breakout.c, games/likemario/LikeMario.c, graphics/Backgrounds/Mode1/Mode1.c, graphics/Backgrounds/Mode1LZ77/Mode1LZ77.c, graphics/Backgrounds/Mode1MixedScroll/Mode1MixedScroll.c, graphics/Backgrounds/Mode1Png/Mode1.c, graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c, graphics/Backgrounds/Mode3/Mode3.c, graphics/Backgrounds/Mode5/Mode5.c, graphics/Effects/Fading/Fading.c, graphics/Effects/GradientColors/GradientColors.c, graphics/Effects/HDMAGradient/HDMAGradient.c, graphics/Effects/MosaicShading/MosaicShading.c, graphics/Effects/ParallaxScrolling/ParallaxScrolling.c, graphics/Effects/Transparency/Transparency.c, graphics/Effects/TransparentWindow/src/main.c, graphics/Effects/Waves/Waves.c, graphics/Effects/Window/Window.c, graphics/Palette/GetColors/GetColors.c, graphics/Sprites/AnimatedSprite/AnimatedSprite.c, graphics/Sprites/DynamicEngineMetaSprite/DynamicEngineMetaSprite.c, graphics/Sprites/DynamicEngineSprite/DynamicEngineSprite.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/ObjectSize/ObjectSize.c, graphics/Sprites/SimpleSprite/SimpleSprite.c, hello_world/src/hello_world.c, input/controller/controller.c, input/mouse/mouse.c, input/multiplay5/multiplay5.c, input/superscope/superscope.c, maps/mapscroll/mapscroll.c, maps/tiled/tiled.c, memory_mapping/src/memory_mapping.c, objects/mapandobjects/mapandobjects.c, objects/moveobjects/moveobjects.c, objects/nogravityobject/nogravityobjects.c, random/random.c, scoring/scoring.c, sram/sramoffset/sramoffset.c, sram/sramsimple/sram.c, testregion/testregion.c, timer/timer.c, and typeconsole/src/pal_ntsc.c.

◆ bgSetDisableSub()

void bgSetDisableSub ( u8  bgNumber)

Disable a BG from sub screen (translucent) in the actual SNES mode.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)
Examples
graphics/Backgrounds/Mode5/Mode5.c.

◆ bgSetEnable()

void bgSetEnable ( u8  bgNumber)

Enable a BG in the actual SNES mode.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)
Examples
graphics/Effects/TransparentWindow/src/main.c, and graphics/Effects/Window/Window.c.

◆ bgSetEnableSub()

void bgSetEnableSub ( u8  bgNumber)

Enable a BG from sub screen (translucent) in the actual SNES mode.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)
Examples
graphics/Effects/Transparency/Transparency.c.

◆ bgSetGfxPtr()

◆ bgSetMapPtr()

◆ bgSetScroll()

void bgSetScroll ( u8  bgNumber,
u16  x,
u16  y 
)

◆ bgSetWindowsRegions()

void bgSetWindowsRegions ( u8  bgNumber,
u8  winNumber,
u8  xLeft,
u8  xRight 
)

Define a region on screen where map / sprite can be disable.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)
winNumberwindows number (0 to 1 regarding current window)
xLeftleft value where we begin to add map/sprites
xRightright value where we stop to add map/sprites