From 616b0b08f6e6c71dbab78c787e814101c74c5d6d Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 17 Sep 2024 15:01:08 -0400 Subject: [PATCH 1/4] 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 af4a0cdd15fe..ccaf2b6a6ea0 100644 --- a/dynamic.h +++ b/dynamic.h @@ -68,6 +68,7 @@ struct retro_core_t enum poll_type 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 73ff390c508e..4a9aed1fdde5 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2955,6 +2955,31 @@ struct retro_memory_status uint64_t total; /**< Total physical memory installed. */ }; +/** + * 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 95 + +/** + * 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 96 + /**@}*/ /** diff --git a/runloop.c b/runloop.c index c21a32682e11..c282686fc08a 100644 --- a/runloop.c +++ b/runloop.c @@ -4119,6 +4119,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 d7664555e1aef56709ade41ff3e4364377d41adb Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 2 Jan 2025 17:55:22 -0500 Subject: [PATCH 2/4] 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 ccaf2b6a6ea0..f8c530a73e73 100644 --- a/dynamic.h +++ b/dynamic.h @@ -68,7 +68,13 @@ struct retro_core_t enum poll_type 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 4a9aed1fdde5..899d1700c633 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2965,7 +2965,7 @@ struct retro_memory_status * * @see RETRO_ENVIRONMENT_GET_CORE_DATA */ -#define RETRO_ENVIRONMENT_SET_CORE_DATA 95 +#define RETRO_ENVIRONMENT_SET_CORE_DATA (95 | RETRO_ENVIRONMENT_EXPERIMENTAL) /** * Gets a pointer to arbitrary data for the actively running core. @@ -2978,7 +2978,7 @@ struct retro_memory_status * * @see RETRO_ENVIRONMENT_SET_CORE_DATA */ -#define RETRO_ENVIRONMENT_GET_CORE_DATA 96 +#define RETRO_ENVIRONMENT_GET_CORE_DATA (96 | RETRO_ENVIRONMENT_EXPERIMENTAL) /**@}*/ From 475a18c20a165e15c4a5e183318fbf7222d8a9e2 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 17 Sep 2024 15:45:05 -0400 Subject: [PATCH 3/4] 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 899d1700c633..9a3e241df68b 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2958,7 +2958,8 @@ struct retro_memory_status /** * 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 f13644a35141d93e73dd2a1e9c8addd0a8f48c84 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 7 Sep 2026 19:19:51 -0400 Subject: [PATCH 4/4] libretro: Fix order --- libretro-common/include/libretro.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index 9a3e241df68b..b00b77d3f240 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -2944,17 +2944,6 @@ enum retro_mod | RETRO_AUDIO_SPEAKER_SIDE_LEFT | RETRO_AUDIO_SPEAKER_SIDE_RIGHT) #define RETRO_AUDIO_LAYOUT_7_1 (RETRO_AUDIO_LAYOUT_5_1 | RETRO_AUDIO_SPEAKER_SIDE_LEFT | RETRO_AUDIO_SPEAKER_SIDE_RIGHT) -/** - * Result of \c RETRO_ENVIRONMENT_GET_MEMORY_STATUS. - * - * Sizes are in bytes; a field the frontend cannot determine is left at 0. - */ -struct retro_memory_status -{ - uint64_t free; /**< Physical memory currently available to allocate. */ - uint64_t total; /**< Total physical memory installed. */ -}; - /** * Sets a pointer to arbitrary data for the actively running core. * @@ -2981,6 +2970,17 @@ struct retro_memory_status */ #define RETRO_ENVIRONMENT_GET_CORE_DATA (96 | RETRO_ENVIRONMENT_EXPERIMENTAL) +/** + * Result of \c RETRO_ENVIRONMENT_GET_MEMORY_STATUS. + * + * Sizes are in bytes; a field the frontend cannot determine is left at 0. + */ +struct retro_memory_status +{ + uint64_t free; /**< Physical memory currently available to allocate. */ + uint64_t total; /**< Total physical memory installed. */ +}; + /**@}*/ /**