summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/emucore.c
blob: c7ad49a25b56b6d56b0eb917a5253f92937526ad (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***************************************************************************

    emucore.c

    Simple core functions that are defined in emucore.h and which may
    need to be accessed by other MAME-related tools.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

****************************************************************************/

#include "emu.h"
#include "emucore.h"
#include "osdcore.h"

emu_fatalerror::emu_fatalerror(const char *format, ...)
: code(0)
{
	if (format == NULL)
	{
		text[0] = '\0';
	}
	else
	{
		va_list ap;
		va_start(ap, format);
		vsprintf(text, format, ap);
		va_end(ap);
	}
	osd_break_into_debugger(text);
}

emu_fatalerror::emu_fatalerror(const char *format, va_list ap)
: code(0)
{
	if (format == NULL)
	{
		text[0] = '\0';
	}
	else
	{
		vsprintf(text, format, ap);
	}
	osd_break_into_debugger(text);
}

emu_fatalerror::emu_fatalerror(int _exitcode, const char *format, ...)
: code(_exitcode)
{
	if (format == NULL)
	{
		text[0] = '\0';
	}
	else
	{
		va_list ap;
		va_start(ap, format);
		vsprintf(text, format, ap);
		va_end(ap);
	}
}

emu_fatalerror::emu_fatalerror(int _exitcode, const char *format, va_list ap)
: code(_exitcode)
{
	if (format == NULL)
	{
		text[0] = '\0';
	}
	else
	{
		vsprintf(text, format, ap);
	}
}


void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type)
{
	throw emu_fatalerror("Error: bad downcast<> or device<>.  Tried to convert a %s to a %s, which are incompatible.\n",
			src_type.name(), dst_type.name());
}

void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type)
{
	throw emu_fatalerror("Error: bad downcast<> or device<>.  Tried to convert the device %s (%s) of type %s to a %s, which are incompatible.\n",
			dev->tag(), dev->name(), src_type.name(), dst_type.name());
}

void fatalerror(const char *format, ...)
{
	va_list ap;
	va_start(ap, format);
	emu_fatalerror error(format, ap);
	va_end(ap);
	throw error;
}

void fatalerror_exitcode(running_machine &machine, int exitcode, const char *format, ...)
{
	va_list ap;
	va_start(ap, format);
	emu_fatalerror error(exitcode, format, ap);
	va_end(ap);
	throw error;
}