2019-09-09 07:01:26 +00:00
|
|
|
#pragma once
|
2020-02-09 13:16:25 +00:00
|
|
|
#include "common/timer.h"
|
2019-11-07 15:07:39 +00:00
|
|
|
#include "host_interface.h"
|
2020-09-29 13:29:28 +00:00
|
|
|
#include "settings.h"
|
2020-01-24 04:53:40 +00:00
|
|
|
#include "timing_event.h"
|
2020-01-24 04:51:05 +00:00
|
|
|
#include "types.h"
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <optional>
|
2020-01-24 04:51:05 +00:00
|
|
|
#include <string>
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
class ByteStream;
|
2019-11-16 05:27:57 +00:00
|
|
|
class CDImage;
|
2019-09-14 10:28:47 +00:00
|
|
|
class StateWrapper;
|
|
|
|
|
2019-12-08 14:51:52 +00:00
|
|
|
class Controller;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2020-09-09 12:11:28 +00:00
|
|
|
struct CheatCode;
|
|
|
|
class CheatList;
|
|
|
|
|
2020-03-02 01:08:16 +00:00
|
|
|
struct SystemBootParameters
|
|
|
|
{
|
|
|
|
SystemBootParameters();
|
2020-09-12 20:14:50 +00:00
|
|
|
SystemBootParameters(SystemBootParameters&& other);
|
2020-03-02 01:08:16 +00:00
|
|
|
SystemBootParameters(std::string filename_);
|
|
|
|
~SystemBootParameters();
|
|
|
|
|
|
|
|
std::string filename;
|
|
|
|
std::optional<bool> override_fast_boot;
|
2020-04-13 12:13:46 +00:00
|
|
|
std::optional<bool> override_fullscreen;
|
2020-12-26 14:28:04 +00:00
|
|
|
std::optional<bool> override_start_paused;
|
2020-05-26 16:01:09 +00:00
|
|
|
std::unique_ptr<ByteStream> state_stream;
|
2020-07-22 16:36:05 +00:00
|
|
|
u32 media_playlist_index = 0;
|
|
|
|
bool load_image_to_ram = false;
|
2020-06-28 15:51:01 +00:00
|
|
|
bool force_software_renderer = false;
|
2020-03-02 01:08:16 +00:00
|
|
|
};
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
namespace System {
|
2020-02-05 08:43:00 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
// 5 megabytes is sufficient for now, at the moment they're around 4.2MB.
|
|
|
|
MAX_SAVE_STATE_SIZE = 5 * 1024 * 1024
|
|
|
|
};
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-09-29 13:29:28 +00:00
|
|
|
enum : TickCount
|
|
|
|
{
|
|
|
|
MASTER_CLOCK = 44100 * 0x300 // 33868800Hz or 33.8688MHz, also used as CPU clock
|
|
|
|
};
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
enum class State
|
|
|
|
{
|
|
|
|
Shutdown,
|
|
|
|
Starting,
|
|
|
|
Running,
|
|
|
|
Paused
|
|
|
|
};
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-09-29 13:29:28 +00:00
|
|
|
extern TickCount g_ticks_per_second;
|
|
|
|
|
2020-09-01 02:29:22 +00:00
|
|
|
/// Returns true if the filename is a PlayStation executable we can inject.
|
|
|
|
bool IsExeFileName(const char* path);
|
|
|
|
|
|
|
|
/// Returns true if the filename is a Portable Sound Format file we can uncompress/load.
|
|
|
|
bool IsPsfFileName(const char* path);
|
|
|
|
|
|
|
|
/// Returns true if the filename is a M3U Playlist we can handle.
|
|
|
|
bool IsM3UFileName(const char* path);
|
|
|
|
|
2021-02-18 08:07:09 +00:00
|
|
|
/// Returns true if the filename is one we can load.
|
|
|
|
bool IsLoadableFilename(const char* path);
|
|
|
|
|
2020-09-01 02:29:22 +00:00
|
|
|
/// Parses an M3U playlist, returning the entries.
|
|
|
|
std::vector<std::string> ParseM3UFile(const char* path);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Returns the preferred console type for a disc.
|
|
|
|
ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region);
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2021-02-21 06:53:29 +00:00
|
|
|
std::string GetExecutableNameForImage(CDImage* cdi);
|
|
|
|
bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data);
|
|
|
|
|
2020-09-01 02:29:22 +00:00
|
|
|
std::string GetGameCodeForImage(CDImage* cdi);
|
|
|
|
std::string GetGameCodeForPath(const char* image_path);
|
|
|
|
DiscRegion GetRegionForCode(std::string_view code);
|
|
|
|
DiscRegion GetRegionFromSystemArea(CDImage* cdi);
|
|
|
|
DiscRegion GetRegionForImage(CDImage* cdi);
|
2021-01-24 04:05:45 +00:00
|
|
|
DiscRegion GetRegionForExe(const char* path);
|
|
|
|
DiscRegion GetRegionForPsf(const char* path);
|
2020-09-01 02:29:22 +00:00
|
|
|
std::optional<DiscRegion> GetRegionForPath(const char* image_path);
|
|
|
|
std::string_view GetTitleForPath(const char* path);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
State GetState();
|
|
|
|
void SetState(State new_state);
|
|
|
|
bool IsRunning();
|
|
|
|
bool IsPaused();
|
|
|
|
bool IsShutdown();
|
|
|
|
bool IsValid();
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2021-02-18 15:48:44 +00:00
|
|
|
bool IsStartupCancelled();
|
|
|
|
void CancelPendingStartup();
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
ConsoleRegion GetRegion();
|
|
|
|
bool IsPALRegion();
|
2020-09-29 13:29:28 +00:00
|
|
|
|
|
|
|
ALWAYS_INLINE TickCount GetTicksPerSecond()
|
|
|
|
{
|
|
|
|
return g_ticks_per_second;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE_RELEASE TickCount ScaleTicksToOverclock(TickCount ticks)
|
|
|
|
{
|
|
|
|
if (!g_settings.cpu_overclock_active)
|
|
|
|
return ticks;
|
|
|
|
|
|
|
|
return static_cast<TickCount>((static_cast<u64>(static_cast<u32>(ticks)) * g_settings.cpu_overclock_numerator) /
|
|
|
|
g_settings.cpu_overclock_denominator);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE_RELEASE TickCount UnscaleTicksToOverclock(TickCount ticks, TickCount* remainder)
|
|
|
|
{
|
|
|
|
if (!g_settings.cpu_overclock_active)
|
|
|
|
return ticks;
|
|
|
|
|
|
|
|
const u64 num =
|
|
|
|
(static_cast<u32>(ticks) * static_cast<u64>(g_settings.cpu_overclock_denominator)) + static_cast<u32>(*remainder);
|
|
|
|
const TickCount t = static_cast<u32>(num / g_settings.cpu_overclock_numerator);
|
|
|
|
*remainder = static_cast<u32>(num % g_settings.cpu_overclock_numerator);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
TickCount GetMaxSliceTicks();
|
|
|
|
void UpdateOverclock();
|
|
|
|
|
2021-01-24 03:17:22 +00:00
|
|
|
/// Injects a PS-EXE into memory at its specified load location. If patch_loader is set, the BIOS will be patched to
|
|
|
|
/// direct execution to this executable.
|
|
|
|
bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader = true);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
u32 GetFrameNumber();
|
|
|
|
u32 GetInternalFrameNumber();
|
|
|
|
void FrameDone();
|
|
|
|
void IncrementInternalFrameNumber();
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
const std::string& GetRunningPath();
|
|
|
|
const std::string& GetRunningCode();
|
|
|
|
const std::string& GetRunningTitle();
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
float GetFPS();
|
|
|
|
float GetVPS();
|
|
|
|
float GetEmulationSpeed();
|
|
|
|
float GetAverageFrameTime();
|
|
|
|
float GetWorstFrameTime();
|
|
|
|
float GetThrottleFrequency();
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
bool Boot(const SystemBootParameters& params);
|
|
|
|
void Reset();
|
|
|
|
void Shutdown();
|
2019-11-16 05:27:57 +00:00
|
|
|
|
2020-11-25 13:06:39 +00:00
|
|
|
bool LoadState(ByteStream* state, bool update_display = true);
|
2020-07-31 07:09:18 +00:00
|
|
|
bool SaveState(ByteStream* state, u32 screenshot_size = 128);
|
2020-07-22 16:35:23 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Recreates the GPU component, saving/loading the state so it is preserved. Call when the GPU renderer changes.
|
2020-11-25 13:06:39 +00:00
|
|
|
bool RecreateGPU(GPURenderer renderer, bool update_display = true);
|
2019-11-16 05:27:57 +00:00
|
|
|
|
2020-12-16 15:18:02 +00:00
|
|
|
void SingleStepCPU();
|
2020-07-31 07:09:18 +00:00
|
|
|
void RunFrame();
|
2021-01-28 10:20:15 +00:00
|
|
|
void RunFrames();
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-11-03 11:21:11 +00:00
|
|
|
/// Sets target emulation speed.
|
2021-01-12 16:36:11 +00:00
|
|
|
float GetTargetSpeed();
|
2020-11-03 11:21:11 +00:00
|
|
|
void SetTargetSpeed(float speed);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Adjusts the throttle frequency, i.e. how many times we should sleep per second.
|
|
|
|
void SetThrottleFrequency(float frequency);
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Updates the throttle period, call when target emulation speed changes.
|
|
|
|
void UpdateThrottlePeriod();
|
2020-12-06 16:43:46 +00:00
|
|
|
void ResetThrottler();
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
|
|
|
|
void Throttle();
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
void UpdatePerformanceCounters();
|
|
|
|
void ResetPerformanceCounters();
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
// Access controllers for simulating input.
|
|
|
|
Controller* GetController(u32 slot);
|
|
|
|
void UpdateControllers();
|
|
|
|
void UpdateControllerSettings();
|
|
|
|
void ResetControllers();
|
|
|
|
void UpdateMemoryCards();
|
2021-01-21 07:59:40 +00:00
|
|
|
void UpdateMultitaps();
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-08-16 13:20:36 +00:00
|
|
|
/// Dumps RAM to a file.
|
|
|
|
bool DumpRAM(const char* filename);
|
|
|
|
|
2021-01-13 09:24:41 +00:00
|
|
|
/// Dumps video RAM to a file.
|
|
|
|
bool DumpVRAM(const char* filename);
|
|
|
|
|
|
|
|
/// Dumps sound RAM to a file.
|
|
|
|
bool DumpSPURAM(const char* filename);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
bool HasMedia();
|
2021-02-16 16:16:23 +00:00
|
|
|
std::string GetMediaFileName();
|
2020-07-31 07:09:18 +00:00
|
|
|
bool InsertMedia(const char* path);
|
|
|
|
void RemoveMedia();
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2020-08-15 10:38:54 +00:00
|
|
|
/// Returns true if a playlist is being used.
|
|
|
|
bool HasMediaPlaylist();
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Returns the number of entries in the media/disc playlist.
|
|
|
|
u32 GetMediaPlaylistCount();
|
2020-01-24 04:51:05 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Returns the current image from the media/disc playlist.
|
|
|
|
u32 GetMediaPlaylistIndex();
|
2020-01-24 04:51:05 +00:00
|
|
|
|
2021-02-26 14:44:53 +00:00
|
|
|
/// Returns the index of the specified path in the playlist, or UINT32_MAX if it does not exist.
|
|
|
|
u32 GetMediaPlaylistIndexForPath(const std::string& path);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Returns the path to the specified playlist index.
|
|
|
|
const std::string& GetMediaPlaylistPath(u32 index);
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Adds a new path to the media playlist.
|
|
|
|
bool AddMediaPathToPlaylist(const std::string_view& path);
|
2020-02-09 13:16:25 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Removes a path from the media playlist.
|
|
|
|
bool RemoveMediaPathFromPlaylist(const std::string_view& path);
|
|
|
|
bool RemoveMediaPathFromPlaylist(u32 index);
|
2020-02-09 13:16:25 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Changes a path from the media playlist.
|
|
|
|
bool ReplaceMediaPathFromPlaylist(u32 index, const std::string_view& path);
|
2020-02-09 13:16:25 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Switches to the specified media/disc playlist index.
|
|
|
|
bool SwitchMediaFromPlaylist(u32 index);
|
2020-07-22 16:36:05 +00:00
|
|
|
|
2020-09-09 12:11:28 +00:00
|
|
|
/// Returns true if there is currently a cheat list.
|
|
|
|
bool HasCheatList();
|
|
|
|
|
|
|
|
/// Accesses the current cheat list.
|
|
|
|
CheatList* GetCheatList();
|
|
|
|
|
|
|
|
/// Applies a single cheat code.
|
|
|
|
void ApplyCheatCode(const CheatCode& code);
|
|
|
|
|
|
|
|
/// Sets or clears the provided cheat list, applying every frame.
|
|
|
|
void SetCheatList(std::unique_ptr<CheatList> cheats);
|
|
|
|
|
2021-01-23 09:00:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Memory Save States (Rewind and Runahead)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void CalculateRewindMemoryUsage(u32 num_saves, u64* ram_usage, u64* vram_usage);
|
|
|
|
void ClearMemorySaveStates();
|
|
|
|
void UpdateMemorySaveStateSettings();
|
|
|
|
bool LoadRewindState(u32 skip_saves = 0, bool consume_state = true);
|
|
|
|
void SetRewinding(bool enabled);
|
2021-01-23 16:52:52 +00:00
|
|
|
void SetRunaheadReplayFlag();
|
2021-01-23 09:00:54 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
} // namespace System
|