examples: Cleanup and translate more examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-20 02:43:19 +01:00
parent fa21c62ac4
commit b20bb1ca2c
10 changed files with 1040 additions and 1338 deletions

View File

@ -1,180 +1,145 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Water reflection effect (with scroll).
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de reflejo del agua (con scroll)
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 <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
// Wave effect variables
u16 mapa[32][24]; // Map
s16 bgx[192]; // X scroll of each line
s8 i[192]; // Movement control of each line
// Defines especiales del ejemplo
#define VLINE *(vu16*)0x04000006 // Obtiene via registro la linea actual del dibujado
// Variables del efecto wave
u16 mapa[32][24]; // Almacena el mapa
s16 bgx[192]; // Posicion X de cada linea
s8 i[192]; // Control de movimiento de cada linea
// Variables para el control de fondo
// Background control variables
s16 bg_x[4];
// Function that runs after a scanline is drawn. By modifying the values of the
// scroll registers it's possible to add a wave effect.
void hblank_handler(void)
{
u32 vline = REG_VCOUNT; // Get the current line
// Define la funcion a ejecutar para el HBLANK
void _WaveEffect(void);
if ((vline >= 138) && (vline <= 159))
{
// If the current line is between 138 and 159, apply effect to layer 1
bgx[vline] += i[vline];
if ((bgx[vline] < 1) || (bgx[vline] > 63))
i[vline] *= -1;
NF_ScrollBg(0, 1, bg_x[1] + ((bgx[vline] >> 3) - 4), 0);
}
if ((vline >= 160) && (vline <= 191))
{
// If the current line is between 160 and 191, apply effect to layer 0
bgx[vline] += i[vline];
if ((bgx[vline] < 1) || (bgx[vline] > (vline - 156)))
i[vline] *= -1;
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/layer0", "layer0", 512, 256); // Carga el fondo para la pantalla inferior
NF_LoadTiledBg("bg/layer1", "layer1", 512, 256); // Carga el fondo para la pantalla inferior
NF_LoadTiledBg("bg/layer2", "layer2", 512, 256); // Carga el fondo para la pantalla inferior
NF_LoadTiledBg("bg/layer3", "layer3", 512, 256); // Carga el fondo para la pantalla inferior
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla inferior
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "layer3");
NF_CreateTiledBg(0, 2, "layer2");
NF_CreateTiledBg(0, 1, "layer1");
NF_CreateTiledBg(0, 0, "layer0");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "nfl");
// Inicializa el efecto wave
s16 y = 0;
s8 inc = 1;
for (y = 138; y < 192; y ++) {
// Calculos para la capa 1
if ((y >= 138) && (y <= 159)) {
bgx[y] = 32;
inc *= -1;
i[y] = inc;
}
// Calculos para la capa 0
if ((y >= 160) && (y <= 191)) {
bgx[y] = ((y - 156) >> 1);
i[y] = inc;
inc *= -1;
}
}
// Y definimos que funcion se ejecutara al final de cada linea de dibujado (HBLANK)
irqSet(IRQ_HBLANK, _WaveEffect);
// Para finalizar, habilitamos la interrupcion
irqEnable(IRQ_HBLANK);
// Lectura del keypad
u16 keys = 0;
// Bucle (repite para siempre)
while(1) {
// Lee el keypad
scanKeys();
keys = keysHeld();
// Mueve el fondo
if ((keys & KEY_LEFT) && (bg_x[0] > 8)) bg_x[0] --;
if ((keys & KEY_RIGHT) && (bg_x[0] < 247)) bg_x[0] ++;
// Calcula el parallax
bg_x[1] = (int)(bg_x[0] / 1.5);
bg_x[2] = (int)(bg_x[1] / 1.5);
bg_x[3] = (int)(bg_x[2] / 1.5);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Posiciona cada fondo donde le corresponde
NF_ScrollBg(0, 3, bg_x[3], 0);
NF_ScrollBg(0, 2, bg_x[2], 0);
NF_ScrollBg(0, 1, bg_x[1], 0);
NF_ScrollBg(0, 0, bg_x[0], 0);
}
return 0;
NF_ScrollBg(0, 0, (bg_x[0] + (((vline - 156) >> 1) - bgx[vline])), 0);
}
}
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
void _WaveEffect(void) {
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
if ((VLINE >= 138) && (VLINE <= 159)) { // Si la linea esta entre la 138 - 159, ejecuta el efecto para la capa 1
bgx[VLINE] += i[VLINE];
if ((bgx[VLINE] < 1) || (bgx[VLINE] > 63)) i[VLINE] *= -1;
NF_ScrollBg(0, 1, bg_x[1] + ((bgx[VLINE] >> 3) - 4), 0);
}
if ((VLINE >= 160) && (VLINE <= 191)) { // Si la linea esta entre la 160 - 191, ejecuta el efecto para la capa 0
bgx[VLINE] += i[VLINE];
if ((bgx[VLINE] < 1) || (bgx[VLINE] > (VLINE - 156))) i[VLINE] *= -1;
NF_ScrollBg(0, 0, (bg_x[0] + (((VLINE - 156) >> 1) - bgx[VLINE])), 0);
}
// Load background files from NitroFS
NF_LoadTiledBg("bg/layer0", "layer0", 512, 256);
NF_LoadTiledBg("bg/layer1", "layer1", 512, 256);
NF_LoadTiledBg("bg/layer2", "layer2", 512, 256);
NF_LoadTiledBg("bg/layer3", "layer3", 512, 256);
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
// Create top screen backgrounds
NF_CreateTiledBg(0, 3, "layer3");
NF_CreateTiledBg(0, 2, "layer2");
NF_CreateTiledBg(0, 1, "layer1");
NF_CreateTiledBg(0, 0, "layer0");
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "nfl");
// Initialize wave effect
s16 y = 0;
s8 inc = 1;
for (y = 138; y < 192; y++)
{
// Layer 1 calculations
if ((y >= 138) && (y <= 159))
{
bgx[y] = 32;
inc *= -1;
i[y] = inc;
}
// Layer 0 calculations
if ((y >= 160) && (y <= 191))
{
bgx[y] = ((y - 156) >> 1);
i[y] = inc;
inc *= -1;
}
}
// Register a function to be called after a screen line has been drawn (when
// the horizontal blanking period starts)
irqSet(IRQ_HBLANK, hblank_handler);
irqEnable(IRQ_HBLANK);
while (1)
{
scanKeys(); // Read keypad
u16 keys = keysHeld(); // Keys currently pressed
// Move background
if ((keys & KEY_LEFT) && (bg_x[0] > 8))
bg_x[0] --;
if ((keys & KEY_RIGHT) && (bg_x[0] < 247))
bg_x[0] ++;
// Calculate parallax
bg_x[1] = (int)(bg_x[0] / 1.5);
bg_x[2] = (int)(bg_x[1] / 1.5);
bg_x[3] = (int)(bg_x[2] / 1.5);
// Wait for the screen refresh
swiWaitForVBlank();
// Scroll all backgrounds
NF_ScrollBg(0, 3, bg_x[3], 0);
NF_ScrollBg(0, 2, bg_x[2], 0);
NF_ScrollBg(0, 1, bg_x[1], 0);
NF_ScrollBg(0, 0, bg_x[0], 0);
}
return 0;
}

View File

@ -1,156 +1,120 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Simple wave effect
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de efecto onda (simple)
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 <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
// Defines especiales del ejemplo
#define VLINE *(vu16*)0x04000006 // Obtiene via registro la linea actual del dibujado
// Variables
u16 mapa[32][24]; // Almacena el mapa
s16 bgx[192]; // Posicion X de cada linea
s8 i[192]; // Control de movimiento de cada linea
u16 mapa[32][24]; // Almacena el mapa
s16 bgx[192]; // Posicion X de cada linea
s8 i[192]; // Control de movimiento de cada linea
// Function that runs after a scanline is drawn. By modifying the values of the
// scroll registers it's possible to add a wave effect.
void hblank_handler(void)
{
u32 vline = REG_VCOUNT; // Get the current line
if (vline < 192)
{
// If this is a line inside the screen, handle the effect
bgx[vline] += i[vline];
if ((bgx[vline] < 1) || (bgx[vline] > 63))
i[vline] *= -1;
// Define la funcion a ejecutar en cada HBLANK
void _WaveEffect(void);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "nfl");
// Invierte todos los tiles (V) del mapa de la pantalla inferior y copia los tiles al buffer temporal
s16 x = 0;
s16 y = 0;
for (y = 0; y < 24; y ++) {
for (x = 0; x < 32; x ++) {
NF_SetTileVflip(1, 3, x, y);
mapa[x][y] = NF_GetTileOfMap(1, 3, x, y);
}
}
// Ahora coloca los tiles en orden inverso para compensar la imagen
for (y = 0; y < 24; y ++) {
for (x = 0; x < 32; x ++) {
NF_SetTileOfMap(1, 3, x, (23 - y), mapa[x][y]);
}
}
// Y para finalizar, actualiza el mapa en la VRAM
NF_UpdateVramMap(1, 3);
// Inicializa el efecto wave
s8 inc = 1;
x = 0;
for (y = 0; y < 192; y ++) {
x += inc;
bgx[y] = x;
if ((x < 1) || (x > 63)) inc *= -1;
i[y] = inc;
}
// Definimos que funcion se ejecutara al final de cada linea de dibujado (HBLANK)
irqSet(IRQ_HBLANK, _WaveEffect);
// Para finalizar, habilitamos la interrupcion
irqEnable(IRQ_HBLANK);
// Bucle (repite para siempre)
while(1) {
swiWaitForVBlank(); // Espera al sincronismo vertical
}
return 0;
NF_ScrollBg(1, 3, ((bgx[vline] >> 3) - 4), 0);
}
}
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Efecto WAVE (Se ejecuta al final de cada linea de dibujado)
void _WaveEffect(void) {
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
if (VLINE < 192) { // Si la linea esta entre la 0 - 191, ejecuta el efecto
bgx[VLINE] += i[VLINE];
if ((bgx[VLINE] < 1) || (bgx[VLINE] > 63)) i[VLINE] *= -1;
NF_ScrollBg(1, 3, ((bgx[VLINE] >> 3) - 4), 0);
}
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// Create bottom screen background
NF_CreateTiledBg(1, 3, "nfl");
// Flip vertically all the tiles in the map of the bottom screen, and copy
// them to a temporary buffer
for (int y = 0; y < 24; y ++)
{
for (int x = 0; x < 32; x ++)
{
NF_SetTileVflip(1, 3, x, y);
mapa[x][y] = NF_GetTileOfMap(1, 3, x, y);
}
}
// Now copy the tiles in reverse order to flip the image correctly
for (int y = 0; y < 24; y ++)
{
for (int x = 0; x < 32; x ++)
{
NF_SetTileOfMap(1, 3, x, (23 - y), mapa[x][y]);
}
}
// Finally, update the copy of the map in VRAM
NF_UpdateVramMap(1, 3);
// Initialize the wave effect
s8 inc = 1;
int x = 0;
for (int y = 0; y < 192; y ++)
{
x += inc;
bgx[y] = x;
if ((x < 1) || (x > 63))
inc *= -1;
i[y] = inc;
}
// Register a function to be called after a screen line has been drawn (when
// the horizontal blanking period starts)
irqSet(IRQ_HBLANK, hblank_handler);
irqEnable(IRQ_HBLANK);
while (1)
{
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,281 +1,236 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of applying a x2 zoom with interpolation to a 16 bit image.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
Zoom x2 con filtro por interpolacion
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 <string.h>
#include <unistd.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize storage buffers
NF_Init16bitsBgBuffers();
int main(int argc, char **argv) {
// Initialize backbuffers
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Enable backbuffers
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Load bitmap files from NitroFS
NF_Load16bitsBg("bmp/img16_c", 0);
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5);
// Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa los fondos en modo "BITMAP"
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Window location
s16 square_x = 0;
s16 square_y = 0;
// Inicializa los buffers para guardar fondos en formato BITMAP
NF_Init16bitsBgBuffers();
while (1)
{
// Copy original image
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa el BackBuffer de 16 bits
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Read keys and touchscreen
scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen);
u16 keys = keysHeld();
if (keys & KEY_TOUCH)
{
square_x = touchscreen.px - 64;
square_y = touchscreen.py - 48;
}
// Habilita el backbuffer en la pantalla superior
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Restrict coordinates of the window
if (square_x < 0)
square_x = 0;
if (square_x > 127)
square_x = 127;
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
NF_Load16bitsBg("bmp/img16_c", 0);
if (square_y < 0)
square_y = 0;
if (square_y > 95)
square_y = 95;
// Tranfiere la imagen al BackBuffer de la pantalla inferior
NF_Copy16bitsBuffer(1, 1, 0);
// Zoom read coordinate pointers
int zoom_x = 0;
int zoom_y = 0;
// Variables RGB
u8 r[4];
u8 g[4];
u8 b[4];
u8 red = 0;
u8 green = 0;
u8 blue = 0;
// Fill buffer
for (int y = square_y; y < (square_y + 96); y ++)
{
for (int x = square_x; x < (square_x + 128); x ++)
{
u32 rgb;
u32 red, green, blue;
// Calculo del valor RGB
u16 rgb = 0;
if (zoom_x < 128)
{
// The left part of the screen has bilinear interpolation
// Ventana
s16 x = 0;
s16 y = 0;
s16 composite = 0;
s16 square_x = 0;
s16 square_y = 0;
s16 zoom_x = 0;
s16 zoom_y = 0;
u32 r[4], g[4], b[4];
// Variables del control del touchpad
u16 keys = 0;
touchPosition touchscreen;
// Color matrix:
// 0 1
// 2 3
u32 loops = 0;
// 0: Get color of (X, Y)
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
r[0] = rgb & 0x1F;
g[0] = (rgb >> 5) & 0x1F;
b[0] = (rgb >> 10) & 0x1F;
while (1) {
// 1: Get color of (X + 1, Y)
if (x < 255)
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + (x + 1)];
else
rgb = 0;
// Copia el original
NF_Copy16bitsBuffer(1, 1, 0);
r[1] = rgb & 0x1F;
g[1] = (rgb >> 5) & 0x1F;
b[1] = (rgb >> 10) & 0x1F;
// Lectura de posicion del stylus
scanKeys(); // Lee el touchpad via Libnds
touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen
if (keys & KEY_TOUCH) {
square_x = (touchscreen.px - 64);
square_y = (touchscreen.py - 48);
}
// 2: Get color of (X, Y + 1)
if (y < 191)
rgb = NF_16BITS_BACKBUFFER[1][((y + 1) << 8) + x];
else
rgb = 0;
// Calcula la ventana
if (square_x < 0) square_x = 0;
if (square_x > 127) square_x = 127;
if (square_y < 0) square_y = 0;
if (square_y > 95) square_y = 95;
r[2] = rgb & 0x1F;
g[2] = (rgb >> 5) & 0x1F;
b[2] = (rgb >> 10) & 0x1F;
// Resetea el control de zoom
zoom_x = 0;
zoom_y = 0;
// 3: Get color of (X + 1, Y + 1)
if ((x < 255) && (y < 191))
rgb = NF_16BITS_BACKBUFFER[1][((y + 1) << 8) + (x + 1)];
else
rgb = 0;
// Rellena el buffer
for (y = square_y; y < (square_y + 96); y ++) {
for (x = square_x; x < (square_x + 128); x ++) {
r[3] = rgb & 0x1F;
g[3] = (rgb >> 5) & 0x1F;
b[3] = (rgb >> 10) & 0x1F;
// La parte de la izquierda tiene interpolacion bilinear
if (zoom_x < 128) {
// Draw the vertical line that splits both halves
if (zoom_x == 126)
{
for (int i = 0; i < 4; i ++)
{
r[i] = 5;
g[i] = 10;
b[i] = 15;
}
}
// Matriz de colores
// 0 1
// 2 3
// Calculate value of (X, Y)
rgb = r[0] | (g[0] << 5) | (b[0] << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + zoom_x] = rgb;
// Obten el color actual (0)
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
r[0] = (rgb & 0x1F);
g[0] = ((rgb >> 5) & 0x1F);
b[0] = ((rgb >> 10) & 0x1F);
// Calculate value of (X + 1, Y)
red = (r[0] + r[1]) >> 1;
green = (g[0] + g[1]) >> 1;
blue = (b[0] + b[1]) >> 1;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb;
// Obten el color del pixel X + 1 (1)
if (x < 255) {
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + (x + 1))];
} else {
rgb = 0;
}
r[1] = (rgb & 0x1F);
g[1] = ((rgb >> 5) & 0x1F);
b[1] = ((rgb >> 10) & 0x1F);
// Calculate value of (X, Y + 1)
red = (r[0] + r[2]) >> 1;
green = (g[0] + g[2]) >> 1;
blue = (b[0] + b[2]) >> 1;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb;
// Obten el color del pixel Y + 1 (2)
if (y < 191) {
rgb = NF_16BITS_BACKBUFFER[1][(((y + 1) << 8) + x)];
} else {
rgb = 0;
}
r[2] = (rgb & 0x1F);
g[2] = ((rgb >> 5) & 0x1F);
b[2] = ((rgb >> 10) & 0x1F);
// Calculate value of (X + 1, Y + 1)
red = ((r[0] + r[3]) >> 1);
green = ((g[0] + g[3]) >> 1);
blue = ((b[0] + b[3]) >> 1);
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb;
}
else
{
// The right half of the screen uses the nearest pixel
// Obten el color del pixel XY + 1 (3)
if ((x < 255) && (y < 191)) {
rgb = NF_16BITS_BACKBUFFER[1][(((y + 1) << 8) + (x + 1))];
} else {
rgb = 0;
}
r[3] = (rgb & 0x1F);
g[3] = ((rgb >> 5) & 0x1F);
b[3] = ((rgb >> 10) & 0x1F);
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
// Dibuja la linea divisoria
if (zoom_x == 126) {
for (loops = 0; loops < 4; loops ++) {
r[loops] = 5;
g[loops] = 10;
b[loops] = 15;
}
}
// Write pixels in the backbuffer of the top screen.
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + zoom_x] = rgb;
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb;
}
// Calcula el valor del ZOOM XY
rgb = ((r[0])|((g[0]) << 5)|((b[0]) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb;
// Get RGB components
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
red = rgb & 0x1F;
green = (rgb >> 5) & 0x1F;
blue = (rgb >> 10) & 0x1F;
// Calcula el pixel del ZOOM X + 1
red = ((r[0] + r[1]) >> 1);
green = ((g[0] + g[1]) >> 1);
blue = ((b[0] + b[1]) >> 1);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb;
// Generate a grayscale value based on the RGB components
u32 composite = ((red + green + blue) / 3) + 3;
if (composite > 31)
composite = 31;
// Calcula el pixel ZOOM Y + 1
red = ((r[0] + r[2]) >> 1);
green = ((g[0] + g[2]) >> 1);
blue = ((b[0] + b[2]) >> 1);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb;
// Replace the RGB values by the grayscale value (this shows up
// as a rectangular window on the screen)
red = composite >> 1;
green = composite >> 2;
blue = composite;
// Calcula el pixel ZOOM XY + 1
red = ((r[0] + r[3]) >> 1);
green = ((g[0] + g[3]) >> 1);
blue = ((b[0] + b[3]) >> 1);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb;
// Pack the components as a RGB value
rgb = red | (green << 5) | (blue << 10) | BIT(15);
} else {
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
// La parte de la derecha usa pixel doubling
// Increment X coordinate pointer
zoom_x += 2;
}
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
// Escribe los pixeles en el Backbuffer de la pantalla superior
// Esto genera el Zoom x2 en la pantalla superior
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb;
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb;
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb;
// Set X coordinate from the beginning
zoom_x = 0;
// Increment Y coordinate pointer
zoom_y += 2;
}
}
// Wait for the screen refresh
swiWaitForVBlank();
// Desglosa el RGB
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
red = (rgb & 0x1F);
green = ((rgb >> 5) & 0x1F);
blue = ((rgb >> 10) & 0x1F);
// Genera el equivalente a blanco y negro y sube el brillo 3 puntos
composite = ((int)((red + green + blue) / 3) + 3);
if (composite > 31) composite = 31;
// Reemplaza los valores RGB (efecto marco)
red = (composite >> 1);
green = (composite >> 2);
blue = (composite);
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
// Escribelos en el buffer
NF_16BITS_BACKBUFFER[1][((y << 8) + x)] = rgb;
// Incrementa dos puntos la X del zoom
zoom_x += 2;
}
zoom_x = 0; // Resetea la X del zoom
zoom_y += 2; // Incrementa dos puntos la Y del zoom
}
// Sincronismo Vertical
swiWaitForVBlank();
// Copia el contenido del Backbuffer a la VRAM
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
// Swap backbuffers and visible buffers
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
}

View File

@ -1,334 +1,289 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of applying a x3 zoom with interpolation to a 16 bit image.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
Zoom x3 con filtro por interpolacion
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 <string.h>
#include <unistd.h>
#include <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize storage buffers
NF_Init16bitsBgBuffers();
int main(int argc, char **argv) {
// Initialize backbuffers
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Enable backbuffers
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Load bitmap files from NitroFS
NF_Load16bitsBg("bmp/img16_c", 0);
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5);
// Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa los fondos en modo "BITMAP"
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Window location
s16 square_x = 0;
s16 square_y = 0;
// Inicializa los buffers para guardar fondos en formato BITMAP
NF_Init16bitsBgBuffers();
while (1)
{
// Copy original image
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa el BackBuffer de 16 bits
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Read keys and touchscreen
scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen);
u16 keys = keysHeld();
if (keys & KEY_TOUCH)
{
square_x = touchscreen.px - 42;
square_y = touchscreen.py - 32;
}
// Habilita el backbuffer en la pantalla superior
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Restrict coordinates of the window
if (square_x < 0)
square_x = 0;
if (square_x > 170)
square_x = 170;
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
NF_Load16bitsBg("bmp/img16_c", 0);
if (square_y < 0)
square_y = 0;
if (square_y > 128)
square_y = 128;
// Tranfiere la imagen al BackBuffer de la pantalla inferior
NF_Copy16bitsBuffer(1, 1, 0);
// Zoom read coordinate pointers
int zoom_x = 0;
int zoom_y = 0;
// Variables RGB
u8 r[5];
u8 g[5];
u8 b[5];
u8 red = 0;
u8 green = 0;
u8 blue = 0;
// Fill buffer
for (int y = square_y; y < (square_y + 64); y ++)
{
for (int x = square_x; x < (square_x + 85); x ++)
{
u32 rgb;
u32 red, green, blue;
// Calculo del valor RGB
u16 rgb = 0;
if (zoom_x < 128)
{
// The left part of the screen has bilinear interpolation
// Ventana
s16 x = 0;
s16 y = 0;
s16 composite = 0;
s16 square_x = 0;
s16 square_y = 0;
s16 zoom_x = 0;
s16 zoom_y = 0;
u32 r[5], g[5], b[5];
// Variables del control del touchpad
u16 keys = 0;
touchPosition touchscreen;
// Pixel matrix:
// 01 A1 A2 02
// B1 C1 D1
// B2 D2 C2
// 03 04
u32 loops = 0;
// Calculations:
// A1 = (1 + 1 + 2) / 3
// A2 = (1 + 2 + 2) / 3
// B1 = (1 + 1 + 3) / 3
// B2 = (1 + 3 + 3) / 3
// C1 = (1 + 1 + 4) / 3
// C2 = (1 + 4 + 4) / 3
// D1 = (2 + 2 + 3) / 3
// D2 = (2 + 3 + 3) / 3
while (1) {
// 01: Get color of (X, Y)
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
r[1] = rgb & 0x1F;
g[1] = (rgb >> 5) & 0x1F;
b[1] = (rgb >> 10) & 0x1F;
// Copia el original
NF_Copy16bitsBuffer(1, 1, 0);
// 02: Get color of (X + 1, Y)
if (x < 255)
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + (x + 1)];
else
rgb = 0;
// Lectura de posicion del stylus
scanKeys(); // Lee el touchpad via Libnds
touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen
if (keys & KEY_TOUCH) {
square_x = (touchscreen.px - 42);
square_y = (touchscreen.py - 32);
}
r[2] = rgb & 0x1F;
g[2] = (rgb >> 5) & 0x1F;
b[2] = (rgb >> 10) & 0x1F;
// Calcula la ventana
if (square_x < 0) square_x = 0;
if (square_x > 170) square_x = 170;
if (square_y < 0) square_y = 0;
if (square_y > 128) square_y = 128;
// 03: Get color of (X, Y + 1)
if (y < 191)
rgb = NF_16BITS_BACKBUFFER[1][((y + 1) << 8) + x];
else
rgb = 0;
// Resetea el control de zoom
zoom_x = 0;
zoom_y = 0;
r[3] = rgb & 0x1F;
g[3] = (rgb >> 5) & 0x1F;
b[3] = (rgb >> 10) & 0x1F;
// Rellena el buffer
for (y = square_y; y < (square_y + 64); y ++) {
for (x = square_x; x < (square_x + 85); x ++) {
// 04: Get color of (X + 1, Y + 1)
if ((x < 255) && (y < 191))
rgb = NF_16BITS_BACKBUFFER[1][((y + 1) << 8) + (x + 1)];
else
rgb = 0;
// La parte de la izquierda tiene interpolacion bilinear
if (zoom_x < 128) {
r[4] = rgb & 0x1F;
g[4] = (rgb >> 5) & 0x1F;
b[4] = (rgb >> 10) & 0x1F;
// Matriz de pixeles
// 01 A1 A2 02
// B1 C1 D1
// B2 D2 C2
// 03 04
// Draw the vertical line that splits both halves
if (zoom_x == 126)
{
for (int i = 1; i < 5; i ++)
{
r[i] = 5;
g[i] = 10;
b[i] = 15;
}
}
// Calculos
// A1 = (1+1+2)/3
// A2 = (1+2+2)/3
// B1 = (1+1+3)/3
// B2 = (1+3+3)/3
// C1 = (1+1+4)/3
// C2 = (1+4+4)/3
// D1 = (2+2+3)/3
// D2 = (2+3+3)/3
// Calculate value of pixel 01
rgb = r[1] | (g[1] << 5) | (b[1] << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb;
// Obten el color actual XY (01)
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
r[1] = (rgb & 0x1F);
g[1] = ((rgb >> 5) & 0x1F);
b[1] = ((rgb >> 10) & 0x1F);
// Calculate value of pixel A1
red = (r[1] + r[1] + r[2]) / 3;
green = (g[1] + g[1] + g[2]) / 3;
blue = (b[1] + b[1] + b[2]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb;
// Obten el color del pixel X + 1 (02)
if (x < 255) {
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + (x + 1))];
} else {
rgb = 0;
}
r[2] = (rgb & 0x1F);
g[2] = ((rgb >> 5) & 0x1F);
b[2] = ((rgb >> 10) & 0x1F);
// Calculate value of pixel A2
red = (r[1] + r[2] + r[2]) / 3;
green = (g[1] + g[2] + g[2]) / 3;
blue = (b[1] + b[2] + b[2]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 2)] = rgb;
// Obten el color del pixel Y + 1 (03)
if (y < 191) {
rgb = NF_16BITS_BACKBUFFER[1][(((y + 1) << 8) + x)];
} else {
rgb = 0;
}
r[3] = (rgb & 0x1F);
g[3] = ((rgb >> 5) & 0x1F);
b[3] = ((rgb >> 10) & 0x1F);
// Calculate value of pixel B1
red = (r[1] + r[1] + r[3]) / 3;
green = (g[1] + g[1] + g[3]) / 3;
blue = (b[1] + b[1] + b[3]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb;
// Obten el color del pixel XY + 1 (04)
if ((x < 255) && (y < 191)) {
rgb = NF_16BITS_BACKBUFFER[1][(((y + 1) << 8) + (x + 1))];
} else {
rgb = 0;
}
r[4] = (rgb & 0x1F);
g[4] = ((rgb >> 5) & 0x1F);
b[4] = ((rgb >> 10) & 0x1F);
// Calculate value of pixel B2
red = (r[1] + r[3] + r[3]) / 3;
green = (g[1] + g[3] + g[3]) / 3;
blue = (b[1] + b[3] + b[3]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + zoom_x] = rgb;
// Dibuja la linea divisoria
if (zoom_x == 126) {
for (loops = 1; loops < 5; loops ++) {
r[loops] = 5;
g[loops] = 10;
b[loops] = 15;
}
}
// Calculate value of pixel C1
red = (r[1] + r[1] + r[4]) / 3;
green = (g[1] + g[1] + g[4]) / 3;
blue = (b[1] + b[1] + b[4]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb;
// Calcula el valor del pixel 01
rgb = ((r[1])|((g[1]) << 5)|((b[1]) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb;
// Calculate value of pixel C2
red = (r[1] + r[4] + r[4]) / 3;
green = (g[1] + g[4] + g[4]) / 3;
blue = (b[1] + b[4] + b[4]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + (zoom_x + 2)] = rgb;
// Calcula el pixel del pixel A1
red = ((r[1] + r[1] + r[2]) / 3);
green = ((g[1] + g[1] + g[2]) / 3);
blue = ((b[1] + b[1] + b[2]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb;
// Calculate value of pixel D1
red = (r[2] + r[2] + r[3]) / 3;
green = (g[2] + g[2] + g[3]) / 3;
blue = (b[2] + b[2] + b[3]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 2)] = rgb;
// Calcula el pixel del pixel A2
red = ((r[1] + r[2] + r[2]) / 3);
green = ((g[1] + g[2] + g[2]) / 3);
blue = ((b[1] + b[2] + b[2]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 2))] = rgb;
// Calculate value of pixel D2
red = (r[2] + r[3] + r[3]) / 3;
green = (g[2] + g[3] + g[3]) / 3;
blue = (b[2] + b[3] + b[3]) / 3;
rgb = red | (green << 5) | (blue << 10) | BIT(15);
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + (zoom_x + 1)] = rgb;
}
else
{
// The right half of the screen uses the nearest pixel
// Calcula el pixel del pixel B1
red = ((r[1] + r[1] + r[3]) / 3);
green = ((g[1] + g[1] + g[3]) / 3);
blue = ((b[1] + b[1] + b[3]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb;
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
// Calcula el pixel del pixel B2
red = ((r[1] + r[3] + r[3]) / 3);
green = ((g[1] + g[3] + g[3]) / 3);
blue = ((b[1] + b[3] + b[3]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + zoom_x)] = rgb;
// Write pixels in the backbuffer of the top screen.
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + zoom_x] = rgb; // 01
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb; // A1
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 2)] = rgb; // A2
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb; // B1
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + zoom_x] = rgb; // B2
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb; // C1
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + (zoom_x + 2)] = rgb; // C2
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 2)] = rgb; // D1
NF_16BITS_BACKBUFFER[0][((zoom_y + 2) << 8) + (zoom_x + 1)] = rgb; // D2
}
// Calcula el pixel del pixel C1
red = ((r[1] + r[1] + r[4]) / 3);
green = ((g[1] + g[1] + g[4]) / 3);
blue = ((b[1] + b[1] + b[4]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb;
// Get RGB components
rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
red = rgb & 0x1F;
green = (rgb >> 5) & 0x1F;
blue = (rgb >> 10) & 0x1F;
// Calcula el pixel del pixel C2
red = ((r[1] + r[4] + r[4]) / 3);
green = ((g[1] + g[4] + g[4]) / 3);
blue = ((b[1] + b[4] + b[4]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + (zoom_x + 2))] = rgb;
// Generate a grayscale value based on the RGB components
int composite = ((red + green + blue) / 3) + 3;
if (composite > 31)
composite = 31;
// Calcula el pixel del pixel D1
red = ((r[2] + r[2] + r[3]) / 3);
green = ((g[2] + g[2] + g[3]) / 3);
blue = ((b[2] + b[2] + b[3]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 2))] = rgb;
// Replace the RGB values by the grayscale value (this shows up
// as a rectangular window on the screen)
red = composite >> 1;
green = composite >> 2;
blue = composite;
// Calcula el pixel del pixel D2
red = ((r[2] + r[3] + r[3]) / 3);
green = ((g[2] + g[3] + g[3]) / 3);
blue = ((b[2] + b[3] + b[3]) / 3);
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + (zoom_x + 1))] = rgb;
// Pack the components as a RGB value
rgb = red | (green << 5) | (blue << 10) | BIT(15);
} else {
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
// La parte de la derecha tiene usa pixel doubling
// Increment X coordinate pointer
zoom_x += 3;
}
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
// Escribe los pixeles en el Backbuffer de la pantalla superior
// Esto genera el Zoom x2 en la pantalla superior
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb; // 01
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb; // A1
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 2))] = rgb; // A2
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb; // B1
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + zoom_x)] = rgb; // B2
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb; // C1
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + (zoom_x + 2))] = rgb; // C2
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 2))] = rgb; // D1
NF_16BITS_BACKBUFFER[0][(((zoom_y + 2) << 8) + (zoom_x + 1))] = rgb; // D2
// Set X coordinate from the beginning
zoom_x = 0;
// Increment Y coordinate pointer
zoom_y += 3;
}
}
// Wait for the screen refresh
swiWaitForVBlank();
// Desglosa el RGB
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
red = (rgb & 0x1F);
green = ((rgb >> 5) & 0x1F);
blue = ((rgb >> 10) & 0x1F);
// Genera el equivalente a blanco y negro y sube el brillo 3 puntos
composite = ((int)((red + green + blue) / 3) + 3);
if (composite > 31) composite = 31;
// Reemplaza los valores RGB (efecto marco)
red = (composite >> 1);
green = (composite >> 2);
blue = (composite);
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((red)|((green) << 5)|((blue) << 10)|(BIT(15)));
// Escribelos en el buffer
NF_16BITS_BACKBUFFER[1][((y << 8) + x)] = rgb;
// Incrementa dos puntos la X del zoom
zoom_x += 3;
}
zoom_x = 0; // Resetea la X del zoom
zoom_y += 3; // Incrementa dos puntos la Y del zoom
}
// Sincronismo Vertical
swiWaitForVBlank();
// Copia el contenido del Backbuffer a la VRAM
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
// Swap backbuffers and visible buffers
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
}

View File

@ -16,11 +16,13 @@
// fade registers it's possible to add a shading effect.
void hblank_handler(void)
{
u32 vline = REG_VCOUNT; // Get the current line
// If the current line is inside the screen
if (REG_VCOUNT < 192)
if (vline < 192)
{
// Calculate fade value based on the line
int fade = (0x0F - (((REG_VCOUNT + 1) * 16) / 192));
int fade = 0x0F - (((vline + 1) * 16) / 192);
REG_BLDY = fade >> 1; // Top screen
REG_BLDY_SUB = fade; // Bottom screen
@ -81,7 +83,7 @@ int main(int argc, char **argv)
while (1)
{
scanKeys(); // Read keypad
uint16_t keys = keysHeld(); // Keys currently pressed
u16 keys = keysHeld(); // Keys currently pressed
// Move center of the backgrounds
if (keys & KEY_UP)

View File

@ -1,155 +1,130 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2010
//
// Example of 8x16 text with extended palettes
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de texto de 8x16 con paletas extendidas
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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include "nf_lib.h"
#include <nf_lib.h>
// Algunos defines interesantes
#define RED 1
#define GREEN 2
#define BLUE 3
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize text system
NF_InitTextSys(1); // Bottom screen
int main(int argc, char **argv) {
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Load text font files from NitroFS
NF_LoadTextFont16("fnt/font16", "down", 256, 256, 0);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create a text layer
NF_CreateTextLayer16(1, 0, 0, "down");
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Define a few colors for the text font (bottom screen, layer 3)
NF_DefineTextColor(1, 0, 1, 31, 0, 0); // Red
NF_DefineTextColor(1, 0, 2, 0, 31, 0); // Green
NF_DefineTextColor(1, 0, 3, 0, 0, 31); // Blue
// Inicializa el motor de texto (requiere tener los fondos tileados inicializados)
NF_InitTextSys(1); // Inicializa el texto para la pantalla inferior
// Generate a few colors randomly
srand(time(NULL));
for (int n = 4; n < 10; n ++)
{
NF_DefineTextColor(1, 0, n,
(rand() % 31) + 1,
(rand() % 31) + 1,
(rand() % 31) + 1);
}
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla inferior
// Print text with predefined colors
NF_WriteText16(1, 0, 1, 1, "Defecto / Default"); // Text with default color
NF_SetTextColor(1, 0, 1); // Set color for new text
NF_WriteText16(1, 0, 1, 2, "Rojo / Red"); // Print text with the new color
NF_SetTextColor(1, 0, 2);
NF_WriteText16(1, 0, 1, 3, "Verde / Green");
NF_SetTextColor(1, 0, 3);
NF_WriteText16(1, 0, 1, 4, "Azul / Blue");
// Carga la fuente por defecto para el texto
NF_LoadTextFont16("fnt/font16", "down", 256, 256, 0);
// Print text with random colors
for (int n = 4; n < 10; n ++)
{
NF_SetTextColor(1, 0, n);
NF_WriteText16(1, 0, 1, n + 1, "Random Aa 0123456789 Ññ Çç");
}
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Restore default text color
NF_SetTextColor(1, 0, 0);
// Crea una capa de texto
NF_CreateTextLayer16(1, 0, 0, "down");
// Update text layers
NF_UpdateTextLayers();
// Define algunos colores para el texto (pantalla inferior, capa 3)
NF_DefineTextColor(1, 0, 1, 31, 0, 0); // Rojo
NF_DefineTextColor(1, 0, 2, 0, 31, 0); // Verde
NF_DefineTextColor(1, 0, 3, 0, 0, 31); // Azul
// Variables
int speed = 0;
// Ahora algunos colores aleatorios
srand(time(NULL));
u8 n = 0;
for (n = 4; n < 10; n ++) {
NF_DefineTextColor(1, 0, n, ((rand() % 31) + 1), ((rand() % 31) + 1), ((rand() % 31)) + 1);
}
while (1)
{
speed++;
if (speed > 60)
{
speed = 0;
// Texto
NF_WriteText16(1, 0, 1, 1, "Defecto / Default"); // Texto con el color por defecto de la fuente
NF_SetTextColor(1, 0, 1); // Selecciona el color del texto a escribir
NF_WriteText16(1, 0, 1, 2, "Rojo / Red"); // y escribe el texto en ese color
NF_SetTextColor(1, 0, 2);
NF_WriteText16(1, 0, 1, 3, "Verde / Green");
NF_SetTextColor(1, 0, 3);
NF_WriteText16(1, 0, 1, 4, "Azul / Blue");
// Texto con color aleatorio
for (n = 4; n < 10; n ++) {
NF_SetTextColor(1, 0, n);
NF_WriteText16(1, 0, 1, (n + 1), "Random Aa 0123456789 Ññ Çç");
}
NF_SetTextColor(1, 0, 0); // Deja color del texto por defecto (definido en la fuente)
// Generate new colors randomly
for (int n = 4; n < 10; n ++)
{
NF_DefineTextColor(1, 0, n,
(rand() % 31) + 1,
(rand() % 31) + 1,
(rand() % 31) + 1);
}
// Actualiza las capas de texto
NF_UpdateTextLayers();
// Print text with the new random colors
for (int n = 4; n < 10; n ++)
{
NF_SetTextColor(1, 0, n);
NF_WriteText16(1, 0, 1, n + 1, "Random Aa 0123456789 Ññ Çç");
}
// Variables
u8 speed = 0;
// Update text layers
NF_UpdateTextLayers();
}
// Bucle (repite para siempre)
while(1) {
speed ++;
if (speed > 60) {
speed = 0;
// Calcula un nuevo set de paletas
for (n = 4; n < 10; n ++) {
NF_DefineTextColor(1, 0, n, ((rand() % 31) + 1), ((rand() % 31) + 1), ((rand() % 31)) + 1);
}
// Escribe de nuevo el texto con los nuevos colores
for (n = 4; n < 10; n ++) {
NF_SetTextColor(1, 0, n);
NF_WriteText16(1, 0, 1, (n + 1), "Random Aa 0123456789 Ññ Çç");
}
// Actualiza las capas de texto
NF_UpdateTextLayers();
}
swiWaitForVBlank(); // Espera al sincronismo vertical
}
return 0;
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,155 +1,130 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of text with extended palettes
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de texto con paletas extendidas
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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
// Algunos defines interesantes
#define RED 1
#define GREEN 2
#define BLUE 3
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize text system
NF_InitTextSys(1); // Bottom screen
int main(int argc, char **argv) {
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Load text font files from NitroFS
NF_LoadTextFont("fnt/default", "down", 256, 256, 0);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create a text layer
NF_CreateTextLayer(1, 0, 0, "down");
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Define a few colors for the text font (bottom screen, layer 3)
NF_DefineTextColor(1, 0, 1, 31, 0, 0); // Red
NF_DefineTextColor(1, 0, 2, 0, 31, 0); // Green
NF_DefineTextColor(1, 0, 3, 0, 0, 31); // Blue
// Inicializa el motor de texto (requiere tener los fondos tileados inicializados)
NF_InitTextSys(1); // Inicializa el texto para la pantalla inferior
// Generate a few colors randomly
srand(time(NULL));
for (int n = 4; n < 16; n ++)
{
NF_DefineTextColor(1, 0, n,
(rand() % 31) + 1,
(rand() % 31) + 1,
(rand() % 31) + 1);
}
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla inferior
// Print text with predefined colors
NF_WriteText(1, 0, 1, 1, "Defecto / Default"); // Print text with predefined colors
NF_SetTextColor(1, 0, 1); // Set color for new text
NF_WriteText(1, 0, 1, 2, "Rojo / Red"); // Print text with the new color
NF_SetTextColor(1, 0, 2);
NF_WriteText(1, 0, 1, 3, "Verde / Green");
NF_SetTextColor(1, 0, 3);
NF_WriteText(1, 0, 1, 4, "Azul / Blue");
// Carga la fuente por defecto para el texto
NF_LoadTextFont("fnt/default", "down", 256, 256, 0);
// Print text with random colors
for (int n = 4; n < 16; n ++)
{
NF_SetTextColor(1, 0, n);
NF_WriteText(1, 0, 1, n + 1, "Random color");
}
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Restore default text color
NF_SetTextColor(1, 0, 0);
// Crea una capa de texto
NF_CreateTextLayer(1, 0, 0, "down");
// Update text layers
NF_UpdateTextLayers();
// Define algunos colores para el texto (pantalla inferior, capa 3)
NF_DefineTextColor(1, 0, 1, 31, 0, 0); // Rojo
NF_DefineTextColor(1, 0, 2, 0, 31, 0); // Verde
NF_DefineTextColor(1, 0, 3, 0, 0, 31); // Azul
// Variables
int speed = 0;
// Ahora algunos colores aleatorios
srand(time(NULL));
u8 n = 0;
for (n = 4; n < 16; n ++) {
NF_DefineTextColor(1, 0, n, ((rand() % 31) + 1), ((rand() % 31) + 1), ((rand() % 31)) + 1);
}
while (1)
{
speed++;
if (speed > 60)
{
speed = 0;
// Texto
NF_WriteText(1, 0, 1, 1, "Defecto / Default"); // Texto con el color por defecto de la fuente
NF_SetTextColor(1, 0, 1); // Selecciona el color del texto a escribir
NF_WriteText(1, 0, 1, 2, "Rojo / Red"); // y escribe el texto en ese color
NF_SetTextColor(1, 0, 2);
NF_WriteText(1, 0, 1, 3, "Verde / Green");
NF_SetTextColor(1, 0, 3);
NF_WriteText(1, 0, 1, 4, "Azul / Blue");
// Texto con color aleatorio
for (n = 4; n < 16; n ++) {
NF_SetTextColor(1, 0, n);
NF_WriteText(1, 0, 1, (n + 1), "Random color");
}
NF_SetTextColor(1, 0, 0); // Deja color del texto por defecto (definido en la fuente)
// Generate new colors randomly
for (int n = 4; n < 16; n ++)
{
NF_DefineTextColor(1, 0, n,
(rand() % 31) + 1,
(rand() % 31) + 1,
(rand() % 31) + 1);
}
// Actualiza las capas de texto
NF_UpdateTextLayers();
// Print text with the new random colors
for (int n = 4; n < 16; n ++)
{
NF_SetTextColor(1, 0, n);
NF_WriteText(1, 0, 1, n + 1, "Random color");
}
// Variables
u8 speed = 0;
// Update text layers
NF_UpdateTextLayers();
}
// Bucle (repite para siempre)
while(1) {
speed ++;
if (speed > 60) {
speed = 0;
// Calcula un nuevo set de paletas
for (n = 4; n < 16; n ++) {
NF_DefineTextColor(1, 0, n, ((rand() % 31) + 1), ((rand() % 31) + 1), ((rand() % 31)) + 1);
}
// Escribe de nuevo el texto con los nuevos colores
for (n = 4; n < 16; n ++) {
NF_SetTextColor(1, 0, n);
NF_WriteText(1, 0, 1, (n + 1), "Random color");
}
// Actualiza las capas de texto
NF_UpdateTextLayers();
}
swiWaitForVBlank(); // Espera al sincronismo vertical
}
return 0;
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,128 +1,94 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic text example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de texto en pantalla
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 <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize text system
NF_InitTextSys(0); // Top screen
int main(int argc, char **argv) {
// Load background files from NitroFS
NF_LoadTiledBg("bg/layer3", "moon", 256, 256);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Load text font files from NitroFS
NF_LoadTextFont("fnt/default", "normal", 256, 256, 0); // Load normal text
NF_LoadTextFont("fnt/default", "right", 256, 256, 1); // Load rotated text
NF_LoadTextFont("fnt/default", "left", 256, 256, 2); // Load rotated text
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Create top screen background
NF_CreateTiledBg(0, 3, "moon");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create bottom screen background
NF_CreateTiledBg(1, 3, "moon");
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Create text layers
NF_CreateTextLayer(0, 0, 0, "normal");
NF_CreateTextLayer(0, 1, 1, "right");
NF_CreateTextLayer(0, 2, 2, "left");
// Inicializa el motor de texto (requiere tener los fondos tileados inicializados)
NF_InitTextSys(0); // Inicializa el texto para la pantalla superior
// Scroll text background to offset the unused space in the background
// that uses text rotated to the left.
NF_ScrollBg(0, 2, 0, 63);
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/layer3", "moon", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
// Print text in all layers
NF_WriteText(0, 0, 1, 1, "Hola Mundo!\n Hello World!");
NF_WriteText(0, 1, 1, 1, "Hola Mundo!\n Hello World!");
NF_WriteText(0, 2, 1, 1, "Hola Mundo!\n Hello World!");
// Carga la fuente por defecto para el texto
NF_LoadTextFont("fnt/default", "normal", 256, 256, 0); // Carga la seccion "normal" de la fuente, tamaño del mapa 256x256
NF_LoadTextFont("fnt/default", "right", 256, 256, 1); // Carga la seccion "rotar derecha" de la fuente, tamaño del mapa 256x256
NF_LoadTextFont("fnt/default", "left", 256, 256, 2); // Carga la seccion "rotar izquierda· de la fuente, tamaño del mapa 256x256
// Update text layers
NF_UpdateTextLayers();
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "moon");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "moon");
// Variables
u32 myvar = 0;
// Crea una capa de texto
NF_CreateTextLayer(0, 0, 0, "normal");
NF_CreateTextLayer(0, 1, 1, "right");
NF_CreateTextLayer(0, 2, 2, "left");
while (1)
{
myvar++;
// Compensa el espacio "muerto" de la pantalla al rotar el texto a la izquierda
// Desplazandolo 64 pixeles en vertical
NF_ScrollBg(0, 2, 0, 63);
char mytext[32];
snprintf(mytext, sizeof(mytext), "Contador: %lu", myvar);
// Escribe un texto en cada capa de texto
NF_WriteText(0, 0, 1, 1, "Hola Mundo!\n Hello World!"); // Normal
NF_WriteText(0, 1, 1, 1, "Hola Mundo!\n Hello World!"); // Rotado derecha
NF_WriteText(0, 2, 1, 1, "Hola Mundo!\n Hello World!"); // Rotado izquierda
NF_WriteText(0, 0, 1, 5, mytext);
NF_WriteText(0, 1, 1, 5, mytext);
NF_WriteText(0, 2, 1, 5, mytext);
// Actualiza las capas de texto
NF_UpdateTextLayers();
// Update text layers
NF_UpdateTextLayers();
// Variables
char mytext[32];
u32 myvar = 0;
// Bucle (repite para siempre)
while(1) {
myvar ++;
snprintf(mytext, sizeof(mytext), "Contador: %lu", myvar);
NF_WriteText(0, 0, 1, 5, mytext);
NF_WriteText(0, 1, 1, 5, mytext);
NF_WriteText(0, 2, 1, 5, mytext);
NF_UpdateTextLayers(); // Actualiza las capas de texto
swiWaitForVBlank(); // Espera al sincronismo vertical
}
return 0;
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,128 +1,94 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic 8x16 text example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de texto 8x16 en pantalla
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 <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize text system
NF_InitTextSys(0); // Top screen
int main(int argc, char **argv) {
// Load background files from NitroFS
NF_LoadTiledBg("bg/layer3", "moon", 256, 256);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Load text font files from NitroFS
NF_LoadTextFont16("fnt/font16", "normal", 256, 256, 0); // Load normal text
NF_LoadTextFont16("fnt/font16", "right", 256, 256, 1); // Load rotated text
NF_LoadTextFont16("fnt/font16", "left", 256, 256, 2); // Load rotated text
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Create top screen background
NF_CreateTiledBg(0, 3, "moon");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create bottom screen background
NF_CreateTiledBg(1, 3, "moon");
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Create a text layer
NF_CreateTextLayer16(0, 0, 0, "normal");
NF_CreateTextLayer16(1, 1, 1, "right");
NF_CreateTextLayer16(1, 2, 2, "left");
// Inicializa el motor de texto (requiere tener los fondos tileados inicializados)
NF_InitTextSys(0); // Inicializa el texto para la pantalla superior
// Scroll text background to offset the unused space in the background
// that uses text rotated to the left.
NF_ScrollBg(1, 2, 0, 63);
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/layer3", "moon", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
// Print text in all layers
NF_WriteText16(0, 0, 1, 1, "Hola Mundo!\n Hello World!");
NF_WriteText16(1, 1, 1, 1, "Hola Mundo!\n Hello World!");
NF_WriteText16(1, 2, 1, 1, "Hola Mundo!\n Hello World!");
// Carga la fuente por defecto para el texto
NF_LoadTextFont16("fnt/font16", "normal", 256, 256, 0); // Carga la seccion "normal" de la fuente, tamaño del mapa 256x256
NF_LoadTextFont16("fnt/font16", "right", 256, 256, 1); // Carga la seccion "rotar derecha" de la fuente, tamaño del mapa 256x256
NF_LoadTextFont16("fnt/font16", "left", 256, 256, 2); // Carga la seccion "rotar izquierda· de la fuente, tamaño del mapa 256x256
// Update text layers
NF_UpdateTextLayers();
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "moon");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "moon");
// Variables
u32 myvar = 0;
// Crea una capa de texto
NF_CreateTextLayer16(0, 0, 0, "normal");
NF_CreateTextLayer16(1, 1, 1, "right");
NF_CreateTextLayer16(1, 2, 2, "left");
while (1)
{
myvar++;
// Compensa el espacio "muerto" de la pantalla al rotar el texto a la izquierda
// Desplazandolo 64 pixeles en vertical
NF_ScrollBg(1, 2, 0, 63);
char mytext[32];
snprintf(mytext, sizeof(mytext), "Contador: %lu", myvar);
// Escribe un texto en cada capa de texto
NF_WriteText16(0, 0, 1, 1, "Hola Mundo!\n Hello World!"); // Normal
NF_WriteText16(1, 1, 1, 1, "Hola Mundo!\n Hello World!"); // Rotado derecha
NF_WriteText16(1, 2, 1, 1, "Hola Mundo!\n Hello World!"); // Rotado izquierda
NF_WriteText16(0, 0, 1, 4, mytext);
NF_WriteText16(1, 1, 1, 4, mytext);
NF_WriteText16(1, 2, 1, 4, mytext);
// Actualiza las capas de texto
NF_UpdateTextLayers();
// Update text layers
NF_UpdateTextLayers();
// Variables
char mytext[32];
u32 myvar = 0;
// Bucle (repite para siempre)
while(1) {
myvar ++;
snprintf(mytext, sizeof(mytext), "Contador: %lu", myvar);
NF_WriteText16(0, 0, 1, 4, mytext);
NF_WriteText16(1, 1, 1, 4, mytext);
NF_WriteText16(1, 2, 1, 4, mytext);
NF_UpdateTextLayers(); // Actualiza las capas de texto
swiWaitForVBlank(); // Espera al sincronismo vertical
}
return 0;
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,162 +1,141 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic example of text with scroll.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de texto con scroll
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 <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize text system
NF_InitTextSys(0); // Top screen
NF_InitTextSys(1); // Bottom screen
int main(int argc, char **argv) {
// Load background files from NitroFS
NF_LoadTiledBg("bg/layer3", "moon", 256, 256);
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Load text font files from NitroFS
NF_LoadTextFont("fnt/default", "up", 256, 768, 0); // Normal text
NF_LoadTextFont("fnt/default", "down", 768, 256, 2); // Text rotated 180 degrees
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Create top screen background
NF_CreateTiledBg(0, 3, "moon");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create bottom screen background
NF_CreateTiledBg(1, 3, "moon");
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Create text layers
NF_CreateTextLayer(0, 0, 0, "up");
NF_CreateTextLayer(1, 0, 2, "down");
// Inicializa el motor de texto (requiere tener los fondos tileados inicializados)
NF_InitTextSys(0); // Inicializa el texto para la pantalla superior
NF_InitTextSys(1); // Inicializa el texto para la pantalla inferior
// Variables
char mytext[32];
s16 x = 0;
s16 y = 0;
s16 contador = 0;
s8 delay = 0;
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/layer3", "moon", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
// Print 96 text lines
for (int n = 0; n < 96; n ++)
{
sprintf(mytext," Linea: %02d", n);
NF_WriteText(0, 0, 0, n, mytext);
NF_WriteText(1, 0, 0, n, mytext);
}
// Carga la fuente por defecto para el texto
NF_LoadTextFont("fnt/default", "up", 256, 768, 0); // Carga la seccion "normal" de la fuente, tamaño del mapa 256x256
NF_LoadTextFont("fnt/default", "down", 768, 256, 2); // Carga la seccion "normal" de la fuente, tamaño del mapa 256x256
// Update text layers
NF_UpdateTextLayers();
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "moon");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "moon");
while (1)
{
delay ++;
if (delay > 10) {
// Crea una capa de texto
NF_CreateTextLayer(0, 0, 0, "up");
NF_CreateTextLayer(1, 0, 2, "down");
delay = 0;
// Variables
u16 n = 0;
char mytext[32];
u16 keys;
s16 x = 0;
s16 y = 0;
s16 contador = 0;
s8 delay = 0;
// Print 96 text lines
for (int n = 0; n < 96; n ++)
{
sprintf(mytext,"%04d", contador);
NF_WriteText(0, 0, 26, n, mytext);
NF_WriteText(1, 0, 18, n, mytext);
// Escribe 96 lineas de texto
for (n = 0; n < 96; n ++) {
sprintf(mytext," Linea: %02d", n);
NF_WriteText(0, 0, 0, n, mytext);
NF_WriteText(1, 0, 0, n, mytext);
}
contador++;
if (contador > 9999)
contador = 0;
}
// Actualiza las capas de texto
NF_UpdateTextLayers();
// Update text layers
NF_UpdateTextLayers();
}
// Bucle (repite para siempre)
while(1) {
scanKeys(); // Read keypad
u16 keys = keysHeld(); // Keys currently pressed
delay ++;
if (delay > 10) {
// Scroll top screen text
if (keys & KEY_UP)
{
y -= 2;
if (y < 0)
y = 0;
}
if (keys & KEY_DOWN)
{
y += 2;
if (y > 575)
y = 575;
}
delay = 0;
// Scroll bottom screen text
if (keys & KEY_LEFT)
{
x -= 2;
if (x < 0)
x = 0;
}
if (keys & KEY_RIGHT)
{
x += 2;
if (x > 511)
x = 511;
}
// Escribe 96 lineas de texto
for (n = 0; n < 96; n ++) {
sprintf(mytext,"%04d", contador);
NF_WriteText(0, 0, 26, n, mytext);
NF_WriteText(1, 0, 18, n, mytext);
contador ++;
if (contador > 9999) contador = 0;
}
// Wait for the screen refresh
swiWaitForVBlank();
// Actualiza las capas de texto
NF_UpdateTextLayers();
}
// Lee el teclado
scanKeys();
keys = keysHeld();
// Scroll del texto pantalla superior
if (keys & KEY_UP) y -= 2;
if (keys & KEY_DOWN) y += 2;
if (y < 0) y = 0;
if (y > 575) y = 575;
// Scroll del texto de la pantalla inferior
if (keys & KEY_LEFT) x -= 2;
if (keys & KEY_RIGHT) x += 2;
if (x < 0) x = 0;
if (x > 511) x = 511;
swiWaitForVBlank(); // Espera al sincronismo vertical
// Mueve la capa de texto
NF_ScrollBg(0, 0, 0, y);
NF_ScrollBg(1, 0, x, 63);
}
return 0;
// Scroll text layer
NF_ScrollBg(0, 0, 0, y);
NF_ScrollBg(1, 0, x, 63);
}
return 0;
}