コード例 #1
0
ファイル: mame.cpp プロジェクト: AlanApter/steamlink-sdk
/***************************************************************************

  Run the emulation. Start the various subsystems and the CPU emulation.
  Returns non zero in case of error.

***************************************************************************/
int run_machine(void)
{
	int res = 1;


	if (vh_open() == 0)
	{
		tilemap_init();
		sprite_init();
		gfxobj_init();
		if (drv->vh_start == 0 || (*drv->vh_start)() == 0)      /* start the video hardware */
		{
			if (sound_start() == 0) /* start the audio hardware */
			{
				int	region;

				real_scrbitmap = artwork_overlay ? overlay_real_scrbitmap : Machine->scrbitmap;

				/* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
				for (region = 0; region < MAX_MEMORY_REGIONS; region++)
				{
					if (Machine->memory_region_type[region] & REGIONFLAG_DISPOSE)
					{
						int i;

						/* invalidate contents to avoid subtle bugs */
						for (i = 0;i < memory_region_length(region);i++)
							memory_region(region)[i] = rand();
						free(Machine->memory_region[region]);
						Machine->memory_region[region] = 0;
					}
				}

				if (settingsloaded == 0)
				{
					/* if there is no saved config, it must be first time we run this game, */
					/* so show the disclaimer. */
//sq					if (showcopyright(real_scrbitmap)) goto userquit;
				}

//sq				if (showgamewarnings(real_scrbitmap) == 0)  /* show info about incorrect behaviour (wrong colors etc.) */
				{
					/* shut down the leds (work around Allegro hanging bug in the DOS port) */
					osd_led_w(0,1);
					osd_led_w(1,1);
					osd_led_w(2,1);
					osd_led_w(3,1);
					osd_led_w(0,0);
					osd_led_w(1,0);
					osd_led_w(2,0);
					osd_led_w(3,0);

					init_user_interface();

					/* disable cheat if no roms */
					if (!gamedrv->rom) options.cheat = 0;

					if (options.cheat) InitCheat();

					if (drv->nvram_handler)
					{
						void *f;

						f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,0);
						(*drv->nvram_handler)(f,0);
						if (f) osd_fclose(f);
					}

					cpu_run();      /* run the emulation! */

					if (drv->nvram_handler)
					{
						void *f;

						if ((f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,1)) != 0)
						{
							(*drv->nvram_handler)(f,1);
							osd_fclose(f);
						}
					}

					if (options.cheat) StopCheat();

					/* save input ports settings */
					save_input_port_settings();
				}

userquit:
				/* the following MUST be done after hiscore_save() otherwise */
				/* some 68000 games will not work */
				sound_stop();
				if (drv->vh_stop) (*drv->vh_stop)();
				overlay_free();
				backdrop_free();

				res = 0;
			}
			else if (!bailing)
			{
				bailing = 1;
				printf("Unable to start audio emulation\n");
			}
		}
		else if (!bailing)
		{
			bailing = 1;
			printf("Unable to start video emulation\n");
		}

		gfxobj_close();
		sprite_close();
		tilemap_close();
		vh_close();
	}
	else if (!bailing)
	{
		bailing = 1;
		printf("Unable to start video emulation\n");
	}

	return res;
}
コード例 #2
0
ファイル: cleanup.c プロジェクト: timofonic/dopus5allamigas
// Quit the program
void quit(BOOL script)
{
	// If main status window is open, close it
	if (main_status)
	{
		CloseProgressWindow(main_status);
		main_status=0;
	}

	if (GUI)
	{
		// Clear 'startup' flag for scripts
		GUI->flags&=~GUIF_DONE_STARTUP;

		// Close commodities
		cx_remove(GUI->cx);

		// Update environment settings
		env_update_settings(1);

		// Stop notify request
		RemoveNotifyRequest(GUI->notify_req);
		GUI->notify_req=0;

		// Is there a hide appicon?
		if (GUI->hide_appicon)
		{
			RemoveAppIcon(GUI->hide_appicon);
			FreeCachedDiskObject(GUI->hide_diskobject);
		}

		// Or an appmenuitem?
		if (GUI->hide_appitem) RemoveAppMenuItem(GUI->hide_appitem);

		// Launch shutdown script
		if (script)
			RunScript(SCRIPT_SHUTDOWN,0);

		// Set quit flag
		GUI->flags|=GUIF_PENDING_QUIT;

		// Shut the display down
		close_display(CLOSE_ALL,TRUE);

		// Send quit notifications
		quit_notify();

		// Stop notifications
		stop_file_notify(GUI->pattern_notify);
		stop_file_notify(GUI->font_notify);
		stop_file_notify(GUI->modules_notify);
		stop_file_notify(GUI->commands_notify);
		stop_file_notify(GUI->env_notify);
		stop_file_notify(GUI->desktop_notify);
		stop_file_notify(GUI->filetype_notify);

		// Free application port
		if (GUI->appmsg_port)
		{
			DOpusAppMessage *amsg;
			RemPort(GUI->appmsg_port);
			while ((amsg=(DOpusAppMessage *)GetMsg(GUI->appmsg_port)))
				ReplyAppMessage(amsg);
			DeleteMsgPort(GUI->appmsg_port);
			GUI->appmsg_port=0;

			// Remove public semaphore
			RemSemaphore((struct SignalSemaphore *)&pub_semaphore);
		}

		// Flush IPC port
		IPC_Flush(&main_ipc);

		// Close all processes
		IPC_ListQuit(&GUI->lister_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->group_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->buttons_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->startmenu_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->process_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->function_list,&main_ipc,0,TRUE);

		// Free buffers
		buffers_clear(0);

		// Remove all handlers
		RemFunctionTrap("*","#?");

		// Free filetypes
		FreeMemHandle(GUI->filetype_memory);

		// Flush the filetype cache
		ClearFiletypeCache();

		// Free lister toolbar
		FreeToolBar(GUI->toolbar);

		// Free menus and hotkeys
		CloseButtonBank(GUI->lister_menu);
		CloseButtonBank(GUI->hotkeys);

		// Free user menus
		CloseButtonBank(GUI->user_menu);
		FreeVec(GUI->user_menu_data);

		// Free backdrop list
		backdrop_free(GUI->backdrop);

		// Free icons
		if (GUI->lister_icon) FreeCachedDiskObject(GUI->lister_icon);
		if (GUI->button_icon) FreeCachedDiskObject(GUI->button_icon);

		// Free arrow image
		CloseImage(GUI->toolbar_arrow_image);

#ifdef __amigaos3__
		FreeVec(arrow_hi_data_chip);
		FreeVec(arrow_lo_data_chip);
		FreeVec(small_arrow_chip);
		FreeVec(big_arrow_chip);
#ifndef USE_SCREENTITLE
		FreeVec(moon_big_data_chip);
		FreeVec(moon_small_data_chip);
#endif
		FreeVec(command_arrow_chip);
		FreeVec(parent_arrow_chip);
#endif

		// Free screen signal
		if (GUI->screen_signal!=-1) FreeSignal(GUI->screen_signal);

		// Delete notify port
		if (GUI->notify_port) DeleteMsgPort(GUI->notify_port);

		// Free position memory
		FreeMemHandle(GUI->position_memory);

		// Free command history
		Att_RemList(GUI->command_history,0);

		// Delete icon positioning port
		DeleteMsgPort(GUI->iconpos_port);

		// Free popup menu
		PopUpFreeHandle(GUI->desktop_menu);

		// Clear requester pattern hook in library
		if (GUI->flags2&GUIF2_BACKFILL_SET)
			SetReqBackFill(0,0);
	}

	// Free scripts
	FreeScripts();

	// Free environment
	environment_free(environment);
	
	// Delete main message ports
	IPC_Flush(&main_ipc);
	DeleteMsgPort(main_ipc.command_port);
	DeleteMsgPort(main_ipc.reply_port);

	// Pause here for a couple of seconds to let everything clean up
	Delay(3*50);

	// Free global data
	FreeMemHandle(global_memory_pool);

	// Delete any temporary files
	delete_temp_files(0);

	// Free locale data
	free_locale_data(&locale);

	// Close input device
	if (InputBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IInput);
	#endif
	CloseDevice((struct IORequest *)&input_req);
	}

	// Close timer device
	if (TimerBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ITimer);
	#endif
	CloseDevice((struct IORequest *)&timer_req);
	}

	// Close console device
	if (ConsoleDevice) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IConsole);
	#endif
	CloseDevice((struct IORequest *)&console_req);
	}

	// Close libraries
	#ifdef __amigaos4__
	DropInterface((struct Interface *)Imu);
	#endif
	CloseLibrary(muBase);
	
#ifndef __amigaos3__	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)INewIcon);
	#endif
	CloseLibrary((struct Library *)NewIconBase);
#endif

	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICyberGfx);
	#endif
	CloseLibrary(CyberGfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAmigaGuide);
	#endif
	CloseLibrary(AmigaGuideBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDataTypes);
	#endif
	CloseLibrary(DataTypesBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAsl);
	#endif
	CloseLibrary(AslBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIcon);
	#endif
	CloseLibrary(IconBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDiskfont);
	#endif
	CloseLibrary(DiskfontBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IWorkbench);
	#endif
	CloseLibrary(WorkbenchBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICommodities);
	#endif
	CloseLibrary(CxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IRexxSys);
	#endif
	CloseLibrary((struct Library *)RexxSysBase); 
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IUtility);
	#endif
	CloseLibrary(UtilityBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGadTools);
	#endif
	CloseLibrary(GadToolsBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ILayers);
	#endif
	CloseLibrary((struct Library *)LayersBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGraphics);
	#endif
	CloseLibrary((struct Library *)GfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIntuition);
	#endif
	CloseLibrary((struct Library *)IntuitionBase);
	
	// Restore old current directory?
	if (old_current_dir)
	{
		UnLock(CurrentDir(old_current_dir));
	}

	// Close the dopus5.library
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDOpus);
	#endif
	CloseLibrary(DOpusBase);

	// Outahere!
	exit(0);
}