NightFox’s Lib
|
Functions related to regular (non-affine) tiled backgrounds. More...
Data Structures | |
struct | NF_TYPE_TBG_INFO |
Struct that holds information about regular tiled backgrounds. More... | |
struct | NF_TYPE_EXBGPAL_INFO |
Struct that holds information about extended palettes. More... | |
struct | NF_TYPE_TBGLAYERS_INFO |
Struct that holds information about backgrounds loaded to the screen. More... | |
Functions | |
void | NF_InitTiledBgBuffers (void) |
Initialize library to load files from the filesystem to create tiled BGs. More... | |
void | NF_ResetTiledBgBuffers (void) |
Reset state used for tiled BGs loaded from FAT. More... | |
void | NF_InitTiledBgSys (int screen) |
Initialize the tiled BG engine of the selected screen. More... | |
void | NF_LoadTiledBg (const char *file, const char *name, u32 width, u32 height) |
Load all files needed to create a tiled BG from FAT to RAM. More... | |
void | NF_LoadTilesForBg (const char *file, const char *name, u32 width, u32 height, u32 tile_start, u32 tile_end) |
Load a tilesed and palette from FAT to RAM. More... | |
void | NF_UnloadTiledBg (const char *name) |
Delete from RAM the BG with the specified name. More... | |
void | NF_CreateTiledBg (int screen, u32 layer, const char *name) |
Create a BG on the screen, using data loaded in RAM. More... | |
void | NF_DeleteTiledBg (int screen, u32 layer) |
Delete the BG of the specified screen and layer. More... | |
u32 | NF_GetTileMapAddress (int screen, u32 layer, u32 tile_x, u32 tile_y) |
Gets the address of the tile at the specified position. More... | |
u32 | NF_GetTileOfMap (int screen, u32 layer, u32 tile_x, u32 tile_y) |
Gets the value of the tile at the specified position. More... | |
void | NF_SetTileOfMap (int screen, u32 layer, u32 tile_x, u32 tile_y, u32 tile) |
Sets the value of the tile at the specified position. More... | |
void | NF_UpdateVramMap (int screen, u32 layer) |
Updates the map of the specified screen and layer specified. More... | |
void | NF_BgSetPalColor (int screen, u32 layer, u32 number, u32 r, u32 g, u32 b) |
Changes the value of one color of the palette of a background. More... | |
void | NF_BgEditPalColor (int screen, u32 layer, u32 number, u32 r, u32 g, u32 b) |
Changes the value of one color of the palete of the specified background. More... | |
void | NF_BgUpdatePalette (int screen, u32 layer) |
Updates the palette of a background from RAM to VRAM. More... | |
void | NF_BgGetPalColor (int screen, u32 layer, u32 number, u8 *r, u8 *g, u8 *b) |
Gets the RGB value of a color of the palette of the selected background, which is loaded in RAM. More... | |
u32 | NF_GetTilePal (int screen, u32 layer, u32 tile_x, u32 tile_y) |
Returns the number of extended palette used by specified tile. More... | |
void | NF_SetTilePal (int screen, u32 layer, u32 tile_x, u32 tile_y, u32 pal) |
Sets the extended palette to use for the tile especified. More... | |
void | NF_LoadExBgPal (const char *file, u32 slot) |
Load a palette from a file to RAM to use it as a background extended palette. More... | |
void | NF_UnloadExBgPal (u32 slot) |
Deletes a loaded palette from RAM. More... | |
void | NF_VramExBgPal (int screen, u32 layer, u32 id, u32 slot) |
Transfers a palette from RAM to VRAM to be used as extended palette. More... | |
void | NF_SetExBgPal (int screen, u32 layer, u32 pal) |
Sets the extended palette to be used in the specified background. More... | |
void | NF_SetTileHflip (int screen, u32 layer, u32 tile_x, u32 tile_y) |
Inverts the horizontal flip status of a tile in the specified map. More... | |
void | NF_SetTileVflip (int screen, u32 layer, u32 tile_x, u32 tile_y) |
Inverts the vertical flip status of a tile in the specified map. More... | |
void | NF_RotateTileGfx (u32 slot, u32 tile, u32 rotation) |
Rotates the graphics of a tile in RAM by the specified angle. More... | |
Variables | |
u8 | NF_BANKS_TILES [2] |
Maxmimum number of tile banks. More... | |
u8 | NF_BANKS_MAPS [2] |
Maxmimum number of map banks. More... | |
char * | NF_BUFFER_BGTILES [NF_SLOTS_TBG] |
Buffers to hold background tiles. | |
char * | NF_BUFFER_BGMAP [NF_SLOTS_TBG] |
Buffers to hold background maps. | |
char * | NF_BUFFER_BGPAL [NF_SLOTS_TBG] |
Buffers to hold background palettes. | |
NF_TYPE_TBG_INFO | NF_TILEDBG [NF_SLOTS_TBG] |
Information of all tiled backgrounds. | |
NF_TYPE_EXBGPAL_INFO | NF_EXBGPAL [NF_SLOTS_EXBGPAL] |
Information of all extended palettes. | |
NF_TYPE_TBGLAYERS_INFO | NF_TILEDBG_LAYERS [2][4] |
Information of all backgrounds loaded to the screen. | |
u8 | NF_TILEBLOCKS [2][NF_MAX_BANKS_TILES] |
Array of free blocks used for tiles. | |
u8 | NF_MAPBLOCKS [2][NF_MAX_BANKS_MAPS] |
Array of free blocks used for maps. | |
Functions related to regular (non-affine) tiled backgrounds.
void NF_BgEditPalColor | ( | int | screen, |
u32 | layer, | ||
u32 | number, | ||
u32 | r, | ||
u32 | g, | ||
u32 | b | ||
) |
Changes the value of one color of the palete of the specified background.
The change is made in the RAM copy of the palette, so you won't see any change until you update it on VRAM with NF_BgUpdatePalette().
Use this function to make cool effect on your tiled backgrounds.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
number | Color number (0 - 255). |
r | Red component (0 - 31). |
g | Green component (0 - 31). |
b | Blue component (0 - 31). |
void NF_BgGetPalColor | ( | int | screen, |
u32 | layer, | ||
u32 | number, | ||
u8 * | r, | ||
u8 * | g, | ||
u8 * | b | ||
) |
Gets the RGB value of a color of the palette of the selected background, which is loaded in RAM.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
number | Color number (0 - 255). |
r | Red component result (0 - 31). |
g | Green component result (0 - 31). |
b | Blue component result (0 - 31). |
void NF_BgSetPalColor | ( | int | screen, |
u32 | layer, | ||
u32 | number, | ||
u32 | r, | ||
u32 | g, | ||
u32 | b | ||
) |
Changes the value of one color of the palette of a background.
The change is made directly in VRAM, so it may be overwritten from the copy in RAM. It's also a very slow function, use it twice or 3 times per frame.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
number | Color number (0 - 255). |
r | Red component (0 - 31). |
g | Green component (0 - 31). |
b | Blue component (0 - 31). |
void NF_BgUpdatePalette | ( | int | screen, |
u32 | layer | ||
) |
Updates the palette of a background from RAM to VRAM.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
void NF_CreateTiledBg | ( | int | screen, |
u32 | layer, | ||
const char * | name | ||
) |
Create a BG on the screen, using data loaded in RAM.
This function copies to VRAM all required data. Before you create the BG, you must load data to RAM using NF_LoadTiledBg(). The BG is created on the specified screen and layer.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
name | Name used for the BG. |
void NF_DeleteTiledBg | ( | int | screen, |
u32 | layer | ||
) |
Delete the BG of the specified screen and layer.
This also deletes from VRAM the data used by this BG.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
u32 NF_GetTileMapAddress | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y | ||
) |
Gets the address of the tile at the specified position.
Internal use.
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
u32 NF_GetTileOfMap | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y | ||
) |
Gets the value of the tile at the specified position.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
u32 NF_GetTilePal | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y | ||
) |
Returns the number of extended palette used by specified tile.
By default, all tiles use extended palette 0.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
void NF_InitTiledBgBuffers | ( | void | ) |
Initialize library to load files from the filesystem to create tiled BGs.
Use this function once before loading any BG from FAT. Don't call it more than once.
Example:
void NF_InitTiledBgSys | ( | int | screen | ) |
Initialize the tiled BG engine of the selected screen.
You must call this function before using any tiled BG. This function:
The memory allocated for tiles and maps is defined in:
Each tile bank is as big as 8 map banks.
Example:
screen | Screen (0 - 1). |
void NF_LoadExBgPal | ( | const char * | file, |
u32 | slot | ||
) |
Load a palette from a file to RAM to use it as a background extended palette.
Example:
file | File (.pal extension). |
slot | RAM slot (0 - 127) |
void NF_LoadTiledBg | ( | const char * | file, |
const char * | name, | ||
u32 | width, | ||
u32 | height | ||
) |
Load all files needed to create a tiled BG from FAT to RAM.
All files for a BG must have the same name, using IMG extension for tiles files, MAP for map files and PAL for palette files.
Check the GRIT folder for more info about BG files conversion.
You can load up to 32 BGs at the same time, this is defined in:
Example:
file | File path without extension. |
name | Name used for the BG for other functions. |
width | BG width. |
height | BG height. |
void NF_LoadTilesForBg | ( | const char * | file, |
const char * | name, | ||
u32 | width, | ||
u32 | height, | ||
u32 | tile_start, | ||
u32 | tile_end | ||
) |
Load a tilesed and palette from FAT to RAM.
It works like NF_LoadTiledBg() but it lets you specify the range of tiles to load. Also, no actual map is loaded. Instead, a blank map of the given size is created. The background is created using NF_CreateTiledBg().
Example:
file | File name, without extension. |
name | Name of the BG. |
width | Width of the BG in pixels. |
height | Height of the BG in pixels. |
tile_start | First tile to load. |
tile_end | Last tile to load. |
void NF_ResetTiledBgBuffers | ( | void | ) |
Reset state used for tiled BGs loaded from FAT.
This function empties all buffers in use and resets variables to their default values. It’s useful to do this when you change a level in a game, to clean all stuff from RAM and make free space to load the new level.
Example:
void NF_RotateTileGfx | ( | u32 | slot, |
u32 | tile, | ||
u32 | rotation | ||
) |
Rotates the graphics of a tile in RAM by the specified angle.
The rotated graphics are stored int the same tile.
Rotation values: 1 - 90 degrees clockwise 2 - 90 degrees counter-clockwise 3 - 180 degrees
Example:
slot | RAM slot (0 - 127). |
tile | Tile index. |
rotation | Rotation value. |
void NF_SetExBgPal | ( | int | screen, |
u32 | layer, | ||
u32 | pal | ||
) |
Sets the extended palette to be used in the specified background.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
pal | Extended palette index (0 - 15). |
void NF_SetTileHflip | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y | ||
) |
Inverts the horizontal flip status of a tile in the specified map.
The changes are done to the copy of the map in RAM, so changes won't be visible until you update the copy in VRAM with NF_UpdateVramMap().
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
void NF_SetTileOfMap | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y, | ||
u32 | tile | ||
) |
Sets the value of the tile at the specified position.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
tile | Tile index. |
void NF_SetTilePal | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y, | ||
u32 | pal | ||
) |
Sets the extended palette to use for the tile especified.
The palette has to be loaded in VRAM, and the changes won't be visible until you use NF_UpdateVramMap() because all operations are done in the copy of the map in RAM.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
pal | Extended palette index (0 - 15). |
void NF_SetTileVflip | ( | int | screen, |
u32 | layer, | ||
u32 | tile_x, | ||
u32 | tile_y | ||
) |
Inverts the vertical flip status of a tile in the specified map.
The changes are done to the copy of the map in RAM, so changes won't be visible until you update the copy in VRAM with NF_UpdateVramMap().
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
tile_x | X coordinate. |
tile_y | Y coordinate. |
void NF_UnloadExBgPal | ( | u32 | slot | ) |
Deletes a loaded palette from RAM.
Example:
slot | RAM slot (0 - 127) |
void NF_UnloadTiledBg | ( | const char * | name | ) |
Delete from RAM the BG with the specified name.
You can delete from RAM the BG if you don't need it more or if the size of the BG size is less or equal than 512 x 512. If it's bigger, you must keep it in RAM until you don't need it anymore.
Example:
name | Name used for the BG. |
void NF_UpdateVramMap | ( | int | screen, |
u32 | layer | ||
) |
Updates the map of the specified screen and layer specified.
This updates the map on VRAM with the copy of RAM, that can be modified. Use this fuction to apply changes made with NF_SetTileOfMap().
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
void NF_VramExBgPal | ( | int | screen, |
u32 | layer, | ||
u32 | id, | ||
u32 | slot | ||
) |
Transfers a palette from RAM to VRAM to be used as extended palette.
Example:
screen | Screen (0 - 1). |
layer | Layer (0 - 3). |
id | Slot of the palette in RAM. |
slot | Slot of extended palette in VRAM. |
|
extern |
Maxmimum number of map banks.
1 bank = 2 KB. One tile bank is equivalent to 8 map banks.
Use multiples of 8 for those values.
|
extern |
Maxmimum number of tile banks.
1 bank = 16 KB. One tile bank is equivalent to 8 map banks.