Duckstation/src/duckstation-libretro/libretro_host_interface.h

108 lines
4.1 KiB
C
Raw Normal View History

2020-06-08 16:44:42 +00:00
#pragma once
#include "core/host_interface.h"
#include "core/system.h"
#include "libretro.h"
#include <limits>
#include <optional>
2020-06-08 16:44:42 +00:00
class LibretroHostInterface : public HostInterface
{
public:
LibretroHostInterface();
~LibretroHostInterface() override;
2020-08-18 14:04:37 +00:00
void InitInterfaces();
2020-06-08 16:44:42 +00:00
JIT optimizations and refactoring (#675) * CPU/Recompiler: Use rel32 call where possible for no-args * JitCodeBuffer: Support using preallocated buffer * CPU/Recompiler/AArch64: Use bl instead of blr for short branches * CPU/CodeCache: Allocate recompiler buffer in program space This means we don't need 64-bit moves for every call out of the recompiler. * GTE: Don't store as u16 and load as u32 * CPU/Recompiler: Add methods to emit global load/stores * GTE: Convert class to namespace * CPU/Recompiler: Call GTE functions directly * Settings: Turn into a global variable * GPU: Replace local pointers with global * InterruptController: Turn into a global pointer * System: Replace local pointers with global * Timers: Turn into a global instance * DMA: Turn into a global instance * SPU: Turn into a global instance * CDROM: Turn into a global instance * MDEC: Turn into a global instance * Pad: Turn into a global instance * SIO: Turn into a global instance * CDROM: Move audio FIFO to the heap * CPU/Recompiler: Drop ASMFunctions No longer needed since we have code in the same 4GB window. * CPUCodeCache: Turn class into namespace * Bus: Local pointer -> global pointers * CPU: Turn class into namespace * Bus: Turn into namespace * GTE: Store registers in CPU state struct Allows relative addressing on ARM. * CPU/Recompiler: Align code storage to page size * CPU/Recompiler: Fix relative branches on A64 * HostInterface: Local references to global * System: Turn into a namespace, move events out * Add guard pages * Android: Fix build
2020-07-31 07:09:18 +00:00
ALWAYS_INLINE u32 GetResolutionScale() const { return g_settings.gpu_resolution_scale; }
2020-06-08 16:44:42 +00:00
bool Initialize() override;
void Shutdown() override;
void ReportError(const char* message) override;
void ReportMessage(const char* message) override;
bool ConfirmMessage(const char* message) override;
void AddOSDMessage(std::string message, float duration = 2.0f) override;
2020-06-08 16:44:42 +00:00
void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title) override;
std::string GetSharedMemoryCardPath(u32 slot) const override;
std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const override;
std::string GetShaderCacheBasePath() const override;
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
2020-06-08 16:44:42 +00:00
// Called by frontend
void retro_get_system_av_info(struct retro_system_av_info* info);
bool retro_load_game(const struct retro_game_info* game);
void retro_run_frame();
unsigned retro_get_region();
size_t retro_serialize_size();
bool retro_serialize(void* data, size_t size);
bool retro_unserialize(const void* data, size_t size);
2020-07-17 13:17:49 +00:00
void* retro_get_memory_data(unsigned id);
size_t retro_get_memory_size(unsigned id);
2020-06-08 16:44:42 +00:00
protected:
bool AcquireHostDisplay() override;
void ReleaseHostDisplay() override;
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
void OnSystemDestroyed() override;
void CheckForSettingsChanges(const Settings& old_settings) override;
2020-06-08 16:44:42 +00:00
private:
2020-08-18 14:04:37 +00:00
bool SetCoreOptions();
bool HasCoreVariablesChanged();
void InitLogging();
void InitDiskControlInterface();
void InitRumbleInterface();
2020-09-13 02:11:52 +00:00
void LoadSettings();
2020-06-08 16:44:42 +00:00
void UpdateSettings();
void UpdateControllers();
void UpdateControllersDigitalController(u32 index);
void UpdateControllersAnalogController(u32 index);
void GetSystemAVInfo(struct retro_system_av_info* info, bool use_resolution_scale);
void UpdateSystemAVInfo(bool use_resolution_scale);
void UpdateGeometry();
void UpdateLogging();
2020-06-08 16:44:42 +00:00
// Hardware renderer setup.
bool RequestHardwareRendererContext();
void SwitchToHardwareRenderer();
void SwitchToSoftwareRenderer();
2020-06-08 16:44:42 +00:00
static void HardwareRendererContextReset();
static void HardwareRendererContextDestroy();
// Disk control callbacks
static bool RETRO_CALLCONV DiskControlSetEjectState(bool ejected);
static bool RETRO_CALLCONV DiskControlGetEjectState();
static unsigned RETRO_CALLCONV DiskControlGetImageIndex();
static bool RETRO_CALLCONV DiskControlSetImageIndex(unsigned index);
static unsigned RETRO_CALLCONV DiskControlGetNumImages();
static bool RETRO_CALLCONV DiskControlReplaceImageIndex(unsigned index, const retro_game_info* info);
static bool RETRO_CALLCONV DiskControlAddImageIndex();
static bool RETRO_CALLCONV DiskControlSetInitialImage(unsigned index, const char* path);
static bool RETRO_CALLCONV DiskControlGetImagePath(unsigned index, char* path, size_t len);
static bool RETRO_CALLCONV DiskControlGetImageLabel(unsigned index, char* label, size_t len);
2020-06-08 16:44:42 +00:00
retro_hw_render_callback m_hw_render_callback = {};
std::unique_ptr<HostDisplay> m_hw_render_display;
bool m_hw_render_callback_valid = false;
bool m_using_hardware_renderer = false;
std::optional<u32> m_next_disc_index;
2020-08-18 14:04:37 +00:00
retro_rumble_interface m_rumble_interface = {};
bool m_rumble_interface_valid = false;
2020-08-18 14:41:34 +00:00
bool m_supports_input_bitmasks = false;
bool m_interfaces_initialized = false;
2020-06-08 16:44:42 +00:00
};
extern LibretroHostInterface g_libretro_host_interface;
// libretro callbacks
extern retro_environment_t g_retro_environment_callback;
extern retro_video_refresh_t g_retro_video_refresh_callback;
extern retro_audio_sample_t g_retro_audio_sample_callback;
extern retro_audio_sample_batch_t g_retro_audio_sample_batch_callback;
extern retro_input_poll_t g_retro_input_poll_callback;
extern retro_input_state_t g_retro_input_state_callback;