~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/Core/Src/CoreParameter.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#include "Common.h"
 
6
#include "CommonPaths.h"
 
7
#include "FileUtil.h"
 
8
#include "StringUtil.h"
 
9
#include "CDUtils.h"
 
10
#include "NANDContentLoader.h"
 
11
 
 
12
#include "VolumeCreator.h" // DiscIO
 
13
 
 
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"
 
20
 
 
21
SCoreStartupParameter::SCoreStartupParameter()
 
22
: hInstance(0),
 
23
  bEnableDebugging(false), bAutomaticStart(false), bBootToPause(false),
 
24
  bJITNoBlockCache(false), bJITBlockLinking(true),
 
25
  bJITOff(false),
 
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),
 
31
  bJITBranchOff(false),
 
32
  bJITILTimeProfiling(false), bJITILOutputIR(false),
 
33
  bEnableFPRF(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),
 
51
  bLoopFifoReplay(true)
 
52
{
 
53
        LoadDefaults();
 
54
}
 
55
 
 
56
void SCoreStartupParameter::LoadDefaults()
 
57
{
 
58
        bEnableDebugging = false;
 
59
        bAutomaticStart = false;
 
60
        bBootToPause = false;
 
61
 
 
62
        #ifdef USE_GDBSTUB
 
63
        iGDBPort = -1;
 
64
        #endif
 
65
 
 
66
        iCPUCore = 1;
 
67
        bCPUThread = false;
 
68
        bSkipIdle = false;
 
69
        bRunCompareServer = false;
 
70
        bDSPHLE = true;
 
71
        bDSPThread = true;
 
72
        bFastmem = true;
 
73
        bEnableFPRF = false;
 
74
        bMMU = false;
 
75
        bDCBZOFF = false;
 
76
        bTLBHack = false;
 
77
        iBBDumpPort = -1;
 
78
        bVBeamSpeedHack = false;
 
79
        bSyncGPU = false;
 
80
        bFastDiscSpeed = false;
 
81
        bMergeBlocks = false;
 
82
        bEnableMemcardSaving = true;
 
83
        SelectedLanguage = 0;
 
84
        bWii = false;
 
85
        bDPL2Decoder = false;
 
86
        iLatency = 14;
 
87
 
 
88
        iPosX = 100;
 
89
        iPosY = 100;
 
90
        iWidth = 800;
 
91
        iHeight = 600;
 
92
 
 
93
        bLoopFifoReplay = true;
 
94
 
 
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;
 
103
 
 
104
        m_strName = "NONE";
 
105
        m_strUniqueID = "00000000";
 
106
}
 
107
 
 
108
bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
 
109
{
 
110
        std::string Region(EUR_DIR);
 
111
 
 
112
        switch (_BootBS2)
 
113
        {
 
114
        case BOOT_DEFAULT:
 
115
                {
 
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))
 
120
                        {
 
121
                                PanicAlertT("The specified file \"%s\" does not exist", m_strFilename.c_str());
 
122
                                return false;
 
123
                        }
 
124
 
 
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") ||
 
132
                                bootDrive)
 
133
                        {
 
134
                                m_BootType = BOOT_ISO;
 
135
                                DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
 
136
                                if (pVolume == NULL)
 
137
                                {
 
138
                                        if (bootDrive)
 
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());
 
143
                                        else
 
144
                                                PanicAlertT("\"%s\" is an invalid GCM/ISO file, or is not a GC/Wii ISO.",
 
145
                                                                m_strFilename.c_str());
 
146
                                        return false;
 
147
                                }
 
148
                                m_strName = pVolume->GetName();
 
149
                                m_strUniqueID = pVolume->GetUniqueID();
 
150
                                m_strRevisionSpecificUniqueID = pVolume->GetRevisionSpecificUniqueID();
 
151
 
 
152
                                // Check if we have a Wii disc
 
153
                                bWii = DiscIO::IsVolumeWiiDisc(pVolume);
 
154
                                switch (pVolume->GetCountry())
 
155
                                {
 
156
                                case DiscIO::IVolume::COUNTRY_USA:
 
157
                                        bNTSC = true;
 
158
                                        Region = USA_DIR;
 
159
                                        break;
 
160
 
 
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:
 
165
                                        bNTSC = true;
 
166
                                        Region = JAP_DIR;
 
167
                                        break;
 
168
 
 
169
                                case DiscIO::IVolume::COUNTRY_EUROPE:
 
170
                                case DiscIO::IVolume::COUNTRY_FRANCE:
 
171
                                case DiscIO::IVolume::COUNTRY_ITALY:
 
172
                                case DiscIO::IVolume::COUNTRY_RUSSIA:
 
173
                                        bNTSC = false;
 
174
                                        Region = EUR_DIR;
 
175
                                        break;
 
176
 
 
177
                                default:
 
178
                                        if (PanicYesNoT("Your GCM/ISO file seems to be invalid (invalid country)."
 
179
                                                                   "\nContinue with PAL region?"))
 
180
                                        {
 
181
                                                bNTSC = false;
 
182
                                                Region = EUR_DIR;
 
183
                                                break;
 
184
                                        }else return false;
 
185
                                }
 
186
 
 
187
                                delete pVolume;
 
188
                        }
 
189
                        else if (!strcasecmp(Extension.c_str(), ".elf"))
 
190
                        {
 
191
                                bWii = CBoot::IsElfWii(m_strFilename.c_str());
 
192
                                Region = USA_DIR;
 
193
                                m_BootType = BOOT_ELF;
 
194
                                bNTSC = true;
 
195
                        }
 
196
                        else if (!strcasecmp(Extension.c_str(), ".dol"))
 
197
                        {
 
198
                                CDolLoader dolfile(m_strFilename.c_str());
 
199
                                bWii = dolfile.IsWii();
 
200
                                Region = USA_DIR;
 
201
                                m_BootType = BOOT_DOL;
 
202
                                bNTSC = true;
 
203
                        }
 
204
                        else if (!strcasecmp(Extension.c_str(), ".dff"))
 
205
                        {
 
206
                                bWii = true;
 
207
                                Region = USA_DIR;
 
208
                                bNTSC = true;
 
209
                                m_BootType = BOOT_DFF;
 
210
 
 
211
                                FifoDataFile *ddfFile = FifoDataFile::Load(m_strFilename.c_str(), true);
 
212
 
 
213
                                if (ddfFile)
 
214
                                {
 
215
                                        bWii = ddfFile->GetIsWii();
 
216
                                        delete ddfFile;
 
217
                                }
 
218
                        }
 
219
                        else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid())
 
220
                        {
 
221
                                const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename.c_str());
 
222
                                const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename);
 
223
 
 
224
                                if (ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex()) == NULL)
 
225
                                {
 
226
                                        //WAD is valid yet cannot be booted. Install instead.
 
227
                                        u64 installed = DiscIO::CNANDContentManager::Access().Install_WiiWAD(m_strFilename);
 
228
                                        if (installed)
 
229
                                                SuccessAlertT("The WAD has been installed successfully");
 
230
                                        return false; //do not boot
 
231
                                }
 
232
 
 
233
                                switch (ContentLoader.GetCountry())
 
234
                                {
 
235
                                case DiscIO::IVolume::COUNTRY_USA:
 
236
                                        bNTSC = true;
 
237
                                        Region = USA_DIR;
 
238
                                        break;
 
239
 
 
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:
 
244
                                        bNTSC = true;
 
245
                                        Region = JAP_DIR;
 
246
                                        break;
 
247
 
 
248
                                case DiscIO::IVolume::COUNTRY_EUROPE:
 
249
                                case DiscIO::IVolume::COUNTRY_FRANCE:
 
250
                                case DiscIO::IVolume::COUNTRY_ITALY:
 
251
                                case DiscIO::IVolume::COUNTRY_RUSSIA:
 
252
                                        bNTSC = false;
 
253
                                        Region = EUR_DIR;
 
254
                                        break;
 
255
 
 
256
                                default:
 
257
                                        bNTSC = false;
 
258
                                        Region = EUR_DIR;
 
259
                                                break;
 
260
                                }
 
261
 
 
262
                                bWii = true;
 
263
                                m_BootType = BOOT_WII_NAND;
 
264
 
 
265
                                if (pVolume)
 
266
                                {
 
267
                                        m_strName = pVolume->GetName();
 
268
                                        m_strUniqueID = pVolume->GetUniqueID();
 
269
                                        delete pVolume;
 
270
                                }
 
271
                                else
 
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
 
274
                                        m_strName.clear();
 
275
                                        m_strUniqueID.clear();
 
276
                                }
 
277
 
 
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)
 
280
                                char titleidstr[17];
 
281
                                snprintf(titleidstr, 17, "%016llx", ContentLoader.GetTitleID());
 
282
 
 
283
                                if (!m_strName.length())
 
284
                                {
 
285
                                        m_strName = titleidstr;
 
286
                                }
 
287
                                if (!m_strUniqueID.length())
 
288
                                {
 
289
                                        m_strUniqueID = titleidstr;
 
290
                                }
 
291
 
 
292
                        }
 
293
                        else
 
294
                        {
 
295
                                PanicAlertT("Could not recognize ISO file %s", m_strFilename.c_str());
 
296
                                return false;
 
297
                        }
 
298
                }
 
299
                break;
 
300
 
 
301
        case BOOT_BS2_USA:
 
302
                Region = USA_DIR;
 
303
                m_strFilename.clear();
 
304
                bNTSC = true;
 
305
                break;
 
306
 
 
307
        case BOOT_BS2_JAP:
 
308
                Region = JAP_DIR;
 
309
                m_strFilename.clear();
 
310
                bNTSC = true;
 
311
                break;
 
312
 
 
313
        case BOOT_BS2_EUR:
 
314
                Region = EUR_DIR;
 
315
                m_strFilename.clear();
 
316
                bNTSC = false;
 
317
                break;
 
318
        }
 
319
 
 
320
        // Setup paths
 
321
        CheckMemcardPath(SConfig::GetInstance().m_strMemoryCardA, Region, true);
 
322
        CheckMemcardPath(SConfig::GetInstance().m_strMemoryCardB, Region, false);
 
323
        m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
 
324
        if (!bWii)
 
325
        {
 
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;
 
329
 
 
330
                if (!bHLE_BS2)
 
331
                {
 
332
                        if (!File::Exists(m_strBootROM))
 
333
                        {
 
334
                                WARN_LOG(BOOT, "Bootrom file %s not found - using HLE.", m_strBootROM.c_str());
 
335
                                bHLE_BS2 = true;
 
336
                        }
 
337
                }
 
338
        }
 
339
        else if (bWii && !bHLE_BS2)
 
340
        {
 
341
                WARN_LOG(BOOT, "GC bootrom file will not be loaded for Wii mode.");
 
342
                bHLE_BS2 = true;
 
343
        }
 
344
 
 
345
        return true;
 
346
}
 
347
 
 
348
void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::string gameRegion, bool isSlotA)
 
349
{
 
350
        std::string ext("." + gameRegion + ".raw");
 
351
        if (memcardPath.empty())
 
352
        {
 
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;
 
356
        }
 
357
        else
 
358
        {
 
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;
 
365
                if (!hasregion)
 
366
                {
 
367
                        // filename doesn't have region in the extension
 
368
                        if (File::Exists(filename))
 
369
                        {
 
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"
 
376
                                        "%s\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()))
 
379
                                {
 
380
                                        if (!File::Copy(oldFilename, filename))
 
381
                                                PanicAlertT("Copy failed");
 
382
                                }
 
383
                        }
 
384
                        memcardPath = filename; // Always correct the path!
 
385
                }
 
386
                else if (region.compare(gameRegion) != 0)
 
387
                {
 
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);;
 
391
                }
 
392
        }
 
393
}
 
394
 
 
395
IniFile SCoreStartupParameter::LoadGameIni() const
 
396
{
 
397
        IniFile game_ini;
 
398
        game_ini.Load(m_strGameIniDefault);
 
399
        if (m_strGameIniDefaultRevisionSpecific != "")
 
400
                game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
 
401
        game_ini.Load(m_strGameIniLocal, true);
 
402
        return game_ini;
 
403
}
 
404
 
 
405
IniFile SCoreStartupParameter::LoadDefaultGameIni() const
 
406
{
 
407
        IniFile game_ini;
 
408
        game_ini.Load(m_strGameIniDefault);
 
409
        if (m_strGameIniDefaultRevisionSpecific != "")
 
410
                game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
 
411
        return game_ini;
 
412
}
 
413
 
 
414
IniFile SCoreStartupParameter::LoadLocalGameIni() const
 
415
{
 
416
        IniFile game_ini;
 
417
        game_ini.Load(m_strGameIniLocal);
 
418
        return game_ini;
 
419
}