bool Window::bLoadROM(const std::string& _rsFile) { vOnFileClose(); // clear cheat list cheatsDeleteAll(false); gbCheatRemoveAll(); m_sRomFile = _rsFile; const char* csFile = _rsFile.c_str(); IMAGE_TYPE eType = utilFindType(csFile); if (eType == IMAGE_UNKNOWN) { vPopupError(_("Unknown file type %s"), csFile); return false; } bool bLoaded = false; if (eType == IMAGE_GB) { bLoaded = gbLoadRom(csFile); if (bLoaded) { m_eCartridge = CartridgeGB; m_stEmulator = GBSystem; useBios = m_poCoreConfig->oGetKey<bool>("gb_use_bios_file"); gbGetHardwareType(); if (gbHardware & 5) { gbCPUInit(m_poCoreConfig->sGetKey("gb_bios_file").c_str(), useBios); } // If the bios file was rejected by gbCPUInit if (m_poCoreConfig->oGetKey<bool>("gb_use_bios_file") && !useBios) { m_poCoreConfig->vSetKey("gb_bios_file", ""); } gbReset(); } } else if (eType == IMAGE_GBA) { int iSize = CPULoadRom(csFile); bLoaded = (iSize > 0); if (bLoaded) { m_eCartridge = CartridgeGBA; m_stEmulator = GBASystem; vApplyPerGameConfig(); useBios = m_poCoreConfig->oGetKey<bool>("use_bios_file"); CPUInit(m_poCoreConfig->sGetKey("bios_file").c_str(), useBios); CPUReset(); // If the bios file was rejected by CPUInit if (m_poCoreConfig->oGetKey<bool>("use_bios_file") && !useBios) { m_poCoreConfig->vSetKey("bios_file", ""); } } } if (!bLoaded) { return false; } vLoadBattery(); vLoadCheats(); vUpdateScreen(); emulating = 1; m_bWasEmulating = false; vApplyConfigSoundSampleRate(); vUpdateGameSlots(); vHistoryAdd(_rsFile); for (std::list<Gtk::Widget*>::iterator it = m_listSensitiveWhenPlaying.begin(); it != m_listSensitiveWhenPlaying.end(); it++) { (*it)->set_sensitive(); } if (m_poCoreConfig->oGetKey<bool>("load_game_auto")) { vOnLoadGameMostRecent(); } // reserve rewind space for write operation // this is used as work space // actual state blocks are reserved in bOnEmuSaveStateRewind() // when resulted size is known // if (m_state_count_max > 0 && m_psavestate == NULL) { m_psavestate = new char[SZSTATE]; } vStartEmu(); return true; }
bool MainWnd::FileRun() { // save battery file before we change the filename... if(rom != NULL || gbRom != NULL) { if(theApp.autoSaveLoadCheatList) winSaveCheatListDefault(); writeBatteryFile(); cheatSearchCleanup(&cheatSearchData); theApp.emulator.emuCleanUp(); remoteCleanUp(); emulating = false; #ifdef APU_LOGGER_H end_apu_log(); #endif } char tempName[2048]; char file[2048]; CString oldFile = theApp.filename; utilStripDoubleExtension(theApp.szFile, tempName); _fullpath(file, tempName, 2048); theApp.filename = file; int index = theApp.filename.ReverseFind('.'); if(index != -1) theApp.filename = theApp.filename.Left(index); if( theApp.filename != oldFile ) { // clear cheat list when another game is loaded cheatsDeleteAll( false ); gbCheatRemoveAll(); } CString patchName; patchName.Format("%s.ips", theApp.filename); if( !fileExists( patchName ) ) { patchName.Format("%s.ups", theApp.filename); if( !fileExists( patchName ) ) { patchName.Format("%s.ppf", theApp.filename); if( !fileExists( patchName ) ) { // don't use any patches patchName.Empty(); } } } if(!theApp.dir.GetLength()) { int index = theApp.filename.ReverseFind('\\'); if(index != -1) { theApp.dir = theApp.filename.Left(index-1); } } IMAGE_TYPE type = utilFindType(theApp.szFile); if(type == IMAGE_UNKNOWN) { systemMessage(IDS_UNSUPPORTED_FILE_TYPE, "Unsupported file type: %s", theApp.szFile); return false; } systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; theApp.cartridgeType = type; if(type == IMAGE_GB) { if(!gbLoadRom(theApp.szFile)) return false; gbGetHardwareType(); // used for the handling of the gb Boot Rom if (gbHardware & 5) { skipBios = theApp.skipBiosFile; gbCPUInit(theApp.biosFileNameGB, theApp.useBiosFileGB); } gbReset(); theApp.emulator = GBSystem; gbBorderOn = theApp.winGbBorderOn; theApp.romSize = gbRomSize; if(theApp.autoPatch && !patchName.IsEmpty()) { int size = gbRomSize; applyPatch(patchName, &gbRom, &size); if(size != gbRomSize) { extern bool gbUpdateSizes(); gbUpdateSizes(); gbReset(); theApp.romSize = size; } } } else { int size = CPULoadRom(theApp.szFile); if(!size) return false; theApp.romSize = size; flashSetSize(theApp.winFlashSize); rtcEnable(theApp.winRtcEnable); cpuSaveType = theApp.winSaveType; GetModuleFileName(NULL, tempName, 2048); char *p = strrchr(tempName, '\\'); if(p) *p = 0; char buffer[5]; strncpy(buffer, (const char *)&rom[0xac], 4); buffer[4] = 0; strcat(tempName, "\\vba-over.ini"); UINT i = GetPrivateProfileInt(buffer, "rtcEnabled", -1, tempName); if(i != (UINT)-1) rtcEnable(i == 0 ? false : true); i = GetPrivateProfileInt(buffer, "flashSize", -1, tempName); if(i != (UINT)-1 && (i == 0x10000 || i == 0x20000)) flashSetSize((int)i); i = GetPrivateProfileInt(buffer, "saveType", -1, tempName); if(i != (UINT)-1 && (i <= 5)) cpuSaveType = (int)i; i = GetPrivateProfileInt(buffer, "mirroringEnabled", -1, tempName); if(i != (UINT)-1) doMirroring (i == 0 ? false : true); theApp.emulator = GBASystem; /* disabled due to problems if(theApp.removeIntros && rom != NULL) { *((u32 *)rom)= 0xea00002e; } */ if(theApp.autoPatch && !patchName.IsEmpty()) { int size = 0x2000000; applyPatch(patchName, &rom, &size); if(size != 0x2000000) { CPUReset(); } } } if(theApp.soundInitialized) { if(theApp.cartridgeType == 1) gbSoundReset(); else soundReset(); } else { soundInit(); theApp.soundInitialized = true; } #ifdef APU_LOGGER_H begin_apu_log("apu_log.txt"); #endif if(type == IMAGE_GBA) { skipBios = theApp.skipBiosFile; CPUInit(theApp.biosFileNameGBA.GetString(), theApp.useBiosFileGBA); CPUReset(); } readBatteryFile(); if(theApp.autoSaveLoadCheatList) winLoadCheatListDefault(); theApp.addRecentFile(theApp.szFile); theApp.updateWindowSize(theApp.videoOption); theApp.updateFrameSkip(); emulating = true; if(theApp.autoLoadMostRecent) OnFileLoadgameMostrecent(); theApp.frameskipadjust = 0; theApp.renderedFrames = 0; theApp.autoFrameSkipLastTime = systemGetClock(); theApp.rewindCount = 0; theApp.rewindCounter = 0; theApp.rewindSaveNeeded = false; toolsClearLog(); return true; }