NightFox’s Lib
Data Structures | Macros | Functions | Variables
Bitmap background support.

Functions to load and manage bitmap backgrounds. More...

Data Structures

struct  NF_TYPE_BG16B_INFO
 Struct that holds information about 16-bit bitmap backgrounds. More...
 
struct  NF_TYPE_BG8B_INFO
 Struct that holds information about 8-bit bitmap backgrounds. More...
 
struct  NF_TYPE_BB8B_INFO
 Information of a backbuffer of 8 bit. More...
 

Macros

#define NF_SLOTS_BG16B   16
 Maximum number of slots of 16-bit bitmap backgrounds.
 
#define NF_SLOTS_BG8B   16
 Maximum number of slots of 8-bit bitmap backgrounds.
 

Functions

void NF_Init16bitsBgBuffers (void)
 Initialize buffers to store 16-bit bitmap backgrounds. More...
 
void NF_Reset16bitsBgBuffers (void)
 Resets all 16 bit background buffers and clears them. More...
 
void NF_Init16bitsBackBuffer (int screen)
 Initialize the 16 bit background backbuffer of the selected screen. More...
 
void NF_Enable16bitsBackBuffer (int screen)
 Enables the 16-bit backbuffer of the selected screen. More...
 
void NF_Disble16bitsBackBuffer (int screen)
 Disables the 16-bit backbuffer of selected screen. More...
 
void NF_Flip16bitsBackBuffer (int screen)
 Sends the 16-bit backbuffer to the VRAM of the selected screen. More...
 
void NF_InitBitmapBgSys (int screen, u32 mode)
 Initializes the selected screen in "bitmap" mode. More...
 
void NF_Load16bitsBg (const char *file, u32 slot)
 Loads a 16-bit bitmap from the filesystem. More...
 
void NF_Load16bitsImage (const char *file, u32 slot, u32 size_x, u32 size_y)
 Loads a 16 bits image into a RAM slot. More...
 
void NF_Unload16bitsBg (u32 slot)
 Deletes from RAM the 16-bit image stored in the selected slot. More...
 
void NF_Copy16bitsBuffer (int screen, int destination, u32 slot)
 Copy the selected 16-bit slot to VRAM or the backbuffer. More...
 
void NF_Draw16bitsImage (int screen, u32 slot, s32 x, s32 y, bool alpha)
 Draws the image in a slot into the backbuffer of the selected screen. More...
 
void NF_Init8bitsBgBuffers (void)
 Initialize buffers to store 8-bit bitmap backgrounds. More...
 
void NF_Reset8bitsBgBuffers (void)
 Resets all 8 bit background buffers and clears them. More...
 
void NF_Load8bitsBg (const char *file, u32 slot)
 Loads a 8-bit bitmap from the filesystem. More...
 
void NF_Unload8bitsBg (u32 slot)
 Deletes from RAM the 8-bit image stored in the selected slot. More...
 
void NF_Copy8bitsBuffer (int screen, int destination, u32 slot)
 Copy the selected 8-bit slot to VRAM or the backbuffer. More...
 
void NF_Init8bitsBackBuffer (int screen)
 Initialize the 8 bit background backbuffer of the selected screen. More...
 
void NF_Enable8bitsBackBuffer (int screen)
 Enables the 8-bit backbuffer of the selected screen. More...
 
void NF_Disble8bitsBackBuffer (int screen)
 Disables the 8-bit backbuffer of selected screen. More...
 
void NF_Flip8bitsBackBuffer (int screen, int destination)
 Sends the 8-bit backbuffer to the VRAM of the selected screen. More...
 

Variables

NF_TYPE_BG16B_INFO NF_BG16B [NF_SLOTS_BG16B]
 Information of all 16-bit bitmap backgrounds.
 
NF_TYPE_BG8B_INFO NF_BG8B [NF_SLOTS_BG8B]
 Information of all 8-bit bitmap backgrounds.
 
NF_TYPE_BB8B_INFO NF_8BITS_BACKBUFFER [2]
 Backbuffer of 8 bit of each screen.
 

Detailed Description

Functions to load and manage bitmap backgrounds.

Function Documentation

◆ NF_Copy16bitsBuffer()

void NF_Copy16bitsBuffer ( int  screen,
int  destination,
u32  slot 
)

Copy the selected 16-bit slot to VRAM or the backbuffer.

Example:

// Copy the image of slot 0 to the backbuffer of the top screen
void NF_Copy16bitsBuffer(int screen, int destination, u32 slot)
Copy the selected 16-bit slot to VRAM or the backbuffer.
Definition: nf_bitmapbg.c:248
Parameters
screenScreen (0 - 1).
destinationUse 0 for VRAM or 1 for backbuffer.
slotSlot number (0 - 15).

◆ NF_Copy8bitsBuffer()

void NF_Copy8bitsBuffer ( int  screen,
int  destination,
u32  slot 
)

Copy the selected 8-bit slot to VRAM or the backbuffer.

Example:

// Copy the image of slot 0 to the backbuffer of the top screen
void NF_Copy8bitsBuffer(int screen, int destination, u32 slot)
Copy the selected 8-bit slot to VRAM or the backbuffer.
Definition: nf_bitmapbg.c:383
Parameters
screenScreen (0 - 1).
destinationUse 0 for VRAM or 1 for backbuffer.
slotSlot number (0 - 15).

◆ NF_Disble16bitsBackBuffer()

void NF_Disble16bitsBackBuffer ( int  screen)

Disables the 16-bit backbuffer of selected screen.

It frees the RAM used by it (128 KB).

Parameters
screenScreen (0 - 1).

◆ NF_Disble8bitsBackBuffer()

void NF_Disble8bitsBackBuffer ( int  screen)

Disables the 8-bit backbuffer of selected screen.

It frees the RAM used by it (64 KB).

Parameters
screenScreen (0 - 1).

◆ NF_Draw16bitsImage()

void NF_Draw16bitsImage ( int  screen,
u32  slot,
s32  x,
s32  y,
bool  alpha 
)

Draws the image in a slot into the backbuffer of the selected screen.

You can specify the coordinates where the image is drawn.

If "alpha" is set to true, all magenta pixels (0xFF00FF) won't be drawn.

Example:

// Draws the image from Slot 1 to the backbuffer of the bottom screen, at
// coordinates (100, 50).
NF_ Draw16bitsImage(1, 1, 100, 50, true);
Parameters
screenScreen (0 - 1).
slotSlot number (0 - 15).
xX coordinate.
yY coordinate.
alphaTrue to make magenta pixels transparent.

◆ NF_Enable16bitsBackBuffer()

void NF_Enable16bitsBackBuffer ( int  screen)

Enables the 16-bit backbuffer of the selected screen.

If the backbuffer is already enabled, the contents are cleared.

Parameters
screenScreen (0 - 1).

◆ NF_Enable8bitsBackBuffer()

void NF_Enable8bitsBackBuffer ( int  screen)

Enables the 8-bit backbuffer of the selected screen.

If the backbuffer is already enabled, the contents are cleared.

Parameters
screenScreen (0 - 1).

◆ NF_Flip16bitsBackBuffer()

void NF_Flip16bitsBackBuffer ( int  screen)

Sends the 16-bit backbuffer to the VRAM of the selected screen.

Use it to edit the image in the backbuffer and to update the image displayed on the screen without showing the drawing process (which may be very slow).

Parameters
screenScreen (0 - 1).

◆ NF_Flip8bitsBackBuffer()

void NF_Flip8bitsBackBuffer ( int  screen,
int  destination 
)

Sends the 8-bit backbuffer to the VRAM of the selected screen.

Use it to edit the image in the backbuffer and to update the image displayed on the screen without showing the drawing process (which may be very slow).

You can send it to layer 2 (0) or layer 3 (1).

Parameters
screenScreen (0 - 1).
destinationDestination layer (0: layer 2, 1: layer 3).

◆ NF_Init16bitsBackBuffer()

void NF_Init16bitsBackBuffer ( int  screen)

Initialize the 16 bit background backbuffer of the selected screen.

Use this function once before using the backbuffer.

Parameters
screenScreen (0 - 1).

◆ NF_Init16bitsBgBuffers()

void NF_Init16bitsBgBuffers ( void  )

Initialize buffers to store 16-bit bitmap backgrounds.

You must call this function once in you code before loading any 16-bit bitmap.

◆ NF_Init8bitsBackBuffer()

void NF_Init8bitsBackBuffer ( int  screen)

Initialize the 8 bit background backbuffer of the selected screen.

Use this function once before using the backbuffer.

Parameters
screenScreen (0 - 1).

◆ NF_Init8bitsBgBuffers()

void NF_Init8bitsBgBuffers ( void  )

Initialize buffers to store 8-bit bitmap backgrounds.

You must call this function once in you code before loading any 8-bit bitmap.

◆ NF_InitBitmapBgSys()

void NF_InitBitmapBgSys ( int  screen,
u32  mode 
)

Initializes the selected screen in "bitmap" mode.

The color depth of the bitmap can be 8 or 16 bits.

The DS 2D engine must be set to video mode 5.

Example:

// Setup the top screen to use 16-bit bitmaps
void NF_InitBitmapBgSys(int screen, u32 mode)
Initializes the selected screen in "bitmap" mode.
Definition: nf_bitmapbg.c:96
Parameters
screenScreen (0 - 1).
modeDepth mode (0: 8 bits / 256 colors; 1: 16 bits)

◆ NF_Load16bitsBg()

void NF_Load16bitsBg ( const char *  file,
u32  slot 
)

Loads a 16-bit bitmap from the filesystem.

The file must be in binary format ".img", and its max size is 256x256 pixels (128 KB).

You can convert the file using this GRIT command line:

grit file.png -ftb -fh! -gb -gB16

You can load as many files as defined in NF_SLOTS_BG16B.

Example:

// Load "bitmap16.img" to slot 0
NF_Load16bitsBg("bmp/bitmap16", 0);
void NF_Load16bitsBg(const char *file, u32 slot)
Loads a 16-bit bitmap from the filesystem.
Definition: nf_bitmapbg.c:185
Parameters
fileFile name without extension.
slotSlot number (0 - 15).

◆ NF_Load16bitsImage()

void NF_Load16bitsImage ( const char *  file,
u32  slot,
u32  size_x,
u32  size_y 
)

Loads a 16 bits image into a RAM slot.

The image must be in ".img" format, and it has a max size of 256x256 pixels You must also specify the size of the image. The image will be loaded into the specified 16-bits bitmap background slot.

Use NF_Unload16bitsBg() to remove it from RAM.

Example:

// Loads file "character" file to slot 1. The size is 64x128 pixels.
NF_Load16bitsImage("bmp/character", 1, 64, 128);
void NF_Load16bitsImage(const char *file, u32 slot, u32 size_x, u32 size_y)
Loads a 16 bits image into a RAM slot.
Definition: nf_bitmapbg.c:190

Any magenta pixel (0xFF00FF) will be transparent.

Parameters
fileFile name without extension.
slotSlot number (0 - 15).
size_xWidth in pixels.
size_yHeight in pixels.

◆ NF_Load8bitsBg()

void NF_Load8bitsBg ( const char *  file,
u32  slot 
)

Loads a 8-bit bitmap from the filesystem.

The file must be in binary format ".img", and its max size is 256x256 pixels (64 KB). It will also load its palette in ".pal" format.

You can convert the file using this GRIT command line:

grit file.png -ftb -fh! -gb -gB8

If you want to share the palette with a different background:

grit file1.png file2.png -ftb -fh! -gb -gu8 -gB8 -pu16 -pS -Ofile1.pal -gTFF00FF
cp file1.pal.bin file2.pal.bin

If you want to display 2 8-bit backgrounds on same screen they must share the palette.

You can load as many files as defined in NF_SLOTS_BG8B.

Example:

// Loads "bitmap8.img" and "bitmap8.pal" to slot 0
NF_Load8bitsBg("bmp/bitmap8", 0);
void NF_Load8bitsBg(const char *file, u32 slot)
Loads a 8-bit bitmap from the filesystem.
Definition: nf_bitmapbg.c:328
Parameters
fileFile name without extension.
slotSlot number (0 - 15).

◆ NF_Reset16bitsBgBuffers()

void NF_Reset16bitsBgBuffers ( void  )

Resets all 16 bit background buffers and clears them.

Useful when changing game levels, for example.

◆ NF_Reset8bitsBgBuffers()

void NF_Reset8bitsBgBuffers ( void  )

Resets all 8 bit background buffers and clears them.

Useful when changing game levels, for example.

◆ NF_Unload16bitsBg()

void NF_Unload16bitsBg ( u32  slot)

Deletes from RAM the 16-bit image stored in the selected slot.

This is useful, for example, when the image has been copied to VRAM so it is no longer needed in RAM.

Example:

// Delete from RAM the image stored in slot 0.
void NF_Unload16bitsBg(u32 slot)
Deletes from RAM the 16-bit image stored in the selected slot.
Definition: nf_bitmapbg.c:234
Parameters
slotSlot number (0 - 15).

◆ NF_Unload8bitsBg()

void NF_Unload8bitsBg ( u32  slot)

Deletes from RAM the 8-bit image stored in the selected slot.

This is useful, for example, when the image has been copied to VRAM so it is no longer needed in RAM.

Example:

// Delete from RAM the image stored in slot 0.
void NF_Unload8bitsBg(u32 slot)
Deletes from RAM the 8-bit image stored in the selected slot.
Definition: nf_bitmapbg.c:366
Parameters
slotSlot number (0 - 15).