2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - 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 *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
typedef std::list<SystemEvent> EVENT_LIST;
|
|
|
|
|
|
|
|
typedef std::map<DWORD, DWORD> FUNC_CALLS;
|
|
|
|
|
|
|
|
class CPlugins;
|
|
|
|
class CRSP_Plugin;
|
|
|
|
|
|
|
|
//#define TEST_SP_TRACKING //track the SP to make sure all ops pick it up fine
|
|
|
|
|
|
|
|
class CN64System :
|
|
|
|
private CMipsMemory_CallBack,
|
2010-05-22 04:47:15 +00:00
|
|
|
private CTLB_CB,
|
2010-06-04 06:25:07 +00:00
|
|
|
private CSystemEvents,
|
2008-09-18 03:15:49 +00:00
|
|
|
protected CN64SystemSettings,
|
2012-11-29 11:23:35 +00:00
|
|
|
public CGameSettings,
|
2012-09-28 20:07:45 +00:00
|
|
|
protected CDebugSettings,
|
2008-09-18 03:15:49 +00:00
|
|
|
public CDebugger
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
public:
|
2012-09-30 06:07:08 +00:00
|
|
|
CN64System ( CPlugins * Plugins, bool SavesReadOnly );
|
2010-06-04 06:25:07 +00:00
|
|
|
virtual ~CN64System ( void );
|
2010-05-22 04:47:15 +00:00
|
|
|
|
2013-01-03 08:51:00 +00:00
|
|
|
typedef struct {
|
|
|
|
HANDLE * ThreadHandle;
|
|
|
|
DWORD ThreadID;
|
|
|
|
} ThreadInfo;
|
|
|
|
|
2012-09-30 06:07:08 +00:00
|
|
|
CProfiling m_Profile;
|
|
|
|
CCheats m_Cheats;
|
2012-09-30 14:37:40 +00:00
|
|
|
bool m_EndEmulation;
|
2012-10-02 19:42:06 +00:00
|
|
|
SAVE_CHIP_TYPE m_SaveUsing;
|
2012-09-30 06:07:08 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//Methods
|
2013-01-03 08:51:00 +00:00
|
|
|
static bool RunFileImage ( const char * FileLoc );
|
|
|
|
static void CloseSystem ( void );
|
2010-05-22 04:47:15 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CloseCpu ();
|
2010-06-04 06:25:07 +00:00
|
|
|
void ExternalEvent ( SystemEvent action ); //covers gui interacting and timers etc..
|
2015-01-27 05:07:44 +00:00
|
|
|
stdstr ChooseFileToOpen ( HWND hParent );
|
|
|
|
void DisplayRomInfo ( HWND hParent );
|
|
|
|
void SelectCheats ( HWND hParent );
|
2010-05-22 04:47:15 +00:00
|
|
|
void StartEmulation ( bool NewThread );
|
2015-04-28 22:19:02 +00:00
|
|
|
void SyncToAudio ();
|
2010-05-22 04:47:15 +00:00
|
|
|
bool IsDialogMsg ( MSG * msg );
|
2015-04-28 22:19:02 +00:00
|
|
|
void IncreaseSpeed () { m_Limitor.IncreaseSpeed(); }
|
|
|
|
void DecreaseSpeed () { m_Limitor.DecreaseSpeed(); }
|
2010-06-14 21:14:58 +00:00
|
|
|
void Reset ( bool bInitReg, bool ClearMenory );
|
2015-04-28 22:19:02 +00:00
|
|
|
void GameReset ();
|
|
|
|
void PluginReset ();
|
2010-05-22 04:47:15 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void Pause ();
|
|
|
|
void RunRSP ();
|
|
|
|
bool SaveState ();
|
2012-09-30 06:07:08 +00:00
|
|
|
bool LoadState ( LPCSTR FileName );
|
2015-04-28 22:19:02 +00:00
|
|
|
bool LoadState ();
|
2013-01-03 08:51:00 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
bool DmaUsed() const { return m_DMAUsed; }
|
|
|
|
void SetDmaUsed(bool DMAUsed) { m_DMAUsed = DMAUsed; }
|
|
|
|
DWORD GetButtons(int Control) const { return m_Buttons[Control]; }
|
2010-05-22 04:47:15 +00:00
|
|
|
|
|
|
|
//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
|
|
|
|
DWORD m_CurrentSP;
|
|
|
|
#endif
|
|
|
|
//For Sync CPU
|
|
|
|
void UpdateSyncCPU ( CN64System * const SecondCPU, DWORD const Cycles );
|
|
|
|
void SyncCPU ( CN64System * const SecondCPU );
|
2012-10-23 08:02:47 +00:00
|
|
|
void SyncCPUPC ( CN64System * const SecondCPU );
|
2015-04-28 22:19:02 +00:00
|
|
|
void SyncSystem ();
|
|
|
|
void SyncSystemPC ();
|
2010-05-22 04:47:15 +00:00
|
|
|
private:
|
2008-09-18 03:15:49 +00:00
|
|
|
//Make sure plugins can directly access this information
|
|
|
|
friend CGfxPlugin;
|
|
|
|
friend CAudioPlugin;
|
|
|
|
friend CRSP_Plugin;
|
|
|
|
friend CControl_Plugin;
|
|
|
|
|
|
|
|
//Recompiler has access to manipulate and call functions
|
2010-06-07 02:23:58 +00:00
|
|
|
friend CSystemTimer;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
//Used for loading and potentially executing the CPU in its own thread.
|
2013-01-03 08:51:00 +00:00
|
|
|
static void StartEmulationThread ( ThreadInfo * Info );
|
2010-06-04 06:25:07 +00:00
|
|
|
static bool EmulationStarting ( HANDLE hThread, DWORD ThreadId );
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void ExecuteCPU ();
|
|
|
|
void RefreshScreen ();
|
|
|
|
bool InternalEvent ();
|
2008-09-18 03:15:49 +00:00
|
|
|
void DumpSyncErrors ( CN64System * SecondCPU );
|
|
|
|
void StartEmulation2 ( bool NewThread );
|
2010-05-31 00:21:08 +00:00
|
|
|
bool SetActiveSystem ( bool bActive = true );
|
2010-05-23 10:05:41 +00:00
|
|
|
void InitRegisters ( bool bPostPif, CMipsMemory & MMU );
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//CPU Methods
|
2015-04-28 22:19:02 +00:00
|
|
|
void ExecuteRecompiler();
|
|
|
|
void ExecuteInterpret();
|
|
|
|
void ExecuteSyncCPU();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void AddEvent(SystemEvent Event);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Notification of changing conditions
|
2015-04-28 22:19:02 +00:00
|
|
|
void FunctionStarted(DWORD NewFuncAddress, DWORD OldFuncAddress, DWORD ReturnAddress);
|
|
|
|
void FunctionEnded(DWORD ReturnAddress, DWORD StackPos);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
//Mark information saying that the CPU has stopped
|
|
|
|
void CpuStopped();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Function in CMipsMemory_CallBack
|
2015-04-28 22:19:02 +00:00
|
|
|
virtual bool WriteToProtectedMemory(DWORD Address, int length);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//Functions in CTLB_CB
|
2015-04-28 22:19:02 +00:00
|
|
|
void TLB_Mapped(DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly);
|
|
|
|
void TLB_Unmaped(DWORD VAddr, DWORD Len);
|
|
|
|
void TLB_Changed();
|
2010-05-22 04:47:15 +00:00
|
|
|
|
|
|
|
CPlugins * const m_Plugins; //The plugin container
|
|
|
|
CN64System * m_SyncCPU;
|
2013-01-03 08:51:00 +00:00
|
|
|
CPlugins * m_SyncPlugins;
|
|
|
|
CMainGui * m_SyncWindow;
|
2015-04-28 22:19:02 +00:00
|
|
|
CMipsMemoryVM m_MMU_VM; //Memory of the n64
|
|
|
|
CTLB m_TLB;
|
|
|
|
CRegisters m_Reg;
|
2010-05-22 04:47:15 +00:00
|
|
|
CFramePerSecond m_FPS;
|
2015-04-28 22:19:02 +00:00
|
|
|
CProfiling m_CPU_Usage; //used to track the cpu usage
|
|
|
|
CRecompiler * m_Recomp;
|
2010-05-22 04:47:15 +00:00
|
|
|
CAudio m_Audio;
|
|
|
|
CSpeedLimitor m_Limitor;
|
|
|
|
bool m_InReset;
|
2015-04-16 02:38:53 +00:00
|
|
|
int m_NextTimer;
|
2010-05-23 10:05:41 +00:00
|
|
|
CSystemTimer m_SystemTimer;
|
2010-05-22 04:47:15 +00:00
|
|
|
bool m_bCleanFrameBox;
|
2015-04-20 20:01:18 +00:00
|
|
|
bool m_bInitialized;
|
2013-01-29 10:41:32 +00:00
|
|
|
bool m_RspBroke;
|
2010-06-04 06:25:07 +00:00
|
|
|
bool m_DMAUsed;
|
2010-06-14 21:14:58 +00:00
|
|
|
DWORD m_Buttons[4];
|
2015-05-02 22:14:19 +00:00
|
|
|
bool m_TestTimer;
|
2012-09-25 05:58:06 +00:00
|
|
|
DWORD m_NextInstruction;
|
|
|
|
DWORD m_JumpToLocation;
|
2012-09-29 07:58:16 +00:00
|
|
|
DWORD m_TLBLoadAddress;
|
|
|
|
DWORD m_TLBStoreAddress;
|
2013-02-05 09:14:26 +00:00
|
|
|
DWORD m_SyncCount;
|
2012-09-29 07:58:16 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//When Syncing cores this is the PC where it last Sync'ed correctly
|
|
|
|
DWORD m_LastSuccessSyncPC[10];
|
|
|
|
int m_CyclesToSkip;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//Handle to the cpu thread
|
|
|
|
HANDLE m_CPU_Handle;
|
|
|
|
DWORD m_CPU_ThreadID;
|
|
|
|
|
|
|
|
//Handle to pause mutex
|
|
|
|
void * m_hPauseEvent;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//No of Alist and Dlist sent to the RSP
|
|
|
|
DWORD m_AlistCount, m_DlistCount, m_UnknownCount;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
//list of function that have been called .. used in profiling
|
|
|
|
FUNC_CALLS m_FunctionCalls;
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|