From 6e3588f36aedb6912505a1782151d104f6585770 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 17 Sep 2024 15:01:08 -0400 Subject: [PATCH 1/3] libretro: Add RETRO_ENVIRONMENT_GET_CORE_DATA and RETRO_ENVIRONMENT_SET_CORE_DATA --- dynamic.h | 1 + libretro-common/include/libretro.h | 25 +++++++++++++++++++++++++ runloop.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) diff --git a/dynamic.h b/dynamic.h index 79ed70ab16df..084ccf67d3eb 100644 --- a/dynamic.h +++ b/dynamic.h @@ -68,6 +68,7 @@ struct retro_core_t unsigned poll_type; uint8_t flags; + void *core_data; /* Arbitrary core data. @see RETRO_ENVIRONMENT_GET_CORE_DATA */ }; diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index f1764ef42959..dea823bb3d7e 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2569,6 +2569,31 @@ enum retro_mod */ #define RETRO_ENVIRONMENT_GET_FILE_BROWSER_START_DIRECTORY 80 +/** + * Sets a pointer to arbitrary data for the actively running core. + * + * This is can be set in either \c retro_init() or \c retro_load_game(). + * + * @param[in] data void *. Pointer to the data to set. + * @return \c true if the environment call is available. + * + * @see RETRO_ENVIRONMENT_GET_CORE_DATA + */ +#define RETRO_ENVIRONMENT_SET_CORE_DATA 81 + +/** + * Gets a pointer to arbitrary data for the actively running core. + * + * This is persistent for the lifetime of the core until \c retro_deinit() is called. + * + * @param[out] data void **. Pointer to the data that was set. + * May be \c NULL if the data was not set yet. + * @return \c true if the environment call is available. + * + * @see RETRO_ENVIRONMENT_SET_CORE_DATA + */ +#define RETRO_ENVIRONMENT_GET_CORE_DATA 82 + /**@}*/ /** diff --git a/runloop.c b/runloop.c index 11e4a32f920b..69ea7ea19250 100644 --- a/runloop.c +++ b/runloop.c @@ -3583,6 +3583,18 @@ bool runloop_environment_cb(unsigned cmd, void *data) } } break; + + case RETRO_ENVIRONMENT_SET_CORE_DATA: + runloop_st->current_core.core_data = data; + break; + + case RETRO_ENVIRONMENT_GET_CORE_DATA: + if (data != NULL) { + void **core_data = (void **)data; + *core_data = runloop_st->current_core.core_data; + } + break; + default: RARCH_LOG("[Environ]: UNSUPPORTED (#%u).\n", cmd); return false; From 1368eddee60b251c9197354c357076117dcf8354 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 17 Sep 2024 15:45:05 -0400 Subject: [PATCH 2/3] libretro: Add docs around SET_CORE_INFO --- libretro-common/include/libretro.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index dea823bb3d7e..36b37fe13b1e 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2572,7 +2572,8 @@ enum retro_mod /** * Sets a pointer to arbitrary data for the actively running core. * - * This is can be set in either \c retro_init() or \c retro_load_game(). + * Intended for use as a substitute for global state, which is a common + * source of bugs. Can be set in either \c retro_init() or \c retro_load_game(). * * @param[in] data void *. Pointer to the data to set. * @return \c true if the environment call is available. From 7201865c2f8814b1e03e82a08e797c8f7203fe42 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 2 Jan 2025 17:55:22 -0500 Subject: [PATCH 3/3] Set RETRO_ENVIRONMENT_GET_CORE_DATA and RETRO_ENVIRONMENT_SET_CORE_DATA as experimental --- dynamic.h | 8 +++++++- libretro-common/include/libretro.h | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dynamic.h b/dynamic.h index 084ccf67d3eb..0f1d238ee759 100644 --- a/dynamic.h +++ b/dynamic.h @@ -68,7 +68,13 @@ struct retro_core_t unsigned poll_type; uint8_t flags; - void *core_data; /* Arbitrary core data. @see RETRO_ENVIRONMENT_GET_CORE_DATA */ + + /** + * Arbitrary core data. + * + * @see RETRO_ENVIRONMENT_GET_CORE_DATA + */ + void *core_data; }; diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index f5a96ea697f2..de3613bfeb22 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2584,7 +2584,7 @@ enum retro_mod * * @see RETRO_ENVIRONMENT_GET_CORE_DATA */ -#define RETRO_ENVIRONMENT_SET_CORE_DATA 81 +#define RETRO_ENVIRONMENT_SET_CORE_DATA (81 | RETRO_ENVIRONMENT_EXPERIMENTAL) /** * Gets a pointer to arbitrary data for the actively running core. @@ -2597,7 +2597,7 @@ enum retro_mod * * @see RETRO_ENVIRONMENT_SET_CORE_DATA */ -#define RETRO_ENVIRONMENT_GET_CORE_DATA 82 +#define RETRO_ENVIRONMENT_GET_CORE_DATA (82 | RETRO_ENVIRONMENT_EXPERIMENTAL) /**@}*/