diff --git a/Core/Core.cpp b/Core/Core.cpp index e2928c9356..a7d9e90b4c 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -80,12 +80,19 @@ bool Core_IsInactive() { return coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && !coreStatePending; } + void Core_WaitInactive() { while (!Core_IsInactive()) m_hInactiveEvent.wait(m_hInactiveMutex); } +void Core_WaitInactive(int milliseconds) +{ + // TODO + Core_WaitInactive(); +} + void Core_RunLoop() { while (!coreState) { diff --git a/Core/Core.h b/Core/Core.h index 3d57df2870..2b9d359fad 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -46,6 +46,7 @@ enum CoreState void Core_UpdateState(CoreState newState); bool Core_IsInactive(); void Core_WaitInactive(); +void Core_WaitInactive(int milliseconds); extern volatile CoreState coreState; diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 47b106197f..cbb960f8ab 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -133,14 +133,14 @@ void CBreakPoints::AddBreakPoint(u32 _iAddress, bool temp) void CBreakPoints::InvalidateJit(u32 _iAddress) { // Don't want to clear cache while running, I think? - if (MIPSComp::jit && Core_IsStepping()) + if (MIPSComp::jit && Core_IsInactive()) MIPSComp::jit->ClearCacheAt(_iAddress); } void CBreakPoints::InvalidateJit() { // Don't want to clear cache while running, I think? - if (MIPSComp::jit && Core_IsStepping()) + if (MIPSComp::jit && Core_IsInactive()) MIPSComp::jit->ClearCache(); } diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 8a450081c3..a320c4e70b 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -90,7 +90,7 @@ namespace SaveState // Don't actually run it until next CoreTiming::Advance(). // It's possible there might be a duplicate but it won't hurt us. - if (Core_IsStepping() && __KernelIsRunning()) + if (Core_IsInactive() && __KernelIsRunning()) { // Warning: this may run on a different thread. Process(0, 0); diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 30674cf9b4..d8c35701ef 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -308,7 +308,7 @@ namespace MainWindow if (disasmWindow[i]) SendMessage(disasmWindow[i]->GetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - Sleep(100);//UGLY wait for event instead + Core_WaitInactive(); for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - Sleep(100);//UGLY wait for event instead + Core_WaitInactive(); for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - } if (W32Util::BrowseForFileName(true, hWnd, "Load state",0,"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0","ppst",fn)) { SetCursor(LoadCursor(0,IDC_WAIT)); @@ -369,13 +362,6 @@ namespace MainWindow break; case ID_FILE_SAVESTATEFILE: - if (g_State.bEmuThreadStarted) - { - nextState = Core_IsStepping() ? CORE_STEPPING : CORE_RUNNING; - for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - } if (W32Util::BrowseForFileName(false, hWnd, "Save state",0,"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0","ppst",fn)) { SetCursor(LoadCursor(0,IDC_WAIT)); @@ -386,25 +372,11 @@ namespace MainWindow // TODO: Add UI for multiple slots case ID_FILE_QUICKLOADSTATE: - if (g_State.bEmuThreadStarted) - { - nextState = Core_IsStepping() ? CORE_STEPPING : CORE_RUNNING; - for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - } SetCursor(LoadCursor(0,IDC_WAIT)); SaveState::LoadSlot(0, SaveStateActionFinished); break; case ID_FILE_QUICKSAVESTATE: - if (g_State.bEmuThreadStarted) - { - nextState = Core_IsStepping() ? CORE_STEPPING : CORE_RUNNING; - for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - } SetCursor(LoadCursor(0,IDC_WAIT)); SaveState::SaveSlot(0, SaveStateActionFinished); break; @@ -643,7 +615,8 @@ namespace MainWindow break; case WM_CLOSE: - Sleep(100);//UGLY wait for event instead + Core_Stop(); + Core_WaitInactive(200); EmuThread_Stop(); /*