PVSnesLib  3.4.0
Macros | Functions | Variables
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 BG_MODE0   (0 << 0)
 4-color 4-color 4-color 4-color ;Normal
 
#define BG_MODE1   (1 << 0)
 16-color 16-color 4-color - ;Normal
 
#define BG_MODE2   (2 << 0)
 16-color 16-color (o.p.t) - ;Offset-per-tile
 
#define BG_MODE3   (3 << 0)
 256-color 16-color - - ;Normal
 
#define BG_MODE4   (4 << 0)
 256-color 4-color (o.p.t) - ;Offset-per-tile
 
#define BG_MODE5   (5 << 0)
 16-color 4-color - - ;512-pix-hires
 
#define BG_MODE6   (6 << 0)
 16-color - (o.p.t) - ;512-pix plus Offs-p-t
 
#define BG_MODE7   (7 << 0)
 256-color EXTBG - - ;Rotation/Scaling
 
#define COLWIN_MB24W1ENABLEIN   (1<<4)
 BG2 BG4 MATH Window-1 Area Inside.
 
#define COLWIN_MB24W1ENABLEOUT   (2<<4)
 BG2 BG4 MATH Window-1 Area Outside.
 
#define COLWIN_MB24W2ENABLEIN   (1<<6)
 BG2 BG4 MATH Window-2 Area Inside.
 
#define COLWIN_MB24W2ENABLEOUT   (2<<6)
 BG2 BG4 MATH Window-2 Area Outside.
 
#define COLWIN_OB13W1ENABLEIN   (1<<0)
 BG1 BG3 OBJ Window-1 Area Inside.
 
#define COLWIN_OB13W1ENABLEOUT   (2<<0)
 BG1 BG3 OBJ Window-1 Area Outside.
 
#define COLWIN_OB13W2ENABLEIN   (1<<2)
 BG1 BG3 OBJ Window-2 Area Inside.
 
#define COLWIN_OB13W2ENABLEOUT   (2<<2)
 BG1 BG3 OBJ Window-2 Area Outside.
 
#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_32x32   (0 << 0)
 Bit defines for the background control registers. More...
 
#define SC_32x64   (2 << 0)
 32 x 64 tile size
 
#define SC_64x32   (1 << 0)
 64 x 32 tile size
 
#define SC_64x64   (3 << 0)
 64 x 64 tile size
 
#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 adress 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 tileSize, 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 veritical 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".

◆ SC_32x32

#define SC_32x32   (0 << 0)

Function Documentation

◆ bgInitMapSet()

void bgInitMapSet ( u8  bgNumber,
u8 *  mapSource,
u16  mapSize,
u8  sizeMode,
u16  address 
)

◆ 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 begining 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/Mode1MixedScroll/Mode1MixedScroll.c, graphics/Backgrounds/Mode1Png/Mode1.c, graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c, graphics/Backgrounds/Mode3/Mode3.c, graphics/Backgrounds/Mode7Perspective/Mode7Perspective.c, graphics/Effects/HDMAGradient/HDMAGradient.c, graphics/Effects/MosaicShading/MosaicShading.c, graphics/Effects/Transparency/Transparency.c, graphics/Palette/GetColors/GetColors.c, and maps/mapscroll/mapscroll.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  tileSize,
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 begining 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)

◆ bgSetDisable()

void bgSetDisable ( u8  bgNumber)

◆ 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)

◆ bgSetEnable()

void bgSetEnable ( u8  bgNumber)

Enable a BG in the actual SNES mode.

Parameters
bgNumberbackground number (0 to 3 regarding current mode)

◆ 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()

void bgSetGfxPtr ( u8  bgNumber,
u16  address 
)

Definition of each background address.

Change Background Char address

Parameters
bgNumberbackground number (0 to 3)
addressaddress of tile graphics (4K aligned)
Examples:
games/breakout/breakout.c.

◆ bgSetMapPtr()

void bgSetMapPtr ( u8  bgNumber,
u16  address,
u8  mapSize 
)

Change Background Map address.

Parameters
bgNumberbackground number (0 to 3)
addressaddress of tile map
mapSize->map size (0=32x32, 1=64x32, 2=32x64, 3=64x64 tiles)
Examples:
games/likemario/LikeMario.c, and maps/mapscroll/mapscroll.c.

◆ bgSetScroll()

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

Sets the scroll hardware to the specified location.

Parameters
bgNumberbackground number (0 to 3)
xthe horizontal scroll
ythe vertical scroll
Examples:
games/likemario/LikeMario.c, graphics/Backgrounds/Mode0/Mode0.c, graphics/Backgrounds/Mode1MixedScroll/Mode1MixedScroll.c, graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c, and graphics/Effects/Transparency/Transparency.c.

◆ 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