From bd6764b65e71c305f7369c16fc816150006a0ced Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sat, 28 Jan 2017 11:51:20 +0800 Subject: [PATCH 1/6] Fix "Akaya Akashiya Ayakashi" umd switch Also,make "switch umd" menu enable faster, --- Core/HLE/sceUmd.cpp | 22 +++++++++++++++++++--- Windows/MainWindowMenu.cpp | 4 ++++ Windows/MainWindowMenu.h | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index ce28b59d0700..59fde8cffc2d 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -38,6 +38,9 @@ #include "Core/FileSystems/MetaFileSystem.h" #include "Core/FileSystems/ISOFileSystem.h" #include "Core/FileSystems/VirtualDiscFileSystem.h" +#ifdef USING_WIN_UI +#include "Windows/MainWindowMenu.h" +#endif const u64 MICRO_DELAY_ACTIVATE = 4000; @@ -51,6 +54,7 @@ static std::vector umdWaitingThreads; static std::map umdPausedWaits; bool UMDReplacePermit = false; +bool UMD_insterted = true; struct PspUmdInfo { u32_le size; @@ -225,8 +229,12 @@ void __UmdEndCallback(SceUID threadID, SceUID prevCallbackId) static int sceUmdCheckMedium() { - DEBUG_LOG(SCEIO, "1=sceUmdCheckMedium()"); - return 1; //non-zero: disc in drive + if (UMD_insterted) { + DEBUG_LOG(SCEIO, "1=sceUmdCheckMedium()"); + return 1; //non-zero: disc in drive + } + DEBUG_LOG(SCEIO, "0=sceUmdCheckMedium()"); + return 0; } static u32 sceUmdGetDiscInfo(u32 infoAddr) @@ -495,7 +503,9 @@ void __UmdReplace(std::string filepath) { } } delete currentUMD; - + UMD_insterted = false; + Sleep(200); // Wait sceUmdCheckMedium call + UMD_insterted = true; // TODO Is this always correct if UMD was not activated? u32 notifyArg = PSP_UMD_PRESENT | PSP_UMD_READABLE | PSP_UMD_CHANGED; if (driveCBId != -1) @@ -510,6 +520,9 @@ static u32 sceUmdReplaceProhibit() { UMDReplacePermit = false; DEBUG_LOG(SCEIO,"sceUmdReplaceProhibit()"); +#ifdef USING_WIN_UI + MainWindow::ChangeMenu(); +#endif return 0; } @@ -517,6 +530,9 @@ static u32 sceUmdReplacePermit() { UMDReplacePermit = true; DEBUG_LOG(SCEIO,"sceUmdReplacePermit()"); +#ifdef USING_WIN_UI + MainWindow::ChangeMenu(); +#endif return 0; } diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 0cf34fdb39d7..da870a8d1a4c 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1258,4 +1258,8 @@ namespace MainWindow { } return FALSE; } + + void ChangeMenu() { + SetIngameMenuItemStates(GetMenu(GetHWND()), UISTATE_INGAME); + } } diff --git a/Windows/MainWindowMenu.h b/Windows/MainWindowMenu.h index 03e04baf18a9..7351b9be5b2d 100644 --- a/Windows/MainWindowMenu.h +++ b/Windows/MainWindowMenu.h @@ -10,4 +10,5 @@ namespace MainWindow { void BrowseAndBoot(std::string defaultPath, bool browseDirectory = false); void BrowseAndBootDone(); void setTexScalingMultiplier(int level); + void ChangeMenu(); } From 033e0604e90d00d1a88fee0c131114d3eda34326 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sat, 28 Jan 2017 13:40:13 +0800 Subject: [PATCH 2/6] Build fix for non-windows --- Core/HLE/sceUmd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index 59fde8cffc2d..a38af72cb0e8 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -38,6 +38,7 @@ #include "Core/FileSystems/MetaFileSystem.h" #include "Core/FileSystems/ISOFileSystem.h" #include "Core/FileSystems/VirtualDiscFileSystem.h" +#include "base/timeutil.h" #ifdef USING_WIN_UI #include "Windows/MainWindowMenu.h" #endif @@ -504,7 +505,7 @@ void __UmdReplace(std::string filepath) { } delete currentUMD; UMD_insterted = false; - Sleep(200); // Wait sceUmdCheckMedium call + sleep_ms(200); // Wait sceUmdCheckMedium call UMD_insterted = true; // TODO Is this always correct if UMD was not activated? u32 notifyArg = PSP_UMD_PRESENT | PSP_UMD_READABLE | PSP_UMD_CHANGED; From 3f92bac4bb49d807f3087ad5a9f04f0d0e9e98e9 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sat, 28 Jan 2017 18:39:20 +0800 Subject: [PATCH 3/6] Rename UMD_insterted to UMDInserted --- Core/HLE/sceUmd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index a38af72cb0e8..d42c2e54b661 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -55,7 +55,7 @@ static std::vector umdWaitingThreads; static std::map umdPausedWaits; bool UMDReplacePermit = false; -bool UMD_insterted = true; +bool UMDInserted = true; struct PspUmdInfo { u32_le size; @@ -230,7 +230,7 @@ void __UmdEndCallback(SceUID threadID, SceUID prevCallbackId) static int sceUmdCheckMedium() { - if (UMD_insterted) { + if (UMDInserted) { DEBUG_LOG(SCEIO, "1=sceUmdCheckMedium()"); return 1; //non-zero: disc in drive } @@ -504,9 +504,9 @@ void __UmdReplace(std::string filepath) { } } delete currentUMD; - UMD_insterted = false; + UMDInserted = false; sleep_ms(200); // Wait sceUmdCheckMedium call - UMD_insterted = true; + UMDInserted = true; // TODO Is this always correct if UMD was not activated? u32 notifyArg = PSP_UMD_PRESENT | PSP_UMD_READABLE | PSP_UMD_CHANGED; if (driveCBId != -1) From c83db04a25666584da4b0f3722087b99b615c66a Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sat, 28 Jan 2017 21:09:37 +0800 Subject: [PATCH 4/6] Change to "schedule an event" --- Core/HLE/sceUmd.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index d42c2e54b661..50fe28ab7a24 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -38,7 +38,6 @@ #include "Core/FileSystems/MetaFileSystem.h" #include "Core/FileSystems/ISOFileSystem.h" #include "Core/FileSystems/VirtualDiscFileSystem.h" -#include "base/timeutil.h" #ifdef USING_WIN_UI #include "Windows/MainWindowMenu.h" #endif @@ -51,6 +50,7 @@ static u32 umdErrorStat = 0; static int driveCBId = 0; static int umdStatTimeoutEvent = -1; static int umdStatChangeEvent = -1; +static int umdInsertChangeEvent = -1; static std::vector umdWaitingThreads; static std::map umdPausedWaits; @@ -64,6 +64,7 @@ struct PspUmdInfo { void __UmdStatTimeout(u64 userdata, int cyclesLate); void __UmdStatChange(u64 userdata, int cyclesLate); +void __UmdInsertChange(u64 userdata, int cyclesLate); void __UmdBeginCallback(SceUID threadID, SceUID prevCallbackId); void __UmdEndCallback(SceUID threadID, SceUID prevCallbackId); @@ -71,6 +72,7 @@ void __UmdInit() { umdStatTimeoutEvent = CoreTiming::RegisterEvent("UmdTimeout", __UmdStatTimeout); umdStatChangeEvent = CoreTiming::RegisterEvent("UmdChange", __UmdStatChange); + umdInsertChangeEvent = CoreTiming::RegisterEvent("UmdInsertChange", __UmdInsertChange); umdActivated = 1; umdStatus = 0; umdErrorStat = 0; @@ -113,6 +115,11 @@ static u8 __KernelUmdGetState() return state; } +void __UmdInsertChange(u64 userdata, int cyclesLate) +{ + UMDInserted = true; +} + void __UmdStatChange(u64 userdata, int cyclesLate) { // TODO: Why not a bool anyway? @@ -505,8 +512,7 @@ void __UmdReplace(std::string filepath) { } delete currentUMD; UMDInserted = false; - sleep_ms(200); // Wait sceUmdCheckMedium call - UMDInserted = true; + CoreTiming::ScheduleEvent(usToCycles(200*1000), umdInsertChangeEvent, 0); // Wait sceUmdCheckMedium call // TODO Is this always correct if UMD was not activated? u32 notifyArg = PSP_UMD_PRESENT | PSP_UMD_READABLE | PSP_UMD_CHANGED; if (driveCBId != -1) From 2c58d34f3e02e5ddb6af5f7e523064436559b35a Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sun, 29 Jan 2017 03:38:28 +0800 Subject: [PATCH 5/6] Add save status --- Core/HLE/sceUmd.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index 50fe28ab7a24..f8bef0d8efe2 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -85,7 +85,7 @@ void __UmdInit() void __UmdDoState(PointerWrap &p) { - auto s = p.Section("sceUmd", 1, 2); + auto s = p.Section("sceUmd", 1, 3); if (!s) return; @@ -100,8 +100,18 @@ void __UmdDoState(PointerWrap &p) p.Do(umdWaitingThreads); p.Do(umdPausedWaits); - if (s > 1) + if (s > 1) { p.Do(UMDReplacePermit); + if (UMDReplacePermit) + MainWindow::ChangeMenu(); + } + if (s > 2) { + p.Do(umdInsertChangeEvent); + CoreTiming::RestoreRegisterEvent(umdInsertChangeEvent, "UmdInsertChange", __UmdInsertChange); + p.Do(UMDInserted); + } + else + UMDInserted = true; } static u8 __KernelUmdGetState() From 860661dc14a3e9ee4f02e8b9d35f9d1135c9a3d6 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sun, 29 Jan 2017 03:56:49 +0800 Subject: [PATCH 6/6] Build fix for non-windows First step to fix UnitTest --- Core/HLE/sceUmd.cpp | 8 +++++--- Windows/MainWindowMenu.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index f8bef0d8efe2..e2aac0021e65 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -102,8 +102,10 @@ void __UmdDoState(PointerWrap &p) if (s > 1) { p.Do(UMDReplacePermit); +#ifdef USING_WIN_UI if (UMDReplacePermit) - MainWindow::ChangeMenu(); + MainWindowMenu:MainWindow::_ChangeMenu(); +#endif } if (s > 2) { p.Do(umdInsertChangeEvent); @@ -538,7 +540,7 @@ static u32 sceUmdReplaceProhibit() UMDReplacePermit = false; DEBUG_LOG(SCEIO,"sceUmdReplaceProhibit()"); #ifdef USING_WIN_UI - MainWindow::ChangeMenu(); + MainWindowMenu:MainWindow::_ChangeMenu(); #endif return 0; } @@ -548,7 +550,7 @@ static u32 sceUmdReplacePermit() UMDReplacePermit = true; DEBUG_LOG(SCEIO,"sceUmdReplacePermit()"); #ifdef USING_WIN_UI - MainWindow::ChangeMenu(); + MainWindowMenu:MainWindow::_ChangeMenu(); #endif return 0; } diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index da870a8d1a4c..fed360fb4a7c 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1259,7 +1259,7 @@ namespace MainWindow { return FALSE; } - void ChangeMenu() { + void _ChangeMenu() { SetIngameMenuItemStates(GetMenu(GetHWND()), UISTATE_INGAME); } }