Skip to content

Commit

Permalink
Add basic individual save function
Browse files Browse the repository at this point in the history
If the first file can be read or written successfully, the following ones will no longer be processed.

1:Read or save settings in the following order.
usb:/wiisxrx/settings/GameId.cfg
sd:/wiisxrx/settings/GameId.cfg

2:When switching games, read settings in the following order.
usb:/wiisxrx/settings/GameId.cfg
sd:/wiisxrx/settings/GameId.cfg
usb:/wiisxrx/settingsRX2022.cfg
sd:/wiisxrx/settingsRX2022.cfg
  • Loading branch information
xjsxjs197 committed Nov 19, 2023
1 parent 987777e commit ea714bc
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 52 deletions.
101 changes: 89 additions & 12 deletions Gamecube/GamecubeMain.cpp
Expand Up @@ -148,6 +148,7 @@ char smbShareName[CONFIG_STRING_SIZE];
char smbIpAddr[CONFIG_STRING_SIZE];

int stop = 0;
bool needInitCpu = true;

static struct {
const char* key;
Expand Down Expand Up @@ -227,6 +228,8 @@ void handleConfigPair(char* kv);
void readConfig(FILE* f);
void writeConfig(FILE* f);
int checkBiosExists(int testDevice);
void loadSeparatelySetting();
bool loadSeparatelySettingItem(char* s1, char* s2, bool isUsb);

void loadSettings(int argc, char *argv[])
{
Expand Down Expand Up @@ -530,11 +533,6 @@ int main(int argc, char *argv[])
memset(AutobootROM, 0, sizeof(AutobootROM));
}

if (Config.Cpu == DYNACORE_DYNAREC)
{
VM_Init(1024*1024, 256*1024); // whatever for now, we're not really using this for anything other than mmap on Wii.
}

L2Enhance();

u32 ios = IOS_GetVersion();
Expand All @@ -553,6 +551,10 @@ int main(int argc, char *argv[])

loadSettings(argc, argv);

#ifdef HW_RVL
VM_Init(1024*1024, 256*1024); // whatever for now, we're not really using this for anything other than mmap on Wii.
#endif // HW_RVL

LoadLanguage();
ChangeLanguage();

Expand Down Expand Up @@ -600,6 +602,83 @@ int main(int argc, char *argv[])
return 0;
}

void psxCpuInit()
{
if (Config.Cpu == DYNACORE_INTERPRETER) {
psxCpu = &psxInt;
}
#if defined(__x86_64__) || defined(__i386__) || defined(__sh__) || defined(__ppc__) || defined(HW_RVL) || defined(HW_DOL)
if (Config.Cpu == DYNACORE_DYNAREC)
{
psxCpu = &psxLightrec;
}
if (Config.Cpu == DYNACORE_DYNAREC_OLD)
{
psxCpu = &psxRec;
}
#endif

psxCpu->Init();
}

bool loadSeparatelySettingItem(char* s1, char* s2, bool isUsb)
{
struct stat s;
char settingPathBuf[256];
fileBrowser_file* configFile_file;
sprintf(settingPathBuf, "%s%s%s", s1, s2, ".cfg");
if (stat(settingPathBuf, &s))
{
return false;
}

configFile_file = isUsb ? &saveDir_libfat_USB : &saveDir_libfat_Default;
int (*configFile_init)(fileBrowser_file*) = fileBrowser_libfat_init;
if (configFile_init(configFile_file)) { //only if device initialized ok
FILE* f = fopen( settingPathBuf, "r" ); //attempt to open file
if (f) {
readConfig(f);
fclose(f);
return true;
}
}
return false;
}

void loadSeparatelySetting()
{
// first load Separately Setting from usb
if (!loadSeparatelySettingItem("usb:/wiisxrx/settings/", CdromId, true))
{
// load Separately Setting from sd
if (!loadSeparatelySettingItem("sd:/wiisxrx/settings/", CdromId, false))
{
// load common Setting from usb
if (!loadSeparatelySettingItem("usb:/wiisxrx/", "settingsRX2022", true))
{
// load common Setting from sd
loadSeparatelySettingItem("sd:/wiisxrx/", "settingsRX2022", false);
}
}
}

Config.pR3000Fix = 0;
Config.Cpu = dynacore;
if (biosDevice == BIOSDEVICE_HLE) {
Config.HLE = BIOS_HLE;
} else {
Config.HLE = BIOS_USER_DEFINED;
}

extern bool lightrec_mmap_inited;
if (Config.Cpu == DYNACORE_DYNAREC && !lightrec_mmap_inited) // Lightrec
{
psxMemInit();
}
psxCpuInit();
needInitCpu = true;
}

// loadISO loads an ISO file as current media to read from.
int loadISOSwap(fileBrowser_file* file) {

Expand All @@ -621,6 +700,8 @@ int loadISOSwap(fileBrowser_file* file) {

CheckCdrom();

loadSeparatelySetting();

swapIso = true;
LoadCdrom();

Expand All @@ -644,6 +725,7 @@ int loadISO(fileBrowser_file* file)
SysClose();
hasLoadedISO = FALSE;
}
needInitCpu = false;
if(SysInit() < 0)
return -1;
hasLoadedISO = TRUE;
Expand All @@ -654,14 +736,9 @@ int loadISO(fileBrowser_file* file)
Load(file);
}
else {
long lastPsxType = Config.PsxType;
CheckCdrom();
// if (Config.PsxType != lastPsxType)
// {
// SysClose();
// SysInit();
// CheckCdrom();
// }

loadSeparatelySetting();

SysReset();
LoadCdrom();
Expand Down
5 changes: 5 additions & 0 deletions Gamecube/menu/FileBrowserFrame.cpp
Expand Up @@ -652,6 +652,11 @@ static void CheckGameAutoFix(void)

static void CheckGameR3000AutoFix(void)
{
if (Config.Cpu != DYNACORE_DYNAREC_OLD)
{
return;
}

int autoFixR3000Len = 8;
char autoFixR3000JR[autoFixR3000Len][10] = {
"SLES00037" // Alone in the Dark - Jack is Back
Expand Down
70 changes: 62 additions & 8 deletions Gamecube/menu/SettingsFrame.cpp
Expand Up @@ -64,6 +64,7 @@ void Func_ExecuteBios();
void Func_SelectLanguage();
void Func_SaveSettingsSD();
void Func_SaveSettingsUSB();
void Func_SaveSettingsSeparately();

void Func_ShowFpsOn();
void Func_ShowFpsOff();
Expand Down Expand Up @@ -139,7 +140,7 @@ void IplFont_loadFontFile(FILE* fontFile);
FILE* IplFont_getFontFile(char* sdUsb);
}

#define NUM_FRAME_BUTTONS 62
#define NUM_FRAME_BUTTONS 63
#define NUM_TAB_BUTTONS 5
#define FRAME_BUTTONS settingsFrameButtons
#define FRAME_STRINGS settingsFrameStrings
Expand Down Expand Up @@ -181,7 +182,7 @@ Auto Save Memcards: Yes; No
Save States Device: SD; USB
*/

static char FRAME_STRINGS[77][24] =
static char FRAME_STRINGS[78][24] =
{ "General",
"Video",
"Input",
Expand Down Expand Up @@ -251,7 +252,7 @@ static char FRAME_STRINGS[77][24] =
"Es", // SPANISH
"Pte", // PORTUGUESE
"It", // ITALIAN
// Strings for display Fast Load (starting at FRAME_STRINGS[63]) ..was[63]
// Strings for display Fast Load (starting at FRAME_STRINGS[63]) ..was[77]
"Fast Load",
"240p",
"Bilinear",
Expand All @@ -265,7 +266,8 @@ static char FRAME_STRINGS[77][24] =
"Mouse",
"Memcard 1",
"Memcard 2",
"Enable Memcard"
"Enable Memcard",
"Separately"
};

static char LANG_STRINGS[13][24] =
Expand Down Expand Up @@ -318,8 +320,9 @@ struct ButtonInfo
{ NULL, BTN_A_SEL, FRAME_STRINGS[17], 380.0, 240.0, 75.0, 56.0, 8, 54, 11, 13, Func_BootBiosNo, Func_ReturnFromSettingsFrame }, // Boot Thru Bios: No
{ NULL, BTN_A_NRM, FRAME_STRINGS[8], 465.0, 240.0, 180.0, 56.0, 9, 54, 12, 11, Func_ExecuteBios, Func_ReturnFromSettingsFrame }, // Execute Bios

{ NULL, BTN_A_NRM, FRAME_STRINGS[13], 295.0, 380.0, 55.0, 56.0, 54, 0, 15, 15, Func_SaveSettingsSD, Func_ReturnFromSettingsFrame }, // Save Settings: SD
{ NULL, BTN_A_NRM, FRAME_STRINGS[14], 360.0, 380.0, 70.0, 56.0, 54, 0, 14, 14, Func_SaveSettingsUSB, Func_ReturnFromSettingsFrame }, // Save Settings: USB
{ NULL, BTN_A_NRM, FRAME_STRINGS[13], 235.0, 380.0, 55.0, 56.0, 54, 0, 62, 15, Func_SaveSettingsSD, Func_ReturnFromSettingsFrame }, // Save Settings: SD
{ NULL, BTN_A_NRM, FRAME_STRINGS[14], 300.0, 380.0, 70.0, 56.0, 54, 0, 14, 62, Func_SaveSettingsUSB, Func_ReturnFromSettingsFrame }, // Save Settings: USB

//Buttons for Video Tab (starts at button[16])
{ NULL, BTN_A_SEL, FRAME_STRINGS[24], 325.0, 100.0, 75.0, 56.0, 1, 18, 17, 17, Func_ShowFpsOn, Func_ReturnFromSettingsFrame }, // Show FPS: On
{ NULL, BTN_A_SEL, FRAME_STRINGS[25], 420.0, 100.0, 75.0, 56.0, 1, 19, 16, 16, Func_ShowFpsOff, Func_ReturnFromSettingsFrame }, // Show FPS: Off
Expand Down Expand Up @@ -370,7 +373,9 @@ struct ButtonInfo
{ NULL, BTN_A_SEL, FRAME_STRINGS[11], 505.0, 100.0, 130.0, 56.0, 0, 9, 6, 5, Func_CpuDynarec, Func_ReturnFromSettingsFrame }, // CPU: Dynarec
{ NULL, BTN_A_SEL, FRAME_STRINGS[70], 510.0, 170.0, 115.0, 56.0, 31, 35, 33, 32, Func_PsxTypeLightgun, Func_ReturnFromSettingsFrame }, // PSX Controller Type: Lightgun
{ NULL, BTN_A_SEL, FRAME_STRINGS[74], 295.0, 310.0, 155.0, 56.0, 52, 4, 61, 61, Func_Memcard1, Func_ReturnFromSettingsFrame }, // Memcard 1 toggle
{ NULL, BTN_A_SEL, FRAME_STRINGS[75], 460.0, 310.0, 155.0, 56.0, 53, 4, 60, 60, Func_Memcard2, Func_ReturnFromSettingsFrame } // Memcard 2 toggle
{ NULL, BTN_A_SEL, FRAME_STRINGS[75], 460.0, 310.0, 155.0, 56.0, 53, 4, 60, 60, Func_Memcard2, Func_ReturnFromSettingsFrame }, // Memcard 2 toggle

{ NULL, BTN_A_NRM, FRAME_STRINGS[77], 385.0, 380.0, 140.0, 56.0, 54, 0, 15, 14, Func_SaveSettingsSeparately, Func_ReturnFromSettingsFrame }, // Save Settings: Separately
};

struct TextBoxInfo
Expand All @@ -387,7 +392,7 @@ struct TextBoxInfo
{ NULL, FRAME_STRINGS[5], 105.0, 128.0, 1.0, true }, // CPU Core: Pure Interp/Dynarec
{ NULL, FRAME_STRINGS[6], 155.0, 198.0, 1.0, true }, // Bios: HLE/SD/USB/DVD
{ NULL, FRAME_STRINGS[7], 155.0, 268.0, 1.0, true }, // Boot Thru Bios: Yes/No
{ NULL, FRAME_STRINGS[9], 155.0, 408.0, 1.0, true }, // Save settings: SD/USB
{ NULL, FRAME_STRINGS[9], 130.0, 408.0, 1.0, true }, // Save settings: SD/USB
//TextBoxes for Video Tab (starts at textBox[4])
{ NULL, FRAME_STRINGS[18], 190.0, 128.0, 1.0, true }, // Show FPS: On/Off
{ NULL, FRAME_STRINGS[19], 190.0, 188.0, 1.0, true }, // Limit FPS: Auto/Off
Expand Down Expand Up @@ -533,6 +538,10 @@ void SettingsFrame::activateSubmenu(int submenu)
// CPU: Dynarec
FRAME_BUTTONS[58].button->setVisible(true);
FRAME_BUTTONS[58].button->setActive(true);

// Save Settings: Separately
FRAME_BUTTONS[62].button->setVisible(true);
FRAME_BUTTONS[62].button->setActive(hasLoadedISO ? true : false);
break;
case SUBMENU_VIDEO:
setDefaultFocus(FRAME_BUTTONS[1].button);
Expand Down Expand Up @@ -1110,6 +1119,51 @@ void Func_SaveSettingsUSB()
menu::MessageBox::getInstance().setMessage("Error saving settings to USB");
}

void Func_SaveSettingsSeparately()
{
struct stat s;
char settingPathBuf[256];
fileBrowser_file* configFile_file;
extern char CdromId[10];
if (stat("usb:/wiisxrx/", &s)) {
if (stat("sd:/wiisxrx/", &s)) {
menu::MessageBox::getInstance().setMessage("Error opening directory sd:/wiisxrx");
return;
}
else
{
sprintf(settingPathBuf, "%s%s%s", "sd:/wiisxrx/settings/", CdromId, ".cfg");
configFile_file = &saveDir_libfat_Default;
int (*configFile_init)(fileBrowser_file*) = fileBrowser_libfat_init;
if(configFile_init(configFile_file)) { //only if device initialized ok
FILE* f = fopen( settingPathBuf, "wb" ); //attempt to open file
if(f) {
writeConfig(f); //write out the config
fclose(f);
menu::MessageBox::getInstance().setMessage("Saved settings to SD");
return;
}
}
menu::MessageBox::getInstance().setMessage("Error saving settings to SD");
}
}
else
{
printf(settingPathBuf, "%s%s%s", "usb:/wiisxrx/settings/", CdromId, ".cfg");
configFile_file = &saveDir_libfat_USB;
int (*configFile_init)(fileBrowser_file*) = fileBrowser_libfat_init;
if (configFile_init(configFile_file)) { //only if device initialized ok
FILE* f = fopen( settingPathBuf, "wb" ); //attempt to open file
if(f) {
writeConfig(f); //write out the config
fclose(f);
menu::MessageBox::getInstance().setMessage("Saved settings to USB");
return;
}
}
menu::MessageBox::getInstance().setMessage("Error saving settings to USB");
}
}
void Func_ShowFpsOn()
{
for (int i = 16; i <= 17; i++)
Expand Down
3 changes: 3 additions & 0 deletions lang/zh.lang
Expand Up @@ -574,3 +574,6 @@ msgstr "快速加载"

msgid "Because the language has changed, please restart"
msgstr "因为语言变更了,请重新启动"

msgid "Separately"
msgstr "单独保存"
10 changes: 5 additions & 5 deletions ppc/pR3000A.c
Expand Up @@ -813,11 +813,11 @@ static void iJump(u32 branchPC) {
FlushAllHWReg();
CALLFunc((u32)psxBranchTest);

if (!Config.HLE && Config.PsxOut &&
((branchPC & 0x1fffff) == 0xa0 ||
(branchPC & 0x1fffff) == 0xb0 ||
(branchPC & 0x1fffff) == 0xc0))
CALLFunc((u32)psxJumpTest);
// if (!Config.HLE && Config.PsxOut &&
// ((branchPC & 0x1fffff) == 0xa0 ||
// (branchPC & 0x1fffff) == 0xb0 ||
// (branchPC & 0x1fffff) == 0xc0))
// CALLFunc((u32)psxJumpTest);

// always return for now...
//Return();
Expand Down
2 changes: 1 addition & 1 deletion psxhw.c
Expand Up @@ -45,7 +45,7 @@ void psxHwReset() {
mdecInit(); // initialize mdec decoder
cdrReset();
psxRcntInit();
HW_GPU_STATUS = SWAP32(0x14802000);
HW_GPU_STATUS = SWAP32(0x10802000);
psxHwReadGpuSRptr = Config.hacks.gpu_busy_hack
? psxHwReadGpuSRbusyHack : psxHwReadGpuSR;
}
Expand Down
2 changes: 1 addition & 1 deletion psxinterpreter.c
Expand Up @@ -687,7 +687,7 @@ void psxJAL() { _SetLink(31); doBranch(_JumpTarget_); }
*********************************************************/
void psxJR() {
doBranch(_u32(_rRs_) & ~3);
psxJumpTest();
//psxJumpTest();
}

void psxJALR() {
Expand Down

1 comment on commit ea714bc

@xjsxjs197
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that the directory "usb:/wiisxrx/settings" or "sd:/wiisxrx/settings" exists.

Please sign in to comment.