File: assert.cpp

package info (click to toggle)
powder 117-2
  • links: PTS
  • area: non-free
  • in suites: stretch
  • size: 10,576 kB
  • ctags: 3,545
  • sloc: cpp: 55,002; makefile: 541; sh: 258; objc: 245; ansic: 107; csh: 54
file content (80 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * PROPRIETARY INFORMATION.  This software is proprietary to POWDER
 * Development, and is not to be reproduced, transmitted, or disclosed
 * in any way without written permission.
 *
 * Produced by:	Jeff Lait
 *
 *      	POWDER Development
 *
 * NAME:        assert.cpp ( POWDER Library, C++ )
 *
 * COMMENTS:
 *	This implements the UT_ASSERT methods for POWDER.  These are
 *	a bit more complex than your usual int3 as you don't have
 *	a debugger on the hardware.
 */

#include "assert.h"
//
// Assert implementation
//

#include "assert.h"
#include <stdio.h>
#include "control.h"
#include "gfxengine.h"
#include "buf.h"

#ifdef USING_SDL
#include <assert.h>
#endif

// THis is a blank line so we can undo the assert message.
#define blank "                             "

void
triggerassert(int cond, const char *msg, int line, const char *file)
{
#ifdef HAS_PRINTF
    if (!cond)
    {
	printf("Assertion failure: File %s, Line %d\n", file, line);
	assert(0);
    }
#else
    if (!cond)
    {
	BUF		buf;
	
	// Print the message...
	gfx_printtext(0, 10, msg);
	buf.sprintf("%s: %d", file, line);
	gfx_printtext(0, 11, buf);

	// Wait for R & L to go low.  This way if an assert occurs while
	// the user has double pressed, it doesn't go away quickly.
	while (ctrl_rawpressed(BUTTON_R) ||
	       ctrl_rawpressed(BUTTON_L))
	{
	}
	// Wait for R & L to go high.
	while (!ctrl_rawpressed(BUTTON_R) ||
	       !ctrl_rawpressed(BUTTON_L))
	{
	}
	// Wait for them to go low again...
	while (ctrl_rawpressed(BUTTON_R) ||
	       ctrl_rawpressed(BUTTON_L))
	{
	}

	// Clear out the assert...
	gfx_printtext(0, 10, blank);
	gfx_printtext(0, 11, blank);

	// Now we return to our regularly scheduled program, which will
	// likely crash.
    }
#endif
}