Ejemplo n.º 1
0
int SysInit( void )
{
#ifdef EMU_LOG
#ifndef LOG_STDOUT
    emuLog = fopen( "emuLog.txt", "wb" );
#else
    emuLog = stdout;
#endif
    setvbuf( emuLog, NULL, _IONBF, 0 );
#endif
    if ( EmuInit() == -1 )
    {
        printf( _( "PSX emulator couldn't be initialized.\n" ) );
        return -1;
    }

    LoadMcds( Config.Mcd1, Config.Mcd2 );   /* TODO Do we need to have this here, or in the calling main() function?? */

    if ( Config.Debug )
    {
        StartDebugger();
    }

    return 0;
}
Ejemplo n.º 2
0
int SysInit() {
#ifdef EMU_LOG
#ifndef LOG_STDOUT
	emuLog = fopen("emuLog.txt","wb");
#else
	emuLog = stdout;
#endif
#ifdef PSXCPU_LOG
	if (Config.PsxOut) { //PSXCPU_LOG generates so much stuff that buffer is necessary
		const int BUFSZ = 20 * 1024*1024;
		void* buf = malloc(BUFSZ);
		setvbuf(emuLog, buf, _IOFBF, BUFSZ);
	} else {
		setvbuf(emuLog, NULL, _IONBF, 0u);
	}
#else
	setvbuf(emuLog, NULL, _IONBF, 0u);
#endif
#endif

	if (EmuInit() == -1) {
		printf(_("PSX emulator couldn't be initialized.\n"));
		return -1;
	}

	LoadMcds(Config.Mcd1, Config.Mcd2);	/* TODO Do we need to have this here, or in the calling main() function?? */

	if (Config.Debug) {
		StartDebugger();
	}

	return 0;
}
Ejemplo n.º 3
0
int OpenPlugins() {
	int ret;

	while ((ret = _OpenPlugins()) == -2) {
		ReleasePlugins();
		LoadMcds(Config.Mcd1, Config.Mcd2);
		if (LoadPlugins() == -1) return -1;
	}
	return ret;
}
Ejemplo n.º 4
0
int OpenPlugins(HWND hWnd, int internaliso) {
	int ret;

	while ((ret = _OpenPlugins(hWnd)) == -2) {
		ReleasePlugins();
		LoadMcds(Config.Mcd1, Config.Mcd2);
		if (LoadPlugins() == -1) return -1;
	}
	return ret;
}
Ejemplo n.º 5
0
int emu_core_init(void)
{
	SysPrintf("Starting PCSX-ReARMed " REV "\n");

	if (EmuInit() == -1) {
		SysPrintf("PSX emulator couldn't be initialized.\n");
		return -1;
	}

	LoadMcds(Config.Mcd1, Config.Mcd2);

#ifdef DEBUG
	if (Config.Debug)
		StartDebugger();
#endif

	return 0;
}
Ejemplo n.º 6
0
int emu_core_init(void)
{
    CheckSubDir();
    check_memcards();

    if (EmuInit() == -1) {
        SysPrintf("PSX emulator couldn't be initialized.\n");
        return -1;
    }

    LoadMcds(Config.Mcd1, Config.Mcd2);

    if (Config.Debug) {
        StartDebugger();
    }

    return 0;
}
Ejemplo n.º 7
0
int emu_core_init(void)
{
	SysPrintf("Starting PCSX-ReARMed " REV "\n");

#ifndef NO_FRONTEND
	check_profile();
	check_memcards();
#endif

	if (EmuInit() == -1) {
		SysPrintf("PSX emulator couldn't be initialized.\n");
		return -1;
	}

	LoadMcds(Config.Mcd1, Config.Mcd2);

	if (Config.Debug) {
		StartDebugger();
	}

	return 0;
}
Ejemplo n.º 8
0
int LoadPlugins(void) {
	int ret;
	const char *cdrfilename=NULL;

	ReleasePlugins();

	LoadMcds(Config.Mcd1, Config.Mcd2);

	ret = CDR_init();
	if (ret < 0) { printf ("Error initializing CD-ROM plugin: %d\n", ret); return -1; }

	ret = GPU_init();
	if (ret < 0) { printf ("Error initializing GPU plugin: %d\n", ret); return -1; }

	ret = SPU_init();
	if (ret < 0) { printf ("Error initializing SPU plugin: %d\n", ret); return -1; }

#ifdef spu_pcsxrearmed
	//senquack - NOTE: this is an important function to call, as SPU
	// IRQs will not be acknowledged otherwise, leading to repeating sound
	// problems in games like NFS3, Grandia, Fifa98, and some games will
	// lack music like Chrono Cross FMV music, THPS2 etc.
	// Only spu_pcsxrearmed supports this (older SPU plugins all had
	// problems with sound in these games.. TODO: add support?)
	SPU_registerCallback(AcknowledgeSPUIRQ);

	//senquack - pcsx_rearmed SPU plugin schedules its own updates:
	SPU_registerScheduleCb(ScheduleSPUUpdate);
#endif

	cdrfilename=GetIsoFile();
	if (cdrfilename[0] != '\0') {
		ret=CDR_open();
		if (ret < 0) { printf ("Error opening CD-ROM: %s\n", cdrfilename); return -1; }
	}
	
	printf("Plugins loaded.\n");
	return 0;
}
Ejemplo n.º 9
0
int SysInit() {
#ifdef GTE_DUMP
	gteLog = fopen("gteLog.txt","wb");
	setvbuf(gteLog, NULL, _IONBF, 0);
#endif

#ifdef EMU_LOG
#ifndef LOG_STDOUT
	emuLog = fopen("emuLog.txt","wb");
#else
	emuLog = stdout;
#endif
	setvbuf(emuLog, NULL, _IONBF, 0);

	SysMessage(PSX4ALL_INT);
	fflush(emuLog);
#endif

	psxInit();

	LoadMcds(Config.Mcd1, Config.Mcd2);

	return 0;
}
Ejemplo n.º 10
0
	static int								ModuleLoad				()
	{
		//Load the BIOS
		MDFNFILE biosFile;
		if(biosFile.Open(MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, MDFN_GetSettingS("pcsxr.bios").c_str()).c_str(), 0))
		{
			if(biosFile.size == 512 * 1024)
			{
				memcpy(BiosBuffer, biosFile.data, 512 * 1024);
			}
			else
			{
				MDFN_printf("pcsxr: BIOS file size incorrect\n");
			}
		}
		else
		{
			MDFN_printf("pcsxr: Failed to load bios\n");
			return 0;
		}
	
		//Setup the config structure
		memset(&Config, 0, sizeof(Config));
		Config.PsxAuto = 1;
		Config.Cpu = MDFN_GetSettingB("pcsxr.recompiler") ? CPU_DYNAREC : CPU_INTERPRETER;
		Config.SlowBoot = MDFN_GetSettingB("pcsxr.slowboot");
		strcpy(Config.PluginsDir, "builtin");
		strcpy(Config.Gpu, "builtin");
		strcpy(Config.Spu, "builtin");
		strcpy(Config.Pad1, "builtin");
		strcpy(Config.Pad2, "builtin");
		strcpy(Config.Cdr, "builtin");
		strcpy(Config.Net, "Disabled");
		strncpy(Config.Mcd1, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), MAXPATHLEN);
		strncpy(Config.Mcd2, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav2").c_str(), MAXPATHLEN);

		//Init psx cpu emulator and memory mapping
		EmuInit();

		//Open and initialize all of the plugins
		OpenPlugins();

		//Load memory cards
		LoadMcds(Config.Mcd1, Config.Mcd2);

		//Get cdrom ID and init PPF support...
		CheckCdrom();

		//Reset the emulated CPU and Memory
		EmuReset();

		//Prepares the game to run, either runs the CPU thru the bios or finds and loads the game EXE if using the emulated bios
		LoadCdrom();

		//TODO: Set the clock if the machine is PAL

		//Just say two 1M pages, for fun not profit
		MDFNMP_Init(1024 * 1024, 2);
		MDFNMP_AddRAM(1024 * 1024 * 2, 0, (uint8_t*)psxM);

		return 1;
	}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
	char file[MAXPATHLEN] = "";
	char path[MAXPATHLEN];
	int runcd = RUN;
	int loadst = 0;
	int i;

#ifdef ENABLE_NLS
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	memset(&Config, 0, sizeof(PcsxConfig));

	// what is the name of the config file?
	// it may be redefined by -cfg on the command line
	strcpy(cfgfile_basename, "pcsxr.cfg");

	// read command line options
	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-runcd")) runcd = RUN_CD;
		else if (!strcmp(argv[i], "-nogui")) UseGui = FALSE;
		else if (!strcmp(argv[i], "-psxout")) Config.PsxOut = TRUE;
		else if (!strcmp(argv[i], "-slowboot")) Config.SlowBoot = TRUE;
		else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
		else if (!strcmp(argv[i], "-cfg")) {
			if (i+1 >= argc) break;
			strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100);	/* TODO buffer overruns */
			printf("Using config file %s.\n", cfgfile_basename);
		}
		else if (!strcmp(argv[i], "-cdfile")) {
			char isofilename[MAXPATHLEN];

			if (i+1 >= argc) break;
			strncpy(isofilename, argv[++i], MAXPATHLEN);
			if (isofilename[0] != '/') {
				getcwd(path, MAXPATHLEN);
				if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
					strcat(path, "/");
					strcat(path, isofilename);
					strcpy(isofilename, path);
				} else
					isofilename[0] = 0;
			}

			SetIsoFile(isofilename);
			runcd = RUN_CD;
		}
		else if (!strcmp(argv[i], "-h") ||
			 !strcmp(argv[i], "-help") ||
			 !strcmp(argv[i], "--help")) {
			 printf(PACKAGE_STRING "\n");
			 printf("%s\n", _(
							" pcsxr [options] [file]\n"
							"\toptions:\n"
							"\t-runcd\t\tRuns CD-ROM\n"
							"\t-cdfile FILE\tRuns a CD image file\n"
							"\t-nogui\t\tDon't open the GTK GUI\n"
							"\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsxr/pcsxr.cfg)\n"
							"\t-psxout\t\tEnable PSX output\n"
							"\t-slowboot\tEnable BIOS Logo\n"
							"\t-load STATENUM\tLoads savestate STATENUM (1-9)\n"
							"\t-h -help\tDisplay this message\n"
							"\tfile\t\tLoads file\n"));
			 return 0;
		} else {
			strncpy(file, argv[i], MAXPATHLEN);
			if (file[0] != '/') {
				getcwd(path, MAXPATHLEN);
				if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
					strcat(path, "/");
					strcat(path, file);
					strcpy(file, path);
				} else
					file[0] = 0;
			}
		}
	}

	strcpy(Config.Net, "Disabled");

	if (UseGui) gtk_init(NULL, NULL);

	CheckSubDir();
	ScanAllPlugins();

	// try to load config
	// if the config file doesn't exist
	if (LoadConfig() == -1) {
		if (!UseGui) {
			printf(_("PCSXR cannot be configured without using the GUI -- you should restart without -nogui.\n"));
			return 1;
		}

		// Uh oh, no config file found, use some defaults
		Config.PsxAuto = 1;

		gchar *str_bios_dir = g_strconcat(getenv("HOME"), BIOS_DIR, NULL);
		strcpy(Config.BiosDir, str_bios_dir);
		g_free(str_bios_dir);

		gchar *str_plugin_dir = g_strconcat(getenv("HOME"), PLUGINS_DIR, NULL);
		strcpy(Config.PluginsDir, str_plugin_dir);
		g_free(str_plugin_dir);

		gtk_init(NULL, NULL);

		// Update available plugins, but not GUI
		UpdatePluginsBIOS();

		// Pick some defaults, if they're available
		set_default_plugin(GpuConfS.plist[0], Config.Gpu);
		set_default_plugin(SpuConfS.plist[0], Config.Spu);
		set_default_plugin(CdrConfS.plist[0], Config.Cdr);
		set_default_plugin(Pad1ConfS.plist[0], Config.Pad1);
		set_default_plugin(Pad2ConfS.plist[0], Config.Pad2);
		set_default_plugin(BiosConfS.plist[0], Config.Bios);

		// create & load default memcards if they don't exist
		CreateMemcard("card1.mcd", Config.Mcd1);
		CreateMemcard("card2.mcd", Config.Mcd2);

		LoadMcds(Config.Mcd1, Config.Mcd2);

		SaveConfig();
	}

	gchar *str_patches_dir = g_strconcat(getenv("HOME"), PATCHES_DIR, NULL);
	strcpy(Config.PatchesDir,  str_patches_dir);
	g_free(str_patches_dir);

	// switch to plugin dotdir
	// this lets plugins work without modification!
	gchar *plugin_default_dir = g_build_filename(getenv("HOME"), PLUGINS_DIR, NULL);
	chdir(plugin_default_dir);
	g_free(plugin_default_dir);

	if (UseGui && runcd != RUN_CD) SetIsoFile(NULL);

	if (SysInit() == -1) return 1;

	if (UseGui && runcd != RUN_CD) {
		StartGui();
	} else {
		// the following only occurs if the gui isn't started
		if (LoadPlugins() == -1) {
			SysErrorMessage(_("Error"), _("Failed loading plugins!"));
			return 1;
		}

		if (OpenPlugins() == -1 || plugins_configured() == FALSE) {
			return 1;
		}

		CheckCdrom();

		// Auto-detect: get region first, then rcnt-bios reset
		SysReset();

		if (file[0] != '\0') {
			Load(file);
		} else {
			if (runcd == RUN_CD) {
				if (LoadCdrom() == -1) {
					ClosePlugins();
					printf(_("Could not load CD-ROM!\n"));
					return -1;
				}
			}
		}

		// If a state has been specified, then load that
		if (loadst) {
			StatesC = loadst - 1;
			gchar *state_filename = get_state_filename(StatesC);
			LoadState(state_filename);
			g_free(state_filename);
		}

		psxCpu->Execute();
	}

	return 0;
}
Ejemplo n.º 12
0
static void WriteMovieHeader()
{
	int empty=0;
	unsigned long emuVersion = PCSXRR_VERSION;
	unsigned long movieVersion = MOVIE_VERSION;	
	const char ENDLN = '\n';	
	int cdidsLen;

	Movie.movieFlags=0;
	if (Movie.saveStateIncluded)
		Movie.movieFlags |= MOVIE_FLAG_FROM_SAVESTATE;
	if (Movie.memoryCardIncluded)
		Movie.movieFlags |= MOVIE_FLAG_MEMORY_CARDS;
	if (Movie.cheatListIncluded)
		Movie.movieFlags |= MOVIE_FLAG_CHEAT_LIST;
	if (Movie.irqHacksIncluded)
		Movie.movieFlags |= MOVIE_FLAG_IRQ_HACKS;
	if (Config.PsxType)
		Movie.movieFlags |= MOVIE_FLAG_PAL_TIMING;
	if (Movie.isText)
		Movie.movieFlags |= MOVIE_FLAG_IS_TEXT;
	if (Movie.Port1_Mtap)	
		Movie.movieFlags |= MOVIE_FLAG_P1_MTAP;
	if (Movie.Port2_Mtap)
		Movie.movieFlags |= MOVIE_FLAG_P2_MTAP;
	if (Config.UsingAnalogHack) 
		Movie.movieFlags |= MOVIE_FLAG_ANALOG_HACK;
	if (Config.RCntFix)
		Movie.movieFlags |= MOVIE_FLAG_RCNTFIX;

	
	fwrite(&szFileHeader, 1, 4, fpMovie);          //header
	fwrite(&movieVersion, 1, 4, fpMovie);          //movie version
	fwrite(&emuVersion, 1, 4, fpMovie);            //emu version
	fwrite(&Movie.movieFlags, 1, 2, fpMovie);      //flags	
	fwrite(&Movie.padType1, 1, 1, fpMovie);        //padType1
	fwrite(&Movie.padType2, 1, 1, fpMovie);        //padType2
	fwrite(&empty, 1, 4, fpMovie);                 //total frames
	fwrite(&empty, 1, 4, fpMovie);                 //rerecord count
	fwrite(&empty, 1, 4, fpMovie);                 //savestate offset
	fwrite(&empty, 1, 4, fpMovie);                 //memory card 1 offset
	fwrite(&empty, 1, 4, fpMovie);                 //memory card 2 offset
	fwrite(&empty, 1, 4, fpMovie);                 //cheat list offset
	fwrite(&empty, 1, 4, fpMovie);                 //cdIds offset
	fwrite(&empty, 1, 4, fpMovie);                 //input offset
	
	int authLen = strnlen(Movie.authorInfo,MOVIE_MAX_METADATA);
	int temp = 512;
	fwrite(&temp, 1, 4, fpMovie);             //author info size
	Movie.authorInfoOffset = ftell(fpMovie);
	fwrite(Movie.authorInfo, 1, authLen, fpMovie);        //author info		printf(authbuf);
	for (int i = MOVIE_MAX_METADATA-authLen;i<MOVIE_MAX_METADATA;i++)
	{
		fputc(0,fpMovie);
	}
	Movie.saveStateOffset = ftell(fpMovie);        //get savestate offset
	if (!Movie.saveStateIncluded)
		fwrite(&empty, 1, 4, fpMovie);               //empty 4-byte savestate
	else {
		fclose(fpMovie);
		SaveStateEmbed(Movie.movieFilename);
		fpMovie = fopen(Movie.movieFilename,"r+b");
		fseek(fpMovie, 0, SEEK_END);
	}
	
	Movie.memoryCard1Offset = ftell(fpMovie);      //get memory card 1 offset
	if (!Movie.memoryCardIncluded) {
		fwrite(&empty, 1, 4, fpMovie);               //empty 4-byte memory card
		SIO_ClearMemoryCardsEmbed();
	}
	else {
		fclose(fpMovie);
		SIO_SaveMemoryCardsEmbed(Movie.movieFilename,1);
		fpMovie = fopen(Movie.movieFilename,"r+b");
		fseek(fpMovie, 0, SEEK_END);
	}
	Movie.memoryCard2Offset = ftell(fpMovie);      //get memory card 2 offset
	if (!Movie.memoryCardIncluded) {
		fwrite(&empty, 1, 4, fpMovie);               //empty 4-byte memory card
		SIO_ClearMemoryCardsEmbed();
	}
	else {
		fclose(fpMovie);
		SIO_SaveMemoryCardsEmbed(Movie.movieFilename,2);
		fpMovie = fopen(Movie.movieFilename,"r+b");
		fseek(fpMovie, 0, SEEK_END);
	}
	LoadMcds(Config.Mcd1, Config.Mcd2);

	Movie.cheatListOffset = ftell(fpMovie);        //get cheat list offset
	if (!Movie.cheatListIncluded) {
		fwrite(&empty, 1, 4, fpMovie);               //empty 4-byte cheat list
		CHT_ClearCheatFileEmbed();
	}
	else {
		fclose(fpMovie);
		CHT_SaveCheatFileEmbed(Movie.movieFilename);
		fpMovie = fopen(Movie.movieFilename,"r+b");
		fseek(fpMovie, 0, SEEK_END);
	}

	Movie.cdIdsOffset = ftell(fpMovie);            //get cdIds offset
	fwrite(&Movie.CdromCount, 1, 1, fpMovie);      //total CDs used
	cdidsLen = Movie.CdromCount*9;
	if (cdidsLen > 0) {
		unsigned char* cdidsbuf = (unsigned char*)malloc(cdidsLen);
		int i;
		for(i=0; i<cdidsLen; ++i) {
			cdidsbuf[i + 0] = Movie.CdromIds[i] & 0xff;
		}
		fwrite(cdidsbuf, 1, cdidsLen, fpMovie);      //CDs IDs
		free(cdidsbuf);
	}

	fwrite(&ENDLN, 1, 1, fpMovie);
	Movie.inputOffset = ftell(fpMovie);            //get input offset

	fseek (fpMovie, 24, SEEK_SET);
	fwrite(&Movie.saveStateOffset, 1, 4, fpMovie); //write savestate offset
	fwrite(&Movie.memoryCard1Offset, 1,4,fpMovie); //write memory card 1 offset
	fwrite(&Movie.memoryCard2Offset, 1,4,fpMovie); //write memory card 2 offset
	fwrite(&Movie.cheatListOffset, 1, 4, fpMovie); //write cheat list offset
	fwrite(&Movie.cdIdsOffset, 1, 4, fpMovie);     //write cd ids offset
	fwrite(&Movie.inputOffset, 1, 4, fpMovie);     //write input offset
	fseek(fpMovie, 0, SEEK_END);
}