2013-04-25 05:51:31 +00:00
|
|
|
#pragma once
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2013-04-25 05:51:31 +00:00
|
|
|
#include <thread>
|
2017-09-07 00:03:04 -04:00
|
|
|
#include <future>
|
2019-10-16 20:51:11 -04:00
|
|
|
#include "filesystem_def.h"
|
2008-03-31 03:37:16 +00:00
|
|
|
#include "Types.h"
|
|
|
|
#include "MIPS.h"
|
|
|
|
#include "MailBox.h"
|
|
|
|
#include "PadHandler.h"
|
2023-03-19 22:24:29 -04:00
|
|
|
#include "GunListener.h"
|
2017-05-16 19:54:38 -04:00
|
|
|
#include "OpticalMedia.h"
|
2008-03-31 03:37:16 +00:00
|
|
|
#include "VirtualMachine.h"
|
2015-05-06 00:54:15 -04:00
|
|
|
#include "ee/Ee_SubSystem.h"
|
2008-11-28 02:56:27 +00:00
|
|
|
#include "iop/Iop_SubSystem.h"
|
2014-10-20 22:34:44 -04:00
|
|
|
#include "../tools/PsfPlayer/Source/SoundHandler.h"
|
2021-02-18 13:18:41 -05:00
|
|
|
#include "FrameLimiter.h"
|
2014-10-05 01:41:06 -04:00
|
|
|
#include "Profiler.h"
|
2008-03-31 03:37:16 +00:00
|
|
|
|
|
|
|
class CPS2VM : public CVirtualMachine
|
|
|
|
{
|
|
|
|
public:
|
2016-09-21 10:24:59 -04:00
|
|
|
struct CPU_UTILISATION_INFO
|
|
|
|
{
|
|
|
|
int32 eeTotalTicks = 0;
|
|
|
|
int32 eeIdleTicks = 0;
|
|
|
|
|
|
|
|
int32 iopTotalTicks = 0;
|
|
|
|
int32 iopIdleTicks = 0;
|
|
|
|
};
|
|
|
|
|
2022-10-03 18:46:38 -04:00
|
|
|
typedef std::unique_ptr<COpticalMedia> OpticalMediaPtr;
|
2014-10-04 23:02:32 -04:00
|
|
|
typedef std::unique_ptr<Ee::CSubSystem> EeSubSystemPtr;
|
|
|
|
typedef std::unique_ptr<Iop::CSubSystem> IopSubSystemPtr;
|
2019-06-20 00:40:28 +01:00
|
|
|
typedef Framework::CSignal<void(const CProfiler::ZoneArray&)> ProfileFrameDoneSignal;
|
2022-11-10 22:06:18 -05:00
|
|
|
typedef std::function<void(CPS2VM*)> ExecutableReloadedHandler;
|
2013-06-09 05:47:33 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CPS2VM();
|
2018-06-22 13:26:49 -04:00
|
|
|
virtual ~CPS2VM() = default;
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void Initialize();
|
|
|
|
void Destroy();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void StepEe();
|
|
|
|
void StepIop();
|
|
|
|
void StepVu0();
|
|
|
|
void StepVu1();
|
2008-11-28 02:56:27 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void Resume() override;
|
|
|
|
void Pause() override;
|
2020-12-24 13:36:40 +00:00
|
|
|
void PauseAsync();
|
2023-06-08 17:12:43 -04:00
|
|
|
void Reset(uint32 = PS2::EE_BASE_RAM_SIZE, uint32 = PS2::IOP_BASE_RAM_SIZE);
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
STATUS GetStatus() const override;
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreateGSHandler(const CGSHandler::FactoryFunction&);
|
|
|
|
CGSHandler* GetGSHandler();
|
|
|
|
void DestroyGSHandler();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreatePadHandler(const CPadHandler::FactoryFunction&);
|
|
|
|
CPadHandler* GetPadHandler();
|
|
|
|
void DestroyPadHandler();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreateSoundHandler(const CSoundHandler::FactoryFunction&);
|
2019-06-27 19:57:15 +01:00
|
|
|
CSoundHandler* GetSoundHandler();
|
2019-10-12 10:58:54 +01:00
|
|
|
void ReloadSpuBlockCount();
|
2023-06-21 12:42:28 -04:00
|
|
|
void DestroySoundHandler();
|
2015-04-06 15:51:59 -04:00
|
|
|
|
2022-11-10 22:06:18 -05:00
|
|
|
void CDROM0_SyncPath();
|
|
|
|
void CDROM0_Reset();
|
|
|
|
|
2023-01-31 09:20:55 -05:00
|
|
|
void SetEeFrequencyScale(uint32, uint32);
|
2021-02-24 11:55:09 -05:00
|
|
|
void ReloadFrameRateLimit();
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
static fs::path GetStateDirectoryPath();
|
|
|
|
fs::path GenerateStatePath(unsigned int) const;
|
2017-09-07 18:00:30 -04:00
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
std::future<bool> SaveState(const fs::path&);
|
|
|
|
std::future<bool> LoadState(const fs::path&);
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CPU_UTILISATION_INFO GetCpuUtilisationInfo() const;
|
2016-09-21 10:24:59 -04:00
|
|
|
|
2008-11-28 02:56:27 +00:00
|
|
|
#ifdef DEBUGGER_INCLUDED
|
2022-05-05 20:00:37 -04:00
|
|
|
fs::path MakeDebugTagsPackagePath(const char*);
|
2018-04-30 21:01:23 +01:00
|
|
|
void LoadDebugTags(const char*);
|
|
|
|
void SaveDebugTags(const char*);
|
2008-11-28 02:56:27 +00:00
|
|
|
#endif
|
|
|
|
|
2023-03-19 22:24:29 -04:00
|
|
|
void ReportGunPosition(float, float);
|
2023-04-27 19:16:43 -04:00
|
|
|
bool HasGunListener() const;
|
2023-03-19 22:24:29 -04:00
|
|
|
void SetGunListener(CGunListener*);
|
|
|
|
|
2022-10-03 18:46:38 -04:00
|
|
|
OpticalMediaPtr m_cdrom0;
|
|
|
|
CPadHandler* m_pad = nullptr;
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
EeSubSystemPtr m_ee;
|
|
|
|
IopSubSystemPtr m_iop;
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
ProfileFrameDoneSignal ProfileFrameDone;
|
2022-12-20 15:39:16 -05:00
|
|
|
|
2022-11-10 22:06:18 -05:00
|
|
|
ExecutableReloadedHandler BeforeExecutableReloaded;
|
|
|
|
ExecutableReloadedHandler AfterExecutableReloaded;
|
2022-12-20 15:39:16 -05:00
|
|
|
|
2021-11-27 10:19:57 -05:00
|
|
|
protected:
|
|
|
|
virtual void CreateVM();
|
2022-01-09 15:02:45 -05:00
|
|
|
void ResumeImpl();
|
2021-11-27 10:19:57 -05:00
|
|
|
|
|
|
|
CMailBox m_mailBox;
|
|
|
|
|
2008-03-31 03:37:16 +00:00
|
|
|
private:
|
2023-06-21 12:42:28 -04:00
|
|
|
void ValidateThreadContext();
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void ResetVM();
|
|
|
|
void DestroyVM();
|
2019-10-16 20:51:11 -04:00
|
|
|
bool SaveVMState(const fs::path&);
|
|
|
|
bool LoadVMState(const fs::path&);
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2022-06-17 14:33:28 -04:00
|
|
|
void SaveVmTimingState(Framework::CZipArchiveWriter&);
|
|
|
|
void LoadVmTimingState(Framework::CZipArchiveReader&);
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void ReloadExecutable(const char*, const CPS2OS::ArgumentList&);
|
2021-02-24 16:04:10 -05:00
|
|
|
void OnCrtModeChange();
|
2011-12-25 04:50:54 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void PauseImpl();
|
|
|
|
void DestroyImpl();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreateGsHandlerImpl(const CGSHandler::FactoryFunction&);
|
|
|
|
void DestroyGsHandlerImpl();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreatePadHandlerImpl(const CPadHandler::FactoryFunction&);
|
|
|
|
void DestroyPadHandlerImpl();
|
2014-10-05 01:41:06 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void CreateSoundHandlerImpl(const CSoundHandler::FactoryFunction&);
|
|
|
|
void DestroySoundHandlerImpl();
|
2008-07-20 17:26:08 +00:00
|
|
|
|
2023-06-21 12:42:28 -04:00
|
|
|
void ReloadSpuBlockCountImpl();
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void UpdateEe();
|
|
|
|
void UpdateIop();
|
|
|
|
void UpdateSpu();
|
2008-03-31 03:37:16 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void SetIopOpticalMedia(COpticalMedia*);
|
2008-11-28 02:56:27 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void RegisterModulesInPadHandler();
|
2014-10-05 01:41:06 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void EmuThread();
|
2014-10-05 01:41:06 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
std::thread m_thread;
|
2023-05-02 08:56:25 -04:00
|
|
|
STATUS m_nStatus = PAUSED;
|
|
|
|
bool m_nEnd = false;
|
2016-09-21 10:24:59 -04:00
|
|
|
|
2023-01-31 09:20:55 -05:00
|
|
|
uint32 m_eeFreqScaleNumerator = 1;
|
|
|
|
uint32 m_eeFreqScaleDenominator = 1;
|
2023-06-08 17:12:43 -04:00
|
|
|
uint32 m_eeRamSize = PS2::EE_BASE_RAM_SIZE;
|
|
|
|
uint32 m_iopRamSize = PS2::IOP_BASE_RAM_SIZE;
|
2023-10-12 16:48:57 -04:00
|
|
|
uint32 m_hblankTicksTotal = 0;
|
2021-02-24 16:32:35 -05:00
|
|
|
uint32 m_onScreenTicksTotal = 0;
|
|
|
|
uint32 m_vblankTicksTotal = 0;
|
2023-10-12 16:48:57 -04:00
|
|
|
int m_hblankTicks = 0;
|
2018-04-30 21:01:23 +01:00
|
|
|
int m_vblankTicks = 0;
|
2023-05-02 08:56:25 -04:00
|
|
|
bool m_inVblank = false;
|
2023-06-21 17:10:21 -04:00
|
|
|
int64 m_spuUpdateTicks = 0;
|
2023-07-09 11:13:53 -04:00
|
|
|
int64 m_spuUpdateTicksTotal = 0;
|
2018-04-30 21:01:23 +01:00
|
|
|
int m_eeExecutionTicks = 0;
|
|
|
|
int m_iopExecutionTicks = 0;
|
2023-01-31 09:20:55 -05:00
|
|
|
static const int m_eeTickStep = 4800;
|
|
|
|
int m_iopTickStep = 0;
|
2021-02-18 13:18:41 -05:00
|
|
|
CFrameLimiter m_frameLimiter;
|
2013-06-09 05:47:33 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CPU_UTILISATION_INFO m_cpuUtilisation;
|
2014-10-05 01:41:06 -04:00
|
|
|
|
2023-05-02 08:56:25 -04:00
|
|
|
bool m_singleStepEe = false;
|
|
|
|
bool m_singleStepIop = false;
|
|
|
|
bool m_singleStepVu0 = false;
|
|
|
|
bool m_singleStepVu1 = false;
|
2018-04-30 21:01:23 +01:00
|
|
|
|
2018-04-16 09:14:24 -04:00
|
|
|
//SPU update parameters
|
2014-10-20 22:34:44 -04:00
|
|
|
enum
|
|
|
|
{
|
2018-04-16 09:14:24 -04:00
|
|
|
DST_SAMPLE_RATE = 44100,
|
2023-06-21 17:10:21 -04:00
|
|
|
SAMPLES_PER_UPDATE = 45, //44100 / 45 -> 980 SPU updates per second
|
|
|
|
SPU_UPDATE_TICKS_PRECISION = 32,
|
|
|
|
BLOCK_SIZE = SAMPLES_PER_UPDATE * 2,
|
2023-06-21 12:42:28 -04:00
|
|
|
MAX_BLOCK_COUNT = 400,
|
2014-10-20 22:34:44 -04:00
|
|
|
};
|
|
|
|
|
2023-06-21 12:42:28 -04:00
|
|
|
int16 m_samples[BLOCK_SIZE * MAX_BLOCK_COUNT];
|
2018-04-30 21:01:23 +01:00
|
|
|
int m_currentSpuBlock = 0;
|
2023-06-21 12:42:28 -04:00
|
|
|
int m_spuBlockCount = 0;
|
2018-04-30 21:01:23 +01:00
|
|
|
CSoundHandler* m_soundHandler = nullptr;
|
2014-10-20 22:34:44 -04:00
|
|
|
|
2023-03-19 22:24:29 -04:00
|
|
|
CGunListener* m_gunListener = nullptr;
|
2023-05-30 21:00:01 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CProfiler::ZoneHandle m_eeProfilerZone = 0;
|
|
|
|
CProfiler::ZoneHandle m_iopProfilerZone = 0;
|
|
|
|
CProfiler::ZoneHandle m_spuProfilerZone = 0;
|
|
|
|
CProfiler::ZoneHandle m_gsSyncProfilerZone = 0;
|
|
|
|
CProfiler::ZoneHandle m_otherProfilerZone = 0;
|
2019-06-20 00:40:28 +01:00
|
|
|
|
2019-08-16 17:11:35 -04:00
|
|
|
CPS2OS::RequestLoadExecutableEvent::Connection m_OnRequestLoadExecutableConnection;
|
2021-02-24 16:04:10 -05:00
|
|
|
Framework::CSignal<void()>::Connection m_OnCrtModeChangeConnection;
|
2008-03-31 03:37:16 +00:00
|
|
|
};
|