mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-18 16:55:32 -04:00
library: Cleanup and translate more source files
This commit is contained in:
parent
0329934b90
commit
18fc4a63ba
@ -153,7 +153,7 @@ void NF_Init3dSpriteSys(void);
|
||||
/// @param ram RAM slot (0 - 255)
|
||||
/// @param vram VRAM slot (0 - 255)
|
||||
/// @param keepframes For animated sprites. If true, copy all frames to VRAM.
|
||||
void NF_Vram3dSpriteGfx(u16 ram, u16 vram, bool keepframes);
|
||||
void NF_Vram3dSpriteGfx(u32 ram, u32 vram, bool keepframes);
|
||||
|
||||
/// Delete from VRAM the texture in the selected slot.
|
||||
///
|
||||
@ -166,7 +166,7 @@ void NF_Vram3dSpriteGfx(u16 ram, u16 vram, bool keepframes);
|
||||
/// ```
|
||||
///
|
||||
/// @param id VRAM slot (0 - 255)
|
||||
void NF_Free3dSpriteGfx(u16 id);
|
||||
void NF_Free3dSpriteGfx(u32 id);
|
||||
|
||||
/// Defragments the free VRAM used for 3D sprite textures.
|
||||
///
|
||||
@ -175,10 +175,10 @@ void NF_Free3dSpriteGfx(u16 id);
|
||||
/// function. You can get the state of VRAM reading the following variables:
|
||||
///
|
||||
/// ```
|
||||
/// NF_TEXVRAM[u8 screen].free // Total free VRAM
|
||||
/// NF_TEXVRAM[u8 screen].fragmented // Total fragmented free VRAM
|
||||
/// NF_TEXVRAM[u8 screen].inarow // Largest free block of VRAM at the end
|
||||
/// NF_TEXVRAM[u8 screen].lost // Unusable free VRAM because fragmentation
|
||||
/// NF_TEXVRAM[screen].free // Total free VRAM
|
||||
/// NF_TEXVRAM[screen].fragmented // Total fragmented free VRAM
|
||||
/// NF_TEXVRAM[screen].inarow // Largest free block of VRAM at the end
|
||||
/// NF_TEXVRAM[screen].lost // Unusable free VRAM because fragmentation
|
||||
/// ```
|
||||
void NF_Vram3dSpriteGfxDefrag(void);
|
||||
|
||||
@ -194,7 +194,7 @@ void NF_Vram3dSpriteGfxDefrag(void);
|
||||
///
|
||||
/// @param id RAM slot (0 - 64)
|
||||
/// @param slot VRAM slot (0 - 31)
|
||||
void NF_Vram3dSpritePal(u8 id, u8 slot);
|
||||
void NF_Vram3dSpritePal(u32 id, u32 slot);
|
||||
|
||||
/// Create a 3D sprite with the specified ID and display it on the screen.
|
||||
///
|
||||
@ -210,7 +210,7 @@ void NF_Vram3dSpritePal(u8 id, u8 slot);
|
||||
/// @param pal Palette slot (0 - 31).
|
||||
/// @param x X coordinate.
|
||||
/// @param y Y coordinate.
|
||||
void NF_Create3dSprite(u16 id, u16 gfx, u16 pal, s16 x, s16 y);
|
||||
void NF_Create3dSprite(u32 id, u32 gfx, u32 pal, s32 x, s32 y);
|
||||
|
||||
/// Remove the sprite with the specified ID from the screen.
|
||||
///
|
||||
@ -223,7 +223,7 @@ void NF_Create3dSprite(u16 id, u16 gfx, u16 pal, s16 x, s16 y);
|
||||
/// ```
|
||||
///
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
void NF_Delete3dSprite(u16 id);
|
||||
void NF_Delete3dSprite(u32 id);
|
||||
|
||||
/// Sets the priorities of 3D sprites based on their sprite IDs.
|
||||
///
|
||||
@ -236,13 +236,13 @@ void NF_Sort3dSprites(void);
|
||||
///
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param prio Priority (0 - 255).
|
||||
void NF_Set3dSpritePriority(u16 id, u16 prio);
|
||||
void NF_Set3dSpritePriority(u32 id, u32 prio);
|
||||
|
||||
/// Swaps the priority of two 3D sprites.
|
||||
///
|
||||
/// @param id_a Sprite ID A (0 - 255).
|
||||
/// @param id_b Sprite ID B (0 - 255).
|
||||
void NF_Swap3dSpritePriority(u16 id_a, u16 id_b);
|
||||
void NF_Swap3dSpritePriority(u32 id_a, u32 id_b);
|
||||
|
||||
/// Move a 3D sprite to the specified position.
|
||||
///
|
||||
@ -255,7 +255,7 @@ void NF_Swap3dSpritePriority(u16 id_a, u16 id_b);
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param x X coordinate.
|
||||
/// @param y Y coordinate.
|
||||
static inline void NF_Move3dSprite(u16 id, s16 x, s16 y)
|
||||
static inline void NF_Move3dSprite(u32 id, s32 x, s32 y)
|
||||
{
|
||||
NF_3DSPRITE[id].x = x;
|
||||
NF_3DSPRITE[id].y = y;
|
||||
@ -275,7 +275,7 @@ static inline void NF_Move3dSprite(u16 id, s16 x, s16 y)
|
||||
///
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param show True to show the sprite, false to hide it.
|
||||
static inline void NF_Show3dSprite(u16 id, bool show)
|
||||
static inline void NF_Show3dSprite(u32 id, bool show)
|
||||
{
|
||||
NF_3DSPRITE[id].show = show;
|
||||
}
|
||||
@ -290,7 +290,7 @@ static inline void NF_Show3dSprite(u16 id, bool show)
|
||||
///
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param frame Frame index.
|
||||
void NF_Set3dSpriteFrame(u16 id, u16 frame);
|
||||
void NF_Set3dSpriteFrame(u32 id, u32 frame);
|
||||
|
||||
/// Draw all created 3D sprites on the screen.
|
||||
///
|
||||
@ -321,7 +321,7 @@ void NF_Update3dSpritesGfx(void);
|
||||
/// @param x Rotation by X axis.
|
||||
/// @param y Rotation by Y axis.
|
||||
/// @param z Rotation by Z axis.
|
||||
void NF_Rotate3dSprite(u16 id, s16 x, s16 y, s16 z);
|
||||
void NF_Rotate3dSprite(u32 id, s32 x, s32 y, s32 z);
|
||||
|
||||
/// Scales 3D sprite on X and Y axes.
|
||||
///
|
||||
@ -330,7 +330,7 @@ void NF_Rotate3dSprite(u16 id, s16 x, s16 y, s16 z);
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param x X axis scale.
|
||||
/// @param y Y axis scale.
|
||||
void NF_Scale3dSprite(u16 id, u16 x, u16 y);
|
||||
void NF_Scale3dSprite(u32 id, u32 x, u32 y);
|
||||
|
||||
/// Set the alpha level of a 3D sprite.
|
||||
///
|
||||
@ -343,7 +343,7 @@ void NF_Scale3dSprite(u16 id, u16 x, u16 y);
|
||||
/// @param sprite Sprite ID (0 - 255).
|
||||
/// @param poly_id Polygon ID (1 - 62).
|
||||
/// @param alpha Transparency (0 - 31).
|
||||
void NF_Blend3dSprite(u8 sprite, u8 poly_id, u8 alpha);
|
||||
void NF_Blend3dSprite(u32 sprite, u32 poly_id, u32 alpha);
|
||||
|
||||
/// Select the layer where 3D sprites are drawn.
|
||||
///
|
||||
@ -351,7 +351,7 @@ void NF_Blend3dSprite(u8 sprite, u8 poly_id, u8 alpha);
|
||||
/// can only be sent to layer 0 because of how the hardware was designed.
|
||||
///
|
||||
/// @param layer Layer (0 - 3).
|
||||
void NF_3dSpritesLayer(u8 layer);
|
||||
void NF_3dSpritesLayer(u32 layer);
|
||||
|
||||
/// Changes one color of one 3D sprite palette.
|
||||
///
|
||||
@ -370,7 +370,7 @@ void NF_3dSpritesLayer(u8 layer);
|
||||
/// @param r Red component (0 - 31).
|
||||
/// @param g Green component (0 - 31).
|
||||
/// @param b Blue component (0 - 31).
|
||||
void NF_3dSpriteEditPalColor(u8 pal, u8 number, u8 r, u8 g, u8 b);
|
||||
void NF_3dSpriteEditPalColor(u32 pal, u32 number, u32 r, u32 g, u32 b);
|
||||
|
||||
/// Updates the VRAM copy of a palette with the RAM copy of it.
|
||||
///
|
||||
@ -381,7 +381,7 @@ void NF_3dSpriteEditPalColor(u8 pal, u8 number, u8 r, u8 g, u8 b);
|
||||
/// ```
|
||||
///
|
||||
/// @param pal Palette slot (0 - 31).
|
||||
void NF_3dSpriteUpdatePalette(u8 pal);
|
||||
void NF_3dSpriteUpdatePalette(u32 pal);
|
||||
|
||||
/// Gets the RGB value of a color from a 3D sprite palette loaded in RAM.
|
||||
///
|
||||
@ -400,7 +400,7 @@ void NF_3dSpriteUpdatePalette(u8 pal);
|
||||
/// @param r Red component (0 - 31).
|
||||
/// @param g Green component (0 - 31).
|
||||
/// @param b Blue component (0 - 31).
|
||||
void NF_3dSpriteGetPalColor(u8 pal, u8 number, u8 *r, u8 *g, u8 *b);
|
||||
void NF_3dSpriteGetPalColor(u32 pal, u32 number, u8 *r, u8 *g, u8 *b);
|
||||
|
||||
/// Sets the depth of the selected 3D sprite.
|
||||
///
|
||||
@ -412,7 +412,7 @@ void NF_3dSpriteGetPalColor(u8 pal, u8 number, u8 *r, u8 *g, u8 *b);
|
||||
///
|
||||
/// @param id Sprite ID (0 - 255).
|
||||
/// @param z Depth (-512 - 512)
|
||||
void NF_3dSpriteSetDepth(u8 id, s16 z);
|
||||
void NF_3dSpriteSetDepth(u32 id, s32 z);
|
||||
|
||||
// Defines for backwards compatibility
|
||||
#define NF_3dSpriteSetDeep NF_3dSpriteSetDepth
|
||||
|
@ -62,7 +62,8 @@ extern "C" {
|
||||
/// @param width Map width (in pixels)
|
||||
/// @param height Map height (in pixels)
|
||||
/// @param rotation Rotation (0 - 2)
|
||||
void NF_LoadTextFont16(const char *file, const char *name, u16 width, u16 height, u8 rotation);
|
||||
void NF_LoadTextFont16(const char *file, const char *name, u32 width, u32 height,
|
||||
u32 rotation);
|
||||
|
||||
/// Create a special tiled background to write text on it with a 8x16 font.
|
||||
///
|
||||
@ -80,7 +81,7 @@ void NF_LoadTextFont16(const char *file, const char *name, u16 width, u16 height
|
||||
/// @param layer Background layer (0 - 3)
|
||||
/// @param rotation Rotation (0 - 2)
|
||||
/// @param name Font name
|
||||
void NF_CreateTextLayer16(u8 screen, u8 layer, u8 rotation, const char *name);
|
||||
void NF_CreateTextLayer16(int screen, u32 layer, u32 rotation, const char *name);
|
||||
|
||||
/// Write text in a layer with a 8x16 font at the specified coordinates.
|
||||
///
|
||||
@ -111,7 +112,7 @@ void NF_CreateTextLayer16(u8 screen, u8 layer, u8 rotation, const char *name);
|
||||
/// @param x X coordinate
|
||||
/// @param y Y coordinate
|
||||
/// @param text String to write to the screen
|
||||
void NF_WriteText16(u8 screen, u8 layer, u16 x, u16 y, const char *text);
|
||||
void NF_WriteText16(int screen, u32 layer, u32 x, u32 y, const char *text);
|
||||
|
||||
/// Clears the contents of a text layer with a 8x16 font filling it with zeroes.
|
||||
///
|
||||
@ -123,7 +124,7 @@ void NF_WriteText16(u8 screen, u8 layer, u16 x, u16 y, const char *text);
|
||||
///
|
||||
/// @param screen Screen (0 - 1)
|
||||
/// @param layer Background layer (0 - 3)
|
||||
void NF_ClearTextLayer16(u8 screen, u8 layer);
|
||||
void NF_ClearTextLayer16(int screen, u32 layer);
|
||||
|
||||
/// @}
|
||||
|
||||
|
1559
source/nf_sprite3d.c
1559
source/nf_sprite3d.c
File diff suppressed because it is too large
Load Diff
@ -154,7 +154,7 @@ void NF_CreateTextLayer(int screen, u32 layer, u32 rotation, const char *name)
|
||||
|
||||
// If it hasn't been found, fail
|
||||
if (slot == 255)
|
||||
NF_Error(103, "Tiled Bg", NF_SLOTS_TBG);
|
||||
NF_Error(103, "Tiled BG", NF_SLOTS_TBG);
|
||||
|
||||
NF_TEXT[screen][layer].rotation = rotation;
|
||||
|
||||
@ -282,7 +282,7 @@ void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text)
|
||||
}
|
||||
|
||||
// Variables to calculate the position of the text
|
||||
int tx, ty;
|
||||
s32 tx, ty;
|
||||
|
||||
// Write text in the background map, according to the specified rotation
|
||||
switch (NF_TEXT[screen][layer].rotation)
|
||||
@ -314,7 +314,6 @@ void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text)
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 1: // 90 degrees of clockwise rotation
|
||||
|
||||
tx = NF_TEXT[screen][layer].width - y;
|
||||
@ -362,7 +361,7 @@ void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text)
|
||||
if ((ty < 0) || (string[n] == 200))
|
||||
{
|
||||
ty = NF_TEXT[screen][layer].height;
|
||||
tx ++;
|
||||
tx++;
|
||||
|
||||
// If the last row is reached, return to the first one
|
||||
if (tx > NF_TEXT[screen][layer].width)
|
||||
@ -402,7 +401,7 @@ void NF_ClearTextLayer(int screen, u32 layer)
|
||||
if (!NF_TEXT[screen][layer].exist)
|
||||
NF_Error(114, NULL, screen);
|
||||
|
||||
// Calculate buffer size
|
||||
// Calculate buffer size (2 bytes per tile)
|
||||
u32 size = (NF_TEXT[screen][layer].width + 1) * (NF_TEXT[screen][layer].height + 1) * 2;
|
||||
|
||||
// Zero the map
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
@ -17,386 +16,385 @@
|
||||
#include "nf_text.h"
|
||||
#include "nf_tiledbg.h"
|
||||
|
||||
void NF_LoadTextFont16(const char* file, const char* name, u16 width, u16 height, u8 rotation) {
|
||||
void NF_LoadTextFont16(const char *file, const char *name, u32 width, u32 height,
|
||||
u32 rotation)
|
||||
{
|
||||
// Look for a free slot and mark it as in use
|
||||
int slot = 255;
|
||||
for (int n = 0; n < NF_SLOTS_TBG; n++)
|
||||
{
|
||||
if (NF_TILEDBG[n].available)
|
||||
{
|
||||
NF_TILEDBG[n].available = false;
|
||||
slot = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Variable temporal del tamaño de la paleta
|
||||
u32 pal_size = 0;
|
||||
// If there are no free slots, fail
|
||||
if (slot == 255)
|
||||
NF_Error(103, "Tiled Bg", NF_SLOTS_TBG);
|
||||
|
||||
// Busca un slot libre
|
||||
u16 n = 0;
|
||||
u8 slot = 255;
|
||||
for (n = 0; n < NF_SLOTS_TBG; n ++) { // Busca en todos los slots
|
||||
if (NF_TILEDBG[n].available) { // Si esta libre
|
||||
NF_TILEDBG[n].available = false; // Marcalo como en uso
|
||||
slot = n; // Guarda el slot a usar
|
||||
n = NF_SLOTS_TBG; // Deja de buscar
|
||||
}
|
||||
}
|
||||
// Si no hay ningun slot libre, error
|
||||
if (slot == 255) {
|
||||
NF_Error(103, "Tiled Bg", NF_SLOTS_TBG);
|
||||
}
|
||||
// Verify that the size of the background is a multiple of 256 px (32 tiles)
|
||||
if (((width % 256) != 0) || ((height % 256) != 0))
|
||||
NF_Error(115, file, 0);
|
||||
|
||||
// Verifica que el fondo sea multiplo de 256px (32 tiles)
|
||||
if (((width % 256) != 0) || ((height % 256) != 0)) {
|
||||
NF_Error(115, file, 0);
|
||||
}
|
||||
// Free buffers if they were in use
|
||||
free(NF_BUFFER_BGMAP[slot]);
|
||||
NF_BUFFER_BGMAP[slot] = NULL;
|
||||
free(NF_BUFFER_BGTILES[slot]);
|
||||
NF_BUFFER_BGTILES[slot] = NULL;
|
||||
free(NF_BUFFER_BGPAL[slot]);
|
||||
NF_BUFFER_BGPAL[slot] = NULL;
|
||||
|
||||
// Vacia los buffers que se usaran
|
||||
free(NF_BUFFER_BGMAP[slot]); // Buffer para los mapas
|
||||
NF_BUFFER_BGMAP[slot] = NULL;
|
||||
free(NF_BUFFER_BGTILES[slot]); // Buffer para los tiles
|
||||
NF_BUFFER_BGTILES[slot] = NULL;
|
||||
free(NF_BUFFER_BGPAL[slot]); // Buffer para los paletas
|
||||
NF_BUFFER_BGPAL[slot] = NULL;
|
||||
// File path
|
||||
char filename[256];
|
||||
|
||||
// Declara los punteros a los ficheros
|
||||
FILE* file_id;
|
||||
// Load .FNT file
|
||||
snprintf(filename, sizeof(filename), "%s/%s.fnt", NF_ROOTFOLDER, file);
|
||||
FILE *file_id = fopen(filename, "rb");
|
||||
if (file_id == NULL)
|
||||
NF_Error(101, filename, 0);
|
||||
|
||||
// Variable para almacenar el path al archivo
|
||||
char filename[256];
|
||||
// Get file size. 256 colors, so 1 byte per pixel
|
||||
NF_TILEDBG[slot].tilesize = NF_TEXT_FONT_CHARS_16 * 8 * 16;
|
||||
|
||||
// Carga el archivo .fnt
|
||||
snprintf(filename, sizeof(filename), "%s/%s.fnt", NF_ROOTFOLDER, file);
|
||||
file_id = fopen(filename, "rb");
|
||||
if (file_id) { // Si el archivo existe...
|
||||
// Obten el tamaño del archivo
|
||||
NF_TILEDBG[slot].tilesize = (NF_TEXT_FONT_CHARS_16 << 7); // 1 letra 128 bytes (letras * 128)
|
||||
// Reserva el espacio en RAM
|
||||
NF_BUFFER_BGTILES[slot] = (char*) calloc (NF_TILEDBG[slot].tilesize, sizeof(char));
|
||||
if (NF_BUFFER_BGTILES[slot] == NULL) { // Si no hay suficiente RAM libre
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].tilesize);
|
||||
}
|
||||
// Lee el archivo y ponlo en la RAM
|
||||
fread(NF_BUFFER_BGTILES[slot], 1, NF_TILEDBG[slot].tilesize, file_id);
|
||||
} else { // Si el archivo no existe...
|
||||
NF_Error(101, filename, 0);
|
||||
}
|
||||
fclose(file_id); // Cierra el archivo
|
||||
// Allocate space in RAM
|
||||
NF_BUFFER_BGTILES[slot] = malloc(NF_TILEDBG[slot].tilesize);
|
||||
if (NF_BUFFER_BGTILES[slot] == NULL)
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].tilesize);
|
||||
|
||||
// Rota los Gfx de los tiles si es necesario
|
||||
if (rotation > 0) {
|
||||
for (n = 0; n < (NF_TEXT_FONT_CHARS_16 << 1); n ++) {
|
||||
NF_RotateTileGfx(slot, n, rotation);
|
||||
}
|
||||
}
|
||||
// Load file to RAM
|
||||
fread(NF_BUFFER_BGTILES[slot], 1, NF_TILEDBG[slot].tilesize, file_id);
|
||||
fclose(file_id);
|
||||
|
||||
// Crea un archivo .MAP vacio en RAM
|
||||
// ((ancho / 8) * (alto / 8)) * 2
|
||||
NF_TILEDBG[slot].mapsize = (((width >> 3) * (height >> 3)) << 1);
|
||||
// Reserva el espacio en RAM
|
||||
NF_BUFFER_BGMAP[slot] = (char*) calloc (NF_TILEDBG[slot].mapsize, sizeof(char));
|
||||
if (NF_BUFFER_BGMAP[slot] == NULL) { // Si no hay suficiente RAM libre
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].mapsize);
|
||||
}
|
||||
// Y ponlo a 0
|
||||
memset(NF_BUFFER_BGMAP[slot], 0, NF_TILEDBG[slot].mapsize);
|
||||
// Rotate graphics if required
|
||||
if (rotation > 0)
|
||||
{
|
||||
for (int n = 0; n < (NF_TEXT_FONT_CHARS_16 * 2); n++)
|
||||
NF_RotateTileGfx(slot, n, rotation);
|
||||
}
|
||||
|
||||
// Carga el archivo .PAL
|
||||
snprintf(filename, sizeof(filename), "%s/%s.pal", NF_ROOTFOLDER, file);
|
||||
file_id = fopen(filename, "rb");
|
||||
if (file_id) { // Si el archivo existe...
|
||||
// Obten el tamaño del archivo
|
||||
fseek(file_id, 0, SEEK_END);
|
||||
pal_size = ftell(file_id);
|
||||
NF_TILEDBG[slot].palsize = pal_size;
|
||||
rewind(file_id);
|
||||
// Si el tamaño es inferior a 512 bytes, ajustalo
|
||||
if (NF_TILEDBG[slot].palsize < 512) NF_TILEDBG[slot].palsize = 512;
|
||||
// Reserva el espacio en RAM
|
||||
NF_BUFFER_BGPAL[slot] = (char*) calloc (NF_TILEDBG[slot].palsize, sizeof(char));
|
||||
if (NF_BUFFER_BGPAL[slot] == NULL) { // Si no hay suficiente RAM libre
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].palsize);
|
||||
}
|
||||
// Lee el archivo y ponlo en la RAM
|
||||
fread(NF_BUFFER_BGPAL[slot], 1, pal_size, file_id);
|
||||
} else { // Si el archivo no existe...
|
||||
NF_Error(101, filename, 0);
|
||||
}
|
||||
fclose(file_id); // Cierra el archivo
|
||||
// Create an empty map in RAM. Each element in the map is 2 bytes.
|
||||
NF_TILEDBG[slot].mapsize = ((width / 8) * (height / 8)) * 2;
|
||||
|
||||
// Guarda el nombre del Fondo
|
||||
snprintf(NF_TILEDBG[slot].name, sizeof(NF_TILEDBG[slot].name), "%s", name);
|
||||
// Allocate space in RAM and zero it
|
||||
NF_BUFFER_BGMAP[slot] = calloc(NF_TILEDBG[slot].mapsize, sizeof(char));
|
||||
if (NF_BUFFER_BGMAP[slot] == NULL)
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].mapsize);
|
||||
|
||||
// Y las medidas
|
||||
NF_TILEDBG[slot].width = width;
|
||||
NF_TILEDBG[slot].height = height;
|
||||
// Load .PAL file
|
||||
snprintf(filename, sizeof(filename), "%s/%s.pal", NF_ROOTFOLDER, file);
|
||||
file_id = fopen(filename, "rb");
|
||||
if (file_id == NULL)
|
||||
NF_Error(101, filename, 0);
|
||||
|
||||
// Get file size
|
||||
fseek(file_id, 0, SEEK_END);
|
||||
u32 pal_size = ftell(file_id);
|
||||
NF_TILEDBG[slot].palsize = pal_size;
|
||||
rewind(file_id);
|
||||
|
||||
// If the size is smaller than 512 increase it to 512
|
||||
if (NF_TILEDBG[slot].palsize < 512)
|
||||
NF_TILEDBG[slot].palsize = 512;
|
||||
|
||||
// Allocate space in RAM
|
||||
NF_BUFFER_BGPAL[slot] = malloc(NF_TILEDBG[slot].palsize);
|
||||
if (NF_BUFFER_BGPAL[slot] == NULL)
|
||||
NF_Error(102, NULL, NF_TILEDBG[slot].palsize);
|
||||
|
||||
// Read file to RAM
|
||||
fread(NF_BUFFER_BGPAL[slot], 1, pal_size, file_id);
|
||||
fclose(file_id);
|
||||
|
||||
// Save the name of the background
|
||||
snprintf(NF_TILEDBG[slot].name, sizeof(NF_TILEDBG[slot].name), "%s", name);
|
||||
|
||||
// And its size
|
||||
NF_TILEDBG[slot].width = width;
|
||||
NF_TILEDBG[slot].height = height;
|
||||
}
|
||||
|
||||
void NF_CreateTextLayer16(u8 screen, u8 layer, u8 rotation, const char* name) {
|
||||
void NF_CreateTextLayer16(int screen, u32 layer, u32 rotation, const char* name)
|
||||
{
|
||||
// Create a background to use it as a text layer
|
||||
NF_CreateTiledBg(screen, layer, name);
|
||||
|
||||
u8 slot = 255; // Slot seleccionado
|
||||
char bg[32]; // Nombre
|
||||
u32 slot = 255;
|
||||
|
||||
// Crea un fondo para usarlo como capa de texto
|
||||
NF_CreateTiledBg(screen, layer, name);
|
||||
// Look for the tiled background with the specified name
|
||||
for (int n = 0; n < NF_SLOTS_TBG; n++)
|
||||
{
|
||||
if (strcmp(name, NF_TILEDBG[n].name) == 0)
|
||||
{
|
||||
slot = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Busca el numero de slot donde esta cargada la fuente
|
||||
snprintf(bg, sizeof(bg), "%s", name); // Obten el nombre del fondo a buscar
|
||||
for (int n = 0; n < NF_SLOTS_TBG; n ++) { // Busca en todos los slots
|
||||
if (strcmp(bg, NF_TILEDBG[n].name) == 0) { // Si lo encuentras
|
||||
slot = n; // Guarda el slot a usar
|
||||
n = NF_SLOTS_TBG; // Deja de buscar
|
||||
}
|
||||
}
|
||||
// If it hasn't been found, fail
|
||||
if (slot == 255)
|
||||
NF_Error(103, "Tiled BG", NF_SLOTS_TBG);
|
||||
|
||||
// Guarda si el texto debe ser rotado
|
||||
NF_TEXT[screen][layer].rotation = rotation;
|
||||
NF_TEXT[screen][layer].rotation = rotation;
|
||||
|
||||
// Guarda las medidas del fondo en tiles (ultimo numero de tile)
|
||||
switch (rotation) {
|
||||
case 0: // Sin rotacion
|
||||
NF_TEXT[screen][layer].width = ((NF_TILEDBG[slot].width >> 3) - 1);
|
||||
NF_TEXT[screen][layer].height = ((NF_TILEDBG[slot].height >> 4) - 1);
|
||||
break;
|
||||
case 1: // 90º derecha
|
||||
NF_TEXT[screen][layer].width = ((NF_TILEDBG[slot].width >> 4) - 1);
|
||||
NF_TEXT[screen][layer].height = ((NF_TILEDBG[slot].height >> 3) - 1);
|
||||
break;
|
||||
case 2: // 90º izquierda
|
||||
NF_TEXT[screen][layer].width = ((NF_TILEDBG[slot].width >> 4) - 1);
|
||||
NF_TEXT[screen][layer].height = ((NF_TILEDBG[slot].height >> 3) - 1);
|
||||
break;
|
||||
}
|
||||
// Save the background size in tiles (save the index of the last row/column)
|
||||
switch (rotation)
|
||||
{
|
||||
case 0: // No rotation
|
||||
NF_TEXT[screen][layer].width = (NF_TILEDBG[slot].width >> 3) - 1;
|
||||
NF_TEXT[screen][layer].height = (NF_TILEDBG[slot].height >> 4) - 1;
|
||||
break;
|
||||
case 1: // 90 degrees clockwise
|
||||
NF_TEXT[screen][layer].width = (NF_TILEDBG[slot].width >> 4) - 1;
|
||||
NF_TEXT[screen][layer].height = (NF_TILEDBG[slot].height >> 3) - 1;
|
||||
break;
|
||||
case 2: // 90 degrees counter-clockwise
|
||||
NF_TEXT[screen][layer].width = (NF_TILEDBG[slot].width >> 4) - 1;
|
||||
NF_TEXT[screen][layer].height = (NF_TILEDBG[slot].height >> 3) - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Almacena el slot donde esta cargada la fuente
|
||||
NF_TEXT[screen][layer].slot = slot;
|
||||
|
||||
// Y marcalo como creado
|
||||
NF_TEXT[screen][layer].exist = true;
|
||||
// Save slot where the font is stored
|
||||
NF_TEXT[screen][layer].slot = slot;
|
||||
|
||||
// Mark layer as used
|
||||
NF_TEXT[screen][layer].exist = true;
|
||||
}
|
||||
|
||||
void NF_WriteText16(u8 screen, u8 layer, u16 x, u16 y, const char* text) {
|
||||
void NF_WriteText16(int screen, u32 layer, u32 x, u32 y, const char *text)
|
||||
{
|
||||
// Verify that the text layer exists
|
||||
if (!NF_TEXT[screen][layer].exist)
|
||||
NF_Error(114, NULL, screen);
|
||||
|
||||
// Verifica si la capa de texto de destino existe
|
||||
if (!NF_TEXT[screen][layer].exist) {
|
||||
NF_Error(114, NULL, screen);
|
||||
}
|
||||
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);
|
||||
|
||||
u16 n = 0; // Variable de uso general
|
||||
// Store the text string in the temporary buffer
|
||||
for (u32 n = 0; n < tsize; n++)
|
||||
{
|
||||
int value = text[n] - 32; // Skip the first 32 non-printable characters
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
|
||||
s16 value = 0; // Valor
|
||||
string[n] = value;
|
||||
|
||||
u16 tsize = strlen(text); // Calcula el numero de letras del texto
|
||||
// Handle special characters
|
||||
if (string[n] > 95)
|
||||
{
|
||||
switch (text[n])
|
||||
{
|
||||
case 10: // \n
|
||||
string[n] = 200;
|
||||
break;
|
||||
|
||||
u8* string; // Buffer temporal
|
||||
string = NULL;
|
||||
string = (u8*) calloc (tsize, sizeof(u8));
|
||||
case 199: // Ç
|
||||
string[n] = 96;
|
||||
break;
|
||||
case 231: // ç
|
||||
string[n] = 97;
|
||||
break;
|
||||
case 209: // Ñ
|
||||
string[n] = 98;
|
||||
break;
|
||||
case 241: // ñ
|
||||
string[n] = 99;
|
||||
break;
|
||||
|
||||
// Almacena en el buffer temporal el valor de los caracteres
|
||||
for (n = 0; n < tsize; n ++) {
|
||||
value = ((int)(text[n])) - 32; // Resta 32 al valor entrado
|
||||
if (value < 0) value = 0;
|
||||
string[n] = value;
|
||||
// Si es un caracter especial...
|
||||
if (string[n] > 95) {
|
||||
// Resetea el caracter...
|
||||
string[n] = 0;
|
||||
// Verifica caracteres especiales
|
||||
switch (((int)(text[n]))) {
|
||||
// Salto de linea
|
||||
case 10: // \n
|
||||
string[n] = 200;
|
||||
break;
|
||||
// Caracteres especiales
|
||||
case 199: // Ç
|
||||
string[n] = 96;
|
||||
break;
|
||||
case 231: // ç
|
||||
string[n] = 97;
|
||||
break;
|
||||
case 209: // Ñ
|
||||
string[n] = 98;
|
||||
break;
|
||||
case 241: // ñ
|
||||
string[n] = 99;
|
||||
break;
|
||||
// Acentos Mayusculas
|
||||
case 193: // Á
|
||||
string[n] = 100;
|
||||
break;
|
||||
case 201: // É
|
||||
string[n] = 101;
|
||||
break;
|
||||
case 205: // Í
|
||||
string[n] = 102;
|
||||
break;
|
||||
case 211: // Ó
|
||||
string[n] = 103;
|
||||
break;
|
||||
case 218: // Ú
|
||||
string[n] = 104;
|
||||
break;
|
||||
// Acentos Minusculas
|
||||
case 225: // á
|
||||
string[n] = 105;
|
||||
break;
|
||||
case 233: // é
|
||||
string[n] = 106;
|
||||
break;
|
||||
case 237: // í
|
||||
string[n] = 107;
|
||||
break;
|
||||
case 243: // ó
|
||||
string[n] = 108;
|
||||
break;
|
||||
case 250: // ú
|
||||
string[n] = 109;
|
||||
break;
|
||||
// Dieresis
|
||||
case 239: // ï
|
||||
string[n] = 110;
|
||||
break;
|
||||
case 252: // ü
|
||||
string[n] = 111;
|
||||
break;
|
||||
// Admiracion e interrogante (Español)
|
||||
case 161: // ¡
|
||||
string[n] = 112;
|
||||
break;
|
||||
case 191: // ¿
|
||||
string[n] = 113;
|
||||
break;
|
||||
// Caracter invalido
|
||||
default:
|
||||
string[n] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case 193: // Á
|
||||
string[n] = 100;
|
||||
break;
|
||||
case 201: // É
|
||||
string[n] = 101;
|
||||
break;
|
||||
case 205: // Í
|
||||
string[n] = 102;
|
||||
break;
|
||||
case 211: // Ó
|
||||
string[n] = 103;
|
||||
break;
|
||||
case 218: // Ú
|
||||
string[n] = 104;
|
||||
break;
|
||||
|
||||
// Variable para calcular la posicion del texto
|
||||
s16 pos_x = 0; // Posicion X real en tiles
|
||||
s16 pos_y = 0; // Posicion Y real en tiles
|
||||
s16 tx = 0; // Posicion X del texto
|
||||
s16 ty = 0; // Posicion Y del texto
|
||||
case 225: // á
|
||||
string[n] = 105;
|
||||
break;
|
||||
case 233: // é
|
||||
string[n] = 106;
|
||||
break;
|
||||
case 237: // í
|
||||
string[n] = 107;
|
||||
break;
|
||||
case 243: // ó
|
||||
string[n] = 108;
|
||||
break;
|
||||
case 250: // ú
|
||||
string[n] = 109;
|
||||
break;
|
||||
|
||||
switch (NF_TEXT[screen][layer].rotation) {
|
||||
case 239: // ï
|
||||
string[n] = 110;
|
||||
break;
|
||||
case 252: // ü
|
||||
string[n] = 111;
|
||||
break;
|
||||
|
||||
case 0: // Sin rotacion
|
||||
// Traspasa las coordenadas
|
||||
tx = x;
|
||||
ty = y;
|
||||
// Copia el texto al buffer letra a letra
|
||||
for (n = 0; n < tsize; n ++) {
|
||||
// Si es un caracter valido
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16) {
|
||||
// Calcula la posicion en el tilemap
|
||||
pos_x = tx;
|
||||
pos_y = (ty << 1);
|
||||
// Escribe la letra correspondiente
|
||||
value = ((((int)(string[n] >> 5)) << 5) + string[n]);
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y, ((NF_TEXT[screen][layer].pal << 12) + value));
|
||||
NF_SetTileOfMap(screen,layer, pos_x, (pos_y + 1), ((NF_TEXT[screen][layer].pal << 12) + (value + 32)));
|
||||
// Siguiente letra
|
||||
tx ++;
|
||||
}
|
||||
if ((tx > NF_TEXT[screen][layer].width) || (string[n] == 200)) { // Si llegas al final de linea,
|
||||
tx = 0; // salto de linea
|
||||
ty ++;
|
||||
if (ty > NF_TEXT[screen][layer].height) { // Si estas en la ultima linea,
|
||||
ty = 0; // vuelve a la primera
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 161: // ¡
|
||||
string[n] = 112;
|
||||
break;
|
||||
case 191: // ¿
|
||||
string[n] = 113;
|
||||
break;
|
||||
|
||||
case 1: // 90º derecha
|
||||
// Traspasa las coordenadas
|
||||
tx = (NF_TEXT[screen][layer].width - y);
|
||||
ty = x;
|
||||
// Copia el texto al buffer letra a letra
|
||||
for (n = 0; n < tsize; n ++) {
|
||||
// Si es un caracter valido
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16) {
|
||||
// Calcula la posicion en el tilemap
|
||||
pos_x = (tx << 1);
|
||||
pos_y = ty;
|
||||
// Escribe la letra correspondiente
|
||||
value = ((((int)(string[n] >> 5)) << 5) + string[n]);
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y, ((NF_TEXT[screen][layer].pal << 12) + value));
|
||||
NF_SetTileOfMap(screen,layer, (pos_x - 1), pos_y, ((NF_TEXT[screen][layer].pal << 12) + (value + 32)));
|
||||
// Siguiente letra
|
||||
ty ++;
|
||||
}
|
||||
if ((ty > NF_TEXT[screen][layer].height) || (string[n] == 200)) { // Si llegas al final de linea,
|
||||
ty = 0; // salto de linea
|
||||
tx --;
|
||||
if (tx < 0) { // Si estas en la ultima linea,
|
||||
tx = NF_TEXT[screen][layer].width; // vuelve a la primera
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
string[n] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case 2: // 90º izquierda
|
||||
// Traspasa las coordenadas
|
||||
tx = y;
|
||||
ty = (NF_TEXT[screen][layer].height - x);
|
||||
// Copia el texto al buffer letra a letra
|
||||
for (n = 0; n < tsize; n ++) {
|
||||
// Si es un caracter valido
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16) {
|
||||
// Calcula la posicion en el tilemap
|
||||
pos_x = (tx << 1);
|
||||
pos_y = ty;
|
||||
// Escribe la letra correspondiente
|
||||
value = ((((int)(string[n] >> 5)) << 5) + string[n]);
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y, ((NF_TEXT[screen][layer].pal << 12) + value));
|
||||
NF_SetTileOfMap(screen,layer, (pos_x + 1), pos_y, ((NF_TEXT[screen][layer].pal << 12) + (value + 32)));
|
||||
// Siguiente letra
|
||||
ty --;
|
||||
}
|
||||
if ((ty < 0) || (string[n] == 200)) { // Si llegas al final de linea,
|
||||
ty = NF_TEXT[screen][layer].height; // Salto de linea
|
||||
tx ++;
|
||||
if (tx > NF_TEXT[screen][layer].width) { // Si llegas a la ultima linea
|
||||
tx = 0; // vuelve a la primera
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Variables to calculate the position of the text
|
||||
s32 tx, ty;
|
||||
|
||||
default:
|
||||
break;
|
||||
// Write text in the background map, according to the specified rotation
|
||||
switch (NF_TEXT[screen][layer].rotation)
|
||||
{
|
||||
case 0: // No rotacion
|
||||
|
||||
}
|
||||
tx = x;
|
||||
ty = y;
|
||||
|
||||
// Marca esta capa de texto para actualizar
|
||||
NF_TEXT[screen][layer].update = true;
|
||||
for (u32 n = 0; n < tsize; n++)
|
||||
{
|
||||
// If it's a valid character, put character
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16)
|
||||
{
|
||||
// Calculate the position in the tilemap
|
||||
s32 pos_x = tx;
|
||||
s32 pos_y = ty << 1;
|
||||
|
||||
// Libera el buffer
|
||||
free(string);
|
||||
// Print character
|
||||
u32 value = (string[n] & ~31) + string[n];
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y,
|
||||
(NF_TEXT[screen][layer].pal << 12) + value);
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y + 1,
|
||||
(NF_TEXT[screen][layer].pal << 12) + (value + 32));
|
||||
tx++;
|
||||
}
|
||||
|
||||
// If the end of the line is reached or a newline character is found
|
||||
if ((tx > NF_TEXT[screen][layer].width) || (string[n] == 200))
|
||||
{
|
||||
tx = 0;
|
||||
ty++;
|
||||
// If the last row is reached, return to the first one
|
||||
if (ty > NF_TEXT[screen][layer].height)
|
||||
ty = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: // 90 degrees of clockwise rotation
|
||||
|
||||
tx = NF_TEXT[screen][layer].width - y;
|
||||
ty = x;
|
||||
|
||||
for (u32 n = 0; n < tsize; n++)
|
||||
{
|
||||
// If it's a valid character, put character
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16)
|
||||
{
|
||||
// Calculate the position in the tilemap
|
||||
s32 pos_x = tx << 1;
|
||||
s32 pos_y = ty;
|
||||
|
||||
// Print character
|
||||
u32 value = (string[n] & ~31) + string[n];
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y,
|
||||
(NF_TEXT[screen][layer].pal << 12) + value);
|
||||
NF_SetTileOfMap(screen,layer, pos_x - 1, pos_y,
|
||||
(NF_TEXT[screen][layer].pal << 12) + (value + 32));
|
||||
ty++;
|
||||
}
|
||||
|
||||
// If the end of the line is reached or a newline character is found
|
||||
if ((ty > NF_TEXT[screen][layer].height) || (string[n] == 200))
|
||||
{
|
||||
ty = 0;
|
||||
tx--;
|
||||
|
||||
// If the last row is reached, return to the first one
|
||||
if (tx < 0)
|
||||
tx = NF_TEXT[screen][layer].width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // 90 degrees of counter-clockwise rotation
|
||||
|
||||
tx = y;
|
||||
ty = NF_TEXT[screen][layer].height - x;
|
||||
|
||||
for (u32 n = 0; n < tsize; n++)
|
||||
{
|
||||
// If it's a valid character, put character
|
||||
if (string[n] <= NF_TEXT_FONT_LAST_VALID_CHAR_16)
|
||||
{
|
||||
s32 pos_x = tx << 1;
|
||||
s32 pos_y = ty;
|
||||
|
||||
// Print the character
|
||||
u32 value = (string[n] & ~31) + string[n];
|
||||
NF_SetTileOfMap(screen,layer, pos_x, pos_y,
|
||||
(NF_TEXT[screen][layer].pal << 12) + value);
|
||||
NF_SetTileOfMap(screen,layer, pos_x + 1, pos_y,
|
||||
(NF_TEXT[screen][layer].pal << 12) + (value + 32));
|
||||
ty--;
|
||||
}
|
||||
|
||||
// If the end of the line is reached or a newline character is found
|
||||
if ((ty < 0) || (string[n] == 200))
|
||||
{
|
||||
ty = NF_TEXT[screen][layer].height;
|
||||
tx++;
|
||||
|
||||
// If the last row is reached, return to the first one
|
||||
if (tx > NF_TEXT[screen][layer].width)
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Mark this layers as requiring an update
|
||||
NF_TEXT[screen][layer].update = true;
|
||||
|
||||
// Free temporary buffer
|
||||
free(string);
|
||||
}
|
||||
|
||||
void NF_ClearTextLayer16(u8 screen, u8 layer) {
|
||||
void NF_ClearTextLayer16(int screen, u32 layer)
|
||||
{
|
||||
// Verify that the text layer exists
|
||||
if (!NF_TEXT[screen][layer].exist)
|
||||
NF_Error(114, NULL, screen);
|
||||
|
||||
// Verifica si la capa de texto de destino existe
|
||||
if (!NF_TEXT[screen][layer].exist) {
|
||||
NF_Error(114, NULL, screen);
|
||||
}
|
||||
// Calculate size of the buffer
|
||||
u32 w = NF_TEXT[screen][layer].width + 1;
|
||||
u32 h = NF_TEXT[screen][layer].height + 1;
|
||||
u32 size = w * h * 4; // 2 tiles per character, 2 bytes per tile
|
||||
|
||||
// Calcula el tamaño del buffer (segun la rotacion)
|
||||
u32 size = 0;
|
||||
switch (NF_TEXT[screen][layer].rotation) {
|
||||
case 0: // Sin rotacion
|
||||
size = (((NF_TEXT[screen][layer].width + 1) * ((NF_TEXT[screen][layer].height + 1) << 1)) << 1);
|
||||
break;
|
||||
case 1: // 90º a la derecha
|
||||
size = ((((NF_TEXT[screen][layer].width + 1) << 1) * (NF_TEXT[screen][layer].height + 1)) << 1);
|
||||
break;
|
||||
case 2: // 90º a la izquierda
|
||||
size = ((((NF_TEXT[screen][layer].width + 1) << 1) * (NF_TEXT[screen][layer].height + 1)) << 1);
|
||||
break;
|
||||
}
|
||||
|
||||
// Pon a 0 todos los bytes del mapa de la capa de texto
|
||||
memset(NF_BUFFER_BGMAP[NF_TEXT[screen][layer].slot], 0, size);
|
||||
|
||||
// Marca esta capa de texto para actualizar
|
||||
NF_TEXT[screen][layer].update = true;
|
||||
// Clear the text layer
|
||||
memset(NF_BUFFER_BGMAP[NF_TEXT[screen][layer].slot], 0, size);
|
||||
|
||||
// Mark this layers as requiring an update
|
||||
NF_TEXT[screen][layer].update = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user