2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
2014-09-13 22:40:12 +02:00
|
|
|
|
2016-04-14 00:59:00 +02:00
|
|
|
#include "VFS.h"
|
2015-09-18 00:41:14 +02:00
|
|
|
|
2016-08-09 16:14:41 +02:00
|
|
|
enum class system_type
|
|
|
|
|
{
|
|
|
|
|
ps3,
|
|
|
|
|
psv, // Experimental
|
|
|
|
|
//psp, // Hypothetical
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Current process type
|
|
|
|
|
extern system_type g_system;
|
|
|
|
|
|
2015-12-02 10:23:25 +01:00
|
|
|
enum class frame_type;
|
2015-10-07 18:02:10 +02:00
|
|
|
|
2015-09-18 00:41:14 +02:00
|
|
|
struct EmuCallbacks
|
|
|
|
|
{
|
|
|
|
|
std::function<void(std::function<void()>)> call_after;
|
|
|
|
|
std::function<void()> process_events;
|
2016-04-14 00:59:00 +02:00
|
|
|
std::function<void()> exit;
|
|
|
|
|
std::function<std::shared_ptr<class KeyboardHandlerBase>()> get_kb_handler;
|
|
|
|
|
std::function<std::shared_ptr<class MouseHandlerBase>()> get_mouse_handler;
|
|
|
|
|
std::function<std::shared_ptr<class PadHandlerBase>()> get_pad_handler;
|
2016-04-27 00:27:24 +02:00
|
|
|
std::function<std::unique_ptr<class GSFrameBase>(frame_type, int, int)> get_gs_frame;
|
2015-12-02 17:12:48 +01:00
|
|
|
std::function<std::shared_ptr<class GSRender>()> get_gs_render;
|
2015-12-30 02:12:18 +01:00
|
|
|
std::function<std::shared_ptr<class AudioThread>()> get_audio;
|
2015-12-19 12:40:52 +01:00
|
|
|
std::function<std::shared_ptr<class MsgDialogBase>()> get_msg_dialog;
|
2015-09-18 00:41:14 +02:00
|
|
|
std::function<std::unique_ptr<class SaveDialogBase>()> get_save_dialog;
|
|
|
|
|
};
|
2014-02-23 17:52:52 +01:00
|
|
|
|
2015-07-01 00:25:52 +02:00
|
|
|
enum Status : u32
|
2014-07-10 22:54:12 +02:00
|
|
|
{
|
|
|
|
|
Running,
|
|
|
|
|
Paused,
|
|
|
|
|
Stopped,
|
|
|
|
|
Ready,
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-18 00:41:14 +02:00
|
|
|
class Emulator final
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2017-03-22 21:23:47 +01:00
|
|
|
atomic_t<u32> m_status{Stopped};
|
2015-09-18 00:41:14 +02:00
|
|
|
|
2016-04-14 00:59:00 +02:00
|
|
|
EmuCallbacks m_cb;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2016-04-14 00:59:00 +02:00
|
|
|
atomic_t<u64> m_pause_start_time; // set when paused
|
|
|
|
|
atomic_t<u64> m_pause_amend_time; // increased when resumed
|
2013-07-03 18:17:16 +02:00
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
std::string m_path;
|
|
|
|
|
std::string m_elf_path;
|
2017-02-22 14:08:53 +01:00
|
|
|
std::string m_cache_path;
|
2014-04-01 02:33:55 +02:00
|
|
|
std::string m_title_id;
|
2014-12-21 17:29:51 +01:00
|
|
|
std::string m_title;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-09-18 00:41:14 +02:00
|
|
|
public:
|
2017-03-22 21:23:47 +01:00
|
|
|
Emulator() = default;
|
2015-09-18 00:41:14 +02:00
|
|
|
|
|
|
|
|
void SetCallbacks(EmuCallbacks&& cb)
|
|
|
|
|
{
|
|
|
|
|
m_cb = std::move(cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto& GetCallbacks() const
|
|
|
|
|
{
|
|
|
|
|
return m_cb;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 00:59:00 +02:00
|
|
|
// Call from the GUI thread
|
|
|
|
|
void CallAfter(std::function<void()>&& func) const
|
2015-09-18 00:41:14 +02:00
|
|
|
{
|
2016-04-14 00:59:00 +02:00
|
|
|
return m_cb.call_after(std::move(func));
|
2015-09-18 00:41:14 +02:00
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-12-05 20:34:09 +01:00
|
|
|
/** Set emulator mode to running unconditionnaly.
|
|
|
|
|
* Required to execute various part (PPUInterpreter, memory manager...) outside of rpcs3.
|
|
|
|
|
*/
|
|
|
|
|
void SetTestMode()
|
|
|
|
|
{
|
|
|
|
|
m_status = Running;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
void Init();
|
2016-04-14 00:59:00 +02:00
|
|
|
void SetPath(const std::string& path, const std::string& elf_path = {});
|
2013-09-24 23:11:29 +02:00
|
|
|
|
2015-09-18 00:41:14 +02:00
|
|
|
const std::string& GetPath() const
|
2014-11-19 15:16:30 +01:00
|
|
|
{
|
|
|
|
|
return m_elf_path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-28 15:41:15 +01:00
|
|
|
const std::string& GetTitleID() const
|
2014-12-21 17:29:51 +01:00
|
|
|
{
|
|
|
|
|
return m_title_id;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-28 15:41:15 +01:00
|
|
|
const std::string& GetTitle() const
|
2014-12-21 17:29:51 +01:00
|
|
|
{
|
|
|
|
|
return m_title;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 14:08:53 +01:00
|
|
|
const std::string& GetCachePath() const
|
|
|
|
|
{
|
|
|
|
|
return m_cache_path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 21:23:10 +02:00
|
|
|
u64 GetPauseTime()
|
|
|
|
|
{
|
|
|
|
|
return m_pause_amend_time;
|
|
|
|
|
}
|
2014-08-28 18:29:05 +02:00
|
|
|
|
2014-12-26 17:16:57 +01:00
|
|
|
bool BootGame(const std::string& path, bool direct = false);
|
2013-12-08 17:54:45 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
static std::string GetGameDir();
|
|
|
|
|
static std::string GetLibDir();
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
void Load();
|
|
|
|
|
void Run();
|
2015-09-13 00:37:57 +02:00
|
|
|
bool Pause();
|
2013-06-30 10:46:29 +02:00
|
|
|
void Resume();
|
|
|
|
|
void Stop();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2016-08-03 22:51:05 +02:00
|
|
|
bool IsRunning() const { return m_status == Running; }
|
|
|
|
|
bool IsPaused() const { return m_status == Paused; }
|
|
|
|
|
bool IsStopped() const { return m_status == Stopped; }
|
|
|
|
|
bool IsReady() const { return m_status == Ready; }
|
2017-02-09 23:51:29 +01:00
|
|
|
auto GetStatus() const { return m_status.load(); }
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
|
2015-07-26 13:21:25 +02:00
|
|
|
extern Emulator Emu;
|