#include <revolution/os.h>
void ASSERT(int expression);
|
Conditional expression used for checking if the _DEBUG macro is defined. |
None.
When the _DEBUG macro is defined, the ASSERT function displays a failure message if expression is FALSE. The message that contains the text of expression appears in the output port, and the console is halted.
If the _DEBUG macro is not defined, ASSERT does nothing.
Tips: By default, the output of the assertion failure message goes to the serial port of the development hardware. In the final phase of game development, output to the TV screen rather than the serial port may be more desirable. When an assertion fails, the OSPanic function shown below in os[D].a is called.
|
Since it is difficult to implement standard output function for the TV screen due to the various graphics configurations, it is acceptable to implement the game-specific version of OSPanic and to replace the one in os[D].a. Because the OSPanic function is weakly defined in os[D].a, the game-specific OSPanic function takes precedence over the default OSPanic in os[D].a.
The following code is an implementation example of the OSPanic function that shows the assertion failure message on a TV screen using the OSFatal function.
char Message[2048]; // Panic message buffer
void OSPanic(const char* file, int line, const char* msg, ...)
{
va_list marker;
u32 i;
u32* p;
int len;
GXColor bg = { 0, 0, 255, 0 };
GXColor fg = { 255, 255, 255, 0 };
va_start(marker, msg);
len = vsprintf(Message, msg, marker);
va_end(marker);
len += sprintf(Message + len, " in \"%s\" on line %d.\n", file, line);
// Stack crawl
len += sprintf(Message + len, "\nAddress: Back Chain LR Save\n");
for (i = 0, p = (u32*) OSGetStackPointer(); // get current sp
p && (u32) p != 0xffffffff && i++ < 16;
p = (u32*) *p) // get caller sp
{
len += sprintf(Message + len, "0x%08x: 0x%08x 0x%08x\n", p, p[0], p[1]);
}
OSFatal(fg, bg, Message);
// NOT REACHED HERE
}
|
Error Functions, ASSERTMSG, OSHalt,OSReport
03/01/2006 Initial version.