From 115368491fba78523dfdcaafec7b92fd74c158fa Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 30 Jul 2025 09:41:46 +0300 Subject: [PATCH] Libretro: Add ZL/ZR support (#796) * iOS: Remove unused hidService * Libretro: Add ZL/ZR support * Test build: Create venv * Install python3-venv package * Update Test_Build.yml --- .github/workflows/Test_Build.yml | 4 +- src/ios_driver.mm | 2 - src/libretro_core.cpp | 82 ++++++++++---------------------- 3 files changed, 27 insertions(+), 61 deletions(-) diff --git a/.github/workflows/Test_Build.yml b/.github/workflows/Test_Build.yml index 54bef27b..edfa9fa9 100644 --- a/.github/workflows/Test_Build.yml +++ b/.github/workflows/Test_Build.yml @@ -16,8 +16,10 @@ jobs: - name: Install and update packages run: | - apt-get -y install python3 python3-pip p7zip-full libarchive13 + apt-get -y install python3 python3-pip python3-venv p7zip-full libarchive13 python3 --version + python3 -m venv venv + . ./venv/bin/activate python3 -m pip install --upgrade pip setuptools - name: Compile tests diff --git a/src/ios_driver.mm b/src/ios_driver.mm index cb98b269..87bd057a 100644 --- a/src/ios_driver.mm +++ b/src/ios_driver.mm @@ -15,13 +15,11 @@ extern "C" { #define IOS_EXPORT extern "C" __attribute__((visibility("default"))) std::unique_ptr emulator = nullptr; -HIDService* hidService = nullptr; IOS_EXPORT void iosCreateEmulator() { printf("Creating emulator\n"); emulator = std::make_unique(); - hidService = &emulator->getServiceManager().getHID(); emulator->initGraphicsContext(nullptr); } diff --git a/src/libretro_core.cpp b/src/libretro_core.cpp index 4786b317..aca8330d 100644 --- a/src/libretro_core.cpp +++ b/src/libretro_core.cpp @@ -1,12 +1,11 @@ -#include +#include + #include #include -#include - -#include -#include -#include +#include "emulator.hpp" +#include "renderer_gl/renderer_gl.hpp" +#include "version.hpp" static retro_environment_t envCallback; static retro_video_refresh_t videoCallback; @@ -23,17 +22,11 @@ static bool usingGLES = false; std::unique_ptr emulator; RendererGL* renderer; -std::filesystem::path Emulator::getConfigPath() { - return std::filesystem::path(savePath / "config.toml"); -} +std::filesystem::path Emulator::getConfigPath() { return std::filesystem::path(savePath / "config.toml"); } +std::filesystem::path Emulator::getAppDataRoot() { return std::filesystem::path(savePath / "Emulator Files"); } -std::filesystem::path Emulator::getAppDataRoot() { - return std::filesystem::path(savePath / "Emulator Files"); -} - -static void* getGLProcAddress(const char* name) { - return (void*)hwRender.get_proc_address(name); -} +static void* getGLProcAddress(const char* name) { return (void*)hwRender.get_proc_address(name); } +static void videoDestroyContext() { emulator->deinitGraphicsContext(); } static void videoResetContext() { if (usingGLES) { @@ -53,10 +46,6 @@ static void videoResetContext() { emulator->initGraphicsContext(nullptr); } -static void videoDestroyContext() { - emulator->deinitGraphicsContext(); -} - static bool setHWRender(retro_hw_context_type type) { hwRender.context_type = type; hwRender.context_reset = videoResetContext; @@ -159,13 +148,8 @@ static int fetchVariableInt(std::string key, int def) { return 0; } -static bool fetchVariableBool(std::string key, bool def) { - return fetchVariable(key, def ? "enabled" : "disabled") == "enabled"; -} - -static int fetchVariableRange(std::string key, int min, int max) { - return std::clamp(fetchVariableInt(key, min), min, max); -} +static bool fetchVariableBool(std::string key, bool def) { return fetchVariable(key, def ? "enabled" : "disabled") == "enabled"; } +static int fetchVariableRange(std::string key, int min, int max) { return std::clamp(fetchVariableInt(key, min), min, max); } static void configInit() { static const retro_variable values[] = { @@ -259,27 +243,13 @@ void retro_get_system_av_info(retro_system_av_info* info) { info->timing.sample_rate = 32768; } -void retro_set_environment(retro_environment_t cb) { - envCallback = cb; -} - -void retro_set_video_refresh(retro_video_refresh_t cb) { - videoCallback = cb; -} - -void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { - audioBatchCallback = cb; -} +void retro_set_environment(retro_environment_t cb) { envCallback = cb; } +void retro_set_video_refresh(retro_video_refresh_t cb) { videoCallback = cb; } +void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audioBatchCallback = cb; } void retro_set_audio_sample(retro_audio_sample_t cb) {} - -void retro_set_input_poll(retro_input_poll_t cb) { - inputPollCallback = cb; -} - -void retro_set_input_state(retro_input_state_t cb) { - inputStateCallback = cb; -} +void retro_set_input_poll(retro_input_poll_t cb) { inputPollCallback = cb; } +void retro_set_input_state(retro_input_state_t cb) { inputStateCallback = cb; } void retro_init() { enum retro_pixel_format xrgb888 = RETRO_PIXEL_FORMAT_XRGB8888; @@ -297,9 +267,7 @@ void retro_init() { emulator = std::make_unique(); } -void retro_deinit() { - emulator = nullptr; -} +void retro_deinit() { emulator = nullptr; } bool retro_load_game(const retro_game_info* game) { configInit(); @@ -325,9 +293,8 @@ void retro_unload_game() { renderer = nullptr; } -void retro_reset() { - emulator->reset(Emulator::ReloadOption::Reload); -} +void retro_reset() { emulator->reset(Emulator::ReloadOption::Reload); } +void retro_cheat_reset() { emulator->getCheats().reset(); } void retro_run() { configCheckVariables(); @@ -345,13 +312,16 @@ void retro_run() { hid.setKey(HID::Keys::Y, getButtonState(RETRO_DEVICE_ID_JOYPAD_Y)); hid.setKey(HID::Keys::L, getButtonState(RETRO_DEVICE_ID_JOYPAD_L)); hid.setKey(HID::Keys::R, getButtonState(RETRO_DEVICE_ID_JOYPAD_R)); + hid.setKey(HID::Keys::ZL, getButtonState(RETRO_DEVICE_ID_JOYPAD_L2)); + hid.setKey(HID::Keys::ZR, getButtonState(RETRO_DEVICE_ID_JOYPAD_R2)); + hid.setKey(HID::Keys::Start, getButtonState(RETRO_DEVICE_ID_JOYPAD_START)); hid.setKey(HID::Keys::Select, getButtonState(RETRO_DEVICE_ID_JOYPAD_SELECT)); hid.setKey(HID::Keys::Up, getButtonState(RETRO_DEVICE_ID_JOYPAD_UP)); hid.setKey(HID::Keys::Down, getButtonState(RETRO_DEVICE_ID_JOYPAD_DOWN)); hid.setKey(HID::Keys::Left, getButtonState(RETRO_DEVICE_ID_JOYPAD_LEFT)); hid.setKey(HID::Keys::Right, getButtonState(RETRO_DEVICE_ID_JOYPAD_RIGHT)); - // TODO: N3DS buttons + // TODO: C-Stick // Get analog values for the left analog stick (Right analog stick is N3DS-only and unimplemented) float xLeft = getAxisState(RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X); @@ -443,8 +413,4 @@ void retro_cheat_set(uint index, bool enabled, const char* code) { } else { emulator->getCheats().disableCheat(id); } -} - -void retro_cheat_reset() { - emulator->getCheats().reset(); -} +} \ No newline at end of file