2015-11-15 09:51:44 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#include "stdafx.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/N64Class.h>
|
|
|
|
#include <Project64-core/Notification.h>
|
2015-12-19 23:57:27 +00:00
|
|
|
#include <Common/Util.h>
|
2015-11-15 09:51:44 +00:00
|
|
|
|
|
|
|
void CN64System::StartEmulationThead()
|
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
|
|
|
CThread * thread = new CThread((CThread::CTHREAD_START_ROUTINE)StartEmulationThread);
|
|
|
|
thread->Start(thread);
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
2015-11-15 09:51:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 19:52:09 +00:00
|
|
|
void CN64System::StartEmulationThread(CThread * thread)
|
2015-11-15 09:51:44 +00:00
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
|
|
|
#ifdef _WIN32
|
2015-11-15 09:51:44 +00:00
|
|
|
if (g_Settings->LoadBool(Setting_CN64TimeCritical))
|
|
|
|
{
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2016-04-17 19:52:09 +00:00
|
|
|
EmulationStarting(thread);
|
2015-11-15 09:51:44 +00:00
|
|
|
|
|
|
|
CoUninitialize();
|
2016-04-17 19:52:09 +00:00
|
|
|
#else
|
|
|
|
EmulationStarting(thread);
|
|
|
|
#endif
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
2015-11-15 09:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CN64System::CloseCpu()
|
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
|
|
|
if (m_thread == NULL)
|
2015-11-15 09:51:44 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Setting end emulation");
|
2015-11-15 09:51:44 +00:00
|
|
|
m_EndEmulation = true;
|
|
|
|
if (g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Resume cpu");
|
2015-11-15 09:51:44 +00:00
|
|
|
m_hPauseEvent.Trigger();
|
|
|
|
}
|
|
|
|
|
2016-04-17 19:52:09 +00:00
|
|
|
if (CThread::GetCurrentThreadId() == m_thread->ThreadID())
|
2015-11-15 09:51:44 +00:00
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "CloseCpu called on emulation thread");
|
2015-11-15 09:51:44 +00:00
|
|
|
ExternalEvent(SysEvent_CloseCPU);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-17 19:52:09 +00:00
|
|
|
CThread * hThread = m_thread;
|
|
|
|
m_thread = NULL;
|
2015-11-15 09:51:44 +00:00
|
|
|
for (int count = 0; count < 200; count++)
|
|
|
|
{
|
2016-04-17 19:52:09 +00:00
|
|
|
if (hThread == NULL || !hThread->isRunning())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Thread no longer running");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "%d - waiting", count);
|
2015-11-15 09:51:44 +00:00
|
|
|
pjutil::Sleep(100);
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "%d - Finished wait", count);
|
2015-11-15 09:51:44 +00:00
|
|
|
if (g_Notify->ProcessGuiMessages())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CpuStopped();
|
2016-04-17 19:52:09 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Deleting thread object");
|
|
|
|
delete hThread;
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
2015-11-15 09:51:44 +00:00
|
|
|
}
|