examples: Cleanup and translate more examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-21 02:25:53 +01:00
parent af329f901a
commit 4d4cb6ab8e
6 changed files with 423 additions and 562 deletions

View File

@ -85,9 +85,9 @@ int main(int argc, char **argv)
square_y = 127; square_y = 127;
// Fill buffer // Fill buffer
for (int y = square_y; y < (square_y + 64); y ++) for (int y = square_y; y < square_y + 64; y++)
{ {
for (int x = square_x; x < (square_x + 64); x ++) for (int x = square_x; x < square_x + 64; x++)
{ {
// Get current color // Get current color
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x]; u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
@ -107,7 +107,7 @@ int main(int argc, char **argv)
b = composite; b = composite;
// Pack the components as a RGB value // Pack the components as a RGB value
rgb = r | (g << 5)| (b << 10) | BIT(15); rgb = r | (g << 5) | (b << 10) | BIT(15);
// Write RGB value in the backbuffer // Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb; NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;

View File

@ -1,60 +1,23 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic example of using a 16-bit bitmap with a backbuffer and loading images.
// It shows two images with a window effect.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
con carga de archivos de imagen.
Efecto de visualizar dos imagenes con efecto ventana.
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -62,114 +25,116 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D en modo BITMAP // Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas NF_Set2D(0, 5);
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP" // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP // Initialize storage buffers
NF_Init16bitsBgBuffers(); NF_Init16bitsBgBuffers();
// Inicializa el BackBuffer de 16 bits // Initialize backbuffer
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(1); NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer en la pantalla superior // Enable backbuffer
NF_Enable16bitsBackBuffer(1); NF_Enable16bitsBackBuffer(1);
// Carga el archivo BITMAP de imagen en formato RAW a la RAM // Load bitmap background files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0); NF_Load16bitsBg("bmp/bitmap16", 0);
NF_Load16bitsBg("bmp/img16_a", 1); NF_Load16bitsBg("bmp/img16_a", 1);
NF_Load16bitsBg("bmp/img16_b", 2); NF_Load16bitsBg("bmp/img16_b", 2);
// Tranfiere la imagen a la VRAM de ambas pantallas // Tranfer image to VRAM of both screens
NF_Copy16bitsBuffer(0, 0, 0); NF_Copy16bitsBuffer(0, 0, 0);
NF_Copy16bitsBuffer(1, 1, 2); NF_Copy16bitsBuffer(1, 1, 2);
// Si no es necesario usarla mas, borrala de la RAM // It's not needed to use it any longer, so remove it from RAM
NF_Unload16bitsBg(0); NF_Unload16bitsBg(0);
// Variables del control del touchpad // Variables to control the window
u16 keys = 0;
touchPosition touchscreen;
// Variables del control de la ventana
u32 move = 0;
s16 y = 0;
s16 xa = 0; s16 xa = 0;
s16 xb = 0; s16 xb = 0;
s16 ya = 0; s16 ya = 0;
s16 yb = 0; s16 yb = 0;
s16 sqr_xa = 0;
s16 sqr_xb = 0;
s16 sqr_ya = 0;
s16 sqr_yb = 0;
bool in_touch = false;
// Repite para siempre while (1)
while (1) { {
// Copy original image to the backbuffer of the top screen
// Copia al backbuffer la imagen de arriba
NF_Copy16bitsBuffer(1, 1, 2); NF_Copy16bitsBuffer(1, 1, 2);
// Lectura de posicion del stylus // Read keys and touchscreen
scanKeys(); // Lee el touchpad via Libnds scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen); touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen u16 keys_held = keysHeld();
if (keys & KEY_TOUCH) { // Si se toca el touchpad u16 keys_down = keysDown();
if (!in_touch) { // Y es el primer toque
xa = touchscreen.px; // Guarda el punto
ya = touchscreen.py;
in_touch = true; // e indicalo
}
xb = touchscreen.px; // Guarda el segundo punto
yb = touchscreen.py;
} else {
in_touch = false; // Ya no se esta tocando el touchpad
}
// Si se ha tocado el touchpad y la ventana es del tamaño suficiente... if (keys_down & KEY_TOUCH)
if (in_touch && (xa != xb) && (ya != yb)) { {
// Calcula los limites de la ventana // If this is the first time the user presses the screen, save that
if (xa < xb) { // point as one corner of the window.
xa = touchscreen.px;
ya = touchscreen.py;
}
else if (keys_held & KEY_TOUCH)
{
// Save the other corner of the window
xb = touchscreen.px;
yb = touchscreen.py;
// If the two points aren't the same
if ((xa != xb) && (ya != yb))
{
int sqr_xa, sqr_xb, sqr_ya, sqr_yb;
// Calculate window bounds
if (xa < xb)
{
sqr_xa = xa; sqr_xa = xa;
sqr_xb = xb; sqr_xb = xb;
} else { }
else
{
sqr_xa = xb; sqr_xa = xb;
sqr_xb = xa; sqr_xb = xa;
} }
if (ya < yb) {
if (ya < yb)
{
sqr_ya = ya; sqr_ya = ya;
sqr_yb = yb; sqr_yb = yb;
} else { }
else
{
sqr_ya = yb; sqr_ya = yb;
sqr_yb = ya; sqr_yb = ya;
} }
// Ahora dibuja la ventana linea a linea
for (y = sqr_ya; y < sqr_yb; y ++) { // Draw the window
// Calcula donde se escribira la linea for (int y = sqr_ya; y < sqr_yb; y ++)
move = ((y << 8) + sqr_xa); {
// Copia la linea de la Imagen A sobre la B u32 offset = (y << 8) + sqr_xa;
memcpy((NF_16BITS_BACKBUFFER[1] + move), (NF_BG16B[1].buffer + move), ((sqr_xb - sqr_xa) << 1));
memcpy(NF_16BITS_BACKBUFFER[1] + offset,
NF_BG16B[1].buffer + offset,
(sqr_xb - sqr_xa) << 1);
}
} }
} }
// Sincronismo Vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
// Manda el backbuffer a la pantalla // Swap backbuffer and visible buffers
NF_Flip16bitsBackBuffer(1); NF_Flip16bitsBackBuffer(1);
} }
return 0; return 0;
} }

View File

@ -1,59 +1,22 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic example of using a 16-bit bitmap and zooming an image.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
Zoom de imagen X2
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -61,124 +24,124 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D en modo BITMAP // Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas NF_Set2D(0, 5);
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP" // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP // Initialize storage buffers
NF_Init16bitsBgBuffers(); NF_Init16bitsBgBuffers();
// Inicializa el BackBuffer de 16 bits // Initialize backbuffers
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(0); NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1); NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer en la pantalla superior // Enable backbuffers
NF_Enable16bitsBackBuffer(0); NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1); NF_Enable16bitsBackBuffer(1);
// Carga el archivo BITMAP de imagen en formato RAW a la RAM // Load bitmap background files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0); NF_Load16bitsBg("bmp/bitmap16", 0);
// Tranfiere la imagen al BackBuffer de la pantalla inferior // Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0); NF_Copy16bitsBuffer(1, 1, 0);
// Variables RGB // Window position
u8 r = 0;
u8 g = 0;
u8 b = 0;
// Calcula el valor RGB
u16 rgb = 0;
// Ventana
s16 x = 0;
s16 y = 0;
s16 composite = 0;
s16 square_x = 0; s16 square_x = 0;
s16 square_y = 0; s16 square_y = 0;
s16 zoom_x = 0;
s16 zoom_y = 0;
// Variables del control del touchpad while (1)
u16 keys = 0; {
touchPosition touchscreen; // Copy original image
while (1) {
// Copia el original
NF_Copy16bitsBuffer(1, 1, 0); NF_Copy16bitsBuffer(1, 1, 0);
// Lectura de posicion del stylus // Read keys and touchscreen
scanKeys(); // Lee el touchpad via Libnds scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen); touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen u16 keys = keysHeld();
if (keys & KEY_TOUCH) { if (keys & KEY_TOUCH)
square_x = (touchscreen.px - 64); {
square_y = (touchscreen.py - 48); square_x = touchscreen.px - 64;
square_y = touchscreen.py - 48;
} }
// Calcula la ventana // Restrict coordinates of the window
if (square_x < 0) square_x = 0; if (square_x < 0)
if (square_x > 127) square_x = 127; square_x = 0;
if (square_y < 0) square_y = 0; if (square_x > 127)
if (square_y > 95) square_y = 95; square_x = 127;
// Resetea el control de zoom if (square_y < 0)
zoom_x = 0; square_y = 0;
zoom_y = 0; if (square_y > 95)
square_y = 95;
// Rellena el buffer // Reset source buffer read pointers
for (y = square_y; y < (square_y + 96); y ++) { u32 zoom_x = 0;
for (x = square_x; x < (square_x + 128); x ++) { u32 zoom_y = 0;
// Obten el color actual
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)]; // Fill the destination buffer
// Escribe los pixeles en el Backbuffer de la pantalla superior for (int y = square_y; y < square_y + 96; y++)
// Esto genera el Zoom x2 en la pantalla superior {
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb; for (int x = square_x; x < square_x + 128; x++)
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb; {
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb; // Get current color
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb; u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
// Desglosa el RGB
r = (rgb & 0x1F); // Write value in 2x2 pixels in the bacbuffer of the bottom
g = ((rgb >> 5) & 0x1F); // screen for the zoom effect.
b = ((rgb >> 10) & 0x1F); NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + zoom_x] = rgb;
// Genera el equivalente a blanco y negro y sube el brillo 3 puntos NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb;
composite = ((int)((r + g + b) / 3) + 3); NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb;
if (composite > 31) composite = 31; NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb;
// Reemplaza los valores RGB
r = (composite); // Get RGB components
g = (composite >> 2); u32 r = rgb & 0x1F;
b = (composite >> 1); u32 g = (rgb >> 5) & 0x1F;
// Calcula el valor RGB (Alpha + RGB555) u32 b = (rgb >> 10) & 0x1F;
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15)));
// Escribelos en el buffer // Generate a grayscale value based on the RGB components
NF_16BITS_BACKBUFFER[1][((y << 8) + x)] = rgb; u32 composite = ((r + g + b) / 3) + 3;
// Incrementa dos puntos la X del zoom if (composite > 31)
composite = 31;
// Replace the RGB values by the grayscale value (this shows up
// as a rectangular window on the screen)
r = composite;
g = composite >> 2;
b = composite >> 1;
// Pack the components as a RGB value
rgb = r | (g << 5) | (b << 10) | BIT(15);
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
// Increment X coordinate pointer
zoom_x += 2; zoom_x += 2;
} }
zoom_x = 0; // Resetea la X del zoom
zoom_y += 2; // Incrementa dos puntos la Y del zoom // Set X coordinate from the beginning
zoom_x = 0;
// Increment Y coordinate pointer
zoom_y += 2;
} }
// Sincronismo Vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
// Copia el contenido del Backbuffer a la VRAM // Swap backbuffers and visible buffers
NF_Flip16bitsBackBuffer(0); NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1); NF_Flip16bitsBackBuffer(1);
} }
return 0; return 0;
} }

View File

@ -1,110 +1,70 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of using 16-bit bitmap graphics.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo graficos en modo BITMAP de 16bits
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en BITMAP // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
u32 r = 0;
// Variables RGB u32 g = 0;
u8 r = 0; u32 b = 0;
u8 g = 0;
u8 b = 0;
// Calcula el valor RGB
u16 rgb = 0;
// Direccion en VRAM
u32 adress = 0;
// Otras
s16 x = 0;
s16 y = 0;
// Rellena la pantalla // Rellena la pantalla
for (y = 0; y < 256; y ++) { for (int y = 0; y < 256; y++)
for (x = 0; x < 256; x ++) { {
// Calcula el nuevo color for (int x = 0; x < 256; x++)
r ++; {
if (r > 31) { // Calculate new color
r++;
if (r > 31)
{
r = 0; r = 0;
g ++; g++;
if (g > 31) { if (g > 31)
{
g = 0; g = 0;
b ++; b++;
if (b > 31) b = 0; if (b > 31)
} b = 0;
}
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15)));
// Calcula la posicion donde se escribira en la VRAM (Banco A, modo bitmap, pantalla superior)
adress = (0x06000000 + (((y << 8) + x) << 1));
// Escribe el valor
*((u16*)adress) = rgb;
// Calcula la posicion donde se escribira en la VRAM (Banco C, modo bitmap, pantalla inferior)
adress = (0x06200000 + (((x << 8) + y) << 1));
// Escribe el valor
*((u16*)adress) = rgb;
} }
} }
// Pack the components as a RGB value
u32 rgb = r | (g << 5) | (b << 10) | BIT(15);
// Bucle (repite para siempre) // Calculate destination address for top screen (VRAM_A)
while(1) { u32 address = 0x06000000 + (((y << 8) + x) << 1);
swiWaitForVBlank(); // Espera al sincronismo vertical // Write RGB value
*((u16*)address) = rgb;
// Calculate destination address for bottom screen (VRAM_C)
address = 0x06200000 + (((x << 8) + y) << 1);
// Write RGB value
*((u16*)address) = rgb;
}
}
while (1)
{
// Wait for the screen refresh
swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -124,9 +124,11 @@ int main(int argc, char **argv)
bola_x[n] += bola_spx[n]; bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1; bola_spx[n] *= -1;
bola_y[n] += bola_spy[n]; bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1; bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]); NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
} }

View File

@ -1,57 +1,24 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of modifying sprite palettes.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de manipulacion de paletas de Sprites
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Prepare a NitroFS initialization screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -59,58 +26,51 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D // Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los Sprites // Initialize sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior NF_InitSpriteSys(0); // Top screen
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior NF_InitSpriteSys(1); // Bottom screen
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
// Load sprite files from NitroFS
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
NF_LoadSpritePal("sprite/personaje", 0); NF_LoadSpritePal("sprite/personaje", 0);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
NF_LoadSpritePal("sprite/bola", 1); NF_LoadSpritePal("sprite/bola", 1);
// Create top screen background
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl"); NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3"); NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2"); NF_CreateTiledBg(1, 2, "capa_2");
// Transfer the required sprites to VRAM
// Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep all frames in VRAM
NF_VramSpriteGfx(1, 0, 0, true); // Bola (mantiene los frames en RAM)
NF_VramSpritePal(1, 0, 0); NF_VramSpritePal(1, 0, 0);
NF_VramSpriteGfx(0, 1, 0, true); // Personaje (mantiene los frames en RAM) Pantalla inferior NF_VramSpriteGfx(0, 1, 0, true); // Character: Keep all frames in VRAM
NF_VramSpritePal(0, 1, 0); NF_VramSpritePal(0, 1, 0);
// Setup character sprite
// Variables generales y inicializacion del random
u16 n = 0;
srand(time(NULL));
// Crea el sprite del personaje en pantalla
s16 pj_x = 0; s16 pj_x = 0;
s16 pj_y = 127; s16 pj_y = 127;
u8 pj_frame = 0; u8 pj_frame = 0;
@ -118,118 +78,129 @@ int main(int argc, char **argv) {
s8 pj_speed = 1; s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y); NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Crea las bolas en la pantalla superior // Setup ball sprites
s16 bola_x[32]; s16 bola_x[32];
s16 bola_y[32]; s16 bola_y[32];
s8 bola_spx[32]; s8 bola_spx[32];
s8 bola_spy[32]; s8 bola_spy[32];
for (n = 0; n < 32; n ++) {
bola_x[n] = (rand() % 223); for (int n = 0; n < 32; n++)
bola_y[n] = (rand() % 159); {
bola_x[n] = rand() % 223;
bola_y[n] = rand() % 159;
bola_spx[n] = (rand() % 3) + 1; bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1; bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]); NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
} }
// Variables para el ciclo de colores // Palette color cycle speed
u8 r, g, b; int speed = 0;
s8 red, green, blue;
s8 speed = 0;
// Bucle (repite para siempre) while (1)
while(1) { {
// Color cycle handling
// Ciclo de colores speed++;
speed ++; if (speed > 2)
if (speed > 2) { {
speed = 0; speed = 0;
// Bolas // Balls
for (n = 1; n < 256; n ++) { for (int n = 1; n < 256; n++)
// Obten el valor actual del color en la paleta {
// Get current color from the palette
u8 r, g, b;
NF_SpriteGetPalColor(0, 0, n, &r, &g, &b); NF_SpriteGetPalColor(0, 0, n, &r, &g, &b);
// Pasa los valores del color a las variables de modificacion
red = r; // Modify color
green = g; r--;
blue = b; if (r > 31)
// Modifica los valores r = 31;
red --;
if (red < 0) red = 31; g++;
green ++; if (g > 31)
if (green > 31) green = 0; g = 0;
blue ++;
if (blue > 31) blue = 0; b++;
// Actualiza el color en la paleta en RAM if (b > 31)
NF_SpriteEditPalColor(0, 0, n, red, green, blue); b = 0;
// Update color in the copy of the palette in RAM
NF_SpriteEditPalColor(0, 0, n, r, g, b);
} }
// Actualiza la paleta en VRAM
// Update palette in VRAM
NF_SpriteUpdatePalette(0, 0); NF_SpriteUpdatePalette(0, 0);
// Personaje // Character
for (n = 1; n < 256; n ++) { for (int n = 1; n < 256; n++)
// Obten el valor actual del color en la paleta {
// Get current color from the palette
u8 r, g, b;
NF_SpriteGetPalColor(1, 0, n, &r, &g, &b); NF_SpriteGetPalColor(1, 0, n, &r, &g, &b);
// Pasa los valores del color a las variables de modificacion
red = r; // Modify color
green = g; r--;
blue = b; if (r > 31)
// Modifica los valores r = 31;
red --;
if (red < 0) red = 31; // Update color in the copy of the palette in RAM
//green ++; NF_SpriteEditPalColor(1, 0, n, r, g, b);
//if (green > 31) green = 0;
//blue ++;
//if (blue > 31) blue = 0;
// Actualiza el color en la paleta en RAM
NF_SpriteEditPalColor(1, 0, n, red, green, blue);
} }
// Actualiza la paleta en VRAM
// Update palette in VRAM
NF_SpriteUpdatePalette(1, 0); NF_SpriteUpdatePalette(1, 0);
} }
// Move character
// Mueve el personaje
pj_x += pj_speed; pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) { if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1; pj_speed *= -1;
if (pj_speed > 0) {
if (pj_speed > 0)
NF_HflipSprite(1, 0, false); NF_HflipSprite(1, 0, false);
} else { else
NF_HflipSprite(1, 0, true); NF_HflipSprite(1, 0, true);
} }
}
NF_MoveSprite(1, 0, pj_x, pj_y); NF_MoveSprite(1, 0, pj_x, pj_y);
// Animacion del personaje // Animate character
pj_anim ++; pj_anim++;
if (pj_anim > 5) { if (pj_anim > 5)
{
pj_anim = 0; pj_anim = 0;
pj_frame ++; pj_frame++;
if (pj_frame > 11) pj_frame = 0; if (pj_frame > 11)
pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame); NF_SpriteFrame(1, 0, pj_frame);
} }
// Mueve las bolas // Move balls
for (n = 0; n < 32; n ++) { for (int n = 0; n < 32; n++)
{
bola_x[n] += bola_spx[n]; bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) bola_spx[n] *= -1; if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1;
bola_y[n] += bola_spy[n]; bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1; if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]); NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
} }
// Actualiza el array de OAM // Update OAM array
NF_SpriteOamSet(0); NF_SpriteOamSet(0);
NF_SpriteOamSet(1); NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank();
// Actualiza el OAM // Update OAM
oamUpdate(&oamMain); oamUpdate(&oamMain);
oamUpdate(&oamSub); oamUpdate(&oamSub);
} }
return 0; return 0;
} }