(c):
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
// git outputs a nice header to reference data
#include "drunkenlogo.h"
//---------------------------------------------------------------------------------
int getSize(uint8 *source, uint16 *dest, uint32 arg)
{
return *(uint32*)source;
}
uint8 readByte(uint8 *source)
{
return *source;
}
TDecompressionStream drunkenlogo_decomp =
{
getSize,
NULL,
readByte
};
//---------------------------------------------------------------------------------
u32 volatile tick = 0;
//---------------------------------------------------------------------------------
void HBLFunction(void)
{
tick++;
}
//---------------------------------------------------------------------------------
void BlackAndWhite(u32 *src, u32 *dst, u32 size)
{
for (int I=size; I >= 0; I--)
{
*(dst++) = ((((*src & 0x1F001F) + ((*src & 0x3E003E0) >> 4) + ((*(src++) & 0x7C007C00) >> 10)) >> 2) & 0x1F001F) * 1057 | 0x80008000;
}
}
//---------------------------------------------------------------------------------
void BlackAndWhite8(u32 *src, u16 *dst, u32 size)
{
for (int I=size; I >= 0; I--)
{
u32 grey = (((*src & 0x1F001F) + ((*src & 0x3E003E0) >> 4) + ((*(src++) & 0x7C007C00) >> 10)) >> 2);
*(dst++) = (grey & 0x1F) | ((grey & 0x001F0000) >> 8);
}
}
//---------------------------------------------------------------------------------
int main(void)
{
// irqs are nice
irqInit();
irqEnable(IRQ_VBLANK);
irqEnable(IRQ_HBLANK);
irqSet(IRQ_HBLANK, HBLFunction);
// set the mode for 2 text layers and two extended background layers
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
// set the sub background up for text display (we could just print to one
// of the main display text backgrounds just as easily
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
// set the first bank as background memory and the third as sub background memory
// B and D are not used (if you want a bitmap greater than 256x256 you will need more
// memory so another vram bank must be used and mapped consecutivly
vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG, VRAM_D_LCD);
// set up text background for text
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31, 31, 31);//by default font will be rendered with color 255
//consoleInit() is a lot more flexible but this gets you up and running quick
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
// set up our bitmap background
BG3_CR = BG_BMP16_256x256;
// these are rotation backgrounds so you must set the rotation attributes:
// these are fixed point numbers with the low 8 bits the fractional part
// this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 0;
BG3_CY = 0;
// set up our bitmap background
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(8);
// these are rotation backgrounds so you must set the rotation attributes:
// these are fixed point numbers with the low 8 bits the fractional part
// this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
BG2_XDX = 1 << 8;
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = 1 << 8;
BG2_CX = 0;
BG2_CY = 0;
for (int I = 0; I < 32; I++)
{
BG_PALETTE[I] = I * 1057;
}
BLEND_CR = BLEND_SRC_BG2 | BLEND_DST_BG3 | BLEND_ALPHA;
BLEND_AB = 16 * 256 + 0;
u32 *buffer = malloc(256 * 192 * 2);
u16 *buffer8 = malloc(256 * 192);
u32 localTick;
==> Ici il ne voit pas localTick, ni buffer, ni buffer8
printf("BlackAndWhite8:\n\n");
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
BlackAndWhite8(BG_BMP_RAM(0), BG_BMP_RAM(8), 256 * 192 / 2);
localTick = tick - localTick;
printf("VRAM: %d FPS\n", 192 * 60 / localTick);
localTick = tick;
dmaCopyWords(0, BG_BMP_RAM(0), buffer, 256 * 192 * 2);
BlackAndWhite8(buffer, buffer8, 256 * 192 / 2);
DC_FlushAll();
dmaCopyWords(0, buffer8, BG_BMP_RAM(8), 256 * 192);
localTick = tick - localTick;
printf("MRAM: %d FPS\n", 192 * 60 / localTick);
printf("\nAsmBlackAndWhite8:\n\n");
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
AsmBlackAndWhite8(BG_BMP_RAM(0), BG_BMP_RAM(8), 256 * 192 / 2);
localTick = tick - localTick;
printf("VRAM: %d FPS\n", 192 * 60 / localTick);
localTick = tick;
dmaCopyWordsAsynch(0, BG_BMP_RAM(0), buffer, 256 * 192 * 2);
AsmBlackAndWhite8(buffer, buffer8, 256 * 192 / 2);
DC_FlushAll();
dmaCopyWordsAsynch(0, buffer8, BG_BMP_RAM(8), 256 * 192);
localTick = tick - localTick;
printf("MRAM: %d FPS\n", 192 * 60 / localTick);
printf("\nBlackAndWhite:\n\n");
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
BlackAndWhite(BG_BMP_RAM(0), BG_BMP_RAM(0), 256 * 192 / 2);
localTick = tick - localTick;
printf("VRAM: %d FPS\n", 192 * 60 / localTick);
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
dmaCopyWordsAsynch(0, BG_BMP_RAM(0), buffer, 256 * 192 * 2);
BlackAndWhite(buffer, buffer, 256 * 192 / 2);
DC_FlushAll();
dmaCopyWordsAsynch(0, buffer, BG_BMP_RAM(0), 256 * 192 * 2);
localTick = tick - localTick;
printf("MRAM: %d FPS\n", 192 * 60 / localTick);
printf("\nAsmBlackAndWhite:\n\n");
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
AsmBlackAndWhite(BG_BMP_RAM(0), BG_BMP_RAM(0), 256 * 192 / 2);
localTick = tick - localTick;
printf("VRAM: %d FPS\n", 192 * 60 / localTick);
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
localTick = tick;
dmaCopyWordsAsynch(0, BG_BMP_RAM(0), buffer, 256 * 192 * 2);
AsmBlackAndWhite(buffer, buffer, 256 * 192 / 2);
DC_FlushAll();
dmaCopyWordsAsynch(0, buffer, BG_BMP_RAM(0), 256 * 192 * 2);
localTick = tick - localTick;
printf("MRAM: %d FPS\n", 192 * 60 / localTick);
swiDecompressLZSSVram((void*)drunkenlogoBitmap, BG_BMP_RAM(0), 0, &drunkenlogo_decomp);
printf("\nAppuyer sur A", 192 * 60 / localTick);
while (1)
{
do
{
swiWaitForVBlank();
scanKeys();
}
while (!(keysDown() & KEY_A) && !(keysDown() & KEY_TOUCH));
for (int I = 0; I <= 16; I++)
{
swiWaitForVBlank();
swiWaitForVBlank();
BLEND_AB = (16 - I) * 256 + I;
}
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
BLEND_CR = BLEND_SRC_BG2 | BLEND_FADE_BLACK;
for (int I = 0; I <= 16; I++)
{
swiWaitForVBlank();
swiWaitForVBlank();
BLEND_Y = I;
}
do
{
swiWaitForVBlank();
scanKeys();
}
while (!(keysDown() & KEY_A) && !(keysDown() & KEY_TOUCH));
for (int I = 16; I >= 0; I--)
{
swiWaitForVBlank();
swiWaitForVBlank();
BLEND_Y = I;
}
BLEND_CR = BLEND_SRC_BG2 | BLEND_DST_BG3 | BLEND_ALPHA;
BLEND_AB = 0 * 256 + 16;
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
for (int I = 16; I >= 0; I--)
{
swiWaitForVBlank();
swiWaitForVBlank();
BLEND_AB = (16 - I) * 256 + I;
}
}
return 0;
}