From ea714bcfaf26ef591f1cb37f95eb0d1251305bc7 Mon Sep 17 00:00:00 2001 From: xjsxjs197 Date: Sun, 19 Nov 2023 16:10:51 +0800 Subject: [PATCH] Add basic individual save function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Gamecube/GamecubeMain.cpp | 101 +++++++++++++++++++++++++---- Gamecube/menu/FileBrowserFrame.cpp | 5 ++ Gamecube/menu/SettingsFrame.cpp | 70 +++++++++++++++++--- lang/zh.lang | 3 + ppc/pR3000A.c | 10 +-- psxhw.c | 2 +- psxinterpreter.c | 2 +- psxmem.c | 50 +++++++------- r3000a.c | 12 +++- 9 files changed, 203 insertions(+), 52 deletions(-) diff --git a/Gamecube/GamecubeMain.cpp b/Gamecube/GamecubeMain.cpp index e875847..901c0d2 100644 --- a/Gamecube/GamecubeMain.cpp +++ b/Gamecube/GamecubeMain.cpp @@ -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; @@ -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[]) { @@ -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(); @@ -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(); @@ -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) { @@ -621,6 +700,8 @@ int loadISOSwap(fileBrowser_file* file) { CheckCdrom(); + loadSeparatelySetting(); + swapIso = true; LoadCdrom(); @@ -644,6 +725,7 @@ int loadISO(fileBrowser_file* file) SysClose(); hasLoadedISO = FALSE; } + needInitCpu = false; if(SysInit() < 0) return -1; hasLoadedISO = TRUE; @@ -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(); diff --git a/Gamecube/menu/FileBrowserFrame.cpp b/Gamecube/menu/FileBrowserFrame.cpp index 6c4981f..4a4d2a5 100644 --- a/Gamecube/menu/FileBrowserFrame.cpp +++ b/Gamecube/menu/FileBrowserFrame.cpp @@ -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 diff --git a/Gamecube/menu/SettingsFrame.cpp b/Gamecube/menu/SettingsFrame.cpp index 44924c3..4ba42e7 100644 --- a/Gamecube/menu/SettingsFrame.cpp +++ b/Gamecube/menu/SettingsFrame.cpp @@ -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(); @@ -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 @@ -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", @@ -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", @@ -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] = @@ -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 @@ -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 @@ -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 @@ -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); @@ -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++) diff --git a/lang/zh.lang b/lang/zh.lang index 02d396f..146667f 100644 --- a/lang/zh.lang +++ b/lang/zh.lang @@ -574,3 +574,6 @@ msgstr "快速加载" msgid "Because the language has changed, please restart" msgstr "因为语言变更了,请重新启动" + +msgid "Separately" +msgstr "单独保存" diff --git a/ppc/pR3000A.c b/ppc/pR3000A.c index 99eff19..c16c7d8 100644 --- a/ppc/pR3000A.c +++ b/ppc/pR3000A.c @@ -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(); diff --git a/psxhw.c b/psxhw.c index 4731cd3..8a2a53c 100644 --- a/psxhw.c +++ b/psxhw.c @@ -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; } diff --git a/psxinterpreter.c b/psxinterpreter.c index 4925d15..a59205a 100644 --- a/psxinterpreter.c +++ b/psxinterpreter.c @@ -687,7 +687,7 @@ void psxJAL() { _SetLink(31); doBranch(_JumpTarget_); } *********************************************************/ void psxJR() { doBranch(_u32(_rRs_) & ~3); - psxJumpTest(); + //psxJumpTest(); } void psxJALR() { diff --git a/psxmem.c b/psxmem.c index 899e4d0..96a0b0a 100644 --- a/psxmem.c +++ b/psxmem.c @@ -51,10 +51,11 @@ #include "Gamecube/fileBrowser/fileBrowser-CARD.h" #include "Gamecube/fileBrowser/fileBrowser-DVD.h" #include "Gamecube/wiiSXconfig.h" +#include "Gamecube/DEBUG.h" #include "Gamecube/vm/vm.h" -static bool lightrec_mmap_inited; +bool lightrec_mmap_inited = false; #include #include @@ -93,24 +94,25 @@ int psxMemInit() { if (Config.Cpu == DYNACORE_DYNAREC) // Lightrec { - if (lightrec_mmap_inited) - return 0; - - /* Memory-map the allocated buffers */ - if (lightrec_mmap(psxM, 0x0, 0x200000) - || lightrec_mmap(psxM, 0x200000, 0x200000) - || lightrec_mmap(psxM, 0x400000, 0x200000) - || lightrec_mmap(psxM, 0x600000, 0x200000)) { - SysMessage(_("Error mapping RAM")); - } + if (!lightrec_mmap_inited) + { + + /* Memory-map the allocated buffers */ + if (lightrec_mmap(psxM, 0x0, 0x200000) + || lightrec_mmap(psxM, 0x200000, 0x200000) + || lightrec_mmap(psxM, 0x400000, 0x200000) + || lightrec_mmap(psxM, 0x600000, 0x200000)) { + SysMessage(_("Error mapping RAM")); + } - if (lightrec_mmap(psxR, 0x1fc00000, 0x80000)) - SysMessage(_("Error mapping BIOS")); + if (lightrec_mmap(psxR, 0x1fc00000, 0x80000)) + SysMessage(_("Error mapping BIOS")); - if (lightrec_mmap(psxM + 0x210000, 0x1f800000, 0x3000)) - SysMessage(_("Error mapping scratch/IO")); + if (lightrec_mmap(psxM + 0x210000, 0x1f800000, 0x3000)) + SysMessage(_("Error mapping scratch/IO")); - lightrec_mmap_inited = true; + lightrec_mmap_inited = true; + } } memset(psxMemRLUT, 0, 0x10000 * sizeof(void*)); @@ -323,9 +325,9 @@ void psxMemWrite8(u32 mem, u8 value) { char *p = (char *)(psxMemWLUT[t]); if (p != NULL) { *(u8 *)(p + (mem & 0xffff)) = value; -#ifdef PSXREC +//#ifdef PSXREC psxCpu->Clear((mem&(~3)), 1); -#endif +//#endif } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err sb %8.8lx\n", mem); @@ -353,9 +355,9 @@ void psxMemWrite16(u32 mem, u16 value) { //*(u16 *)(p + (mem & 0xffff)) = SWAPu16(value); STORE_SWAP16p((p + (mem & 0xffff)), value); // upd xjsxjs197 end -#ifdef PSXREC +//#ifdef PSXREC psxCpu->Clear((mem & (~3)), 1); -#endif +//#endif } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err sh %8.8lx\n", mem); @@ -384,15 +386,15 @@ void psxMemWrite32(u32 mem, u32 value) { //*(u32 *)(p + (mem & 0xffff)) = SWAPu32(value); STORE_SWAP32p((p + (mem & 0xffff)), value); // upd xjsxjs197 end -#ifdef PSXREC +//#ifdef PSXREC psxCpu->Clear(mem, 1); -#endif +//#endif } else { if (mem != 0xfffe0130) { -#ifdef PSXREC +//#ifdef PSXREC if (!writeok) psxCpu->Clear(mem, 1); -#endif +//#endif #ifdef PSXMEM_LOG if (writeok) { PSXMEM_LOG("err sw %8.8lx\n", mem); } diff --git a/r3000a.c b/r3000a.c index 12d3b9d..448e7b0 100644 --- a/r3000a.c +++ b/r3000a.c @@ -28,8 +28,11 @@ #include "mdec.h" #include "psxinterpreter.h" #include "Gamecube/wiiSXconfig.h" +#include "Gamecube/DEBUG.h" + R3000Acpu *psxCpu; psxRegisters psxRegs; +extern bool needInitCpu; int psxInit() { @@ -51,7 +54,14 @@ int psxInit() { int memInitResult = psxMemInit(); if (memInitResult != 0) return memInitResult; - return psxCpu->Init(); + if (needInitCpu) + { + return psxCpu->Init(); + } + else + { + return 0; + } } void psxReset() {