// HEL Library \\

 
Main Page | Modules | Related Pages

Tile Functions

Description. More...

Functions


Detailed Description

Description.

HEL's tile-system implementation dynamically reloads tile graphics and can therefore bypass the hardware limit of 1024 tiles which allows you to design more extended levels. The maximum amount of tiles what can be handled by HEL's tile-system is 32767 tiles. A few functions of HEL's tile-system are located in IWRAM, because they have to be fast. If you don't use dynamic tile reloading, these functions will not be linked into the ELF and therefore consume no extra memory.

HEL's tile-system does not dynamically allocate any memory from EWRAM. You have to pass allocated buffers instead. This option allows to use an own memory manager, in case it is necessary.

It can share tilesetdata between backgrounds. This is helpful if you have one (huge) tileset which is used by several backgrounds. When you share 16 color graphics, you can specify a different palettenumber for the shared data. This makes it possible to use the same tileset with different colors.

It comes with a function to check if specific tiles are loaded to videoram and reload their graphics to perform tileanimations.

16 and 256 color graphics are supported, all associated calculations are done for you automatically. You only have to pass the colormode when initing the tile-system.

In debugmode it displays an errormessage when it tries to load a new tile into videoram but cannot find enough space.

Note:
Dynamic tile reloading with rotatation maps is not supported yet.

Function Documentation

void hel_TileDeInit u32  BgNo  ) 
 

Deinit a Tile-System.

The hel_TileDeInit function deinits the tilesystem for the background specified by BgNo.

Parameters:
BgNo Backgroundnumber to deinit the tilesystem from.
See also:
hel_TileInit

void hel_TileInit u32  BgNo,
const u8 *  pTileData,
u16  NumTilesRom,
u16 *  pBufferA,
u16  NumTilesRam,
u16 *  pBufferB,
u8  ColMode,
u8  PalNo,
u8  CbbOnlyMode
 

Init a Tile-System.

Parameters:
BgNo Backgroundnumber to init the tilesystem for.
pTileData Pointer to source tilesetdata.
NumTilesRom Amount of tiles in the source tileset.
pBufferA A buffer of NumTilesRom allocated halfwords (u16's). pBufferA should be located in EWRAM.
NumTilesRam Amount of tiles you want to use in videoram. It's the maximum amount of tiles what can be displayed at the same time. For example the screen consists entirely of unique tiles, then NumTilesRam has to be set to 21*31.
pBufferB A buffer of NumTilesRam*3 allocated halfwords (u16's). pBufferB should be located in EWRAM.
ColMode Colormode of pTileData. Set it to 0 when using 4bit graphics, otherwise to 1.
PalNo When using 4bit graphics, set PalNo to palette number the graphic uses, otherwise set it to 0.
CbbOnlyMode Please consult your HAM documentation, see ham_InitTileSet
  #define RAM_SLOTS (224)

  u16 BufferA[451] ATTR_MEM_IN_EWRAM;
  u16 BufferB[RAM_SLOTS*3] ATTR_MEM_IN_EWRAM;

  hel_TileInit
    (
      0,                      // BgNo
      world_Tiles,            // Source GraphicData (Tileset)
      SIZEOF_16BIT(BufferA),  // Amount of tiles in GraphicData
      BufferA,                // BufferA
      RAM_SLOTS,              // Amount of tiles to use in videoram
      BufferB,                // BufferB
      1,                      // Colormode (1=256 Colors, 0=16 Colors)
      0,                      // Palettenumber (0..15)
      TRUE                    // CbbOnlyMode
    );

  // Create a Map here and enable dynamic tile reloading
  // This can be done with hel_MapInit and hel_MapSetDynamicTileReloading

See also:
hel_TileDeInit, hel_TileShare, hel_MapSetDynamicTileReloading

u32 hel_TileIsGraphicLoaded u32  BgNo,
u32  RomTileNo
 

Check if a graphic is loaded.

The hel_TileIsGraphicLoaded function can be used to check if a tile is currently loaded or not.

Parameters:
BgNo Backgroundnumber the tilesystem is assigned to
RomTileNo The tilenumber to check
Returns:
TRUE if loaded, otherwise FALSE

void hel_TileReloadGraphic u32  BgNo,
u32  TargetRomTileNo,
const u8 *  pSource
 

Reload tile-graphic(s).

Parameters:
BgNo Backgroundnumber the tilesystem is assigned to
TargetRomTileNo The tilenumber for what you want to reload the graphic.
pSource Pointer to source graphicdata.
#define MAP_WORLD_WIDTH     (3552/8)
#define MAP_WORLD_HEIGHT    (512/8)

extern const unsigned char world_Tiles[];
extern const unsigned short world_Map[MAP_WORLD_WIDTH*MAP_WORLD_HEIGHT];
extern const unsigned char item_heart_Tiles[8*64];

void ReloadWorldGraphic(u32 X, u32 Y, const u8 *pSource)
{
  // get tilenumber from worldmap
  u32 TileToReload = world_Map[(Y*MAP_WORLD_WIDTH)+X];

  // is the tile currently loaded/visible?
  if(hel_TileIsGraphicLoaded(0, TileToReload))
  {
    // YES it is! So lets load some new graphic in.
    hel_TileReloadGraphic(0, TileToReload, pSource);
  }
}

void ReloadHeart()
{
  u32 SourceOffset=256;

  // Reload graphic when currently used
  ReloadWorldGraphic(30, 34, &item_heart_Tiles[SourceOffset]);      // TopLeft
  ReloadWorldGraphic(31, 34, &item_heart_Tiles[SourceOffset+64]);   // TopRight
  ReloadWorldGraphic(30, 35, &item_heart_Tiles[SourceOffset+128]);  // BottomLeft
  ReloadWorldGraphic(31, 35, &item_heart_Tiles[SourceOffset+192]);  // BottomRight
}

void hel_TileShare u8  TargetBgNo,
u8  SourceBgNo,
u8  PalNo
 

Share tilesetdata.

The hel_TileShare function can be used to share tilesetdata. This is helpful if you have one tileset which is used by several backgrounds. Instead of initing for each background an own TileSystem, you can (re)use the tilesetdata of an existing TileSystem. This has a big plus, because it requires less memory!

Parameters:
TargetBgNo Target, this is the backgroundnumber which receives the tilesetdata.
SourceBgNo Source, this is the backgroundnumber which provides the tilesetdata.
PalNo Palettenumber the target background should use. This makes it possible to use the same tilesetdata, but with different colors for each background. If you share 256 color graphics, set it to 0, otherwise to a palettenumber between 0 and 15.
When you no longer need the shared TileSystem, call hel_TileDeInit.

Note:
If you share tilesetdata, please keep in mind it is used by at least two backgrounds. This means it will probably display more tiles from the same tileset and therefore the TileSystem needs more tileslots to work with. To increase the tileslots, use NumTilesRam and pBufferB parameter which you pass to hel_TileInit, when initing the source tileset.
See also:
hel_TileInit, hel_TileDeInit


Generated on Fri Jul 8 19:55:50 2005 by DoxyGen 1.4.3