int cli_execute(int argc, char **argv, const options_entry *osd_options) { core_options *options; astring *gamename = astring_alloc(); astring *exename = astring_alloc(); const char *gamename_option; const game_driver *driver; int result; /* initialize the options manager and add the CLI-specific options */ options = mame_options_init(osd_options); options_add_entries(options, cli_options); /* parse the command line first; if we fail here, we're screwed */ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE)) { result = MAMERR_INVALID_CONFIG; goto error; } /* parse the simple commmands before we go any further */ core_filename_extract_base(exename, argv[0], TRUE); result = execute_simple_commands(options, astring_c(exename)); if (result != -1) { goto error; } /* find out what game we might be referring to */ gamename_option = options_get_string(options, OPTION_GAMENAME); core_filename_extract_base(gamename, gamename_option, TRUE); driver = driver_get_name(astring_c(gamename)); /* execute any commands specified */ result = execute_commands(options, astring_c(exename), driver); if (result != -1) { goto error; } /* if we don't have a valid driver selected, offer some suggestions */ if (strlen(gamename_option) > 0 && driver == NULL) { const game_driver *matches[10]; int drvnum; /* get the top 10 approximate matches */ driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches); /* print them out */ fprintf(stderr, "\n\"%s\" approximately matches the following\n" "supported " GAMESNOUN " (best match first):\n\n", gamename_option); for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++) if (matches[drvnum] != NULL) fprintf(stderr, "%-10s%s\n", matches[drvnum]->name, matches[drvnum]->description); /* exit with an error */ result = MAMERR_NO_SUCH_GAME; goto error; } /* run the game */ result = mame_execute(options); error: /* free our options and exit */ options_free(options); astring_free(gamename); astring_free(exename); return result; }
LibMame_RunGameStatus LibMame_RunGame(int gamenum, bool benchmarking, const LibMame_RunGameOptions *options, const LibMame_RunGameCallbacks *cbs, void *callback_data) { if (gamenum >= LibMame_Get_Game_Count()) { return LibMame_RunGameStatus_InvalidGameNum; } /* Set up MAME's "output channels" so that we accumulate it all in a buffer rather than dumping it to stdout/stderr/wherever */ mame_set_output_channel(OUTPUT_CHANNEL_ERROR, output_callback, 0, 0, 0); mame_set_output_channel(OUTPUT_CHANNEL_WARNING, output_callback, 0, 0, 0); mame_set_output_channel(OUTPUT_CHANNEL_INFO, output_callback, 0, 0, 0); mame_set_output_channel(OUTPUT_CHANNEL_DEBUG, output_callback, 0, 0, 0); mame_set_output_channel(OUTPUT_CHANNEL_VERBOSE, output_callback, 0, 0, 0); mame_set_output_channel(OUTPUT_CHANNEL_LOG, output_callback, 0, 0, 0); /* Set the unfortunate globals. Would greatly prefer to allocate a new one of these and pass it to MAME, having it pass it back in the osd_ callbacks. */ g_state.callbacks = cbs; g_state.callback_data = callback_data; /* Save the game number */ g_state.gamenum = gamenum; /* Look up the game number of players and controllers */ g_state.maximum_player_count = LibMame_Get_Game_MaxSimultaneousPlayers(gamenum); g_state.controllers = LibMame_Get_Game_AllControllers(gamenum); /* Set up options stuff for MAME. If none were supplied, use the defaults. */ core_options *mame_options; if (options == NULL) { LibMame_RunGameOptions default_options; LibMame_Set_Default_RunGameOptions(&default_options); mame_options = get_mame_options (&default_options, LibMame_Get_Game_Short_Name(gamenum)); } else { mame_options = get_mame_options (options, LibMame_Get_Game_Short_Name(gamenum)); } /* Haven't configured special inputs yet */ g_state.special_inputs_configured = false; /* Not waiting for a pause */ g_state.waiting_for_pause = false; /* Run the game */ int result; { libmame_rungame_osd_interface osd; result = mame_execute(osd, mame_options, benchmarking); } /* Free the options */ options_free(mame_options); /* Convert the resulting MAME code to a libmame code and return */ switch (result) { case MAMERR_NONE: return LibMame_RunGameStatus_Success; case MAMERR_FAILED_VALIDITY: return LibMame_RunGameStatus_FailedValidityCheck; case MAMERR_MISSING_FILES: return LibMame_RunGameStatus_MissingFiles; case MAMERR_FATALERROR: case MAMERR_DEVICE: case MAMERR_IDENT_NONROMS: case MAMERR_IDENT_PARTIAL: case MAMERR_IDENT_NONE: return LibMame_RunGameStatus_GeneralError; case MAMERR_NO_SUCH_GAME: return LibMame_RunGameStatus_NoSuchGame; case MAMERR_INVALID_CONFIG: return LibMame_RunGameStatus_InvalidConfig; } return LibMame_RunGameStatus_GeneralError; }
static messtest_result_t run_test(int flags, messtest_results *results) { const game_driver *driver; messtest_result_t rc; clock_t begin_time; double real_run_time; astring *fullpath = NULL; const char *device_opt; const char *fake_argv[2]; core_options *opts; /* lookup driver */ driver = driver_get_name(current_testcase.driver); /* cannot find driver? */ if (driver == NULL) { report_message(MSG_FAILURE, "Cannot find driver '%s'", current_testcase.driver); return MESSTEST_RESULT_STARTFAILURE; } /* prepare testing state */ current_command = current_testcase.commands; state = STATE_READY; test_flags = flags; screenshot_num = 0; runtime_hash = 0; had_failure = FALSE; //videoram = NULL; //videoram_size = 0; /* set up options */ opts = mame_options_init(win_mess_opts); options_set_string(opts, OPTION_GAMENAME, driver->name, OPTION_PRIORITY_CMDLINE); if( current_testcase.bios ) options_set_string(opts, OPTION_BIOS, current_testcase.bios, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_SKIP_GAMEINFO, TRUE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_THROTTLE, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_DEBUG, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_DEBUG_INTERNAL, FALSE, OPTION_PRIORITY_CMDLINE); options_set_bool(opts, OPTION_WRITECONFIG, FALSE, OPTION_PRIORITY_CMDLINE); if (current_testcase.ram != 0) { options_set_int(opts, OPTION_RAMSIZE, current_testcase.ram, OPTION_PRIORITY_CMDLINE); } /* ugh... hideous ugly fake arguments */ fake_argv[0] = "MESSTEST"; fake_argv[1] = driver->name; options_parse_command_line(opts, ARRAY_LENGTH(fake_argv), (char **) fake_argv, OPTION_PRIORITY_CMDLINE,TRUE); /* preload any needed images */ while(current_command->command_type == MESSTEST_COMMAND_IMAGE_PRELOAD) { /* get the path */ fullpath = assemble_software_path(astring_alloc(), driver, current_command->u.image_args.filename); /* get the option name */ device_opt = device_config_image_interface::device_typename(current_command->u.image_args.device_ident.type); /* set the option */ options_set_string(opts, device_opt, astring_c(fullpath), OPTION_PRIORITY_CMDLINE); /* cleanup */ astring_free(fullpath); fullpath = NULL; /* next command */ current_command++; } /* perform the test */ report_message(MSG_INFO, "Beginning test (driver '%s')", current_testcase.driver); begin_time = clock(); mame_set_output_channel(OUTPUT_CHANNEL_ERROR, messtest_output_error, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_WARNING, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_INFO, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_DEBUG, mame_null_output_callback, NULL, NULL, NULL); mame_set_output_channel(OUTPUT_CHANNEL_LOG, mame_null_output_callback, NULL, NULL, NULL); test_osd_interface osd; mame_execute(osd, opts); real_run_time = ((double) (clock() - begin_time)) / CLOCKS_PER_SEC; /* what happened? */ switch(state) { case STATE_ABORTED: report_message(MSG_FAILURE, "Test aborted"); rc = MESSTEST_RESULT_RUNTIMEFAILURE; break; case STATE_DONE: if (had_failure) { report_message(MSG_FAILURE, "Test failed (real time %.2f; emu time %.2f [%i%%])", real_run_time, final_time.as_double(), (int) ((final_time.as_double() / real_run_time) * 100)); rc = MESSTEST_RESULT_RUNTIMEFAILURE; } else { report_message(MSG_INFO, "Test succeeded (real time %.2f; emu time %.2f [%i%%])", real_run_time, final_time.as_double(), (int) ((final_time.as_double() / real_run_time) * 100)); rc = MESSTEST_RESULT_SUCCESS; } break; default: state = STATE_ABORTED; report_message(MSG_FAILURE, "Abnormal termination"); rc = MESSTEST_RESULT_STARTFAILURE; break; } if (results) { results->rc = rc; results->runtime_hash = runtime_hash; } options_free(opts); return rc; }
int cli_execute(int argc, char **argv, const options_entry *osd_options) { core_options *options = NULL; const char *gamename_option; const game_driver *driver; int result = MAMERR_FATALERROR; astring gamename; astring exename; try { /* initialize the options manager and add the CLI-specific options */ options = mame_options_init(osd_options); options_add_entries(options, cli_options); /* parse the command line first; if we fail here, we're screwed */ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE)) { result = MAMERR_INVALID_CONFIG; goto error; } /* parse the simple commmands before we go any further */ core_filename_extract_base(&exename, argv[0], TRUE); result = execute_simple_commands(options, exename); if (result != -1) goto error; /* find out what game we might be referring to */ gamename_option = options_get_string(options, OPTION_GAMENAME); core_filename_extract_base(&gamename, gamename_option, TRUE); driver = driver_get_name(gamename); /* execute any commands specified */ result = execute_commands(options, exename, driver); if (result != -1) goto error; /* if we don't have a valid driver selected, offer some suggestions */ if (strlen(gamename_option) > 0 && driver == NULL) { const game_driver *matches[10]; int drvnum; /* get the top 10 approximate matches */ driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches); /* print them out */ fprintf(stderr, "\n\"%s\" approximately matches the following\n" "supported " GAMESNOUN " (best match first):\n\n", gamename_option); for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++) if (matches[drvnum] != NULL) fprintf(stderr, "%-18s%s\n", matches[drvnum]->name, matches[drvnum]->description); /* exit with an error */ result = MAMERR_NO_SUCH_GAME; goto error; } /* run the game */ result = mame_execute(options); } catch (emu_fatalerror &fatal) { fprintf(stderr, "%s\n", fatal.string()); if (fatal.exitcode() != 0) result = fatal.exitcode(); } catch (emu_exception &) { fprintf(stderr, "Caught unhandled emulator exception\n"); } catch (std::bad_alloc &) { fprintf(stderr, "Out of memory!\n"); } catch (...) { fprintf(stderr, "Caught unhandled exception\n"); } error: /* free our options and exit */ if (options != NULL) options_free(options); /* report any unfreed memory */ dump_unfreed_mem(); return result; }