1
// Copyright 2013 Dolphin Emulator Project
2
// Licensed under GPLv2
3
// Refer to the license.txt file included.
6
#include "CommonPaths.h"
8
#include "StringUtil.h"
10
#include "NANDContentLoader.h"
12
#include "VolumeCreator.h" // DiscIO
14
#include "Boot/Boot.h" // Core
15
#include "Boot/Boot_DOL.h"
16
#include "CoreParameter.h"
17
#include "ConfigManager.h"
18
#include "Core.h" // for bWii
19
#include "FifoPlayer/FifoDataFile.h"
21
SCoreStartupParameter::SCoreStartupParameter()
23
bEnableDebugging(false), bAutomaticStart(false), bBootToPause(false),
24
bJITNoBlockCache(false), bJITBlockLinking(true),
26
bJITLoadStoreOff(false), bJITLoadStorelXzOff(false),
27
bJITLoadStorelwzOff(false), bJITLoadStorelbzxOff(false),
28
bJITLoadStoreFloatingOff(false), bJITLoadStorePairedOff(false),
29
bJITFloatingPointOff(false), bJITIntegerOff(false),
30
bJITPairedOff(false), bJITSystemRegistersOff(false),
32
bJITILTimeProfiling(false), bJITILOutputIR(false),
34
bCPUThread(true), bDSPThread(false), bDSPHLE(true),
35
bSkipIdle(true), bNTSC(false), bForceNTSCJ(false),
36
bHLE_BS2(true), bEnableCheats(false),
37
bMergeBlocks(false), bEnableMemcardSaving(true),
38
bDPL2Decoder(false), iLatency(14),
39
bRunCompareServer(false), bRunCompareClient(false),
40
bMMU(false), bDCBZOFF(false), bTLBHack(false), iBBDumpPort(0), bVBeamSpeedHack(false),
41
bSyncGPU(false), bFastDiscSpeed(false),
42
SelectedLanguage(0), bWii(false),
43
bConfirmStop(false), bHideCursor(false),
44
bAutoHideCursor(false), bUsePanicHandlers(true), bOnScreenDisplayMessages(true),
45
iRenderWindowXPos(-1), iRenderWindowYPos(-1),
46
iRenderWindowWidth(640), iRenderWindowHeight(480),
47
bRenderWindowAutoSize(false), bKeepWindowOnTop(false),
48
bFullscreen(false), bRenderToMain(false),
49
bProgressive(false), bDisableScreenSaver(false),
50
iPosX(100), iPosY(100), iWidth(800), iHeight(600),
56
void SCoreStartupParameter::LoadDefaults()
58
bEnableDebugging = false;
59
bAutomaticStart = false;
69
bRunCompareServer = false;
78
bVBeamSpeedHack = false;
80
bFastDiscSpeed = false;
82
bEnableMemcardSaving = true;
93
bLoopFifoReplay = true;
95
bJITOff = false; // debugger only settings
96
bJITLoadStoreOff = false;
97
bJITLoadStoreFloatingOff = false;
98
bJITLoadStorePairedOff = false; // XXX not 64-bit clean
99
bJITFloatingPointOff = false;
100
bJITIntegerOff = false;
101
bJITPairedOff = false;
102
bJITSystemRegistersOff = false;
105
m_strUniqueID = "00000000";
108
bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
110
std::string Region(EUR_DIR);
116
bool bootDrive = cdio_is_cdrom(m_strFilename);
117
// Check if the file exist, we may have gotten it from a --elf command line
118
// that gave an incorrect file name
119
if (!bootDrive && !File::Exists(m_strFilename))
121
PanicAlertT("The specified file \"%s\" does not exist", m_strFilename.c_str());
125
std::string Extension;
126
SplitPath(m_strFilename, NULL, NULL, &Extension);
127
if (!strcasecmp(Extension.c_str(), ".gcm") ||
128
!strcasecmp(Extension.c_str(), ".iso") ||
129
!strcasecmp(Extension.c_str(), ".wbfs") ||
130
!strcasecmp(Extension.c_str(), ".ciso") ||
131
!strcasecmp(Extension.c_str(), ".gcz") ||
134
m_BootType = BOOT_ISO;
135
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
139
PanicAlertT("Could not read \"%s\". "
140
"There is no disc in the drive, or it is not a GC/Wii backup. "
141
"Please note that original Gamecube and Wii discs cannot be read "
142
"by most PC DVD drives.", m_strFilename.c_str());
144
PanicAlertT("\"%s\" is an invalid GCM/ISO file, or is not a GC/Wii ISO.",
145
m_strFilename.c_str());
148
m_strName = pVolume->GetName();
149
m_strUniqueID = pVolume->GetUniqueID();
150
m_strRevisionSpecificUniqueID = pVolume->GetRevisionSpecificUniqueID();
152
// Check if we have a Wii disc
153
bWii = DiscIO::IsVolumeWiiDisc(pVolume);
154
switch (pVolume->GetCountry())
156
case DiscIO::IVolume::COUNTRY_USA:
161
case DiscIO::IVolume::COUNTRY_TAIWAN:
162
case DiscIO::IVolume::COUNTRY_KOREA:
163
// TODO: Should these have their own Region Dir?
164
case DiscIO::IVolume::COUNTRY_JAPAN:
169
case DiscIO::IVolume::COUNTRY_EUROPE:
170
case DiscIO::IVolume::COUNTRY_FRANCE:
171
case DiscIO::IVolume::COUNTRY_ITALY:
172
case DiscIO::IVolume::COUNTRY_RUSSIA:
178
if (PanicYesNoT("Your GCM/ISO file seems to be invalid (invalid country)."
179
"\nContinue with PAL region?"))
189
else if (!strcasecmp(Extension.c_str(), ".elf"))
191
bWii = CBoot::IsElfWii(m_strFilename.c_str());
193
m_BootType = BOOT_ELF;
196
else if (!strcasecmp(Extension.c_str(), ".dol"))
198
CDolLoader dolfile(m_strFilename.c_str());
199
bWii = dolfile.IsWii();
201
m_BootType = BOOT_DOL;
204
else if (!strcasecmp(Extension.c_str(), ".dff"))
209
m_BootType = BOOT_DFF;
211
FifoDataFile *ddfFile = FifoDataFile::Load(m_strFilename.c_str(), true);
215
bWii = ddfFile->GetIsWii();
219
else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid())
221
const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
222
const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename);
224
if (ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex()) == NULL)
226
//WAD is valid yet cannot be booted. Install instead.
227
u64 installed = DiscIO::CNANDContentManager::Access().Install_WiiWAD(m_strFilename);
229
SuccessAlertT("The WAD has been installed successfully");
230
return false; //do not boot
233
switch (ContentLoader.GetCountry())
235
case DiscIO::IVolume::COUNTRY_USA:
240
case DiscIO::IVolume::COUNTRY_TAIWAN:
241
case DiscIO::IVolume::COUNTRY_KOREA:
242
// TODO: Should these have their own Region Dir?
243
case DiscIO::IVolume::COUNTRY_JAPAN:
248
case DiscIO::IVolume::COUNTRY_EUROPE:
249
case DiscIO::IVolume::COUNTRY_FRANCE:
250
case DiscIO::IVolume::COUNTRY_ITALY:
251
case DiscIO::IVolume::COUNTRY_RUSSIA:
263
m_BootType = BOOT_WII_NAND;
267
m_strName = pVolume->GetName();
268
m_strUniqueID = pVolume->GetUniqueID();
272
{ // null pVolume means that we are loading from nand folder (Most Likely Wii Menu)
273
// if this is the second boot we would be using the Name and id of the last title
275
m_strUniqueID.clear();
278
// Use the TitleIDhex for name and/or unique ID if launching from nand folder
279
// or if it is not ascii characters (specifically sysmenu could potentially apply to other things)
281
snprintf(titleidstr, 17, "%016llx", ContentLoader.GetTitleID());
283
if (!m_strName.length())
285
m_strName = titleidstr;
287
if (!m_strUniqueID.length())
289
m_strUniqueID = titleidstr;
295
PanicAlertT("Could not recognize ISO file %s", m_strFilename.c_str());
303
m_strFilename.clear();
309
m_strFilename.clear();
315
m_strFilename.clear();
321
CheckMemcardPath(SConfig::GetInstance().m_strMemoryCardA, Region, true);
322
CheckMemcardPath(SConfig::GetInstance().m_strMemoryCardB, Region, false);
323
m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
326
m_strBootROM = File::GetUserPath(D_GCUSER_IDX) + DIR_SEP + Region + DIR_SEP GC_IPL;
327
if (!File::Exists(m_strBootROM))
328
m_strBootROM = File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + Region + DIR_SEP GC_IPL;
332
if (!File::Exists(m_strBootROM))
334
WARN_LOG(BOOT, "Bootrom file %s not found - using HLE.", m_strBootROM.c_str());
339
else if (bWii && !bHLE_BS2)
341
WARN_LOG(BOOT, "GC bootrom file will not be loaded for Wii mode.");
348
void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::string gameRegion, bool isSlotA)
350
std::string ext("." + gameRegion + ".raw");
351
if (memcardPath.empty())
353
// Use default memcard path if there is no user defined name
354
std::string defaultFilename = isSlotA ? GC_MEMCARDA : GC_MEMCARDB;
355
memcardPath = File::GetUserPath(D_GCUSER_IDX) + defaultFilename + ext;
359
std::string filename = memcardPath;
360
std::string region = filename.substr(filename.size()-7, 3);
361
bool hasregion = false;
362
hasregion |= region.compare(USA_DIR) == 0;
363
hasregion |= region.compare(JAP_DIR) == 0;
364
hasregion |= region.compare(EUR_DIR) == 0;
367
// filename doesn't have region in the extension
368
if (File::Exists(filename))
370
// If the old file exists we are polite and ask if we should copy it
371
std::string oldFilename = filename;
372
filename.replace(filename.size()-4, 4, ext);
373
if (PanicYesNoT("Memory Card filename in Slot %c is incorrect\n"
374
"Region not specified\n\n"
375
"Slot %c path was changed to\n"
377
"Would you like to copy the old file to this new location?\n",
378
isSlotA ? 'A':'B', isSlotA ? 'A':'B', filename.c_str()))
380
if (!File::Copy(oldFilename, filename))
381
PanicAlertT("Copy failed");
384
memcardPath = filename; // Always correct the path!
386
else if (region.compare(gameRegion) != 0)
388
// filename has region, but it's not == gameRegion
389
// Just set the correct filename, the EXI Device will create it if it doesn't exist
390
memcardPath = filename.replace(filename.size()-ext.size(), ext.size(), ext);;
395
IniFile SCoreStartupParameter::LoadGameIni() const
398
game_ini.Load(m_strGameIniDefault);
399
if (m_strGameIniDefaultRevisionSpecific != "")
400
game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
401
game_ini.Load(m_strGameIniLocal, true);
405
IniFile SCoreStartupParameter::LoadDefaultGameIni() const
408
game_ini.Load(m_strGameIniDefault);
409
if (m_strGameIniDefaultRevisionSpecific != "")
410
game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
414
IniFile SCoreStartupParameter::LoadLocalGameIni() const
417
game_ini.Load(m_strGameIniLocal);