/
N64System.h
222 lines (191 loc) · 6.81 KB
/
N64System.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#pragma once
#include <Common/Random.h>
#include <Common/SyncEvent.h>
#include <Common/Thread.h>
#include <Project64-core/Logging.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/SystemEvents.h>
#include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/Profiling.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/Plugin.h>
#include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/Settings/N64SystemSettings.h>
#include "FramePerSecond.h"
#include "Mips/TLB.h"
#include "SpeedLimiter.h"
typedef std::list<SystemEvent> EVENT_LIST;
typedef std::map<uint32_t, uint32_t> FUNC_CALLS;
class CPlugins;
class CRSP_Plugin;
class CRecompiler;
class VideoInterfaceHandler;
//#define TEST_SP_TRACKING // Track the SP to make sure all ops pick it up fine
enum CN64SystemCB
{
CN64SystemCB_Reset,
CN64SystemCB_LoadedGameState,
};
class CN64System :
public CLogging,
private CSystemEvents,
protected CN64SystemSettings,
public CGameSettings,
protected CDebugSettings
{
public:
typedef void (*CallBackFunction)(void *);
CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem);
virtual ~CN64System(void);
bool m_EndEmulation;
SAVE_CHIP_TYPE m_SaveUsing;
// Methods
static bool LoadFileImage(const char * FileLoc);
static bool LoadFileImageIPL(const char * FileLoc);
static bool LoadDiskImage(const char * FileLoc, const bool Expansion);
static bool SelectAndLoadFileImageIPL(Country country, bool combo);
static bool RunFileImage(const char * FileLoc);
static bool RunDiskImage(const char * FileLoc);
static bool RunDiskComboImage(const char * FileLoc, const char * FileLocDisk);
static void RunLoadedImage(void);
static void CloseSystem(void);
void RegisterCallBack(CN64SystemCB Type, void * Data, CallBackFunction Func);
void UnregisterCallBack(CN64SystemCB Type, void * Data, CallBackFunction Func);
void CloseCpu();
void ExternalEvent(SystemEvent action); // Covers GUI interactions and timers etc.
void StartEmulation(bool NewThread);
void EndEmulation();
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();
}
void Reset(bool bInitReg, bool ClearMenory);
void GameReset();
void PluginReset();
void ApplyGSButton(void);
void Pause();
bool SaveState();
bool LoadState(const char * FileName);
bool LoadState();
uint32_t GetButtons(int32_t Control) const;
// Variable used to track that the SP is being handled and stays the same as the real SP in sync core
#ifdef TEST_SP_TRACKING
uint32_t m_CurrentSP;
#endif
// For sync CPU
void UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycles);
void SyncCPU(CN64System * const SecondCPU);
void SyncCPUPC(CN64System * const SecondCPU);
void SyncSystem();
void SyncSystemPC();
CPlugins * GetPlugins()
{
return m_Plugins;
}
PIPELINE_STAGE PipelineStage() const
{
return m_PipelineStage;
}
uint32_t JumpToLocation() const
{
return m_JumpToLocation;
}
private:
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;
// Make sure plugins can directly access this information
friend class CGfxPlugin;
friend class CAudioPlugin;
friend class CRSP_Plugin;
friend class CControl_Plugin;
// Recompiler has access to manipulate and call functions
friend class CSystemTimer;
friend class CRecompiler;
friend class CX86RecompilerOps;
friend class CArmRecompilerOps;
friend class CMipsMemoryVM;
friend class R4300iOp;
friend class CSystemEvents;
friend class VideoInterfaceHandler;
friend class PifRamHandler;
friend class CRegisters;
// Used for loading and potentially executing the CPU in its own thread
static void StartEmulationThread(CThread * thread);
static bool EmulationStarting(CThread * thread);
static void StartEmulationThead();
void ExecuteCPU();
void RefreshScreen();
void DumpSyncErrors(CN64System * SecondCPU);
void StartEmulation2(bool NewThread);
bool SetActiveSystem(bool bActive = true);
void NotifyCallback(CN64SystemCB Type);
void DelayedJump(uint32_t JumpLocation);
void DelayedRelativeJump(uint32_t RelativeLocation);
// CPU methods
void ExecuteRecompiler();
void ExecuteInterpret();
void ExecuteSyncCPU();
// Mark information saying that the CPU has stopped
void CpuStopped();
// Functions in CTLB_CB
void TLB_Unmaped(uint32_t VAddr, uint32_t Len);
SETTING_CALLBACK m_Callback;
CPlugins * const m_Plugins; // The plugin container
CPlugins * m_SyncPlugins;
CN64System * m_SyncCPU;
CMipsMemoryVM m_MMU_VM;
CRegisters m_Reg;
CTLB m_TLB;
R4300iOp m_OpCodes;
CMempak m_Mempak;
CFramePerSecond m_FPS;
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;
uint32_t m_Buttons[4];
bool m_TestTimer;
PIPELINE_STAGE m_PipelineStage;
uint32_t m_JumpToLocation;
uint32_t m_JumpDelayLocation;
uint32_t m_TLBLoadAddress;
uint32_t m_TLBStoreAddress;
uint32_t m_SyncCount;
bool m_SyncSystem;
CRandom m_Random;
// When syncing cores this is the PC where it last synced correctly
uint32_t m_LastSuccessSyncPC[10];
int32_t m_CyclesToSkip;
// Handle to the CPU thread
CThread * m_thread;
// Handle to pause mutex
SyncEvent m_hPauseEvent;
// List of function that have been called (used in profiling)
FUNC_CALLS m_FunctionCalls;
// List of save state file IDs
const uint32_t SaveID_0 = 0x23D8A6C8; // Main save state info (*.pj)
const uint32_t SaveID_0_1 = 0x25EF3FAC; // 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)
};