PVSnesLib  3.4.0
Data Structures | Macros | Functions
sprite.h File Reference

snes sprites functionality. More...

#include <snes/snestypes.h>

Go to the source code of this file.

Data Structures

struct  oamEntry
 Sprite definition : OAM entry for DMA copy if needed. More...
 

Macros

#define OAM_ATTR(priority, hflip, vflip, gfxoffset, paletteoffset)   ((vflip<<7) | (hflip<<6) | (priority<<4) | (paletteoffset<<1) | ((gfxoffset>>8) & 1))
 defined attribute of a sprite More...
 
#define oamGetX(id)   (oamMemory[id+0])
 get the x oam coordinate to the supplied values More...
 
#define oamGetY(id)   (oamMemory[id+1])
 get the y oam coordinate to the supplied values More...
 
#define oamSet(id, xspr, yspr, priority, hflip, vflip, gfxoffset, paletteoffset)
 sets an oam entry to the supplied values More...
 
#define oamSetGfxOffset(id, gfxoffset)
 sets an oam graphic offset to the supplied values More...
 
#define OBJ_SIZE16_L32   (3<<5)
 default OAM size 16x16 (SM) and 32x32 (LG) pix for OBJSEL register
 
#define OBJ_SIZE16_L64   (4<<5)
 default OAM size 16x16 (SM) and 64x64 (LG) pix for OBJSEL register
 
#define OBJ_SIZE32_L64   (5<<5)
 default OAM size 32x32 (SM) and 64x64 (LG) pix for OBJSEL register
 
#define OBJ_SIZE8_L16   (0<<5)
 default OAM size 8x8 (SM) and 16x16 (LG) pix for OBJSEL register
 
#define OBJ_SIZE8_L32   (1<<5)
 default OAM size 8x8 (SM) and 32x32 (LG) pix for OBJSEL register
 
#define OBJ_SIZE8_L64   (2<<5)
 default OAM size 8x8 (SM) and 64x64 (LG) pix for OBJSEL register
 
#define REG_OAMADDH   (*(vuint8*)0x2103)
 OAM Address and Priority Rotation (W) 15 OAM Priority Rotation (0=OBJ num 0, 1=OBJ num N) (OBJ with highest priority) 9-14 Not used 7-1 OBJ Number num N (for OBJ Priority) ;bit7-1 are used for two purposes 8-0 OAM Address (for OAM read/write) ;. More...
 
#define REG_OAMDATA   (*(vuint8*)0x2104)
 OAM Data Write (W)
 
#define REG_OBSEL   (*(vuint8*)0x2101)
 Object Size and Object Base (W) 7-5 OBJ Size Selection (0-5, see below) (6-7=Reserved) Val Small Large 0 = 8x8 16x16 ;Caution: 1 = 8x8 32x32 ;In 224-lines mode, OBJs with 64-pixel height 2 = 8x8 64x64 ;may wrap from lower to upper screen border. 3 = 16x16 32x32 ;In 239-lines mode, the same problem applies 4 = 16x16 64x64 ;also for OBJs with 32-pixel height. 5 = 32x32 64x64 6 = 16x32 32x64 (undocumented) 7 = 16x32 32x32 (undocumented) (Ie. a setting of 0 means Small OBJs=8x8, Large OBJs=16x16 pixels) (Whether an OBJ is "small" or "large" is selected by a bit in OAM) 4-3 Gap between OBJ 0FFh and 100h (0=None) (4K-word steps) (8K-byte steps) 2-0 Base Address for OBJ Tiles 000h..0FFh (8K-word steps) (16K-byte steps)
 
#define REG_RDOAM   (*(vuint8*)0x2138)
 OAM Data Read (R)
 

Functions

void oamClear (u16 first, u8 numEntries)
 Hides the sprites in the supplied range: if count is zero all 128 sprites will be hidden. More...
 
void oamFlip (u16 id, u8 xf, u8 yf)
 sets an oam entry to the supplied values More...
 
void oamInit (void)
 Initializes the 2D sprite engine.
 
void oamInitGfxAttr (u16 address, u8 oamsize)
 Initializes the default sprite size and address in VRAM. More...
 
void oamInitGfxSet (u8 *tileSource, u16 tileSize, u8 *tilePalette, u16 paletteSize, u8 tilePaletteNumber, u16 address, u8 oamsize)
 Initializes a sprites Gfx and Loads the GFX into VRAM. More...
 
void oamSetAttr (u16 id, u16 xspr, u16 yspr, u16 gfxoffset, u8 attr)
 sets an oam entry to the supplied values More...
 
void oamSetEx (u16 id, u8 size, u8 hide)
 Put the correct size and hide or not a oam. More...
 
void oamSetVisible (u16 id, u8 hide)
 Hide or not a oam. More...
 
void oamSetXY (u16 id, u16 xspr, u16 yspr)
 sets an oam coordinate to the supplied values More...
 
void oamUpdate (void)
 Write all OBJ descriptors to OAM.
 

Detailed Description

snes sprites functionality.

Macro Definition Documentation

◆ OAM_ATTR

#define OAM_ATTR (   priority,
  hflip,
  vflip,
  gfxoffset,
  paletteoffset 
)    ((vflip<<7) | (hflip<<6) | (priority<<4) | (paletteoffset<<1) | ((gfxoffset>>8) & 1))

defined attribute of a sprite

Parameters
priorityThe sprite priority (0 to 3)
vflipflip the sprite vertically
hflipflip the sprite horizontally
gfxoffsettilenumber graphic offset
paletteoffsetpalette default offset for sprite

◆ oamGetX

#define oamGetX (   id)    (oamMemory[id+0])

get the x oam coordinate to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure

◆ oamGetY

#define oamGetY (   id)    (oamMemory[id+1])

get the y oam coordinate to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure

◆ oamSet

#define oamSet (   id,
  xspr,
  yspr,
  priority,
  hflip,
  vflip,
  gfxoffset,
  paletteoffset 
)
Value:
{ \
oamMemory[id+0] = (xspr); \
oamMemory[id+1] = (yspr); \
oamMemory[id+2] = (gfxoffset); \
oamMemory[id+3] = (vflip<<7) | (hflip<<6) | (priority<<4) | (paletteoffset<<1) | ((gfxoffset>>8) & 1); \
}

sets an oam entry to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
xsprthe x location of the sprite in pixels
ysprthe y location of the sprite in pixels
priorityThe sprite priority (0 to 3)
vflipflip the sprite vertically
hflipflip the sprite horizontally
gfxoffsettilenumber graphic offset
paletteoffsetpalette default offset for sprite
Examples:
games/breakout/breakout.c, games/likemario/LikeMario.c, graphics/Sprites/AnimatedSprite/AnimatedSprite.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/SimpleSprite/SimpleSprite.c, maps/mapscroll/mapscroll.c, and objects/moveobjects/moveobjects.c.

◆ oamSetGfxOffset

#define oamSetGfxOffset (   id,
  gfxoffset 
)
Value:
oamMemory[id+2] = (gfxoffset); \
oamMemory[id+3] = (oamMemory[id+3] & 0xFE) | ((gfxoffset>>8) & 1);

sets an oam graphic offset to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
gfxoffsettilenumber graphic offset

◆ REG_OAMADDH

#define REG_OAMADDH   (*(vuint8*)0x2103)

OAM Address and Priority Rotation (W) 15 OAM Priority Rotation (0=OBJ num 0, 1=OBJ num N) (OBJ with highest priority) 9-14 Not used 7-1 OBJ Number num N (for OBJ Priority) ;bit7-1 are used for two purposes 8-0 OAM Address (for OAM read/write) ;.

This register contains of a 9bit Reload value and a 10bit Address register (plus the priority flag). Writing to 2102h or 2103h does change the lower 8bit or upper 1bit of the Reload value, and does additionally copy the (whole) 9bit Reload value to the 10bit Address register (with address Bit0=0 so next access will be an even address). Caution: During rendering, the PPU is destroying the Address register (using it internally for whatever purposes), after rendering (at begin of Vblank, ie. at begin of line 225/240, but only if not in Forced Blank mode) it reinitializes the Address from the Reload value; the same reload occurs also when deactivating forced blank anytime during the first scanline of vblank (ie. during line 225/240).

Function Documentation

◆ oamClear()

void oamClear ( u16  first,
u8  numEntries 
)

Hides the sprites in the supplied range: if count is zero all 128 sprites will be hidden.

Parameters
firstnumber of 1st sprite to write * 4 because of oam structure
numEntriestotal number of sprites to write

◆ oamFlip()

void oamFlip ( u16  id,
u8  xf,
u8  yf 
)

sets an oam entry to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
xfx flipping [0 - 1]
yfy flipping [0 - 1]

◆ oamInitGfxAttr()

void oamInitGfxAttr ( u16  address,
u8  oamsize 
)

Initializes the default sprite size and address in VRAM.

Parameters
addressaddress of sprite graphics (8K-word steps)
oamsizedefault OAM size (OBJ_SIZE8_L16, OBJ_SIZE8_L32, OBJ_SIZE8_L64, OBJ_SIZE16_L32, OBJ_SIZE16_L64 and OBJ_SIZE32_L64)

◆ oamInitGfxSet()

void oamInitGfxSet ( u8 *  tileSource,
u16  tileSize,
u8 *  tilePalette,
u16  paletteSize,
u8  tilePaletteNumber,
u16  address,
u8  oamsize 
)

Initializes a sprites Gfx and Loads the GFX into VRAM.

Parameters
tileSourceaddress of sprites graphics entry
tileSizesize of sprites graphics
tilePaletteaddress of sprites palette entry
tilePaletteNumberpalette number (0..8)
paletteSizesize of palette
addressaddress of sprite graphics (8K-word steps)
oamsizedefault OAM size (OBJ_SIZE8_L16, OBJ_SIZE8_L32, OBJ_SIZE8_L64, OBJ_SIZE16_L32, OBJ_SIZE16_L64 and OBJ_SIZE32_L64)
Examples:
games/likemario/LikeMario.c, graphics/Sprites/AnimatedSprite/AnimatedSprite.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/SimpleSprite/SimpleSprite.c, maps/mapscroll/mapscroll.c, and objects/moveobjects/moveobjects.c.

◆ oamSetAttr()

void oamSetAttr ( u16  id,
u16  xspr,
u16  yspr,
u16  gfxoffset,
u8  attr 
)

sets an oam entry to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
xsprthe x location of the sprite in pixels
ysprthe y location of the sprite in pixels
gfxoffsettilenumber graphic offset
attr(attributes with priority, flipping, palette)

◆ oamSetEx()

void oamSetEx ( u16  id,
u8  size,
u8  hide 
)

Put the correct size and hide or not a oam.

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
sizenormal or large (OBJ_SMALL or OBJ_LARGE)
hide0 or 1 to hide / see oam
Examples:
games/breakout/breakout.c, games/likemario/LikeMario.c, graphics/Sprites/AnimatedSprite/AnimatedSprite.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/SimpleSprite/SimpleSprite.c, maps/mapscroll/mapscroll.c, and objects/moveobjects/moveobjects.c.

◆ oamSetVisible()

void oamSetVisible ( u16  id,
u8  hide 
)

Hide or not a oam.

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
hide0 or 1 to hide / see oam
Examples:
graphics/Sprites/AnimatedSprite/AnimatedSprite.c, and maps/mapscroll/mapscroll.c.

◆ oamSetXY()

void oamSetXY ( u16  id,
u16  xspr,
u16  yspr 
)

sets an oam coordinate to the supplied values

Parameters
idthe oam number to be set [0 - 127] * 4 because of oam structure
xsprthe x location of the sprite in pixels
ysprthe y location of the sprite in pixels