1 /*
2  * PROPRIETARY INFORMATION.  This software is proprietary to POWDER
3  * Development, and is not to be reproduced, transmitted, or disclosed
4  * in any way without written permission.
5  *
6  * Produced by:	Jeff Lait
7  *
8  *      	POWDER Development
9  *
10  * NAME:        assert.cpp ( POWDER Library, C++ )
11  *
12  * COMMENTS:
13  *	This implements the UT_ASSERT methods for POWDER.  These are
14  *	a bit more complex than your usual int3 as you don't have
15  *	a debugger on the hardware.
16  */
17 
18 #include "assert.h"
19 //
20 // Assert implementation
21 //
22 
23 #include "assert.h"
24 #include <stdio.h>
25 #include "control.h"
26 #include "gfxengine.h"
27 #include "buf.h"
28 
29 #ifdef USING_SDL
30 #include <assert.h>
31 #endif
32 
33 // THis is a blank line so we can undo the assert message.
34 #define blank "                             "
35 
36 void
triggerassert(int cond,const char * msg,int line,const char * file)37 triggerassert(int cond, const char *msg, int line, const char *file)
38 {
39 #ifdef HAS_PRINTF
40     if (!cond)
41     {
42 	printf("Assertion failure: File %s, Line %d\n", file, line);
43 	assert(0);
44     }
45 #else
46     if (!cond)
47     {
48 	BUF		buf;
49 
50 	// Print the message...
51 	gfx_printtext(0, 10, msg);
52 	buf.sprintf("%s: %d", file, line);
53 	gfx_printtext(0, 11, buf);
54 
55 	// Wait for R & L to go low.  This way if an assert occurs while
56 	// the user has double pressed, it doesn't go away quickly.
57 	while (ctrl_rawpressed(BUTTON_R) ||
58 	       ctrl_rawpressed(BUTTON_L))
59 	{
60 	}
61 	// Wait for R & L to go high.
62 	while (!ctrl_rawpressed(BUTTON_R) ||
63 	       !ctrl_rawpressed(BUTTON_L))
64 	{
65 	}
66 	// Wait for them to go low again...
67 	while (ctrl_rawpressed(BUTTON_R) ||
68 	       ctrl_rawpressed(BUTTON_L))
69 	{
70 	}
71 
72 	// Clear out the assert...
73 	gfx_printtext(0, 10, blank);
74 	gfx_printtext(0, 11, blank);
75 
76 	// Now we return to our regularly scheduled program, which will
77 	// likely crash.
78     }
79 #endif
80 }
81