Tidy up SetupWiiMemory

This commit is contained in:
Matthew Parlane 2014-02-07 17:26:50 +13:00
parent 70e2ed320d
commit 6b980cbf30
3 changed files with 47 additions and 58 deletions

View File

@ -22,6 +22,10 @@ public:
INITIAL_SEED = 0x73B5DBFA INITIAL_SEED = 0x73B5DBFA
}; };
inline void AddSetting(const char *key, const std::string& value)
{
AddSetting(key, value.c_str());
}
void AddSetting(const char *key, const char *value); void AddSetting(const char *key, const char *value);
const u8 *GetData() const; const u8 *GetData() const;

View File

@ -10,6 +10,17 @@
#include "../CoreParameter.h" #include "../CoreParameter.h"
#include "Volume.h"
using DiscIO::IVolume;
typedef struct CountrySetting
{
const std::string area;
const std::string video;
const std::string game;
const std::string code;
} CountrySetting;
class CBoot class CBoot
{ {
public: public:
@ -45,7 +56,7 @@ private:
static bool Load_BS2(const std::string& _rBootROMFilename); static bool Load_BS2(const std::string& _rBootROMFilename);
static void Load_FST(bool _bIsWii); static void Load_FST(bool _bIsWii);
static bool SetupWiiMemory(unsigned int _CountryCode); static bool SetupWiiMemory(IVolume::ECountry country);
}; };
#endif #endif

View File

@ -158,56 +158,28 @@ bool CBoot::EmulatedBS2_GC()
return true; return true;
} }
bool CBoot::SetupWiiMemory(unsigned int _CountryCode) bool CBoot::SetupWiiMemory(IVolume::ECountry country)
{ {
INFO_LOG(BOOT, "Setup Wii Memory..."); static const CountrySetting SETTING_EUROPE = {"EUR", "PAL", "EU", "LE"};
static const std::map<IVolume::ECountry, const CountrySetting&> country_settings = {
// Write the 256 byte setting.txt to memory. {IVolume::COUNTRY_EUROPE, SETTING_EUROPE},
std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING); {IVolume::COUNTRY_USA, {"USA", "NTSC", "US", "LU"}},
std::string area, model, code, video, game; {IVolume::COUNTRY_JAPAN, {"JPN", "NTSC", "JP", "LJ"}},
{IVolume::COUNTRY_KOREA, {"KOR", "NTSC", "KR", "LKH"}},
switch((DiscIO::IVolume::ECountry)_CountryCode)
{
case DiscIO::IVolume::COUNTRY_KOREA:
area = "KOR";
video = "NTSC";
game = "KR";
code = "LKH";
break;
case DiscIO::IVolume::COUNTRY_TAIWAN:
//TODO: Determine if Taiwan have their own specific settings. //TODO: Determine if Taiwan have their own specific settings.
case DiscIO::IVolume::COUNTRY_JAPAN: // Also determine if there are other specific settings
area = "JPN"; // for other countries.
video = "NTSC"; {IVolume::COUNTRY_TAIWAN, {"JPN", "NTSC", "JP", "LJ"}}
game = "JP"; };
code = "LJ"; auto entryPos = country_settings.find(country);
break; const CountrySetting& country_setting =
case DiscIO::IVolume::COUNTRY_USA: (entryPos != country_settings.end()) ?
area = "USA"; entryPos->second :
video = "NTSC"; SETTING_EUROPE; //Default to EUROPE
game = "US";
code = "LU";
break;
case DiscIO::IVolume::COUNTRY_EUROPE:
area = "EUR";
video = "PAL";
game = "EU";
code = "LE";
break;
default:
// PanicAlertT("SetupWiiMem: Unknown country. Wii boot process will be switched to European settings.");
area = "EUR";
video = "PAL";
game = "EU";
code = "LE";
break;
}
model = "RVL-001(" + area + ")";
SettingsHandler gen; SettingsHandler gen;
std::string serno = ""; std::string serno;
std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING);
if (File::Exists(settings_Filename)) if (File::Exists(settings_Filename))
{ {
File::IOFile settingsFileHandle(settings_Filename, "rb"); File::IOFile settingsFileHandle(settings_Filename, "rb");
@ -230,29 +202,31 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
INFO_LOG(BOOT, "Using serial number: %s", serno.c_str()); INFO_LOG(BOOT, "Using serial number: %s", serno.c_str());
} }
gen.AddSetting("AREA", area.c_str()); std::string model = "RVL-001(" + country_setting.area + ")";
gen.AddSetting("MODEL", model.c_str()); gen.AddSetting("AREA", country_setting.area);
gen.AddSetting("MODEL", model);
gen.AddSetting("DVD", "0"); gen.AddSetting("DVD", "0");
gen.AddSetting("MPCH", "0x7FFE"); gen.AddSetting("MPCH", "0x7FFE");
gen.AddSetting("CODE", code.c_str()); gen.AddSetting("CODE", country_setting.code);
gen.AddSetting("SERNO", serno.c_str()); gen.AddSetting("SERNO", serno);
gen.AddSetting("VIDEO", video.c_str()); gen.AddSetting("VIDEO", country_setting.video);
gen.AddSetting("GAME", game.c_str()); gen.AddSetting("GAME", country_setting.game);
File::CreateFullPath(settings_Filename); File::CreateFullPath(settings_Filename);
{ {
File::IOFile settingsFileHandle(settings_Filename, "wb"); File::IOFile settingsFileHandle(settings_Filename, "wb");
if (!settingsFileHandle.WriteBytes(gen.GetData(), SettingsHandler::SETTINGS_SIZE)) if (!settingsFileHandle.WriteBytes(gen.GetData(), SettingsHandler::SETTINGS_SIZE))
{ {
PanicAlertT("SetupWiiMem: Cant create setting file"); PanicAlertT("SetupWiiMemory: Cant create setting.txt file");
return false; return false;
} }
// Write the 256 byte setting.txt to memory.
Memory::WriteBigEData(gen.GetData(), 0x3800, SettingsHandler::SETTINGS_SIZE); Memory::WriteBigEData(gen.GetData(), 0x3800, SettingsHandler::SETTINGS_SIZE);
} }
INFO_LOG(BOOT, "Setup Wii Memory...");
/* /*
Set hardcoded global variables to Wii memory. These are partly collected from Set hardcoded global variables to Wii memory. These are partly collected from
Wiibrew. These values are needed for the games to function correctly. A few Wiibrew. These values are needed for the games to function correctly. A few