nitro-engine/examples/other/error_handling/source/main.c
Antonio Niño Díaz 1acfca1a24 examples: Wait for VBL in the right place
This change is a bit pedantic, but it makes the ROMs run better in
DeSmuMe.

Some examples (particularly the dual 3D examples) used to flicker during
one or two seconds right after starting. In dual 3D examples the top and
bottom screen would start swapped, and they would eventually swap and
stop flickering. This would never happen in melonDS or real hardware.

I suspect this is because of the interaction between GFX_FLUSH and
swiWaitForVBlank(), where there would be some timing difference to reach
the first swiWaitForVBlank() or GFX_FLUSH, and that caused the desync.

This commit moves swiWaitForVBlank() to the beginning of the game loop.
This means that, even in the first iteration of the game loop, all
emulators and hardware will be synchronized. This doesn't actually
matter in any other situation, it just makes the first iteration
consistent.
2023-01-21 19:32:02 +00:00

56 lines
1.3 KiB
C

// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
//
// This file is part of Nitro Engine
#include <NEMain.h>
// Don't forget to compile Nitro Engine with NE_DEBUG defined or this won't work
void Draw3DScene(void)
{
// Let's generate some error messages...
NE_LightOff(100);
NE_CameraSetI(NULL,
1, 1, 1,
1, 1, 1,
1, 1, 1);
NE_PolyFormat(100, 120, 0, 0, 0);
}
void error_handler(const char * text)
{
// Simple handler. You could write this to a file instead, for example.
printf(text);
}
int main(void)
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
// libnds uses VRAM_C for the text console, reserve A and B only
NE_TextureSystemReset(0, 0, NE_VRAM_AB);
// Init console in non-3D screen
consoleDemoInit();
// Set a custom error handler
NE_DebugSetHandler(error_handler);
// In order to use the default handler again it is needed to call
// NE_DebugSetHandlerConsole(). After that, all messages will be printed
// to the default console
while (1)
{
NE_WaitForVBL(0);
NE_Process(Draw3DScene);
}
return 0;
}