Exemple #1
0
bool retro_load_game(const struct retro_game_info *game)
{
    bool ret = CPULoadRom(game->path);

    gba_init();

    return ret;
}
bool retro_load_game(const struct retro_game_info *game)
{
    update_variables();

    bool ret = CPULoadRom(game->path);

    gba_init();

    return ret;
}
Exemple #3
0
EXPORT bool snes_load_cartridge_normal(const char*, const uint8_t *rom_data, unsigned rom_size)
{
   const char *tmppath = "VBA-tmp.gba";
   unsigned ret;

   if (full_path)
      ret = CPULoadRom(full_path);
   else
   {
      FILE *file = fopen(tmppath, "wb");
      if (!file)
         return false;

      fwrite(rom_data, 1, rom_size, file);
      fclose(file);
      ret = CPULoadRom(tmppath);
      remove(tmppath);
   }

   gba_init();

   return ret;
}
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.emuCleanUp();
    remoteCleanUp(); 
    emulating = false;   
  }
  char tempName[2048];
  char file[2048];
  
  utilGetBaseName(theApp.szFile, tempName);
  
  _fullpath(file, tempName, 1024);
  theApp.filename = file;

  int index = theApp.filename.ReverseFind('.');
  if(index != -1)
    theApp.filename = theApp.filename.Left(index);

  CString ipsname;
  ipsname.Format("%s.ips", theApp.filename);  

  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;
  }

  theApp.cartridgeType = (int)type;
  if(type == IMAGE_GB) {
    if(!gbLoadRom(theApp.szFile))
      return false;
    theApp.emuWriteState = gbWriteSaveState;
    theApp.emuWriteMemState = gbWriteMemSaveState;
    theApp.emuReadState = gbReadSaveState;
    theApp.emuReadMemState = gbReadMemSaveState;
    theApp.emuWriteBattery = gbWriteBatteryFile;
    theApp.emuReadBattery = gbReadBatteryFile;
    theApp.emuReset = gbReset;
    theApp.emuCleanUp = gbCleanUp;
    theApp.emuWritePNG = gbWritePNGFile;
    theApp.emuWriteBMP = gbWriteBMPFile;
    theApp.emuMain = gbEmulate;
#ifdef FINAL_VERSION
    theApp.emuCount = 70000/4;
#else
    theApp.emuCount = 1000;
#endif
    gbBorderOn = theApp.winGbBorderOn;
    if(theApp.autoIPS) {
      int size = gbRomSize;
      utilApplyIPS(ipsname, &gbRom, &size);
      if(size != gbRomSize) {
        extern bool gbUpdateSizes();
        gbUpdateSizes();
        gbReset();
      }
    }
  } else {
    int size = CPULoadRom(theApp.szFile);
    if(!size)
      return false;
    
    flashSetSize(theApp.winFlashSize);
    rtcEnable(theApp.winRtcEnable);
    cpuSaveType = theApp.winSaveType;

    //    if(cpuEnhancedDetection && winSaveType == 0) {
    //      utilGBAFindSave(rom, size);
    //    }
    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;

    theApp.emuWriteState = CPUWriteState;
    theApp.emuWriteMemState = CPUWriteMemState;
    theApp.emuReadState = CPUReadState;
    theApp.emuReadMemState = CPUReadMemState;
    theApp.emuWriteBattery = CPUWriteBatteryFile;
    theApp.emuReadBattery = CPUReadBatteryFile;
    theApp.emuReset = CPUReset;
    theApp.emuCleanUp = CPUCleanUp;
    theApp.emuWritePNG = CPUWritePNGFile;
    theApp.emuWriteBMP = CPUWriteBMPFile;
    theApp.emuMain = CPULoop;
#ifdef FINAL_VERSION
    theApp.emuCount = 250000;
#else
    theApp.emuCount = 5000;
#endif
    if(theApp.removeIntros && rom != NULL) {
      *((u32 *)rom)= 0xea00002e;
    }
    
    if(theApp.autoIPS) {
      int size = 0x2000000;
      utilApplyIPS(ipsname, &rom, &size);
      if(size != 0x2000000) {
        CPUReset();
      }
    }
  }
    
  if(theApp.soundInitialized) {
    if(theApp.cartridgeType == 1)
      gbSoundReset();
    else
      soundReset();
  } else {
    if(!soundOffFlag)
      soundInit();
    theApp.soundInitialized = true;
  }

  if(type == IMAGE_GBA) {
    skipBios = theApp.skipBiosFile ? true : false;
    CPUInit((char *)(LPCTSTR)theApp.biosFileName, theApp.useBiosFile ? true : false);
    CPUReset();
  }
  
  readBatteryFile();

  if(theApp.autoSaveLoadCheatList)
    winLoadCheatListDefault();
  
  theApp.addRecentFile(theApp.szFile);

  theApp.updateWindowSize(theApp.videoOption);

  theApp.updateFrameSkip();

  if(theApp.autoHideMenu && theApp.videoOption > VIDEO_4X && theApp.menuToggle)
    OnFileTogglemenu();
 
  emulating = true;

  if(theApp.autoLoadMostRecent)
    OnFileLoadgameMostrecent();

  theApp.frameskipadjust = 0;
  theApp.renderedFrames = 0;
  theApp.autoFrameSkipLastTime = theApp.throttleLastTime = systemGetClock();

  theApp.rewindCount = 0;
  theApp.rewindCounter = 0;
  theApp.rewindSaveNeeded = false;
  
  theApp.disablePowerManagement();
  
  return true;
}
Exemple #6
0
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;
}