2012-12-19 09:30:18 +00:00
|
|
|
#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>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/Logging.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Mempak.h>
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Mips/SystemEvents.h>
|
|
|
|
#include <Project64-core/N64System/Mips/SystemTiming.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/N64System/Profiling.h>
|
|
|
|
#include <Project64-core/N64System/Recompiler/Recompiler.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/Plugin.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/Settings/DebugSettings.h>
|
|
|
|
#include <Project64-core/Settings/N64SystemSettings.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
|
2021-04-14 05:34:15 +00:00
|
|
|
#include "FramePerSecond.h"
|
2022-10-10 00:22:17 +00:00
|
|
|
#include "Mips/TLB.h"
|
2021-04-14 05:34:15 +00:00
|
|
|
#include "SpeedLimiter.h"
|
2015-11-12 07:08:10 +00:00
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
typedef std::list<SystemEvent> EVENT_LIST;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
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
|
|
|
|
2022-03-14 10:37:06 +00:00
|
|
|
class VideoInterfaceHandler;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
//#define TEST_SP_TRACKING // Track the SP to make sure all ops pick it up fine
|
2022-03-14 10:37:06 +00:00
|
|
|
enum CN64SystemCB
|
|
|
|
{
|
|
|
|
CN64SystemCB_Reset,
|
|
|
|
CN64SystemCB_LoadedGameState,
|
|
|
|
};
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
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:
|
2022-10-10 00:22:17 +00:00
|
|
|
typedef void (*CallBackFunction)(void *);
|
2022-03-14 10:37:06 +00:00
|
|
|
|
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);
|
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
bool m_EndEmulation;
|
2015-11-12 06:52:27 +00:00
|
|
|
SAVE_CHIP_TYPE m_SaveUsing;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Methods
|
2016-12-12 19:22:35 +00:00
|
|
|
static bool LoadFileImage(const char * FileLoc);
|
2019-01-27 11:52:22 +00:00
|
|
|
static bool LoadFileImageIPL(const char * FileLoc);
|
|
|
|
static bool LoadDiskImage(const char * FileLoc, const bool Expansion);
|
2019-08-12 11:39:56 +00:00
|
|
|
static bool SelectAndLoadFileImageIPL(Country country, bool combo);
|
2015-11-12 06:52:27 +00:00
|
|
|
static bool RunFileImage(const char * FileLoc);
|
2019-01-25 20:32:26 +00:00
|
|
|
static bool RunDiskImage(const char * FileLoc);
|
|
|
|
static bool RunDiskComboImage(const char * FileLoc, const char * FileLocDisk);
|
2016-12-12 19:22:35 +00:00
|
|
|
static void RunLoadedImage(void);
|
2015-11-12 06:52:27 +00:00
|
|
|
static void CloseSystem(void);
|
|
|
|
|
2022-03-14 10:37:06 +00:00
|
|
|
void RegisterCallBack(CN64SystemCB Type, void * Data, CallBackFunction Func);
|
|
|
|
void UnregisterCallBack(CN64SystemCB Type, void * Data, CallBackFunction Func);
|
|
|
|
|
2022-01-18 07:47:21 +00:00
|
|
|
void CloseCpu();
|
|
|
|
void ExternalEvent(SystemEvent action); // Covers GUI interactions and timers etc.
|
|
|
|
void StartEmulation(bool NewThread);
|
|
|
|
void EndEmulation();
|
2022-10-10 00:22:17 +00:00
|
|
|
void AlterSpeed(const CSpeedLimiter::ESpeedChange SpeedChange)
|
|
|
|
{
|
|
|
|
m_Limiter.AlterSpeed(SpeedChange);
|
|
|
|
}
|
|
|
|
void SetSpeed(int Speed)
|
|
|
|
{
|
|
|
|
m_Limiter.SetSpeed(Speed);
|
|
|
|
}
|
|
|
|
int GetSpeed(void) const
|
|
|
|
{
|
|
|
|
return m_Limiter.GetSpeed();
|
|
|
|
}
|
|
|
|
int GetBaseSpeed(void) const
|
|
|
|
{
|
|
|
|
return m_Limiter.GetBaseSpeed();
|
|
|
|
}
|
2022-01-18 07:47:21 +00:00
|
|
|
void Reset(bool bInitReg, bool ClearMenory);
|
|
|
|
void GameReset();
|
|
|
|
void PluginReset();
|
|
|
|
void ApplyGSButton(void);
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-06-15 05:00:38 +00:00
|
|
|
void Pause();
|
|
|
|
void RunRSP();
|
|
|
|
bool SaveState();
|
|
|
|
bool LoadState(const char * FileName);
|
|
|
|
bool LoadState();
|
|
|
|
uint32_t GetButtons(int32_t Control) const;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +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
|
2021-05-18 11:51:36 +00:00
|
|
|
// For sync CPU
|
2022-01-18 07:47:21 +00:00
|
|
|
void UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycles);
|
|
|
|
void SyncCPU(CN64System * const SecondCPU);
|
|
|
|
void SyncCPUPC(CN64System * const SecondCPU);
|
|
|
|
void SyncSystem();
|
|
|
|
void SyncSystemPC();
|
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
CPlugins * GetPlugins()
|
|
|
|
{
|
|
|
|
return m_Plugins;
|
|
|
|
}
|
|
|
|
PIPELINE_STAGE PipelineStage() const
|
|
|
|
{
|
|
|
|
return m_PipelineStage;
|
|
|
|
}
|
|
|
|
uint32_t JumpToLocation() const
|
|
|
|
{
|
|
|
|
return m_JumpToLocation;
|
|
|
|
}
|
2022-01-18 07:47:21 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
private:
|
2022-03-14 10:37:06 +00:00
|
|
|
struct SETTING_CHANGED_CB
|
|
|
|
{
|
|
|
|
void * Data;
|
|
|
|
CallBackFunction Func;
|
|
|
|
};
|
|
|
|
typedef std::vector<SETTING_CHANGED_CB> SETTING_CHANGED_CB_LIST;
|
|
|
|
typedef std::map<CN64SystemCB, SETTING_CHANGED_CB_LIST> SETTING_CALLBACK;
|
|
|
|
|
2021-05-18 11:51:36 +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
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Recompiler has access to manipulate and call functions
|
2016-11-27 20:25:56 +00:00
|
|
|
friend class CSystemTimer;
|
|
|
|
friend class CRecompiler;
|
2022-01-18 07:47:21 +00:00
|
|
|
friend class CX86RecompilerOps;
|
2022-06-06 10:19:44 +00:00
|
|
|
friend class CArmRecompilerOps;
|
2016-11-27 20:25:56 +00:00
|
|
|
friend class CMipsMemoryVM;
|
2022-01-18 07:47:21 +00:00
|
|
|
friend class CInterpreterCPU;
|
|
|
|
friend class R4300iOp32;
|
|
|
|
friend class R4300iOp;
|
2016-09-26 11:10:11 +00:00
|
|
|
|
2022-03-14 10:37:06 +00:00
|
|
|
friend class VideoInterfaceHandler;
|
2022-10-16 21:57:52 +00:00
|
|
|
friend class PifRamHandler;
|
2022-03-14 10:37:06 +00:00
|
|
|
|
2021-05-18 11:51:36 +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
|
|
|
|
2022-01-18 07:47:21 +00:00
|
|
|
void ExecuteCPU();
|
|
|
|
void RefreshScreen();
|
|
|
|
void DumpSyncErrors(CN64System * SecondCPU);
|
|
|
|
void StartEmulation2(bool NewThread);
|
|
|
|
bool SetActiveSystem(bool bActive = true);
|
|
|
|
void InitRegisters(bool bPostPif, CMipsMemoryVM & MMU);
|
|
|
|
void DisplayRSPListCount();
|
2022-03-14 10:37:06 +00:00
|
|
|
void NotifyCallback(CN64SystemCB Type);
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// CPU methods
|
2022-01-18 07:47:21 +00:00
|
|
|
void ExecuteRecompiler();
|
|
|
|
void ExecuteInterpret();
|
|
|
|
void ExecuteSyncCPU();
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Mark information saying that the CPU has stopped
|
2022-01-18 07:47:21 +00:00
|
|
|
void CpuStopped();
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Functions in CTLB_CB
|
2015-11-12 06:52:27 +00:00
|
|
|
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();
|
|
|
|
|
2022-03-14 10:37:06 +00:00
|
|
|
SETTING_CALLBACK m_Callback;
|
2022-10-10 00:22:17 +00:00
|
|
|
CPlugins * const m_Plugins; // The plugin container
|
2022-01-18 07:47:21 +00:00
|
|
|
CPlugins * m_SyncPlugins;
|
|
|
|
CN64System * m_SyncCPU;
|
2022-03-21 00:29:02 +00:00
|
|
|
CMipsMemoryVM m_MMU_VM;
|
2022-01-18 07:47:21 +00:00
|
|
|
CTLB m_TLB;
|
|
|
|
CRegisters m_Reg;
|
|
|
|
CMempak m_Mempak;
|
2015-11-12 06:52:27 +00:00
|
|
|
CFramePerSecond m_FPS;
|
2022-01-18 07:47:21 +00:00
|
|
|
CProfiling m_CPU_Usage; // Used to track the CPU usage
|
|
|
|
CRecompiler * m_Recomp;
|
|
|
|
CSpeedLimiter m_Limiter;
|
|
|
|
bool m_InReset;
|
|
|
|
int32_t m_NextTimer;
|
|
|
|
CSystemTimer m_SystemTimer;
|
|
|
|
bool m_bCleanFrameBox;
|
|
|
|
bool m_RspBroke;
|
|
|
|
uint32_t m_Buttons[4];
|
|
|
|
bool m_TestTimer;
|
|
|
|
PIPELINE_STAGE m_PipelineStage;
|
|
|
|
uint32_t m_JumpToLocation;
|
|
|
|
uint32_t m_TLBLoadAddress;
|
|
|
|
uint32_t m_TLBStoreAddress;
|
|
|
|
uint32_t m_SyncCount;
|
|
|
|
bool m_SyncSystem;
|
|
|
|
CRandom m_Random;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// When syncing cores this is the PC where it last synced correctly
|
2015-11-15 05:20:22 +00:00
|
|
|
uint32_t m_LastSuccessSyncPC[10];
|
2022-01-18 07:47:21 +00:00
|
|
|
int32_t m_CyclesToSkip;
|
2015-11-12 06:52:27 +00:00
|
|
|
|
2021-05-18 11:51:36 +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
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Handle to pause mutex
|
2015-11-12 06:52:27 +00:00
|
|
|
SyncEvent m_hPauseEvent;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Number 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
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// List of function that have been called (used in profiling)
|
2015-11-12 06:52:27 +00:00
|
|
|
FUNC_CALLS m_FunctionCalls;
|
2020-06-10 11:34:55 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// List of save state file IDs
|
2022-10-10 00:22:17 +00:00
|
|
|
const uint32_t SaveID_0 = 0x23D8A6C8; // Main save state info (*.pj)
|
|
|
|
const uint32_t SaveID_1 = 0x56D2CD23; // Extra data v1 (system timing) info (*.dat)
|
|
|
|
const uint32_t SaveID_2 = 0x750A6BEB; // Extra data v2 (timing + disk registers) (*.dat)
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|