sgdk
vdp_tile.h File Reference

VDP General Tile / Tilemap operations. More...

Go to the source code of this file.

Classes

struct  TileSet
struct  Map

Defines

#define TILE_ATTR_PRIORITY_MASK   0x8000
#define TILE_ATTR_PALETTE_MASK   0x6000
#define TILE_ATTR_VFLIP_MASK   0x1000
#define TILE_ATTR_HFLIP_MASK   0x0800
#define TILE_ATTR_MASK   (TILE_ATTR_PRIORITY_MASK | TILE_ATTR_PALETTE_MASK | TILE_ATTR_VFLIP_MASK | TILE_ATTR_HFLIP_MASK)
#define TILE_ATTR(pal, prio, flipV, flipH)   (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15))
#define TILE_ATTR_FULL(pal, prio, flipV, flipH, index)   (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15) + (index))

Functions

void VDP_loadTileData (const u32 *data, u16 index, u16 num, u8 use_dma)
 Load tile data (pattern) in VRAM.
u16 VDP_loadTileSet (const TileSet *tileset, u16 index, u8 use_dma)
 Load tile data (pattern) in VRAM.
void VDP_loadFontData (const u32 *font, u16 length, u8 use_dma)
 Load font tile data in VRAM.
Note that you should prefer the VDP_loadBMPFont(..) method to this one (easier to use).
u16 VDP_loadFont (const TileSet *font, u8 use_dma)
 Load font from the specified TileSet structure.
void VDP_loadBMPTileData (const u32 *data, u16 index, u16 w, u16 h, u16 bmp_w)
 Load 4bpp bitmap tile data in VRAM.
void VDP_loadBMPTileDataEx (const u32 *data, u16 index, u16 x, u16 y, u16 w, u16 h, u16 bmp_w)
 Load 4bpp bitmap tile data in VRAM.
void VDP_fillTileData (u8 value, u16 index, u16 num, u8 use_dma)
 Fill tile data in VRAM.
void VDP_setTileMap (u16 plan, u16 tile, u16 ind)
 Set tilemap data at single position.
void VDP_setTileMapXY (u16 plan, u16 tile, u16 x, u16 y)
 Set tilemap data at single position.
void VDP_fillTileMapRectByIndex (u16 plan, u16 tile, u16 ind, u16 num)
void VDP_fillTileMap (u16 plan, u16 tile, u16 ind, u16 num)
 Fill tilemap data.
void VDP_fillTileMapRect (u16 plan, u16 tile, u16 x, u16 y, u16 w, u16 h)
 Fill tilemap data at specified region.
void VDP_clearTileMapRectByIndex (u16 plan, u16 ind, u16 num, u8 use_dma)
void VDP_clearTileMap (u16 plan, u16 ind, u16 num, u8 use_dma)
 Clear tilemap data.
void VDP_clearTileMapRect (u16 plan, u16 x, u16 y, u16 w, u16 h)
 Clear tilemap data at specified region.
void VDP_fillTileMapRectIncByIndex (u16 plan, u16 basetile, u16 ind, u16 num)
void VDP_fillTileMapInc (u16 plan, u16 basetile, u16 ind, u16 num)
 Fill tilemap data with index auto increment.
void VDP_fillTileMapRectInc (u16 plan, u16 basetile, u16 x, u16 y, u16 w, u16 h)
 Fill tilemap data with index auto increment at specified region.
void VDP_setTileMapRectByIndex (u16 plan, const u16 *data, u16 ind, u16 num, u8 use_dma)
void VDP_setTileMapData (u16 plan, const u16 *data, u16 ind, u16 num, u8 use_dma)
 Load tilemap data at specified index.
void VDP_setTileMapDataRect (u16 plan, const u16 *data, u16 x, u16 y, u16 w, u16 h)
 Load tilemap data at specified region.
void VDP_setTileMapRectExByIndex (u16 plan, const u16 *data, u16 baseindex, u16 baseflags, u16 ind, u16 num)
 Use VDP_setTileMapDataEx() instead.
void VDP_setTileMapDataEx (u16 plan, const u16 *data, u16 basetile, u16 ind, u16 num)
 Load tilemap data at specified index (extended version).
void VDP_setTileMapRectEx (u16 plan, const u16 *data, u16 baseindex, u16 baseflags, u16 x, u16 y, u16 w, u16 h)
void VDP_setTileMapDataRectEx (u16 plan, const u16 *data, u16 basetile, u16 x, u16 y, u16 w, u16 h, u16 wm)
 Load tilemap data at specified region (extended version).
u16 VDP_setMap (u16 plan, const Map *map, u16 basetile, u16 x, u16 y)
 Load Map at specified position.
u16 VDP_setMapEx (u16 plan, const Map *map, u16 basetile, u16 x, u16 y, u16 xm, u16 ym, u16 wm, u16 hm)
 Load Map region at specified position.

Detailed Description

VDP General Tile / Tilemap operations.

Author:
Stephane Dallongeville
Date:
08/2011

This unit provides methods to manipulate VDP tiles and tilemap :

  • upload tiles to VDP memory
  • upload tiles to VDP memory from bitmap data
  • clear / fill / set tile map data

Define Documentation

#define TILE_ATTR (   pal,
  prio,
  flipV,
  flipH 
)    (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15))

Encode tile attributes for tilemap data.

Parameters:
palPalette index
prioTile priority
flipVVertical flip
flipHHorizontal flip
#define TILE_ATTR_FULL (   pal,
  prio,
  flipV,
  flipH,
  index 
)    (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15) + (index))

Encode tile attributes for tilemap data.

Parameters:
palPalette index
prioTile priority
flipVVertical flip
flipHHorizontal flip
indexTile index
#define TILE_ATTR_HFLIP_MASK   0x0800

Mask for the tile H flip attribute in tilemap data.

#define TILE_ATTR_MASK   (TILE_ATTR_PRIORITY_MASK | TILE_ATTR_PALETTE_MASK | TILE_ATTR_VFLIP_MASK | TILE_ATTR_HFLIP_MASK)

Mask for the tile attributes (priority, palette and flip) in tilemap data.

#define TILE_ATTR_PALETTE_MASK   0x6000

Mask for the tile palette attribute in tilemap data.

#define TILE_ATTR_PRIORITY_MASK   0x8000

Mask for the tile priority attribute in tilemap data.

#define TILE_ATTR_VFLIP_MASK   0x1000

Mask for the tile V flip attribute in tilemap data.


Function Documentation

void VDP_clearTileMap ( u16  plan,
u16  ind,
u16  num,
u8  use_dma 
)

Clear tilemap data.

Parameters:
planPlan where we want to clear tilemap region.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
indTile index where to start fill.
numNumber of tile to fill.
use_dmaUse DMA transfert (faster but can lock Z80 execution).
See also:
VDP_fillTileMap() (faster method)
VDP_fillTileMapRectInc()
VDP_clearTileMapRect()
void VDP_clearTileMapRect ( u16  plan,
u16  x,
u16  y,
u16  w,
u16  h 
)

Clear tilemap data at specified region.

Parameters:
planPlan where we want to clear tilemap region.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
xRegion X start position (in tile).
yRegion Y start position (in tile).
wRegion Width (in tile).
hRegion Heigh (in tile).
See also:
VDP_clearTileMap() (faster method)
void VDP_clearTileMapRectByIndex ( u16  plan,
u16  ind,
u16  num,
u8  use_dma 
)
void VDP_fillTileData ( u8  value,
u16  index,
u16  num,
u8  use_dma 
)

Fill tile data in VRAM.

Parameters:
valueValue (byte) used to fill VRAM tile data.
indexTile index where start tile data fill (use TILE_USERINDEX as base user index).
numNumber of tile to fill.
use_dmaUse DMA transfert (faster but can lock Z80 execution).

This function is generally used to clear tile data in VRAM.

void VDP_fillTileMap ( u16  plan,
u16  tile,
u16  ind,
u16  num 
)

Fill tilemap data.

Parameters:
planPlan where we want to fill tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
tiletile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
indtile index where to start fill.
numNumber of tile to fill.
See also:
VDP_fillTileMapRect()
VDP_fillTileMapRectInc()
void VDP_fillTileMapInc ( u16  plan,
u16  basetile,
u16  ind,
u16  num 
)

Fill tilemap data with index auto increment.

Parameters:
planPlan where we want to fill tilemap region.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
basetileBase tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
indtile index where to start fill.
numNumber of tile to fill.

Set the specified tilemap with specified tile attributes values.
The function auto increments tile index in tile attribute :
tilemap at index : basetile, basetile+1, basetile+2, basetile+3, ...
...
So this function is pratical to display image.

See also:
also VDP_fillTileMap()
also VDP_fillTileMapRectInc()
void VDP_fillTileMapRect ( u16  plan,
u16  tile,
u16  x,
u16  y,
u16  w,
u16  h 
)

Fill tilemap data at specified region.

Parameters:
planPlan where we want to fill tilemap region.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
tiletile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
xRegion X start position (in tile).
yRegion Y start position (in tile).
wRegion Width (in tile).
hRegion Heigh (in tile).

Fill the specified tilemap region with specified tile attributes values.

See also:
VDP_fillTileMap() (faster method)
VDP_fillTileMapRectInc()
void VDP_fillTileMapRectByIndex ( u16  plan,
u16  tile,
u16  ind,
u16  num 
)
void VDP_fillTileMapRectInc ( u16  plan,
u16  basetile,
u16  x,
u16  y,
u16  w,
u16  h 
)

Fill tilemap data with index auto increment at specified region.

Parameters:
planPlan where we want to fill tilemap region.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
basetileBase tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
xRegion X start position (in tile).
yRegion Y start position (in tile).
wRegion Width (in tile).
hRegion Heigh (in tile).

Set the specified tilemap region with specified tile attributes values.
The function auto increments tile index in tile attribute :
tilemap line 0 : basetile, basetile+1, basetile+2, basetile+3, ...
tilemap line 1 : basetile+w, basetile+w+1, basetile+w+2, ...
...
So this function is pratical to display image.

See also:
also VDP_fillTileMapInc() (faster method)
also VDP_fillTileMapRect()
void VDP_fillTileMapRectIncByIndex ( u16  plan,
u16  basetile,
u16  ind,
u16  num 
)
void VDP_loadBMPTileData ( const u32 *  data,
u16  index,
u16  w,
u16  h,
u16  bmp_w 
)

Load 4bpp bitmap tile data in VRAM.

Parameters:
dataPointer to 4bpp bitmap tile data.
indexTile index where start tile data load (use TILE_USERINDEX as base user index).
wWidth of bitmap region to load (in tile).
hHeigh of bitmap region to load (in tile).
bmp_wWidth of bitmap (in tile), it can differ from 'w' parameter.

This function does "on the fly" 4bpp bitmap conversion to tile data and transfert them to VRAM.
It's very helpful when you use bitmap images but the conversion eats sometime so you should use it only for static screen only.
For "in-game" condition you should use VDP_loadTileData() method with converted tile data.
See also VDP_loadBMPTileDataEx().

void VDP_loadBMPTileDataEx ( const u32 *  data,
u16  index,
u16  x,
u16  y,
u16  w,
u16  h,
u16  bmp_w 
)

Load 4bpp bitmap tile data in VRAM.

Parameters:
dataPointer to 4bpp bitmap tile data.
indexTile index where start tile data load (use TILE_USERINDEX as base user index).
xX start position of bitmap region to load (in tile).
yY start position of bitmap region to load (in tile).
wWidth of bitmap region to load (in tile).
hHeigh of bitmap region to load (in tile).
bmp_wWidth of bitmap (in tile), it can differ from 'w' parameter.

This function does "on the fly" 4bpp bitmap conversion to tile data and transfert them to VRAM.
It's very helpful when you use bitmap images but the conversion eats sometime so you should use it only for static screen only.
For "in-game" condition you should use VDP_loadTileData() method with converted tile data. See also VDP_loadBMPTileData()

u16 VDP_loadFont ( const TileSet font,
u8  use_dma 
)

Load font from the specified TileSet structure.

Parameters:
fontTileSet containing the font.
The TileSet is unpacked "on-the-fly" if needed (require some memory)
use_dmaUse DMA transfert (faster but can lock Z80 execution).
Returns:
FALSE if there is not enough memory to unpack the specified font (only if compression was enabled).

This fonction permits to replace system font by user font.
The font tile data are loaded to TILE_FONTINDEX and can contains FONT_LEN characters at max.
Each character should fit in one tile (8x8 pixels bloc).
See also VDP_loadFontData(..)

void VDP_loadFontData ( const u32 *  font,
u16  length,
u8  use_dma 
)

Load font tile data in VRAM.
Note that you should prefer the VDP_loadBMPFont(..) method to this one (easier to use).

Parameters:
fontPointer to font tile data.
lengthNumber of characters of the font (max = FONT_LEN).
use_dmaUse DMA transfert (faster but can lock Z80 execution).

This fonction permits to replace system font by user font.
The font tile data are loaded to TILE_FONTINDEX and can contains FONT_LEN characters at max.
Each character should fit in one tile (8x8 pixels bloc).
See also VDP_loadFont(..) and VDP_loadTileData(..)

void VDP_loadTileData ( const u32 *  data,
u16  index,
u16  num,
u8  use_dma 
)

Load tile data (pattern) in VRAM.

Parameters:
dataPointer to tile data.
indexTile index where start tile data load (use TILE_USERINDEX as base user index).
numNumber of tile to load.
use_dmaUse DMA transfert (faster but can lock Z80 execution).

Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

u16 VDP_loadTileSet ( const TileSet tileset,
u16  index,
u8  use_dma 
)

Load tile data (pattern) in VRAM.

Parameters:
tilesetPointer to TileSet structure.
The TileSet is unpacked "on-the-fly" if needed (require some memory)
indexTile index where start tile data load (use TILE_USERINDEX as base user index).
use_dmaUse DMA transfert (faster but can lock Z80 execution).
Returns:
FALSE if there is not enough memory to unpack the specified TileSet (only if compression was enabled).

Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

u16 VDP_setMap ( u16  plan,
const Map map,
u16  basetile,
u16  x,
u16  y 
)

Load Map at specified position.

Parameters:
planPlan where we want to load Map.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
mapMap to load.
basetileBase index and flags for tile attributes (see TILE_ATTR_FULL() macro).
xRegion X start position (in tile).
yRegion Y start position (in tile).

Load the specified Map at specified plan position.

See also:
VDP_setTileMapData()
VDP_setTileMapDataEx()
u16 VDP_setMapEx ( u16  plan,
const Map map,
u16  basetile,
u16  x,
u16  y,
u16  xm,
u16  ym,
u16  wm,
u16  hm 
)

Load Map region at specified position.

Parameters:
planPlan where we want to load Map.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
mapMap to load.
basetileBase index and flags for tile attributes (see TILE_ATTR_FULL() macro).
xPlan X destination position (in tile).
yPlan Y destination position (in tile).
xmMap region X start position (in tile).
ymMap region Y start position (in tile).
wmMap region Width (in tile).
hmMap region Heigh (in tile).

Load the specified Map region at specified plan position.

See also:
VDP_setTileMapDataRect()
VDP_setTileMapDataRectEx()
void VDP_setTileMap ( u16  plan,
u16  tile,
u16  ind 
)

Set tilemap data at single position.

Parameters:
planPlan where we want to set tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
tiletile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
indposition in tilemap.
void VDP_setTileMapData ( u16  plan,
const u16 *  data,
u16  ind,
u16  num,
u8  use_dma 
)

Load tilemap data at specified index.

Parameters:
planPlan where we want to load tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
dataTile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
indTile index where to start to set tilemap.
numNumber of tile to set.
use_dmaUse DMA transfert (faster but can lock Z80 execution).

Set the specified tilemap with specified tile attributes values.
Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

See also:
VDP_setTileMapDataEx().
VDP_setTileMapDataRect().
void VDP_setTileMapDataEx ( u16  plan,
const u16 *  data,
u16  basetile,
u16  ind,
u16  num 
)

Load tilemap data at specified index (extended version).

Parameters:
planPlan where we want to load tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
datatile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
basetileBase tile index and flags for tile attributes (see TILE_ATTR_FULL() macro).
indTile index where to start to set tilemap.
numNumber of tile to set.

Set the specified tilemap with specified tile attributes values.

See also:
VDP_setTileMapData()
VDP_setTileMapDataRectEx()
void VDP_setTileMapDataRect ( u16  plan,
const u16 *  data,
u16  x,
u16  y,
u16  w,
u16  h 
)

Load tilemap data at specified region.

Parameters:
planPlan where we want to load tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
datatile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
xRegion X start position (in tile).
yRegion Y start position (in tile).
wRegion Width (in tile).
hRegion Heigh (in tile).

Set the specified tilemap region with specified tile attributes values.

See also:
VDP_setTileMapDataRectEx().
VDP_setTileMapData().
void VDP_setTileMapDataRectEx ( u16  plan,
const u16 *  data,
u16  basetile,
u16  x,
u16  y,
u16  w,
u16  h,
u16  wm 
)

Load tilemap data at specified region (extended version).

Parameters:
planPlan where we want to load tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
datatile attributes data pointer (see TILE_ATTR_FULL() macro).
basetileBase index and flags for tile attributes (see TILE_ATTR_FULL() macro).
xRegion X start position (in tile).
yRegion Y start position (in tile).
wRegion Width (in tile).
hRegion Heigh (in tile).
wmSource tilemap data width (in tile).

Set the specified tilemap region with specified tile attributes values.

See also:
VDP_setTileMapDataRect()
VDP_setTileMapDataEx()
void VDP_setTileMapRectByIndex ( u16  plan,
const u16 *  data,
u16  ind,
u16  num,
u8  use_dma 
)
void VDP_setTileMapRectEx ( u16  plan,
const u16 *  data,
u16  baseindex,
u16  baseflags,
u16  x,
u16  y,
u16  w,
u16  h 
)
void VDP_setTileMapXY ( u16  plan,
u16  tile,
u16  x,
u16  y 
)

Set tilemap data at single position.

Parameters:
planPlan where we want to set tilemap data.
Accepted values are:
  • VDP_PLAN_A
  • VDP_PLAN_B
tiletile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
xX position (in tile).
yy position (in tile).
 All Classes Files Functions Variables Typedefs Enumerations Defines