void print_game_device(FILE* out, const game_driver* game) { const struct IODevice* dev; const char *name; const char *shortname; int id; begin_resource_tracking(); dev = devices_allocate(game); if (dev) { while(dev->type < IO_COUNT) { /* print out device type */ fprintf(out, "\t\t<device type=\"%s\"", normalize_string(device_typename(dev->type))); /* does this device have a tag? */ if (dev->tag) fprintf(out, " tag=\"%s\"", normalize_string(dev->tag)); /* is this device mandatory? */ if (dev->must_be_loaded) fprintf(out, " mandatory=\"1\""); /* close the XML tag */ fprintf(out, ">\n"); for (id = 0; id < dev->count; id++) { name = device_instancename(&dev->devclass, id); shortname = device_briefinstancename(&dev->devclass, id); fprintf(out, "\t\t\t<instance"); fprintf(out, " name=\"%s\"", normalize_string(name)); fprintf(out, " briefname=\"%s\"", normalize_string(shortname)); fprintf(out, "/>\n"); } if (dev->file_extensions) { const char* ext = dev->file_extensions; while (*ext) { fprintf(out, "\t\t\t<extension"); fprintf(out, " name=\"%s\"", normalize_string(ext)); fprintf(out, "/>\n"); ext += strlen(ext) + 1; } } fprintf(out, "\t\t</device>\n"); dev++; } } end_resource_tracking(); }
int frontend_listdevices(FILE *output) { int i, dev, id; const struct IODevice *devices; const char *src; const char *driver_name; const char *name; const char *shortname; char paren_shortname[16]; const char *gamename = "*"; i = 0; fprintf(output, " SYSTEM DEVICE NAME (brief) IMAGE FILE EXTENSIONS SUPPORTED \n"); fprintf(output, "---------- -------------------- ------------------------------------\n"); while (drivers[i]) { if (!strwildcmp(gamename, drivers[i]->name)) { begin_resource_tracking(); devices = devices_allocate(drivers[i]); driver_name = drivers[i]->name; for (dev = 0; devices[dev].type < IO_COUNT; dev++) { src = devices[dev].file_extensions; for (id = 0; id < devices[dev].count; id++) { name = device_instancename(&devices[dev].devclass, id); shortname = device_briefinstancename(&devices[dev].devclass, id); sprintf(paren_shortname, "(%s)", shortname); fprintf(output, "%-13s%-12s%-8s ", driver_name, name, paren_shortname); driver_name = " "; if (id == 0) { while (src && *src) { fprintf(output, ".%-5s", src); src += strlen(src) + 1; } } fprintf(output, "\n"); } } end_resource_tracking(); } i++; } return 0; }
static void cpu_post_run(void) { /* write hi scores to disk - No scores saving if cheat */ hs_close(); /* stop the machine */ if (Machine->drv->machine_stop) (*Machine->drv->machine_stop)(); end_resource_tracking(); }
static void soft_reset(int param) { running_machine *machine = Machine; mame_private *mame = machine->mame_data; callback_item *cb; logerror("Soft reset\n"); /* temporarily in the reset phase */ mame->current_phase = MAME_PHASE_RESET; /* a bit gross -- back off of the resource tracking, and put it back at the end */ assert(get_resource_tag() == 2); end_resource_tracking(); begin_resource_tracking(); /* allow save state registrations during the reset */ state_save_allow_registration(TRUE); /* unfortunately, we can't rely on callbacks to reset the interrupt */ /* structures, as these need to happen before we call the reset */ /* functions registered by the drivers */ cpuint_reset(); /* run the driver's reset callbacks */ if (machine->drv->machine_reset != NULL) (*machine->drv->machine_reset)(machine); if (machine->drv->sound_reset != NULL) (*machine->drv->sound_reset)(machine); if (machine->drv->video_reset != NULL) (*machine->drv->video_reset)(machine); /* call all registered reset callbacks */ for (cb = machine->mame_data->reset_callback_list; cb; cb = cb->next) (*cb->func.reset)(machine); /* disallow save state registrations starting here */ state_save_allow_registration(FALSE); /* now we're running */ mame->current_phase = MAME_PHASE_RUNNING; /* set the global time to the current time */ /* this allows 0-time queued callbacks to run before any CPUs execute */ mame_timer_set_global_time(mame_timer_get_time()); }
static void print_game_switch(FILE* out, const game_driver* game) { const input_port_entry* input; begin_resource_tracking(); input = input_port_allocate(game->construct_ipt, NULL); while (input->type != IPT_END) { if (input->type==IPT_DIPSWITCH_NAME) { int def = input->default_value; fprintf(out, "\t\t<dipswitch"); fprintf(out, " name=\"%s\"", normalize_string(input->name)); ++input; fprintf(out, ">\n"); while (input->type==IPT_DIPSWITCH_SETTING) { fprintf(out, "\t\t\t<dipvalue"); fprintf(out, " name=\"%s\"", normalize_string(input->name)); if (def == input->default_value) fprintf(out, " default=\"yes\""); fprintf(out, "/>\n"); ++input; } fprintf(out, "\t\t</dipswitch>\n"); } else ++input; } end_resource_tracking(); }
void exit_resource_tracking(void) { while (resource_tracking_tag != 0) end_resource_tracking(); free_callback_list(&free_resources_callback_list); }
int run_game(int game) { running_machine *machine; int error = MAMERR_NONE; mame_private *mame; callback_item *cb; /* create the machine structure and driver */ machine = create_machine(game); mame = machine->mame_data; /* looooong term: remove this */ Machine = machine; /* start in the "pre-init phase" */ mame->current_phase = MAME_PHASE_PREINIT; /* perform validity checks before anything else */ if (mame_validitychecks(game) != 0) return MAMERR_FAILED_VALIDITY; /* loop across multiple hard resets */ mame->exit_pending = FALSE; while (error == 0 && !mame->exit_pending) { init_resource_tracking(); add_free_resources_callback(timer_free); add_free_resources_callback(state_save_free); /* use setjmp/longjmp for deep error recovery */ mame->fatal_error_jmpbuf_valid = TRUE; error = setjmp(mame->fatal_error_jmpbuf); if (error == 0) { int settingsloaded; /* move to the init phase */ mame->current_phase = MAME_PHASE_INIT; /* start tracking resources for real */ begin_resource_tracking(); /* if we have a logfile, set up the callback */ mame->logerror_callback_list = NULL; if (options.logfile) add_logerror_callback(machine, logfile_callback); /* then finish setting up our local machine */ init_machine(machine); /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); nvram_load(); /* display the startup screens */ ui_display_startup_screens(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; /* start resource tracking; note that soft_reset assumes it can */ /* call end_resource_tracking followed by begin_resource_tracking */ /* to clear out resources allocated between resets */ begin_resource_tracking(); /* perform a soft reset -- this takes us to the running phase */ soft_reset(0); /* run the CPUs until a reset or exit */ mame->hard_reset_pending = FALSE; while ((!mame->hard_reset_pending && !mame->exit_pending) || mame->saveload_pending_file != NULL) { profiler_mark(PROFILER_EXTRA); /* execute CPUs if not paused */ if (!mame->paused) cpuexec_timeslice(); /* otherwise, just pump video updates through */ else video_frame_update(); /* handle save/load */ if (mame->saveload_schedule_callback) (*mame->saveload_schedule_callback)(machine); profiler_mark(PROFILER_END); } /* and out via the exit phase */ mame->current_phase = MAME_PHASE_EXIT; /* stop tracking resources at this level */ end_resource_tracking(); /* save the NVRAM and configuration */ nvram_save(); config_save_settings(); } mame->fatal_error_jmpbuf_valid = FALSE; /* call all exit callbacks registered */ for (cb = mame->exit_callback_list; cb; cb = cb->next) (*cb->func.exit)(machine); /* close all inner resource tracking */ exit_resource_tracking(); /* free our callback lists */ free_callback_list(&mame->exit_callback_list); free_callback_list(&mame->reset_callback_list); free_callback_list(&mame->pause_callback_list); } /* destroy the machine */ destroy_machine(machine); /* return an error */ return error; }
void exit_resource_tracking(void) { while (resource_tracking_tag != 0) end_resource_tracking(); }
static void print_game_input(FILE* out, const game_driver* game) { const input_port_entry* input; int nplayer = 0; const char* control = 0; int nbutton = 0; int ncoin = 0; const char* service = 0; const char* tilt = 0; begin_resource_tracking(); input = input_port_allocate(game->construct_ipt, NULL); while (input->type != IPT_END) { if (nplayer < input->player+1) nplayer = input->player+1; switch (input->type) { case IPT_JOYSTICK_LEFT: case IPT_JOYSTICK_RIGHT: /* if control not defined, start it off as horizontal 2-way */ if (!control) control = "joy2way"; else if (strcmp(control,"joy2way") == 0) ; /* if already defined as vertical, make it 4 or 8 way */ else if (strcmp(control,"vjoy2way") == 0) { if (input->four_way) control = "joy4way"; else control = "joy8way"; } break; case IPT_JOYSTICK_UP: case IPT_JOYSTICK_DOWN: /* if control not defined, start it off as vertical 2-way */ if (!control) control= "vjoy2way"; else if (strcmp(control,"vjoy2way") == 0) ; /* if already defined as horiz, make it 4 or 8way */ else if (strcmp(control,"joy2way")==0) { if (input->four_way) control = "joy4way"; else control = "joy8way"; } break; case IPT_JOYSTICKRIGHT_UP: case IPT_JOYSTICKRIGHT_DOWN: case IPT_JOYSTICKLEFT_UP: case IPT_JOYSTICKLEFT_DOWN: /* if control not defined, start it off as vertical 2way */ if (!control) control= "vdoublejoy2way"; else if (strcmp(control,"vdoublejoy2way") == 0) ; /* if already defined as horiz, make it 4 or 8 way */ else if (strcmp(control,"doublejoy2way") == 0) { if (input->four_way) control = "doublejoy4way"; else control = "doublejoy8way"; } break; case IPT_JOYSTICKRIGHT_LEFT: case IPT_JOYSTICKRIGHT_RIGHT: case IPT_JOYSTICKLEFT_LEFT: case IPT_JOYSTICKLEFT_RIGHT: /* if control not defined, start it off as horiz 2-way */ if (!control) control="doublejoy2way"; else if (strcmp(control,"doublejoy2way") == 0) ; /* if already defined as vertical, make it 4 or 8 way */ else if (strcmp(control,"vdoublejoy2way") == 0) { if (input->four_way) control = "doublejoy4way"; else control = "doublejoy8way"; } break; case IPT_BUTTON1: if (nbutton<1) nbutton = 1; break; case IPT_BUTTON2: if (nbutton<2) nbutton = 2; break; case IPT_BUTTON3: if (nbutton<3) nbutton = 3; break; case IPT_BUTTON4: if (nbutton<4) nbutton = 4; break; case IPT_BUTTON5: if (nbutton<5) nbutton = 5; break; case IPT_BUTTON6: if (nbutton<6) nbutton = 6; break; case IPT_BUTTON7: if (nbutton<7) nbutton = 7; break; case IPT_BUTTON8: if (nbutton<8) nbutton = 8; break; case IPT_BUTTON9: if (nbutton<9) nbutton = 9; break; case IPT_BUTTON10: if (nbutton<10) nbutton = 10; break; case IPT_PADDLE: control = "paddle"; break; case IPT_DIAL: control = "dial"; break; case IPT_TRACKBALL_X: case IPT_TRACKBALL_Y: control = "trackball"; break; case IPT_AD_STICK_X: case IPT_AD_STICK_Y: control = "stick"; break; case IPT_LIGHTGUN_X: case IPT_LIGHTGUN_Y: control = "lightgun"; break; case IPT_COIN1: if (ncoin < 1) ncoin = 1; break; case IPT_COIN2: if (ncoin < 2) ncoin = 2; break; case IPT_COIN3: if (ncoin < 3) ncoin = 3; break; case IPT_COIN4: if (ncoin < 4) ncoin = 4; break; case IPT_COIN5: if (ncoin < 5) ncoin = 5; break; case IPT_COIN6: if (ncoin < 6) ncoin = 6; break; case IPT_COIN7: if (ncoin < 7) ncoin = 7; break; case IPT_COIN8: if (ncoin < 8) ncoin = 8; break; case IPT_SERVICE : service = "yes"; break; case IPT_TILT : tilt = "yes"; break; } ++input; } fprintf(out, "\t\t<input"); fprintf(out, " players=\"%d\"", nplayer ); if (control) fprintf(out, " control=\"%s\"", normalize_string(control) ); if (nbutton) fprintf(out, " buttons=\"%d\"", nbutton ); if (ncoin) fprintf(out, " coins=\"%d\"", ncoin ); if (service) fprintf(out, " service=\"%s\"", normalize_string(service) ); if (tilt) fprintf(out, " tilt=\"%s\"", normalize_string(tilt) ); fprintf(out, "/>\n"); end_resource_tracking(); }
int run_game(int game) { callback_item *cb; int error = 0; /* start in the "pre-init phase" */ current_phase = MAME_PHASE_PREINIT; /* AdvanceMAME: Disable validity checks */ #if 0 /* perform validity checks before anything else */ if (mame_validitychecks(game) != 0) return 1; #endif /* loop across multiple hard resets */ exit_pending = FALSE; while (error == 0 && !exit_pending) { /* use setjmp/longjmp for deep error recovery */ fatal_error_jmpbuf_valid = TRUE; error = setjmp(fatal_error_jmpbuf); if (error == 0) { int settingsloaded; /* move to the init phase */ current_phase = MAME_PHASE_INIT; /* start tracking resources for real */ begin_resource_tracking(); /* if we have a logfile, set up the callback */ logerror_callback_list = NULL; if (options.logfile) add_logerror_callback(logfile_callback); /* create the Machine structure and driver */ create_machine(game); /* then finish setting up our local machine */ init_machine(); /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); nvram_load(); /* initialize the UI and display the startup screens */ if (ui_init(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo) != 0) fatalerror("User cancelled"); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; /* start resource tracking; note that soft_reset assumes it can */ /* call end_resource_tracking followed by begin_resource_tracking */ /* to clear out resources allocated between resets */ begin_resource_tracking(); /* perform a soft reset -- this takes us to the running phase */ soft_reset(0); /* run the CPUs until a reset or exit */ hard_reset_pending = FALSE; while ((!hard_reset_pending && !exit_pending) || saveload_pending_file != NULL) { profiler_mark(PROFILER_EXTRA); /* execute CPUs if not paused */ if (!mame_paused) cpuexec_timeslice(); /* otherwise, just pump video updates through */ else { updatescreen(); reset_partial_updates(); } /* handle save/load */ if (saveload_schedule_callback) (*saveload_schedule_callback)(); profiler_mark(PROFILER_END); } /* and out via the exit phase */ current_phase = MAME_PHASE_EXIT; /* stop tracking resources at this level */ end_resource_tracking(); /* save the NVRAM and configuration */ nvram_save(); config_save_settings(); } fatal_error_jmpbuf_valid = FALSE; /* call all exit callbacks registered */ for (cb = exit_callback_list; cb; cb = cb->next) (*cb->func.exit)(); /* close all inner resource tracking */ while (resource_tracking_tag != 0) end_resource_tracking(); /* free our callback lists */ free_callback_list(&exit_callback_list); free_callback_list(&reset_callback_list); free_callback_list(&pause_callback_list); } /* return an error */ return error; }