Esempio n. 1
0
void running_machine::start()
{
	/* initialize basic can't-fail systems here */
	fileio_init(this);
	config_init(this);
	input_init(this);
	output_init(this);
	state_init(this);
	state_save_allow_registration(this, true);
	palette_init(this);
	render_init(this);
	ui_init(this);
	generic_machine_init(this);
	generic_video_init(this);
	generic_sound_init(this);

	/* initialize the timers and allocate a soft_reset timer
	   this must be done before cpu_init so that CPU's can allocate timers */
	timer_init(this);
	m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL);

	/* init the osd layer */
	osd_init(this);

	/* initialize the base time (needed for doing record/playback) */
	time(&m_base_time);

	/* initialize the input system and input ports for the game
	   this must be done before memory_init in order to allow specifying
	   callbacks based on input port tags */
	time_t newbase = input_port_init(this, m_game.ipt);
	if (newbase != 0)
		m_base_time = newbase;

	/* intialize UI input */
	ui_input_init(this);

	/* initialize the streams engine before the sound devices start */
	streams_init(this);

	/* first load ROMs, then populate memory, and finally initialize CPUs
	   these operations must proceed in this order */
	rom_init(this);
	memory_init(this);
	watchdog_init(this);

	/* allocate the gfx elements prior to device initialization */
	gfx_init(this);

	/* initialize natural keyboard support */
	inputx_init(this);

	/* initialize image devices */
	image_init(this);

	/* start up the devices */
	m_devicelist.start_all();

	/* call the game driver's init function
	   this is where decryption is done and memory maps are altered
	   so this location in the init order is important */
	ui_set_startup_text(this, "Initializing...", true);
	if (m_game.driver_init != NULL)
		(*m_game.driver_init)(this);

	/* finish image devices init process */
	image_postdevice_init(this);

	/* start the video and audio hardware */
	video_init(this);
	tilemap_init(this);
	crosshair_init(this);

	sound_init(this);

	/* initialize the debugger */
	if ((debug_flags & DEBUG_FLAG_ENABLED) != 0)
		debugger_init(this);

	/* call the driver's _START callbacks */
	if (m_config.m_machine_start != NULL)
		(*m_config.m_machine_start)(this);
	if (m_config.m_sound_start != NULL)
		(*m_config.m_sound_start)(this);
	if (m_config.m_video_start != NULL)
		(*m_config.m_video_start)(this);

	/* set up the cheat engine */    
	cheat_init(this);
	/* set up the hiscore engine */    
    hiscore_init(this);

	/* disallow save state registrations starting here */
	state_save_allow_registration(this, false);
}
Esempio n. 2
0
static void init_machine(void)
{
	int num;

	/* initialize basic can't-fail systems here */
	cpuintrf_init();
	sndintrf_init();
	fileio_init();
	config_init();
	state_init();
	state_save_allow_registration(TRUE);
	drawgfx_init();
	generic_machine_init();
	generic_video_init();
	rand_seed = 0x9d14abd7;

	/* init the osd layer */
	if (osd_init() != 0)
		fatalerror("osd_init failed");

	/* initialize the input system */
	/* this must be done before the input ports are initialized */
	if (code_init() != 0)
		fatalerror("code_init failed");

	/* initialize the input ports for the game */
	/* this must be done before memory_init in order to allow specifying */
	/* callbacks based on input port tags */
	if (input_port_init(Machine->gamedrv->construct_ipt) != 0)
		fatalerror("input_port_init failed");

	/* load the ROMs if we have some */
	/* this must be done before memory_init in order to allocate memory regions */
	if (rom_init(Machine->gamedrv->rom) != 0)
		fatalerror("rom_init failed");

	/* initialize the timers and allocate a soft_reset timer */
	/* this must be done before cpu_init so that CPU's can allocate timers */
	timer_init();
	soft_reset_timer = timer_alloc(soft_reset);

	/* initialize the memory system for this game */
	/* this must be done before cpu_init so that set_context can look up the opcode base */
	if (memory_init() != 0)
		fatalerror("memory_init failed");

	/* now set up all the CPUs */
	if (cpuexec_init() != 0)
		fatalerror("cpuexec_init failed");
	if (cpuint_init() != 0)
		fatalerror("cpuint_init failed");

#ifdef MESS
	/* initialize the devices */
	if (devices_init(Machine->gamedrv))
		fatalerror("devices_init failed");
#endif

	/* start the hiscore system -- remove me */
	hiscore_init(Machine->gamedrv->name);

	/* start the save/load system */
	saveload_init();

	/* call the game driver's init function */
	/* this is where decryption is done and memory maps are altered */
	/* so this location in the init order is important */
	if (Machine->gamedrv->driver_init != NULL)
		(*Machine->gamedrv->driver_init)();

	/* start the audio system */
	if (sound_init() != 0)
		fatalerror("sound_init failed");

	/* start the video hardware */
	if (video_init() != 0)
		fatalerror("video_init failed");

	/* start the cheat engine */
	if (options.cheat)
		cheat_init();

	/* call the driver's _START callbacks */
	if (Machine->drv->machine_start != NULL && (*Machine->drv->machine_start)() != 0)
		fatalerror("Unable to start machine emulation");
	if (Machine->drv->sound_start != NULL && (*Machine->drv->sound_start)() != 0)
		fatalerror("Unable to start sound emulation");
	if (Machine->drv->video_start != NULL && (*Machine->drv->video_start)() != 0)
		fatalerror("Unable to start video emulation");

	/* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
	for (num = 0; num < MAX_MEMORY_REGIONS; num++)
		if (mem_region[num].flags & ROMREGION_DISPOSE)
			free_memory_region(num);

#ifdef MAME_DEBUG
	/* initialize the debugger */
	if (Machine->debug_mode)
		mame_debug_init();
#endif
}
Esempio n. 3
0
int running_machine::run(bool firstrun)
{
   int error = MAMERR_NONE;

   // move to the init phase
   m_current_phase = MACHINE_PHASE_INIT;

   // if we have a logfile, set up the callback
   if (options().log())
   {
      m_logfile.reset(global_alloc(emu_file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)));
      file_error filerr = m_logfile->open("error.log");
      assert_always(filerr == FILERR_NONE, "unable to open log file");
      add_logerror_callback(logfile_callback);
   }

   // then finish setting up our local machine
   start();

   // load the configuration settings and NVRAM
   bool settingsloaded = config_load_settings(*this);

   //MKCHAMP - INITIALIZING THE HISCORE ENGINE
   if (! options().disable_hiscore_patch())
      hiscore_init(*this);

   // disallow save state registrations starting here.
   // Don't do it earlier, config load can create network
   // devices with timers.
   m_save.allow_registration(false);

   nvram_load();
   sound().ui_mute(false);

   // initialize ui lists
   ui().initialize(*this);

   // display the startup screens
   ui().display_startup_screens(firstrun, !options().skip_nagscreen());

   // perform a soft reset -- this takes us to the running phase
   soft_reset();

   // handle initial load
   if (m_saveload_schedule != SLS_NONE)
      handle_saveload();

   // run the CPUs until a reset or exit
   m_hard_reset_pending = false;
   while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != SLS_NONE)
      return 0;

   // and out via the exit phase
   m_current_phase = MACHINE_PHASE_EXIT;

   // save the NVRAM and configuration
   sound().ui_mute(true);
   nvram_save();
   config_save_settings(*this);

   // make sure our phase is set properly before cleaning up,
   // in case we got here via exception
   m_current_phase = MACHINE_PHASE_EXIT;

   // call all exit callbacks registered
   call_notifiers(MACHINE_NOTIFY_EXIT);
   zip_file_cache_clear();

   // close the logfile
   m_logfile.reset();
   return error;
}
Esempio n. 4
0
int main (int argc, char *argv[])
{
    if (sdl_init () != 0)
        return 1;

    if (textures_init ())
        return 1;
    if (audio_init ())
    {
        fprintf (stderr, "Error loading SFX: %s\n", SDL_GetError());
        return 1;
    }
    if (music_init ())
    {
        fprintf (stderr, "Error loading SFX: %s\n", SDL_GetError());
        return 1;
    }

    if (config_load ())
    {
        fprintf (stderr, "Error loading config\n");
    }

    hiscore_init ();
    //gamestate = GAME_DEMO;
    running = 1;
    while (running)
    {
        sdl_read_input ();
        if (!paused)
        {
            SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
            if (gamestate != GAME_OVER)
                SDL_RenderClear (renderer);

            switch (gamestate)
            {
                case GAME_DEMO:
                    draw_test ();
                    break;
                case GAME_RUNNING:
                    game_loop ();
                    break;
                case GAME_AMODE:
                default:
                    amode_loop ();
                    break;
                case GAME_OVER:
                    gameover_loop ();
                    break;
                case GAME_HSENTRY:
                    hsentry_loop ();
                    break;
                case GAME_CONFIG:
                case GAME_CONFIG_INPUT:
                    config_loop ();
                    break;
                case GAME_SELECT_RECORD:
                    playback_loop ();
                    break;
            }
        }

        SDL_RenderPresent (renderer);
    }

    hiscore_save ();
    sdl_close ();
    return 0;
}