trunk/src/emu/emucore.c
| r242895 | r242896 | |
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | mamecore.c |
| 3 | emucore.c |
| 4 | 4 | |
| 5 | 5 | Simple core functions that are defined in emucore.h and which may |
| 6 | 6 | need to be accessed by other MAME-related tools. |
| r242895 | r242896 | |
| 11 | 11 | ****************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | #include "emu.h" |
| 14 | #include "emucore.h" |
| 15 | #include "osdcore.h" |
| 14 | 16 | |
| 17 | emu_fatalerror::emu_fatalerror(const char *format, ...) |
| 18 | : code(0) |
| 19 | { |
| 20 | if (format == NULL) |
| 21 | { |
| 22 | text[0] = '\0'; |
| 23 | } |
| 24 | else |
| 25 | { |
| 26 | va_list ap; |
| 27 | va_start(ap, format); |
| 28 | vsprintf(text, format, ap); |
| 29 | va_end(ap); |
| 30 | } |
| 31 | osd_break_into_debugger(text); |
| 32 | } |
| 33 | |
| 34 | emu_fatalerror::emu_fatalerror(const char *format, va_list ap) |
| 35 | : code(0) |
| 36 | { |
| 37 | if (format == NULL) |
| 38 | { |
| 39 | text[0] = '\0'; |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | vsprintf(text, format, ap); |
| 44 | } |
| 45 | osd_break_into_debugger(text); |
| 46 | } |
| 47 | |
| 48 | emu_fatalerror::emu_fatalerror(int _exitcode, const char *format, ...) |
| 49 | : code(_exitcode) |
| 50 | { |
| 51 | if (format == NULL) |
| 52 | { |
| 53 | text[0] = '\0'; |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | va_list ap; |
| 58 | va_start(ap, format); |
| 59 | vsprintf(text, format, ap); |
| 60 | va_end(ap); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | emu_fatalerror::emu_fatalerror(int _exitcode, const char *format, va_list ap) |
| 65 | : code(_exitcode) |
| 66 | { |
| 67 | if (format == NULL) |
| 68 | { |
| 69 | text[0] = '\0'; |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | vsprintf(text, format, ap); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 15 | 78 | void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type) |
| 16 | 79 | { |
| 17 | 80 | throw emu_fatalerror("Error: bad downcast<> or device<>. Tried to convert a %s to a %s, which are incompatible.\n", |
| r242895 | r242896 | |
| 23 | 86 | 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", |
| 24 | 87 | dev->tag(), dev->name(), src_type.name(), dst_type.name()); |
| 25 | 88 | } |
| 89 | |
| 90 | void fatalerror(const char *format, ...) |
| 91 | { |
| 92 | va_list ap; |
| 93 | va_start(ap, format); |
| 94 | emu_fatalerror error(format, ap); |
| 95 | va_end(ap); |
| 96 | throw error; |
| 97 | } |
| 98 | |
| 99 | void fatalerror_exitcode(running_machine &machine, int exitcode, const char *format, ...) |
| 100 | { |
| 101 | va_list ap; |
| 102 | va_start(ap, format); |
| 103 | emu_fatalerror error(exitcode, format, ap); |
| 104 | va_end(ap); |
| 105 | throw error; |
| 106 | } |
trunk/src/emu/emucore.h
| r242895 | r242896 | |
| 289 | 289 | class emu_fatalerror : public emu_exception |
| 290 | 290 | { |
| 291 | 291 | public: |
| 292 | | emu_fatalerror(const char *format, ...) ATTR_PRINTF(2,3) |
| 293 | | : code(0) |
| 294 | | { |
| 295 | | if (format == NULL) |
| 296 | | { |
| 297 | | text[0] = '\0'; |
| 298 | | } |
| 299 | | else |
| 300 | | { |
| 301 | | va_list ap; |
| 302 | | va_start(ap, format); |
| 303 | | vsprintf(text, format, ap); |
| 304 | | va_end(ap); |
| 305 | | } |
| 306 | | osd_break_into_debugger(text); |
| 307 | | } |
| 292 | emu_fatalerror(const char *format, ...) ATTR_PRINTF(2,3); |
| 293 | emu_fatalerror(const char *format, va_list ap); |
| 294 | emu_fatalerror(int _exitcode, const char *format, ...) ATTR_PRINTF(3,4); |
| 295 | emu_fatalerror(int _exitcode, const char *format, va_list ap); |
| 308 | 296 | |
| 309 | | emu_fatalerror(const char *format, va_list ap) |
| 310 | | : code(0) |
| 311 | | { |
| 312 | | if (format == NULL) |
| 313 | | { |
| 314 | | text[0] = '\0'; |
| 315 | | } |
| 316 | | else |
| 317 | | { |
| 318 | | vsprintf(text, format, ap); |
| 319 | | } |
| 320 | | osd_break_into_debugger(text); |
| 321 | | } |
| 322 | | |
| 323 | | emu_fatalerror(int _exitcode, const char *format, ...) ATTR_PRINTF(3,4) |
| 324 | | : code(_exitcode) |
| 325 | | { |
| 326 | | if (format == NULL) |
| 327 | | { |
| 328 | | text[0] = '\0'; |
| 329 | | } |
| 330 | | else |
| 331 | | { |
| 332 | | va_list ap; |
| 333 | | va_start(ap, format); |
| 334 | | vsprintf(text, format, ap); |
| 335 | | va_end(ap); |
| 336 | | } |
| 337 | | } |
| 338 | | |
| 339 | | emu_fatalerror(int _exitcode, const char *format, va_list ap) |
| 340 | | : code(_exitcode) |
| 341 | | { |
| 342 | | if (format == NULL) |
| 343 | | { |
| 344 | | text[0] = '\0'; |
| 345 | | } |
| 346 | | else |
| 347 | | { |
| 348 | | vsprintf(text, format, ap); |
| 349 | | } |
| 350 | | } |
| 351 | | |
| 352 | 297 | const char *string() const { return text; } |
| 353 | 298 | int exitcode() const { return code; } |
| 354 | 299 | |
| r242895 | r242896 | |
| 421 | 366 | ATTR_NORETURN void fatalerror(const char *format, ...) ATTR_PRINTF(1,2); |
| 422 | 367 | ATTR_NORETURN void fatalerror_exitcode(running_machine &machine, int exitcode, const char *format, ...) ATTR_PRINTF(3,4); |
| 423 | 368 | |
| 424 | | inline void fatalerror(const char *format, ...) |
| 425 | | { |
| 426 | | va_list ap; |
| 427 | | va_start(ap, format); |
| 428 | | emu_fatalerror error(format, ap); |
| 429 | | va_end(ap); |
| 430 | | throw error; |
| 431 | | } |
| 432 | | |
| 433 | | inline void fatalerror_exitcode(running_machine &machine, int exitcode, const char *format, ...) |
| 434 | | { |
| 435 | | va_list ap; |
| 436 | | va_start(ap, format); |
| 437 | | emu_fatalerror error(exitcode, format, ap); |
| 438 | | va_end(ap); |
| 439 | | throw error; |
| 440 | | } |
| 441 | | |
| 442 | | |
| 443 | | |
| 444 | 369 | //************************************************************************** |
| 445 | 370 | // INLINE FUNCTIONS |
| 446 | 371 | //************************************************************************** |