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
This commit is contained in:
wheremyfoodat 2025-07-30 09:41:46 +03:00 committed by GitHub
commit 115368491f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 61 deletions

View file

@ -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

View file

@ -15,13 +15,11 @@ extern "C" {
#define IOS_EXPORT extern "C" __attribute__((visibility("default")))
std::unique_ptr<Emulator> emulator = nullptr;
HIDService* hidService = nullptr;
IOS_EXPORT void iosCreateEmulator() {
printf("Creating emulator\n");
emulator = std::make_unique<Emulator>();
hidService = &emulator->getServiceManager().getHID();
emulator->initGraphicsContext(nullptr);
}

View file

@ -1,12 +1,11 @@
#include <stdexcept>
#include <libretro.h>
#include <cstdio>
#include <regex>
#include <libretro.h>
#include <version.hpp>
#include <emulator.hpp>
#include <renderer_gl/renderer_gl.hpp>
#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> 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<Emulator>();
}
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();
}
}