2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-04 06:25:07 +00:00
|
|
|
#include "stdafx.h"
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Mips/SystemEvents.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
|
|
|
#include <Project64-core/N64System/N64Class.h>
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2015-03-12 06:58:41 +00:00
|
|
|
CSystemEvents::CSystemEvents(CN64System * System, CPlugins * Plugins) :
|
2016-10-04 19:58:11 +00:00
|
|
|
m_System(System),
|
|
|
|
m_Plugins(Plugins),
|
|
|
|
m_bDoSomething(false)
|
2010-06-04 06:25:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSystemEvents::~CSystemEvents()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSystemEvents::QueueEvent(SystemEvent action)
|
|
|
|
{
|
2016-09-24 20:46:19 +00:00
|
|
|
CGuard Guard(m_CS);
|
|
|
|
for (EventList::const_iterator iter = m_Events.begin(); iter != m_Events.end(); iter++)
|
|
|
|
{
|
|
|
|
if (*iter == action)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Events.push_back(action);
|
2016-06-04 08:23:18 +00:00
|
|
|
m_bDoSomething = true;
|
2010-06-04 06:25:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CSystemEvents::ExecuteEvents()
|
2010-06-04 06:25:07 +00:00
|
|
|
{
|
2016-09-24 20:46:19 +00:00
|
|
|
EventList Events;
|
|
|
|
{
|
|
|
|
CGuard Guard(m_CS);
|
2012-12-18 23:55:05 +00:00
|
|
|
|
2016-09-24 20:46:19 +00:00
|
|
|
m_bDoSomething = false;
|
|
|
|
if (m_Events.size() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-11-07 03:32:23 +00:00
|
|
|
|
2016-09-24 20:46:19 +00:00
|
|
|
Events = m_Events;
|
|
|
|
m_Events.clear();
|
|
|
|
}
|
2012-12-18 23:55:05 +00:00
|
|
|
|
2016-09-24 20:46:19 +00:00
|
|
|
bool bPause = false, bLoadedSave = false;
|
|
|
|
for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++)
|
|
|
|
{
|
|
|
|
switch (*iter)
|
|
|
|
{
|
|
|
|
case SysEvent_CloseCPU:
|
|
|
|
m_System->m_EndEmulation = true;
|
|
|
|
break;
|
|
|
|
case SysEvent_ResetCPU_Soft:
|
|
|
|
m_System->GameReset();
|
|
|
|
break;
|
|
|
|
case SysEvent_ResetCPU_SoftDone:
|
|
|
|
m_System->Reset(true, false);
|
|
|
|
break;
|
|
|
|
case SysEvent_ResetCPU_Hard:
|
|
|
|
m_System->Reset(true, true);
|
|
|
|
break;
|
|
|
|
case SysEvent_ExecuteInterrupt:
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_SP:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SP;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_SI:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_AI:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_AI;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_VI:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_VI;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_PI:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_PI;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_Interrupt_DP:
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_DP;
|
|
|
|
g_Reg->DoIntrException(false);
|
|
|
|
break;
|
|
|
|
case SysEvent_SaveMachineState:
|
|
|
|
if (!m_System->SaveState())
|
|
|
|
{
|
|
|
|
m_Events.push_back(SysEvent_SaveMachineState);
|
|
|
|
m_bDoSomething = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_LoadMachineState:
|
|
|
|
if (m_System->LoadState())
|
|
|
|
{
|
|
|
|
bLoadedSave = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_ChangePlugins:
|
|
|
|
ChangePluginFunc();
|
|
|
|
break;
|
2016-10-04 19:58:11 +00:00
|
|
|
case SysEvent_ResetFunctionTimes:
|
|
|
|
if (g_Recompiler)
|
|
|
|
{
|
|
|
|
g_Recompiler->ResetFunctionTimes();
|
|
|
|
}
|
|
|
|
break;
|
2016-10-02 21:46:05 +00:00
|
|
|
case SysEvent_DumpFunctionTimes:
|
|
|
|
if (g_Recompiler)
|
|
|
|
{
|
|
|
|
g_Recompiler->DumpFunctionTimes();
|
|
|
|
}
|
|
|
|
break;
|
2016-09-24 20:46:19 +00:00
|
|
|
case SysEvent_ChangingFullScreen:
|
|
|
|
g_Notify->ChangeFullScreen();
|
|
|
|
break;
|
|
|
|
case SysEvent_GSButtonPressed:
|
|
|
|
if (m_System->HasCheatsSlectionChanged())
|
|
|
|
{
|
|
|
|
m_System->SetCheatsSlectionChanged(false);
|
|
|
|
m_System->m_Cheats.LoadCheats(false, m_Plugins);
|
|
|
|
}
|
|
|
|
m_System->m_Cheats.ApplyGSButton(g_MMU);
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_FromMenu:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_FromMenu);
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_AppLostFocus:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostFocus);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_AppLostActive:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostActive);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_SaveGame:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SaveGame);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_LoadGame:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_LoadGame);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_DumpMemory:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_DumpMemory);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_SearchMemory:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SearchMemory);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_Settings:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Settings);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SysEvent_PauseCPU_Cheats:
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
|
|
|
|
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Cheats);
|
|
|
|
bPause = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2016-09-24 20:46:19 +00:00
|
|
|
if (bPause)
|
|
|
|
{
|
|
|
|
m_System->Pause();
|
|
|
|
}
|
2010-06-29 02:11:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CSystemEvents::ChangePluginFunc()
|
2010-06-29 02:11:22 +00:00
|
|
|
{
|
2016-09-24 20:46:19 +00:00
|
|
|
g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT);
|
|
|
|
m_System->PluginReset();
|
|
|
|
}
|