2019-09-12 14:18:13 +00:00
|
|
|
#pragma once
|
2020-03-15 12:03:53 +00:00
|
|
|
#include "common/string.h"
|
2020-01-10 03:31:12 +00:00
|
|
|
#include "common/timer.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include "settings.h"
|
2019-11-16 10:12:03 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include <chrono>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <deque>
|
2020-01-24 04:51:52 +00:00
|
|
|
#include <functional>
|
2019-09-14 10:28:47 +00:00
|
|
|
#include <memory>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <mutex>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <optional>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <string>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <vector>
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2020-04-30 14:58:32 +00:00
|
|
|
enum LOGLEVEL;
|
|
|
|
|
2019-10-10 16:20:21 +00:00
|
|
|
class AudioStream;
|
2020-02-15 15:14:28 +00:00
|
|
|
class ByteStream;
|
2020-01-24 04:50:46 +00:00
|
|
|
class CDImage;
|
2019-11-03 14:39:48 +00:00
|
|
|
class HostDisplay;
|
2020-01-24 04:50:46 +00:00
|
|
|
class GameList;
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2020-03-02 01:08:16 +00:00
|
|
|
struct SystemBootParameters;
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2020-10-10 07:41:54 +00:00
|
|
|
namespace BIOS {
|
2020-09-22 13:08:07 +00:00
|
|
|
struct ImageInfo;
|
|
|
|
}
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
class HostInterface
|
|
|
|
{
|
|
|
|
public:
|
2020-05-09 14:44:37 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
AUDIO_SAMPLE_RATE = 44100,
|
|
|
|
AUDIO_CHANNELS = 2,
|
2020-06-06 04:40:20 +00:00
|
|
|
DEFAULT_AUDIO_BUFFER_SIZE = 2048
|
2020-05-09 14:44:37 +00:00
|
|
|
};
|
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
HostInterface();
|
|
|
|
virtual ~HostInterface();
|
|
|
|
|
2019-11-07 15:07:39 +00:00
|
|
|
/// Access to host display.
|
2020-06-29 16:46:57 +00:00
|
|
|
ALWAYS_INLINE HostDisplay* GetDisplay() const { return m_display.get(); }
|
2019-11-07 15:07:39 +00:00
|
|
|
|
|
|
|
/// Access to host audio stream.
|
2020-02-15 15:14:28 +00:00
|
|
|
ALWAYS_INLINE AudioStream* GetAudioStream() const { return m_audio_stream.get(); }
|
2019-10-10 16:20:21 +00:00
|
|
|
|
2020-04-05 12:59:06 +00:00
|
|
|
/// Initializes the emulator frontend.
|
|
|
|
virtual bool Initialize();
|
|
|
|
|
|
|
|
/// Shuts down the emulator frontend.
|
|
|
|
virtual void Shutdown();
|
|
|
|
|
2021-06-08 16:38:12 +00:00
|
|
|
virtual bool BootSystem(std::shared_ptr<SystemBootParameters> parameters);
|
2020-12-16 15:12:56 +00:00
|
|
|
virtual void PauseSystem(bool paused);
|
2020-06-08 16:05:55 +00:00
|
|
|
virtual void ResetSystem();
|
|
|
|
virtual void DestroySystem();
|
2019-11-07 15:07:39 +00:00
|
|
|
|
2020-02-28 07:00:09 +00:00
|
|
|
/// Loads state from the specified filename.
|
|
|
|
bool LoadState(const char* filename);
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
virtual void ReportError(const char* message);
|
|
|
|
virtual void ReportMessage(const char* message);
|
2020-12-16 15:17:26 +00:00
|
|
|
virtual void ReportDebuggerMessage(const char* message);
|
2020-02-26 09:25:57 +00:00
|
|
|
virtual bool ConfirmMessage(const char* message);
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2021-03-29 19:56:19 +00:00
|
|
|
void ReportFormattedError(const char* format, ...) printflike(2, 3);
|
|
|
|
void ReportFormattedMessage(const char* format, ...) printflike(2, 3);
|
|
|
|
void ReportFormattedDebuggerMessage(const char* format, ...) printflike(2, 3);
|
|
|
|
bool ConfirmFormattedMessage(const char* format, ...) printflike(2, 3);
|
2020-01-10 03:31:12 +00:00
|
|
|
|
2019-12-01 11:33:56 +00:00
|
|
|
/// Adds OSD messages, duration is in seconds.
|
2020-06-08 16:05:55 +00:00
|
|
|
virtual void AddOSDMessage(std::string message, float duration = 2.0f);
|
2021-03-29 19:56:19 +00:00
|
|
|
void AddFormattedOSDMessage(float duration, const char* format, ...) printflike(3, 4);
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2020-01-24 04:51:00 +00:00
|
|
|
/// Returns the base user directory path.
|
2020-02-15 15:14:28 +00:00
|
|
|
ALWAYS_INLINE const std::string& GetUserDirectory() const { return m_user_directory; }
|
2020-01-24 04:51:00 +00:00
|
|
|
|
|
|
|
/// Returns a path relative to the user directory.
|
2021-03-29 19:56:19 +00:00
|
|
|
std::string GetUserDirectoryRelativePath(const char* format, ...) const printflike(2, 3);
|
2020-01-24 04:51:00 +00:00
|
|
|
|
2020-05-16 12:18:02 +00:00
|
|
|
/// Returns a path relative to the application directory (for system files).
|
2021-03-29 19:56:19 +00:00
|
|
|
std::string GetProgramDirectoryRelativePath(const char* format, ...) const printflike(2, 3);
|
2020-05-16 12:18:02 +00:00
|
|
|
|
2020-03-15 12:03:53 +00:00
|
|
|
/// Returns a string which can be used as part of a filename, based on the current date/time.
|
|
|
|
static TinyString GetTimestampStringForFileName();
|
|
|
|
|
2020-02-15 15:15:16 +00:00
|
|
|
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
|
|
|
/// such as compiling shaders when starting up.
|
2020-06-30 14:33:45 +00:00
|
|
|
virtual void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1,
|
|
|
|
int progress_value = -1);
|
2020-04-20 16:50:45 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Retrieves information about specified game from game list.
|
|
|
|
virtual void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title);
|
2020-03-02 01:08:16 +00:00
|
|
|
|
2021-03-27 05:18:23 +00:00
|
|
|
/// Returns the directory where per-game memory cards will be saved.
|
|
|
|
virtual std::string GetMemoryCardDirectory() const;
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
/// Returns the default path to a memory card.
|
|
|
|
virtual std::string GetSharedMemoryCardPath(u32 slot) const;
|
|
|
|
|
|
|
|
/// Returns the default path to a memory card for a specific game.
|
|
|
|
virtual std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const;
|
|
|
|
|
2020-07-04 10:45:54 +00:00
|
|
|
/// Returns the path to the shader cache directory.
|
|
|
|
virtual std::string GetShaderCacheBasePath() const;
|
|
|
|
|
2020-06-30 14:33:45 +00:00
|
|
|
/// Returns a setting value from the configuration.
|
2020-07-21 09:49:04 +00:00
|
|
|
virtual std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") = 0;
|
2020-06-30 14:33:45 +00:00
|
|
|
|
|
|
|
/// Returns a boolean setting from the configuration.
|
2020-07-21 09:49:04 +00:00
|
|
|
virtual bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false);
|
2020-06-30 14:33:45 +00:00
|
|
|
|
|
|
|
/// Returns an integer setting from the configuration.
|
2020-07-21 09:49:04 +00:00
|
|
|
virtual int GetIntSettingValue(const char* section, const char* key, int default_value = 0);
|
2020-06-30 14:33:45 +00:00
|
|
|
|
|
|
|
/// Returns a float setting from the configuration.
|
2020-07-21 09:49:04 +00:00
|
|
|
virtual float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f);
|
2020-06-07 16:53:53 +00:00
|
|
|
|
2021-02-21 10:22:44 +00:00
|
|
|
/// Returns a string list from the configuration.
|
|
|
|
virtual std::vector<std::string> GetSettingStringList(const char* section, const char* key) = 0;
|
|
|
|
|
2020-08-22 03:01:52 +00:00
|
|
|
/// Translates a string to the current language.
|
2021-03-12 19:03:25 +00:00
|
|
|
virtual TinyString TranslateString(const char* context, const char* str, const char* disambiguation = nullptr,
|
|
|
|
int n = -1) const;
|
|
|
|
virtual std::string TranslateStdString(const char* context, const char* str, const char* disambiguation = nullptr,
|
|
|
|
int n = -1) const;
|
2020-08-22 03:01:52 +00:00
|
|
|
|
2020-09-22 16:11:30 +00:00
|
|
|
/// Returns the path to the directory to search for BIOS images.
|
2020-09-23 12:53:51 +00:00
|
|
|
virtual std::string GetBIOSDirectory();
|
2020-09-22 16:11:30 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
/// Loads the BIOS image for the specified region.
|
|
|
|
std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
|
|
|
|
2020-09-22 13:08:07 +00:00
|
|
|
/// Searches for a BIOS image for the specified region in the specified directory. If no match is found, the first
|
2020-12-25 15:33:33 +00:00
|
|
|
/// BIOS image within 512KB and 4MB will be used.
|
2020-09-22 13:08:07 +00:00
|
|
|
std::optional<std::vector<u8>> FindBIOSImageInDirectory(ConsoleRegion region, const char* directory);
|
|
|
|
|
|
|
|
/// Returns a list of filenames and descriptions for BIOS images in a directory.
|
|
|
|
std::vector<std::pair<std::string, const BIOS::ImageInfo*>> FindBIOSImagesInDirectory(const char* directory);
|
|
|
|
|
2020-10-10 07:41:54 +00:00
|
|
|
/// Returns true if any BIOS images are found in the configured BIOS directory.
|
|
|
|
bool HasAnyBIOSImages();
|
|
|
|
|
2020-11-27 07:57:20 +00:00
|
|
|
/// Opens a file in the DuckStation "package".
|
|
|
|
/// This is the APK for Android builds, or the program directory for standalone builds.
|
|
|
|
virtual std::unique_ptr<ByteStream> OpenPackageFile(const char* path, u32 flags) = 0;
|
|
|
|
|
2021-02-21 06:53:14 +00:00
|
|
|
virtual void OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code,
|
|
|
|
const std::string& game_title);
|
2020-07-31 07:09:18 +00:00
|
|
|
virtual void OnSystemPerformanceCountersUpdated();
|
|
|
|
|
2019-09-30 04:22:30 +00:00
|
|
|
protected:
|
2020-02-15 15:14:28 +00:00
|
|
|
virtual bool AcquireHostDisplay() = 0;
|
|
|
|
virtual void ReleaseHostDisplay() = 0;
|
|
|
|
virtual std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) = 0;
|
2020-12-08 14:48:00 +00:00
|
|
|
virtual s32 GetAudioOutputVolume() const;
|
2020-02-15 15:14:28 +00:00
|
|
|
|
|
|
|
virtual void OnSystemCreated();
|
2020-12-16 15:12:56 +00:00
|
|
|
virtual void OnSystemPaused(bool paused);
|
2020-02-15 15:14:28 +00:00
|
|
|
virtual void OnSystemDestroyed();
|
2020-02-28 07:00:09 +00:00
|
|
|
virtual void OnSystemStateSaved(bool global, s32 slot);
|
2020-02-15 15:14:44 +00:00
|
|
|
virtual void OnControllerTypeChanged(u32 slot);
|
2020-01-24 04:49:47 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Restores all settings to defaults.
|
|
|
|
virtual void SetDefaultSettings(SettingsInterface& si);
|
2020-04-13 12:13:46 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Loads settings to m_settings and any frontend-specific parameters.
|
|
|
|
virtual void LoadSettings(SettingsInterface& si);
|
2020-01-24 04:51:10 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Saves current settings variables to ini.
|
|
|
|
virtual void SaveSettings(SettingsInterface& si);
|
2020-04-30 14:58:32 +00:00
|
|
|
|
2020-08-19 13:26:57 +00:00
|
|
|
/// Checks and fixes up any incompatible settings.
|
2020-08-20 12:25:49 +00:00
|
|
|
virtual void FixIncompatibleSettings(bool display_osd_messages);
|
2020-08-19 13:26:57 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Checks for settings changes, std::move() the old settings away for comparing beforehand.
|
|
|
|
virtual void CheckForSettingsChanges(const Settings& old_settings);
|
2020-01-24 04:51:03 +00:00
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Switches the GPU renderer by saving state, recreating the display window, and restoring state (if needed).
|
|
|
|
virtual void RecreateSystem();
|
2020-01-24 04:52:03 +00:00
|
|
|
|
2020-12-27 04:08:13 +00:00
|
|
|
/// Enables "relative" mouse mode, locking the cursor position and returning relative coordinates.
|
|
|
|
virtual void SetMouseMode(bool relative, bool hide_cursor);
|
|
|
|
|
2021-04-28 16:42:08 +00:00
|
|
|
/// Call when host display size changes, use with "match display" aspect ratio setting.
|
|
|
|
virtual void OnHostDisplayResized();
|
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
/// Sets the user directory to the program directory, i.e. "portable mode".
|
|
|
|
void SetUserDirectoryToProgramDirectory();
|
2020-01-24 04:52:03 +00:00
|
|
|
|
2020-01-24 04:51:53 +00:00
|
|
|
/// Quick switch between software and hardware rendering.
|
|
|
|
void ToggleSoftwareRendering();
|
|
|
|
|
2020-01-24 04:51:56 +00:00
|
|
|
/// Adjusts the internal (render) resolution of the hardware backends.
|
|
|
|
void ModifyResolutionScale(s32 increment);
|
|
|
|
|
2020-06-30 14:35:13 +00:00
|
|
|
/// Updates software cursor state, based on controllers.
|
|
|
|
void UpdateSoftwareCursor();
|
|
|
|
|
2020-06-08 16:05:55 +00:00
|
|
|
bool SaveState(const char* filename);
|
|
|
|
void CreateAudioStream();
|
2019-12-01 11:33:56 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
std::unique_ptr<HostDisplay> m_display;
|
2019-10-10 16:20:21 +00:00
|
|
|
std::unique_ptr<AudioStream> m_audio_stream;
|
2020-05-16 12:18:02 +00:00
|
|
|
std::string m_program_directory;
|
2020-01-24 04:51:00 +00:00
|
|
|
std::string m_user_directory;
|
2019-09-12 14:18:13 +00:00
|
|
|
};
|
2020-07-31 07:09:18 +00:00
|
|
|
|
2020-08-22 03:01:52 +00:00
|
|
|
#define TRANSLATABLE(context, str) str
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
extern HostInterface* g_host_interface;
|