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 *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2017-10-18 03:52:07 +00:00
|
|
|
#include <Common/Random.h>
|
2015-11-12 07:08:10 +00:00
|
|
|
#include <Common/SyncEvent.h>
|
2016-04-17 19:52:09 +00:00
|
|
|
#include <Common/Thread.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/Settings/N64SystemSettings.h>
|
2016-01-04 20:46:56 +00:00
|
|
|
#include <Project64-core/N64System/ProfilingClass.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Recompiler/RecompilerClass.h>
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Audio.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Mips/SystemEvents.h>
|
|
|
|
#include <Project64-core/N64System/Mips/SystemTiming.h>
|
2016-07-07 11:51:06 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Mempak.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/Settings/DebugSettings.h>
|
|
|
|
#include <Project64-core/Plugin.h>
|
|
|
|
#include <Project64-core/Logging.h>
|
|
|
|
|
|
|
|
#include "Mips/TLBClass.h"
|
|
|
|
#include "CheatClass.h"
|
|
|
|
#include "FramePerSecondClass.h"
|
2015-12-14 21:56:39 +00:00
|
|
|
#include "SpeedLimiterClass.h"
|
2015-11-12 07:08:10 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
typedef std::list<SystemEvent> EVENT_LIST;
|
|
|
|
|
2015-11-15 05:20:22 +00:00
|
|
|
typedef std::map<uint32_t, uint32_t> FUNC_CALLS;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
class CPlugins;
|
|
|
|
class CRSP_Plugin;
|
2015-11-06 21:22:02 +00:00
|
|
|
class CRecompiler;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//#define TEST_SP_TRACKING //track the SP to make sure all ops pick it up fine
|
|
|
|
|
|
|
|
class CN64System :
|
2015-11-13 13:23:43 +00:00
|
|
|
public CLogging,
|
2015-11-12 06:52:27 +00:00
|
|
|
public CTLB_CB,
|
|
|
|
private CSystemEvents,
|
|
|
|
protected CN64SystemSettings,
|
|
|
|
public CGameSettings,
|
|
|
|
protected CDebugSettings
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
public:
|
2017-10-18 05:05:38 +00:00
|
|
|
CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem);
|
2015-11-12 06:52:27 +00:00
|
|
|
virtual ~CN64System(void);
|
|
|
|
|
|
|
|
CCheats m_Cheats;
|
|
|
|
bool m_EndEmulation;
|
|
|
|
SAVE_CHIP_TYPE m_SaveUsing;
|
|
|
|
|
|
|
|
//Methods
|
2016-12-12 19:22:35 +00:00
|
|
|
static bool LoadFileImage(const char * FileLoc);
|
2015-11-12 06:52:27 +00:00
|
|
|
static bool RunFileImage(const char * FileLoc);
|
2016-01-25 19:58:57 +00:00
|
|
|
static bool RunFileImageIPL(const char * FileLoc);
|
|
|
|
static bool RunDiskImage(const char * FileLoc);
|
2016-12-12 19:22:35 +00:00
|
|
|
static void RunLoadedImage(void);
|
2015-11-12 06:52:27 +00:00
|
|
|
static void CloseSystem(void);
|
|
|
|
|
|
|
|
void CloseCpu();
|
|
|
|
void ExternalEvent(SystemEvent action); //covers gui interacting and timers etc..
|
|
|
|
void StartEmulation(bool NewThread);
|
2016-08-07 06:51:19 +00:00
|
|
|
void EndEmulation();
|
2016-09-17 18:10:22 +00:00
|
|
|
void AlterSpeed(const CSpeedLimiter::ESpeedChange SpeedChange) { m_Limiter.AlterSpeed(SpeedChange); }
|
2017-09-28 11:43:58 +00:00
|
|
|
void SetSpeed(int Speed) { m_Limiter.SetSpeed(Speed); }
|
2016-11-21 07:17:15 +00:00
|
|
|
int GetSpeed(void) const { return m_Limiter.GetSpeed(); }
|
|
|
|
int GetBaseSpeed(void) const { return m_Limiter.GetBaseSpeed(); }
|
2015-11-12 06:52:27 +00:00
|
|
|
void Reset(bool bInitReg, bool ClearMenory);
|
|
|
|
void GameReset();
|
|
|
|
void PluginReset();
|
|
|
|
|
|
|
|
void Pause();
|
|
|
|
void RunRSP();
|
|
|
|
bool SaveState();
|
2015-11-15 05:20:22 +00:00
|
|
|
bool LoadState(const char * FileName);
|
2015-11-12 06:52:27 +00:00
|
|
|
bool LoadState();
|
|
|
|
|
|
|
|
bool DmaUsed() const { return m_DMAUsed; }
|
|
|
|
void SetDmaUsed(bool DMAUsed) { m_DMAUsed = DMAUsed; }
|
|
|
|
void SetCheatsSlectionChanged(bool changed) { m_CheatsSlectionChanged = changed; }
|
|
|
|
bool HasCheatsSlectionChanged(void) const { return m_CheatsSlectionChanged; }
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t GetButtons(int32_t Control) const { return m_Buttons[Control]; }
|
2016-08-07 06:50:06 +00:00
|
|
|
CPlugins * GetPlugins() { return m_Plugins; }
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//Variable used to track that the SP is being handled and stays the same as the real SP in sync core
|
2010-05-22 04:47:15 +00:00
|
|
|
#ifdef TEST_SP_TRACKING
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_CurrentSP;
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2015-11-12 06:52:27 +00:00
|
|
|
//For Sync CPU
|
2015-11-15 05:20:22 +00:00
|
|
|
void UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycles);
|
2015-11-12 06:52:27 +00:00
|
|
|
void SyncCPU(CN64System * const SecondCPU);
|
|
|
|
void SyncCPUPC(CN64System * const SecondCPU);
|
|
|
|
void SyncSystem();
|
|
|
|
void SyncSystemPC();
|
2010-05-22 04:47:15 +00:00
|
|
|
private:
|
2015-11-12 06:52:27 +00:00
|
|
|
//Make sure plugins can directly access this information
|
2016-11-27 20:25:56 +00:00
|
|
|
friend class CGfxPlugin;
|
|
|
|
friend class CAudioPlugin;
|
|
|
|
friend class CRSP_Plugin;
|
|
|
|
friend class CControl_Plugin;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//Recompiler has access to manipulate and call functions
|
2016-11-27 20:25:56 +00:00
|
|
|
friend class CSystemTimer;
|
|
|
|
friend class CRecompiler;
|
|
|
|
friend class CMipsMemoryVM;
|
2016-09-26 11:10:11 +00:00
|
|
|
|
2015-11-12 06:52:27 +00:00
|
|
|
//Used for loading and potentially executing the CPU in its own thread.
|
2016-04-17 19:52:09 +00:00
|
|
|
static void StartEmulationThread(CThread * thread);
|
|
|
|
static bool EmulationStarting(CThread * thread);
|
2015-11-15 09:51:44 +00:00
|
|
|
static void StartEmulationThead();
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
void ExecuteCPU();
|
|
|
|
void RefreshScreen();
|
|
|
|
void DumpSyncErrors(CN64System * SecondCPU);
|
|
|
|
void StartEmulation2(bool NewThread);
|
|
|
|
bool SetActiveSystem(bool bActive = true);
|
2015-12-21 07:35:22 +00:00
|
|
|
void InitRegisters(bool bPostPif, CMipsMemoryVM & MMU);
|
2016-01-18 11:31:36 +00:00
|
|
|
void DisplayRSPListCount();
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//CPU Methods
|
|
|
|
void ExecuteRecompiler();
|
|
|
|
void ExecuteInterpret();
|
|
|
|
void ExecuteSyncCPU();
|
|
|
|
|
|
|
|
//Mark information saying that the CPU has stopped
|
|
|
|
void CpuStopped();
|
|
|
|
|
|
|
|
//Functions in CTLB_CB
|
|
|
|
void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly);
|
|
|
|
void TLB_Unmaped(uint32_t VAddr, uint32_t Len);
|
|
|
|
void TLB_Changed();
|
|
|
|
|
|
|
|
CPlugins * const m_Plugins; //The plugin container
|
|
|
|
CPlugins * m_SyncPlugins;
|
2016-01-04 20:46:56 +00:00
|
|
|
CN64System * m_SyncCPU;
|
2015-11-12 06:52:27 +00:00
|
|
|
CMipsMemoryVM m_MMU_VM; //Memory of the n64
|
|
|
|
CTLB m_TLB;
|
|
|
|
CRegisters m_Reg;
|
2016-07-07 11:51:06 +00:00
|
|
|
CMempak m_Mempak;
|
2015-11-12 06:52:27 +00:00
|
|
|
CFramePerSecond m_FPS;
|
|
|
|
CProfiling m_CPU_Usage; //used to track the cpu usage
|
|
|
|
CRecompiler * m_Recomp;
|
|
|
|
CAudio m_Audio;
|
2015-12-14 22:10:30 +00:00
|
|
|
CSpeedLimiter m_Limiter;
|
2015-11-12 06:52:27 +00:00
|
|
|
bool m_InReset;
|
2015-11-15 05:20:22 +00:00
|
|
|
int32_t m_NextTimer;
|
2015-11-12 06:52:27 +00:00
|
|
|
CSystemTimer m_SystemTimer;
|
|
|
|
bool m_bCleanFrameBox;
|
|
|
|
bool m_RspBroke;
|
|
|
|
bool m_DMAUsed;
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_Buttons[4];
|
2015-11-12 06:52:27 +00:00
|
|
|
bool m_TestTimer;
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_NextInstruction;
|
|
|
|
uint32_t m_JumpToLocation;
|
2015-11-12 06:52:27 +00:00
|
|
|
uint32_t m_TLBLoadAddress;
|
|
|
|
uint32_t m_TLBStoreAddress;
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_SyncCount;
|
2016-07-04 07:51:11 +00:00
|
|
|
bool m_SyncCpu;
|
2015-11-12 06:52:27 +00:00
|
|
|
bool m_CheatsSlectionChanged;
|
2017-10-18 02:38:38 +00:00
|
|
|
CRandom m_Random;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//When Syncing cores this is the PC where it last Sync'ed correctly
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_LastSuccessSyncPC[10];
|
|
|
|
int32_t m_CyclesToSkip;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//Handle to the cpu thread
|
2016-04-17 19:52:09 +00:00
|
|
|
CThread * m_thread;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//Handle to pause mutex
|
|
|
|
SyncEvent m_hPauseEvent;
|
|
|
|
|
|
|
|
//No of Alist and Dlist sent to the RSP
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_AlistCount, m_DlistCount, m_UnknownCount;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
|
|
|
//list of function that have been called .. used in profiling
|
|
|
|
FUNC_CALLS m_FunctionCalls;
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|