library: Cleanup of types

Types like u8 and u16 aren't always a good idea. For example:

    void function(u8 x, u8 y)
    {
        u32 value = (x << 16) | y;
    }

The left shift of x will overflow because x is 8 bits wide. It is better
to make both arguments 32 bit wide.

It may also cause the compiler to introduce bit masking operations at
the caller side because the caller doesn't know how the function
behaves internally.

In order to prevent this kind of issues, it's better to use 32 bit
variables unless there is a very good reason to use smaller types (like
in structs, to save RAM).
This commit is contained in:
Antonio Niño Díaz 2023-05-24 02:48:37 +01:00
parent f9d6b71a40
commit e1506cc74f
14 changed files with 89 additions and 91 deletions

View File

@ -41,7 +41,7 @@ extern "C" {
///
/// @param screen Screen (0 - 1).
/// @param mode Mode (0, 2, 5).
void NF_Set2D(u8 screen, u8 mode);
void NF_Set2D(int screen, u32 mode);
/// Makes the BG of the selected layer and screen visible.
///
@ -55,7 +55,7 @@ void NF_Set2D(u8 screen, u8 mode);
///
/// @param screen Screen (0 - 1).
/// @param layer Layer (0 - 3).
void NF_ShowBg(u8 screen, u8 layer);
void NF_ShowBg(int screen, u32 layer);
/// Makes the BG of the selected layer and screen invisible.
///
@ -67,7 +67,7 @@ void NF_ShowBg(u8 screen, u8 layer);
///
/// @param screen Screen (0 - 1).
/// @param layer Layer (0 - 3).
void NF_HideBg(u8 screen, u8 layer);
void NF_HideBg(int screen, u32 layer);
/// Moves the BG of the selected layer and screen to the specified coordinates.
///
@ -83,7 +83,7 @@ void NF_HideBg(u8 screen, u8 layer);
/// @param layer Layer (0 - 3).
/// @param x X coordinate.
/// @param y Y coordinate.
void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y);
void NF_ScrollBg(int screen, u32 layer, s32 x, s32 y);
/// Moves the selected sprite of a screen to the specified coordinates.
///
@ -97,7 +97,7 @@ void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y);
/// @param id Sprite ID (0 - 127).
/// @param x X coordinate.
/// @param y Y coordinate.
static inline void NF_MoveSprite(u8 screen, u8 id, s16 x, s16 y)
static inline void NF_MoveSprite(int screen, u32 id, s32 x, s32 y)
{
NF_SPRITEOAM[screen][id].x = x;
NF_SPRITEOAM[screen][id].y = y;
@ -116,7 +116,7 @@ static inline void NF_MoveSprite(u8 screen, u8 id, s16 x, s16 y)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @param layer Layer (0 - 3).
static inline void NF_SpriteLayer(u8 screen, u8 id, u8 layer)
static inline void NF_SpriteLayer(int screen, u32 id, u32 layer)
{
NF_SPRITEOAM[screen][id].layer = layer;
}
@ -136,7 +136,7 @@ static inline void NF_SpriteLayer(u8 screen, u8 id, u8 layer)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @param show Set to true to show the sprite, false otherwise.
static inline void NF_ShowSprite(u8 screen, u8 id, bool show)
static inline void NF_ShowSprite(int screen, u32 id, bool show)
{
NF_SPRITEOAM[screen][id].hide = !show;
}
@ -152,7 +152,7 @@ static inline void NF_ShowSprite(u8 screen, u8 id, bool show)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @param hflip Set to true to flip the sprite, false otherwise.
static inline void NF_HflipSprite(u8 screen, u8 id, bool hflip)
static inline void NF_HflipSprite(int screen, u32 id, bool hflip)
{
NF_SPRITEOAM[screen][id].hflip = hflip;
}
@ -168,7 +168,7 @@ static inline void NF_HflipSprite(u8 screen, u8 id, bool hflip)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @return hflip Returns true if the sprite is flipped, false otherwise.
static inline bool NF_GetSpriteHflip(u8 screen, u8 id)
static inline bool NF_GetSpriteHflip(int screen, u32 id)
{
return NF_SPRITEOAM[screen][id].hflip;
}
@ -184,7 +184,7 @@ static inline bool NF_GetSpriteHflip(u8 screen, u8 id)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @param vflip Set to true to flip the sprite, false otherwise.
static inline void NF_VflipSprite(u8 screen, u8 id, bool vflip)
static inline void NF_VflipSprite(int screen, u32 id, bool vflip)
{
NF_SPRITEOAM[screen][id].vflip = vflip;
}
@ -200,7 +200,7 @@ static inline void NF_VflipSprite(u8 screen, u8 id, bool vflip)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @return vflip Returns true if the sprite is flipped, false otherwise.
static inline bool NF_GetSpriteVflip(u8 screen, u8 id)
static inline bool NF_GetSpriteVflip(int screen, u32 id)
{
return NF_SPRITEOAM[screen][id].vflip;
}
@ -216,7 +216,7 @@ static inline bool NF_GetSpriteVflip(u8 screen, u8 id)
/// @param screen Screen (0 - 1).
/// @param id Sprite ID (0 - 127).
/// @param frame The frame to show.
void NF_SpriteFrame(u8 screen, u8 id, u16 frame);
void NF_SpriteFrame(int screen, u32 id, u32 frame);
/// Makes a sprite available to be rotated and scaled.
///
@ -238,7 +238,7 @@ void NF_SpriteFrame(u8 screen, u8 id, u16 frame);
/// @param sprite Sprite ID (0 - 127).
/// @param id RotSet ID (0 - 31).
/// @param doublesize Set to true to enable double size mode.
void NF_EnableSpriteRotScale(u8 screen, u8 sprite, u8 id, bool doublesize);
void NF_EnableSpriteRotScale(int screen, u32 sprite, u32 id, bool doublesize);
/// Disables the rotation and scalation of sprite.
///
@ -250,7 +250,7 @@ void NF_EnableSpriteRotScale(u8 screen, u8 sprite, u8 id, bool doublesize);
///
/// @param screen Screen (0 - 1).
/// @param sprite Sprite ID (0 - 127).
void NF_DisableSpriteRotScale(u8 screen, u8 sprite);
void NF_DisableSpriteRotScale(int screen, u32 sprite);
/// Setup the rotation and scalation values of a RotSet.
///
@ -274,7 +274,7 @@ void NF_DisableSpriteRotScale(u8 screen, u8 sprite);
/// @param angle Angle (-512 to 512).
/// @param sx X scale (0 to 512), 100% = 256.
/// @param sy Y scale (0 to 512), 100% = 256.
void NF_SpriteRotScale(u8 screen, u8 id, s16 angle, u16 sx, u16 sy);
void NF_SpriteRotScale(int screen, u8 id, s32 angle, u32 sx, u32 sy);
/// @}

View File

@ -45,7 +45,7 @@ extern "C" {
///
/// @param screen Screen (0 - 1).
/// @param mode Mode (0, 2, 5).
void NF_Set3D(u8 screen, u8 mode);
void NF_Set3D(int screen, u32 mode);
/// Initialitzes and configures OpenGL for 3D sprites.
///
@ -55,7 +55,7 @@ void NF_InitOpenGL(void);
// Internal use. It takes a texture size in pixels and returns the internal DS
// hardware representation of that size.
u16 NF_GetTextureSize(u16 textel);
u32 NF_GetTextureSize(u32 textel);
/// @}

View File

@ -53,7 +53,7 @@ extern char NF_ROOTFOLDER[64];
/// @param code Error code.
/// @param text Description.
/// @param value Additional info.
__attribute__((noreturn)) void NF_Error(u16 code, const char *text, unsigned int value);
__attribute__((noreturn)) void NF_Error(u32 code, const char *text, unsigned int value);
/// Defines the root folder of your project (FAT or NitroFS).
///
@ -102,7 +102,7 @@ void NF_DmaMemCopy(void *destination, const void *source, u32 size);
/// 6 : Chinese
///
/// @return The language ID.
static inline u8 NF_GetLanguage(void)
static inline u32 NF_GetLanguage(void)
{
return PersonalData->language;
}

View File

@ -39,7 +39,7 @@ extern "C" {
///
/// @param file File path.
/// @param slot Slot number (0 - 15).
void NF_LoadBMP(const char *file, u8 slot);
void NF_LoadBMP(const char *file, u32 slot);
/// @}

View File

@ -31,7 +31,7 @@ extern "C" {
/// After using this function you can use functions of both background modes.
///
/// @param screen Screen (0 - 1).
void NF_InitMixedBgSys(u8 screen);
void NF_InitMixedBgSys(int screen);
/// @}

View File

@ -67,12 +67,12 @@ void NF_ResetRawSoundBuffers(void);
/// @param id Destination slot number (0 - 31)
/// @param freq Frequency of the sample in Hz (11025, 22050, etc)
/// @param format Sample format (0 -> 8 bits, 1 -> 16 bits, 2 -> ADPCM).
void NF_LoadRawSound(const char *file, u16 id, u16 freq, u8 format);
void NF_LoadRawSound(const char *file, u32 id, u32 freq, u32 format);
/// Deletes from RAM the sound file stored in the specified slot.
///
/// @param id Slot number (0 - 31)
void NF_UnloadRawSound(u8 id);
void NF_UnloadRawSound(u32 id);
/// Play the sound file loaded in the specified slot.
///
@ -97,7 +97,7 @@ void NF_UnloadRawSound(u8 id);
/// @param loop True if you want the sound to loop.
/// @param loopfrom Loop starting point
/// @return Channel number that is playing the sound.
u8 NF_PlayRawSound(u8 id, u8 volume, u8 pan, bool loop, u16 loopfrom);
u32 NF_PlayRawSound(u32 id, u32 volume, u32 pan, bool loop, u32 loopfrom);
/// @}

View File

@ -58,7 +58,7 @@ extern NF_TYPE_TEXT_INFO NF_TEXT[2][4];
/// ```
///
/// @param screen Screen (0 - 1).
void NF_InitTextSys(u8 screen);
void NF_InitTextSys(int screen);
/// Load font and palette files from the filesystem to RAM.
///
@ -92,7 +92,8 @@ void NF_InitTextSys(u8 screen);
/// @param width Map width (in pixels)
/// @param height Map height (in pixels)
/// @param rotation Rotation (0 - 2)
void NF_LoadTextFont(const char *file, const char *name, u16 width, u16 height, u8 rotation);
void NF_LoadTextFont(const char *file, const char *name, u32 width, u32 height,
u32 rotation);
/// Delete from RAM the font with the specified name.
///
@ -121,7 +122,7 @@ void NF_UnloadTextFont(const char *name);
/// @param layer Background layer (0 - 3)
/// @param rotation Rotation (0 - 2)
/// @param name Font name
void NF_CreateTextLayer(u8 screen, u8 layer, u8 rotation, const char *name);
void NF_CreateTextLayer(int screen, u32 layer, u32 rotation, const char *name);
/// Delete a text layer.
///
@ -135,7 +136,7 @@ void NF_CreateTextLayer(u8 screen, u8 layer, u8 rotation, const char *name);
///
/// @param screen Screen (0 - 1)
/// @param layer Background layer (0 - 3)
void NF_DeleteTextLayer(u8 screen, u8 layer);
void NF_DeleteTextLayer(int screen, u32 layer);
/// Write text in a layer at the specified coordinates.
///
@ -166,7 +167,7 @@ void NF_DeleteTextLayer(u8 screen, u8 layer);
/// @param x X coordinate
/// @param y Y coordinate
/// @param text String to write to the screen
void NF_WriteText(u8 screen, u8 layer, u16 x, u16 y, const char *text);
void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text);
/// Copy the temporary text buffers of both screens to VRAM.
///
@ -189,7 +190,7 @@ void NF_UpdateTextLayers(void);
///
/// @param screen Screen (0 - 1)
/// @param layer Background layer (0 - 3)
void NF_ClearTextLayer(u8 screen, u8 layer);
void NF_ClearTextLayer(int screen, u32 layer);
/// Defines a RGB color to be used later as a text color.
///
@ -210,7 +211,7 @@ void NF_ClearTextLayer(u8 screen, u8 layer);
/// @param r Red component (0 - 31)
/// @param g Green component (0 - 31)
/// @param b Blue component (0 - 31)
void NF_DefineTextColor(u8 screen, u8 layer, u8 color, u8 r, u8 g, u8 b);
void NF_DefineTextColor(int screen, u32 layer, u32 color, u32 r, u32 g, u32 b);
/// Sets the color to use in all text written after calling this function.
///
@ -226,7 +227,7 @@ void NF_DefineTextColor(u8 screen, u8 layer, u8 color, u8 r, u8 g, u8 b);
/// @param screen Screen (0 - 1)
/// @param layer Background layer (0 - 3)
/// @param color Color number (0 - 15)
static inline void NF_SetTextColor(u8 screen, u8 layer, u8 color)
static inline void NF_SetTextColor(int screen, u32 layer, u32 color)
{
NF_TEXT[screen][layer].pal = color;
}

View File

@ -12,7 +12,7 @@
#include "nf_sprite256.h"
#include "nf_tiledbg.h"
void NF_Set2D(u8 screen, u8 mode)
void NF_Set2D(int screen, u32 mode)
{
if (screen == 0)
{
@ -48,7 +48,7 @@ void NF_Set2D(u8 screen, u8 mode)
}
}
void NF_ShowBg(u8 screen, u8 layer)
void NF_ShowBg(int screen, u32 layer)
{
if (screen == 0)
{
@ -90,7 +90,7 @@ void NF_ShowBg(u8 screen, u8 layer)
}
}
void NF_HideBg(u8 screen, u8 layer)
void NF_HideBg(int screen, u32 layer)
{
if (screen == 0)
{
@ -132,22 +132,20 @@ void NF_HideBg(u8 screen, u8 layer)
}
}
void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y)
void NF_ScrollBg(int screen, u32 layer, s32 x, s32 y)
{
// Temporary variables
s16 sx = x;
s16 sy = y;
s32 sx = x;
s32 sy = y;
// If the map is infinite (> 512 tiles)
if (NF_TILEDBG_LAYERS[screen][layer].bgtype > 0)
{
// Temporary variables for infinite backgrounds
u32 address = 0; // VRAM address
u16 blockx = 0; // Number of block in the screen
u16 blocky = 0;
u32 mapmovex = 0; // Data copy offset (block x 2048)
u32 mapmovey = 0;
u16 rowsize = 0; // Size used by each row in RAM
u32 blockx = 0; // Number of block in the screen
u32 blocky = 0;
u32 rowsize = 0; // Size used by each row in RAM
// Calculate base address of the map in VRAM
if (screen == 0) // VRAM_A
@ -178,7 +176,7 @@ void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y)
if (NF_TILEDBG_LAYERS[screen][layer].blockx != blockx)
{
// Calculate data offset
mapmovex = blockx << 11;
u32 mapmovex = blockx << 11;
// Copy blocks A and B (32x32) + (32x32) (2kb x 2 = 4kb)
NF_DmaMemCopy((void *)address,
@ -202,7 +200,7 @@ void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y)
if (NF_TILEDBG_LAYERS[screen][layer].blocky != blocky)
{
// Calculate data offset
mapmovey = blocky << 11;
u32 mapmovey = blocky << 11;
// Copy blocks A and B (32x32) + (32x32) (2kb x 2 = 4kb)
NF_DmaMemCopy((void *)address,
@ -226,12 +224,12 @@ void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y)
blocky = y >> 8;
// If you have changed block in any direction...
if ((NF_TILEDBG_LAYERS[screen][layer].blockx != blockx)
|| (NF_TILEDBG_LAYERS[screen][layer].blocky != blocky))
if ((NF_TILEDBG_LAYERS[screen][layer].blockx != blockx) ||
(NF_TILEDBG_LAYERS[screen][layer].blocky != blocky))
{
// Calculate data offset
mapmovex = (blocky * rowsize) + (blockx << 11);
mapmovey = mapmovex + rowsize;
u32 mapmovex = (blocky * rowsize) + (blockx << 11);
u32 mapmovey = mapmovex + rowsize;
// Blocks A and B (32x32) + (32x32) (2kb x 2 = 4kb)
NF_DmaMemCopy((void *)address,
@ -304,7 +302,7 @@ void NF_ScrollBg(u8 screen, u8 layer, s16 x, s16 y)
}
}
void NF_SpriteFrame(u8 screen, u8 id, u16 frame)
void NF_SpriteFrame(int screen, u32 id, u32 frame)
{
// Verify that the sprite ID is valid
if (id > 127)
@ -351,16 +349,15 @@ void NF_SpriteFrame(u8 screen, u8 id, u16 frame)
}
}
void NF_EnableSpriteRotScale(u8 screen, u8 sprite, u8 id, bool doublesize)
void NF_EnableSpriteRotScale(int screen, u32 sprite, u32 id, bool doublesize)
{
// Verify that the sprite ID is valid
if (sprite > 127)
NF_Error(106, "Sprite", 127);
// Verifica el rango de Id's de Rotacion
if (id > 31) {
// Verify range of rotation IDs
if (id > 31)
NF_Error(106, "RotScale", 127);
}
// Verify that the sprite has been created
if (!NF_SPRITEOAM[screen][sprite].created)
@ -376,7 +373,7 @@ void NF_EnableSpriteRotScale(u8 screen, u8 sprite, u8 id, bool doublesize)
NF_SPRITEOAM[screen][sprite].doublesize = doublesize;
}
void NF_DisableSpriteRotScale(u8 screen, u8 sprite)
void NF_DisableSpriteRotScale(int screen, u32 sprite)
{
// Verify that the sprite ID is valid
if (sprite > 127)
@ -396,11 +393,11 @@ void NF_DisableSpriteRotScale(u8 screen, u8 sprite)
NF_SPRITEOAM[screen][sprite].doublesize = false;
}
void NF_SpriteRotScale(u8 screen, u8 id, s16 angle, u16 sx, u16 sy)
void NF_SpriteRotScale(int screen, u8 id, s32 angle, u32 sx, u32 sy)
{
// Temporary variables
s16 in = 0; // Input angle
s16 out = 0; // Converted angle
s32 in = 0; // Input angle
s32 out = 0; // Converted angle
in = angle;

View File

@ -11,7 +11,7 @@
#include "nf_3d.h"
#include "nf_basic.h"
void NF_Set3D(u8 screen, u8 mode)
void NF_Set3D(int screen, u32 mode)
{
// Only the main engine can use 3D, so we need to swap the screens if the
// user wants the 3D output to be in the screen that isn't the main one.
@ -69,7 +69,7 @@ void NF_InitOpenGL(void)
NF_ShowBg(0, 0);
}
u16 NF_GetTextureSize(u16 textel)
u32 NF_GetTextureSize(u32 textel)
{
// Return the texel size as a base 2 log: Real size = 8 << Returned size
switch (textel)

View File

@ -18,7 +18,7 @@
// Folder used as root by NFLib
char NF_ROOTFOLDER[64];
__attribute__((noreturn)) void NF_Error(u16 code, const char *text, unsigned int value)
__attribute__((noreturn)) void NF_Error(u32 code, const char *text, unsigned int value)
{
consoleDemoInit(); // Initialize demo text console
setBrightness(3, 0); // Set the brightness to the top
@ -52,7 +52,7 @@ __attribute__((noreturn)) void NF_Error(u16 code, const char *text, unsigned int
break;
case 106: // Value out of range
iprintf("%s Id out\n", text);
iprintf("%s value out\n", text);
iprintf("of range (%u max).\n", value);
break;

View File

@ -13,7 +13,7 @@
#include "nf_bitmapbg.h"
#include "nf_media.h"
void NF_LoadBMP(const char *file, u8 slot)
void NF_LoadBMP(const char *file, u32 slot)
{
// Temporary buffers
char *buffer = NULL;
@ -80,10 +80,10 @@ void NF_LoadBMP(const char *file, u8 slot)
case 8: // 8 bits per pixel
{
// Calculate palette size
u32 colors = (bmp_header.offset - 0x36) >> 2;
char *palette = malloc(colors << 2);
u32 colors = (bmp_header.offset - 0x36) / 4; // Stored as RGBA
char *palette = malloc(colors * 4);
if (palette == NULL)
NF_Error(102, NULL, colors << 2);
NF_Error(102, NULL, colors * 4);
// Reopen file and read the palette
file_id = fopen(filename, "rb");
@ -91,7 +91,7 @@ void NF_LoadBMP(const char *file, u8 slot)
NF_Error(101, filename, 0);
fseek(file_id, 0x36, SEEK_SET);
fread(palette, 1, colors << 2, file_id);
fread(palette, 1, colors * 4, file_id);
fclose(file_id);
u32 idx = 0;

View File

@ -15,7 +15,7 @@
#include "nf_mixedbg.h"
#include "nf_tiledbg.h"
void NF_InitMixedBgSys(u8 screen)
void NF_InitMixedBgSys(int screen)
{
// Define the number of banks of maps and tiles.
//

View File

@ -42,7 +42,7 @@ void NF_ResetRawSoundBuffers(void)
NF_InitRawSoundBuffers();
}
void NF_LoadRawSound(const char *file, u16 id, u16 freq, u8 format)
void NF_LoadRawSound(const char *file, u32 id, u32 freq, u32 format)
{
// Verify that the ID is inside the valid range
if (id >= NF_SLOTS_RAWSOUND)
@ -96,7 +96,7 @@ void NF_LoadRawSound(const char *file, u16 id, u16 freq, u8 format)
NF_RAWSOUND[id].available = false;
}
void NF_UnloadRawSound(u8 id)
void NF_UnloadRawSound(u32 id)
{
// Verify that the ID is inside the valid range
if (id >= NF_SLOTS_RAWSOUND)
@ -118,7 +118,7 @@ void NF_UnloadRawSound(u8 id)
NF_RAWSOUND[id].available = true;
}
u8 NF_PlayRawSound(u8 id, u8 volume, u8 pan, bool loop, u16 loopfrom)
u32 NF_PlayRawSound(u32 id, u32 volume, u32 pan, bool loop, u32 loopfrom)
{
// Verify that the ID is inside the valid range
if (id >= NF_SLOTS_RAWSOUND)

View File

@ -18,7 +18,7 @@
// Structs that hold information about all text layers
NF_TYPE_TEXT_INFO NF_TEXT[2][4];
void NF_InitTextSys(u8 screen)
void NF_InitTextSys(int screen)
{
for (int n = 0; n < 4; n++)
{
@ -32,8 +32,8 @@ void NF_InitTextSys(u8 screen)
}
}
void NF_LoadTextFont(const char *file, const char *name, u16 width, u16 height,
u8 rotation)
void NF_LoadTextFont(const char *file, const char *name, u32 width, u32 height,
u32 rotation)
{
// Look for a free slot
u32 slot = 255;
@ -135,7 +135,7 @@ void NF_UnloadTextFont(const char *name)
NF_UnloadTiledBg(name);
}
void NF_CreateTextLayer(u8 screen, u8 layer, u8 rotation, const char *name)
void NF_CreateTextLayer(int screen, u32 layer, u32 rotation, const char *name)
{
// Create a background to use it as a text layer
NF_CreateTiledBg(screen, layer, name);
@ -159,8 +159,8 @@ void NF_CreateTextLayer(u8 screen, u8 layer, u8 rotation, const char *name)
NF_TEXT[screen][layer].rotation = rotation;
// Save the background size in tiles (save the index of the last row/column)
NF_TEXT[screen][layer].width = (NF_TILEDBG[slot].width >> 3) - 1;
NF_TEXT[screen][layer].height = (NF_TILEDBG[slot].height >> 3) - 1;
NF_TEXT[screen][layer].width = (NF_TILEDBG[slot].width / 8) - 1;
NF_TEXT[screen][layer].height = (NF_TILEDBG[slot].height / 8) - 1;
// Save slot where the font is stored
NF_TEXT[screen][layer].slot = slot;
@ -169,7 +169,7 @@ void NF_CreateTextLayer(u8 screen, u8 layer, u8 rotation, const char *name)
NF_TEXT[screen][layer].exist = true;
}
void NF_DeleteTextLayer(u8 screen, u8 layer)
void NF_DeleteTextLayer(int screen, u32 layer)
{
// Verify that the selected text layer exists
if (!NF_TEXT[screen][layer].exist)
@ -186,19 +186,19 @@ void NF_DeleteTextLayer(u8 screen, u8 layer)
NF_TEXT[screen][layer].exist = false;
}
void NF_WriteText(u8 screen, u8 layer, u16 x, u16 y, const char *text)
void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text)
{
// Verify that the selected text layer exists
if (!NF_TEXT[screen][layer].exist)
NF_Error(114, NULL, screen);
u16 tsize = strlen(text); // Size of the temporary string buffer
u32 tsize = strlen(text); // Size of the temporary string buffer
u8 *string = malloc(tsize); // Temporary string buffer
if (string == NULL)
NF_Error(102, NULL, tsize);
// Store the text string in the temporary buffer
for (int n = 0; n < tsize; n++)
for (u32 n = 0; n < tsize; n++)
{
int value = text[n] - 32; // Skip the first 32 non-printable characters
if (value < 0)
@ -292,7 +292,7 @@ void NF_WriteText(u8 screen, u8 layer, u16 x, u16 y, const char *text)
tx = x;
ty = y;
for (int n = 0; n < tsize; n++)
for (u32 n = 0; n < tsize; n++)
{
// If it's a valid character, put character
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR)
@ -320,7 +320,7 @@ void NF_WriteText(u8 screen, u8 layer, u16 x, u16 y, const char *text)
tx = NF_TEXT[screen][layer].width - y;
ty = x;
for (int n = 0; n < tsize; n++)
for (u32 n = 0; n < tsize; n++)
{
// If it's a valid character, put character
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR)
@ -348,7 +348,7 @@ void NF_WriteText(u8 screen, u8 layer, u16 x, u16 y, const char *text)
tx = y;
ty = NF_TEXT[screen][layer].height - x;
for (int n = 0; n < tsize; n ++)
for (u32 n = 0; n < tsize; n ++)
{
// If it's a valid character, put character
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR)
@ -396,7 +396,7 @@ void NF_UpdateTextLayers(void)
}
}
void NF_ClearTextLayer(u8 screen, u8 layer)
void NF_ClearTextLayer(int screen, u32 layer)
{
// Verify that the selected text layer exists
if (!NF_TEXT[screen][layer].exist)
@ -412,31 +412,31 @@ void NF_ClearTextLayer(u8 screen, u8 layer)
NF_TEXT[screen][layer].update = true;
}
void NF_DefineTextColor(u8 screen, u8 layer, u8 color, u8 r, u8 g, u8 b)
void NF_DefineTextColor(int screen, u32 layer, u32 color, u32 r, u32 g, u32 b)
{
// Verify that the selected text layer exists
if (!NF_TEXT[screen][layer].exist)
NF_Error(114, NULL, screen);
// Pack RGB value
u16 rgb = r | (g << 5) | (b << 10);
u32 rgb = r | (g << 5) | (b << 10);
// Modify the palette of the selected screen
if (screen == 0)
{
vramSetBankE(VRAM_E_LCD); // Enable CPU access to VRAM_E
u32 address = 0x06880000 + (layer << 13) + (color << 9); // First color
u32 address = 0x06880000 + (layer << 13) + (color * 256 * 2); // First color
*((u16*)address) = (u16)0xFF00FF;
address = 0x06880000 + (layer << 13) + (color << 9) + 2; // Second color
address = 0x06880000 + (layer << 13) + (color * 256 * 2) + 2; // Second color
*((u16*)address) = rgb;
vramSetBankE(VRAM_E_BG_EXT_PALETTE);
}
else
{
vramSetBankH(VRAM_H_LCD); // Enable CPU access to VRAM_H
u32 address = 0x06898000 + (layer << 13) + (color << 9); // First color
u32 address = 0x06898000 + (layer << 13) + (color * 256 * 2); // First color
*((u16*)address) = (u16)0xFF00FF;
address = 0x06898000 + (layer << 13) + (color << 9) + 2; // Second color
address = 0x06898000 + (layer << 13) + (color * 256 * 2) + 2; // Second color
*((u16*)address) = rgb;
vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
}