diff --git a/cheevos.c b/cheevos.c index dd1bfaef04..a10191bab0 100644 --- a/cheevos.c +++ b/cheevos.c @@ -603,8 +603,7 @@ static unsigned cheevos_parse_operator(const char **memaddr) void cheevos_parse_guest_addr(cheevos_var_t *var, unsigned value) { - rarch_system_info_t *system; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); var->bank_id = -1; var->value = value; @@ -1089,8 +1088,7 @@ uint8_t *cheevos_get_memory(const cheevos_var_t *var) { if (var->bank_id >= 0) { - rarch_system_info_t *system; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (system->mmaps.num_descriptors != 0) return (uint8_t *)system->mmaps.descriptors[var->bank_id].ptr + var->value; diff --git a/command.c b/command.c index fa91034a67..88d7630e59 100644 --- a/command.c +++ b/command.c @@ -834,10 +834,8 @@ static void command_event_disk_control_set_eject(bool new_state, bool print_log) { char msg[128] = {0}; bool error = false; - rarch_system_info_t *info = NULL; const struct retro_disk_control_callback *control = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + rarch_system_info_t *info = core_system_info_get(); if (info) control = (const struct retro_disk_control_callback*)&info->disk_control_cb; @@ -884,10 +882,8 @@ static void command_event_disk_control_set_index(unsigned idx) unsigned num_disks; bool error = false; char msg[128] = {0}; - rarch_system_info_t *info = NULL; const struct retro_disk_control_callback *control = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + rarch_system_info_t *info = core_system_info_get(); if (info) control = (const struct retro_disk_control_callback*)&info->disk_control_cb; @@ -942,9 +938,7 @@ static bool command_event_disk_control_append_image(const char *path) struct retro_game_info info = {0}; global_t *global = global_get_ptr(); const struct retro_disk_control_callback *control = NULL; - rarch_system_info_t *sysinfo = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sysinfo); + rarch_system_info_t *sysinfo = core_system_info_get(); if (sysinfo) control = (const struct retro_disk_control_callback*) @@ -1087,9 +1081,7 @@ static void command_event_init_controllers(void) { unsigned i; settings_t *settings = config_get_ptr(); - rarch_system_info_t *info = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + rarch_system_info_t *info = core_system_info_get(); for (i = 0; i < MAX_USERS; i++) { @@ -1814,9 +1806,7 @@ bool command_event(enum event_command cmd, void *data) unsigned i = 0; bool boolean = false; settings_t *settings = config_get_ptr(); - rarch_system_info_t *info = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + rarch_system_info_t *info = core_system_info_get(); (void)i; diff --git a/configuration.c b/configuration.c index f32ecbcbcb..9c310aac64 100644 --- a/configuration.c +++ b/configuration.c @@ -2132,10 +2132,8 @@ bool config_load_override(void) const char *core_name = NULL; const char *game_name = NULL; bool should_append = false; - rarch_system_info_t *system = NULL; global_t *global = global_get_ptr(); - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (system) core_name = system->info.library_name; @@ -2292,9 +2290,7 @@ bool config_load_remap(void) const char *game_name = NULL; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (system) core_name = system->info.library_name; @@ -2415,9 +2411,7 @@ bool config_load_shader_preset(void) const char *game_name = NULL; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (system) core_name = system->info.library_name; @@ -3007,9 +3001,6 @@ bool config_save_overrides(int override_type) const char *game_name = NULL; config_file_t *conf = NULL; settings_t *settings = NULL; - global_t *global = global_get_ptr(); - settings_t *overrides = config_get_ptr(); - rarch_system_info_t *system = NULL; struct config_bool_setting *bool_settings = NULL; struct config_bool_setting *bool_overrides = NULL; struct config_int_setting *int_settings = NULL; @@ -3020,8 +3011,9 @@ bool config_save_overrides(int override_type) struct config_array_setting *array_overrides= NULL; struct config_path_setting *path_settings = NULL; struct config_path_setting *path_overrides = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + global_t *global = global_get_ptr(); + settings_t *overrides = config_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); if (system) core_name = system->info.library_name; diff --git a/core.h b/core.h index 2ae06e6d4f..91b64dad00 100644 --- a/core.h +++ b/core.h @@ -228,6 +228,12 @@ bool core_is_inited(void); bool core_is_game_loaded(void); +rarch_system_info_t *core_system_info_get(void); + +void core_system_info_init(void); + +void core_system_info_free(void); + RETRO_END_DECLS #endif diff --git a/core_impl.c b/core_impl.c index 7e4741996e..e2ec6f838a 100644 --- a/core_impl.c +++ b/core_impl.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -40,6 +41,12 @@ #include "network/netplay/netplay.h" #endif +#ifdef HAVE_ZLIB +#define DEFAULT_EXT "zip" +#else +#define DEFAULT_EXT "" +#endif + static struct retro_core_t core; static bool core_inited; static bool core_symbols_inited; @@ -48,6 +55,7 @@ static unsigned core_poll_type; static bool core_input_polled; static bool core_has_set_input_descriptors = false; static struct retro_callbacks retro_ctx; +static rarch_system_info_t core_system_info; static void core_input_state_poll_maybe(void) { @@ -448,3 +456,45 @@ bool core_is_game_loaded(void) { return core_game_loaded; } + +rarch_system_info_t *core_system_info_get(void) +{ + return &core_system_info; +} + +void core_system_info_init(void) +{ + memset(&core_system_info, 0, sizeof(rarch_system_info_t)); + core_get_system_info(&core_system_info.info); + + if (!core_system_info.info.library_name) + core_system_info.info.library_name = msg_hash_to_str(MSG_UNKNOWN); + if (!core_system_info.info.library_version) + core_system_info.info.library_version = "v0"; + + strlcpy(core_system_info.valid_extensions, + core_system_info.info.valid_extensions ? + core_system_info.info.valid_extensions : DEFAULT_EXT, + sizeof(core_system_info.valid_extensions)); +} + +void core_system_info_free(void) +{ + /* No longer valid. */ + if (core_system_info.subsystem.data) + free(core_system_info.subsystem.data); + core_system_info.subsystem.data = NULL; + core_system_info.subsystem.size = 0; + + if (core_system_info.ports.data) + free(core_system_info.ports.data); + core_system_info.ports.data = NULL; + core_system_info.ports.size = 0; + + if (core_system_info.mmaps.descriptors) + free((void *)core_system_info.mmaps.descriptors); + core_system_info.mmaps.descriptors = NULL; + core_system_info.mmaps.num_descriptors = 0; + + memset(&core_system_info, 0, sizeof(rarch_system_info_t)); +} diff --git a/dynamic.c b/dynamic.c index cdb2df358e..300abc7075 100644 --- a/dynamic.c +++ b/dynamic.c @@ -932,10 +932,8 @@ bool rarch_environment_cb(unsigned cmd, void *data) unsigned p; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); - rarch_system_info_t *system = NULL; + rarch_system_info_t *system = core_system_info_get(); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); - if (ignore_environment_cb) return false; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 54e513367a..541fbccad2 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -590,14 +590,12 @@ static bool init_video(void) video_viewport_t *custom_vp = NULL; const input_driver_t *tmp = NULL; const struct retro_game_geometry *geom = NULL; - rarch_system_info_t *system = NULL; video_info_t video = {0}; static uint16_t dummy_pixels[32] = {0}; settings_t *settings = config_get_ptr(); struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); init_video_filter(video_driver_state.pix_fmt); command_event(CMD_EVENT_SHADER_DIR_INIT, NULL); diff --git a/httpserver/httpserver.c b/httpserver/httpserver.c index e5af993dfc..7f2b24a6fe 100644 --- a/httpserver/httpserver.c +++ b/httpserver/httpserver.c @@ -25,75 +25,75 @@ static struct mg_context* s_httpserver_ctx; /* Based on https://github.com/zeromq/rfc/blob/master/src/spec_32.c */ static void httpserver_z85_encode_inplace(Bytef* data, size_t size) { - static char digits[85 + 1] = - { - "0123456789" - "abcdefghij" - "klmnopqrst" - "uvwxyzABCD" - "EFGHIJKLMN" - "OPQRSTUVWX" - "YZ.-:+=^!/" - "*?&<>()[]{" - "}@%$#" - }; + static char digits[85 + 1] = + { + "0123456789" + "abcdefghij" + "klmnopqrst" + "uvwxyzABCD" + "EFGHIJKLMN" + "OPQRSTUVWX" + "YZ.-:+=^!/" + "*?&<>()[]{" + "}@%$#" + }; - Bytef* source = data + size - 4; - Bytef* dest = data + size * 5 / 4 - 5; - uLong value; + Bytef* source = data + size - 4; + Bytef* dest = data + size * 5 / 4 - 5; + uLong value; - dest[5] = 0; + dest[5] = 0; - if (source >= data) - { - do - { - value = source[0] * 256 * 256 * 256; - value += source[1] * 256 * 256; - value += source[2] * 256; - value += source[3]; - source -= 4; + if (source >= data) + { + do + { + value = source[0] * 256 * 256 * 256; + value += source[1] * 256 * 256; + value += source[2] * 256; + value += source[3]; + source -= 4; - dest[4] = digits[value % 85]; - value /= 85; - dest[3] = digits[value % 85]; - value /= 85; - dest[2] = digits[value % 85]; - value /= 85; - dest[1] = digits[value % 85]; - dest[0] = digits[value / 85]; - dest -= 5; + dest[4] = digits[value % 85]; + value /= 85; + dest[3] = digits[value % 85]; + value /= 85; + dest[2] = digits[value % 85]; + value /= 85; + dest[1] = digits[value % 85]; + dest[0] = digits[value / 85]; + dest -= 5; - } while (source >= data); - } + } while (source >= data); + } } static void json_string_encode(char* output, size_t size, const char* input) { - /* Don't use with UTF-8 strings. */ - char k; + /* Don't use with UTF-8 strings. */ + char k; - if (*input != 0 && size != 0) - { - do - { - switch (k = *input++) + if (*input != 0 && size != 0) + { + do { - case '"': /* fall through */ - case '\\': /* fall through */ - case '/': if (size >= 3) { *output++ = '\\'; *output++ = k; size -= 2; } break; - case '\b': if (size >= 3) { *output++ = '\\'; *output++ = 'b'; size -= 2; } break; - case '\f': if (size >= 3) { *output++ = '\\'; *output++ = 'f'; size -= 2; } break; - case '\n': if (size >= 3) { *output++ = '\\'; *output++ = 'n'; size -= 2; } break; - case '\r': if (size >= 3) { *output++ = '\\'; *output++ = 'r'; size -= 2; } break; - case '\t': if (size >= 3) { *output++ = '\\'; *output++ = 't'; size -= 2; } break; - default: if (size >= 2) { *output++ = k; } size--; break; + switch (k = *input++) + { + case '"': /* fall through */ + case '\\': /* fall through */ + case '/': if (size >= 3) { *output++ = '\\'; *output++ = k; size -= 2; } break; + case '\b': if (size >= 3) { *output++ = '\\'; *output++ = 'b'; size -= 2; } break; + case '\f': if (size >= 3) { *output++ = '\\'; *output++ = 'f'; size -= 2; } break; + case '\n': if (size >= 3) { *output++ = '\\'; *output++ = 'n'; size -= 2; } break; + case '\r': if (size >= 3) { *output++ = '\\'; *output++ = 'r'; size -= 2; } break; + case '\t': if (size >= 3) { *output++ = '\\'; *output++ = 't'; size -= 2; } break; + default: if (size >= 2) { *output++ = k; } size--; break; + } } - } - while (*input != 0); - } + while (*input != 0); + } - *output = 0; + *output = 0; } /*============================================================ @@ -102,35 +102,35 @@ HTTP ERRORS static int httpserver_error(struct mg_connection* conn, unsigned code, const char* fmt, ...) { - const char* reason; - char buffer[1024]; - va_list args; + va_list args; + char buffer[1024]; + const char* reason = NULL; - switch (code) - { - case 404: - reason = "Not Found"; - break; + switch (code) + { + case 404: + reason = "Not Found"; + break; - case 405: - reason = "Method Not Allowed"; - break; + case 405: + reason = "Method Not Allowed"; + break; - default: - /* Send unknown codes as 500 */ - code = 500; - reason = "Internal Server Error"; - break; - } + default: + /* Send unknown codes as 500 */ + code = 500; + reason = "Internal Server Error"; + break; + } - va_start(args, fmt); - vsnprintf(buffer, sizeof(buffer), fmt, args); - va_end(args); - buffer[sizeof(buffer) - 1] = 0; + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); + buffer[sizeof(buffer) - 1] = 0; - mg_printf(conn, "HTTP/1.1 %u %s\r\nContent-Type: text/html\r\n\r\n", code, reason); - mg_printf(conn, "

%u %s

%s

", code, reason, buffer); - return 1; + mg_printf(conn, "HTTP/1.1 %u %s\r\nContent-Type: text/html\r\n\r\n", code, reason); + mg_printf(conn, "

%u %s

%s

", code, reason, buffer); + return 1; } /*============================================================ @@ -139,251 +139,253 @@ INFO static int httpserver_handle_basic_info(struct mg_connection* conn, void* cbdata) { - static const char *libretro_btn_desc[] = { - "B (bottom)", "Y (left)", "Select", "Start", - "D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right", - "A (right)", "X (up)", - "L", "R", "L2", "R2", "L3", "R3", - }; + static const char *libretro_btn_desc[] = { + "B (bottom)", "Y (left)", "Select", "Start", + "D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right", + "A (right)", "X (up)", + "L", "R", "L2", "R2", "L3", "R3", + }; - const struct mg_request_info* req = mg_get_request_info(conn); - const settings_t* settings = config_get_ptr(); - const rarch_system_info_t* system; - char core_path[PATH_MAX_LENGTH]; - retro_ctx_api_info_t api; - retro_ctx_region_info_t region; - const char* pixel_format; - retro_ctx_memory_info_t sram; - retro_ctx_memory_info_t rtc; - retro_ctx_memory_info_t sysram; - retro_ctx_memory_info_t vram; - const struct retro_subsystem_info* subsys; - const struct retro_subsystem_rom_info* rom; - const struct retro_subsystem_memory_info* mem; - const struct retro_controller_description* ctrl; - const struct retro_system_av_info* av_info; - const core_option_manager_t* core_opts; - const struct core_option* opts; - unsigned p, q, r; - const char* comma; + unsigned p, q, r; + char core_path[PATH_MAX_LENGTH]; + retro_ctx_api_info_t api; + retro_ctx_region_info_t region; + const char* pixel_format; + retro_ctx_memory_info_t sram; + retro_ctx_memory_info_t rtc; + retro_ctx_memory_info_t sysram; + retro_ctx_memory_info_t vram; + const struct retro_subsystem_info* subsys = NULL; + const struct retro_subsystem_rom_info* rom = NULL; + const struct retro_subsystem_memory_info* mem = NULL; + const struct retro_controller_description* ctrl = NULL; + const struct retro_system_av_info* av_info = NULL; + const core_option_manager_t* core_opts = NULL; + const struct core_option* opts = NULL; + const char* comma = NULL; + const struct mg_request_info* req = mg_get_request_info(conn); + const settings_t* settings = config_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); - if (!runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system)) - { - return httpserver_error(conn, 500, "Could not get system information in %s", __FUNCTION__); - } + if (!system) + return httpserver_error(conn, 500, "Could not get system information in %s", __FUNCTION__); - if (string_is_empty(system->info.library_name)) - { - return httpserver_error(conn, 500, "Core not initialized in %s", __FUNCTION__); - } + if (string_is_empty(system->info.library_name)) + return httpserver_error(conn, 500, "Core not initialized in %s", __FUNCTION__); - if (!core_is_game_loaded()) - { - return httpserver_error(conn, 500, "Game not loaded in %s", __FUNCTION__); - } + if (!core_is_game_loaded()) + return httpserver_error(conn, 500, "Game not loaded in %s", __FUNCTION__); - json_string_encode(core_path, sizeof(core_path), config_get_active_core_path()); + json_string_encode(core_path, sizeof(core_path), config_get_active_core_path()); - core_api_version(&api); - core_get_region(®ion); + core_api_version(&api); + core_get_region(®ion); - switch (video_driver_get_pixel_format()) - { - case RETRO_PIXEL_FORMAT_0RGB1555: pixel_format = "RETRO_PIXEL_FORMAT_0RGB1555"; break; - case RETRO_PIXEL_FORMAT_XRGB8888: pixel_format = "RETRO_PIXEL_FORMAT_XRGB8888"; break; - case RETRO_PIXEL_FORMAT_RGB565: pixel_format = "RETRO_PIXEL_FORMAT_RGB565"; break; - default: pixel_format = "?"; break; - } + switch (video_driver_get_pixel_format()) + { + case RETRO_PIXEL_FORMAT_0RGB1555: + pixel_format = "RETRO_PIXEL_FORMAT_0RGB1555"; + break; + case RETRO_PIXEL_FORMAT_XRGB8888: + pixel_format = "RETRO_PIXEL_FORMAT_XRGB8888"; + break; + case RETRO_PIXEL_FORMAT_RGB565: + pixel_format = "RETRO_PIXEL_FORMAT_RGB565"; + break; + default: + pixel_format = "?"; + break; + } - sram.id = RETRO_MEMORY_SAVE_RAM; - core_get_memory(&sram); + sram.id = RETRO_MEMORY_SAVE_RAM; + core_get_memory(&sram); - rtc.id = RETRO_MEMORY_RTC; - core_get_memory(&rtc); + rtc.id = RETRO_MEMORY_RTC; + core_get_memory(&rtc); - sysram.id = RETRO_MEMORY_SYSTEM_RAM; - core_get_memory(&sysram); + sysram.id = RETRO_MEMORY_SYSTEM_RAM; + core_get_memory(&sysram); - vram.id = RETRO_MEMORY_VIDEO_RAM; - core_get_memory(&vram); + vram.id = RETRO_MEMORY_VIDEO_RAM; + core_get_memory(&vram); - mg_printf(conn, - "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n" - "{" - "\"corePath\":\"%s\"," - "\"apiVersion\":%u," - "\"systemInfo\":" - "{" - "\"libraryName\":\"%s\"," - "\"libraryVersion\":\"%s\"," - "\"validExtensions\":\"%s\"," - "\"needsFullpath\":%s," - "\"blockExtract\":%s" - "}," - "\"region\":\"%s\"," - "\"pixelFormat\":\"%s\"," - "\"rotation\":%u," - "\"performaceLevel\":%u," - "\"supportsNoGame\":%s," + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n" + "{" + "\"corePath\":\"%s\"," + "\"apiVersion\":%u," + "\"systemInfo\":" + "{" + "\"libraryName\":\"%s\"," + "\"libraryVersion\":\"%s\"," + "\"validExtensions\":\"%s\"," + "\"needsFullpath\":%s," + "\"blockExtract\":%s" + "}," + "\"region\":\"%s\"," + "\"pixelFormat\":\"%s\"," + "\"rotation\":%u," + "\"performaceLevel\":%u," + "\"supportsNoGame\":%s," #ifdef HAVE_CHEEVOS - "\"frontendSupportsAchievements\":true," - "\"coreSupportsAchievements\":%s," + "\"frontendSupportsAchievements\":true," + "\"coreSupportsAchievements\":%s," #else - "\"frontendSupportsAchievements\":false," - "\"coreSupportsAchievements\":null," + "\"frontendSupportsAchievements\":false," + "\"coreSupportsAchievements\":null," #endif - "\"saveRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," - "\"rtcRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," - "\"systemRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," - "\"videoRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "},", - core_path, - api.version, - system->info.library_name, - system->info.library_version, - system->info.valid_extensions, - system->info.need_fullpath ? "true" : "false", - system->info.block_extract ? "true" : "false", - region.region ? "RETRO_REGION_PAL" : "RETRO_REGION_NTSC", - pixel_format, - system->rotation, - system->performance_level, - content_does_not_need_content() ? "true" : "false", + "\"saveRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," + "\"rtcRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," + "\"systemRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "}," + "\"videoRam\":{\"pointer\":\"%" PRIXPTR "\",\"size\":" STRING_REP_UINT64 "},", + core_path, + api.version, + system->info.library_name, + system->info.library_version, + system->info.valid_extensions, + system->info.need_fullpath ? "true" : "false", + system->info.block_extract ? "true" : "false", + region.region ? "RETRO_REGION_PAL" : "RETRO_REGION_NTSC", + pixel_format, + system->rotation, + system->performance_level, + content_does_not_need_content() ? "true" : "false", #ifdef HAVE_CHEEVOS - cheevos_get_support_cheevos() ? "true" : "false", + cheevos_get_support_cheevos() ? "true" : "false", #endif - (uintptr_t)sram.data, sram.size, - (uintptr_t)rtc.data, rtc.size, - (uintptr_t)sysram.data, sysram.size, - (uintptr_t)vram.data, vram.size - ); + (uintptr_t)sram.data, sram.size, + (uintptr_t)rtc.data, rtc.size, + (uintptr_t)sysram.data, sysram.size, + (uintptr_t)vram.data, vram.size + ); - mg_printf(conn, "\"subSystems\":["); - subsys = system->subsystem.data; + mg_printf(conn, "\"subSystems\":["); + subsys = system->subsystem.data; - for (p = 0; p < system->subsystem.size; p++, subsys++) - { - mg_printf(conn, "%s{\"id\":%u,\"description\":\"%s\",\"identifier\":\"%s\",\"roms\":[", p == 0 ? "" : ",", subsys->id, subsys->desc, subsys->ident); - rom = subsys->roms; + for (p = 0; p < system->subsystem.size; p++, subsys++) + { + mg_printf(conn, "%s{\"id\":%u,\"description\":\"%s\",\"identifier\":\"%s\",\"roms\":[", p == 0 ? "" : ",", subsys->id, subsys->desc, subsys->ident); + rom = subsys->roms; - for (q = 0; q < subsys->num_roms; q++, rom++) - { - mg_printf(conn, - "%s{" - "\"description\":\"%s\"," - "\"extensions\":\"%s\"," - "\"needsFullpath\":%s," - "\"blockExtract\":%s," - "\"required\":%s," - "\"memory\":[", - q == 0 ? "" : ",", - rom->desc, - rom->valid_extensions, - rom->need_fullpath ? "true" : "false", - rom->block_extract ? "true" : "false", - rom->required ? "true" : "false" - ); - - mem = rom->memory; - comma = ""; - - for (r = 0; r < rom->num_memory; r++, mem++) + for (q = 0; q < subsys->num_roms; q++, rom++) { - mg_printf(conn, "%s{\"extension\":\"%s\",\"type\":%u}", comma, mem->extension, mem->type); - comma = ","; + mg_printf(conn, + "%s{" + "\"description\":\"%s\"," + "\"extensions\":\"%s\"," + "\"needsFullpath\":%s," + "\"blockExtract\":%s," + "\"required\":%s," + "\"memory\":[", + q == 0 ? "" : ",", + rom->desc, + rom->valid_extensions, + rom->need_fullpath ? "true" : "false", + rom->block_extract ? "true" : "false", + rom->required ? "true" : "false" + ); + + mem = rom->memory; + comma = ""; + + for (r = 0; r < rom->num_memory; r++, mem++) + { + mg_printf(conn, "%s{\"extension\":\"%s\",\"type\":%u}", comma, mem->extension, mem->type); + comma = ","; + } + + mg_printf(conn, "]}"); } mg_printf(conn, "]}"); - } + } - mg_printf(conn, "]}"); - } + av_info = video_viewport_get_system_av_info(); - av_info = video_viewport_get_system_av_info(); + mg_printf(conn, + "],\"avInfo\":{" + "\"geometry\":{" + "\"baseWidth\":%u," + "\"baseHeight\":%u," + "\"maxWidth\":%u," + "\"maxHeight\":%u," + "\"aspectRatio\":%f" + "}," + "\"timing\":{" + "\"fps\":%f," + "\"sampleRate\":%f" + "}" + "},", + av_info->geometry.base_width, + av_info->geometry.base_height, + av_info->geometry.max_width, + av_info->geometry.max_height, + av_info->geometry.aspect_ratio, + av_info->timing.fps, + av_info->timing.sample_rate + ); - mg_printf(conn, - "],\"avInfo\":{" - "\"geometry\":{" - "\"baseWidth\":%u," - "\"baseHeight\":%u," - "\"maxWidth\":%u," - "\"maxHeight\":%u," - "\"aspectRatio\":%f" - "}," - "\"timing\":{" - "\"fps\":%f," - "\"sampleRate\":%f" - "}" - "},", - av_info->geometry.base_width, - av_info->geometry.base_height, - av_info->geometry.max_width, - av_info->geometry.max_height, - av_info->geometry.aspect_ratio, - av_info->timing.fps, - av_info->timing.sample_rate - ); + mg_printf(conn, "\"ports\":["); + comma = ""; - mg_printf(conn, "\"ports\":["); - comma = ""; + for (p = 0; p < system->ports.size; p++) + { + ctrl = system->ports.data[p].types; - for (p = 0; p < system->ports.size; p++) - { - ctrl = system->ports.data[p].types; - - for (q = 0; q < system->ports.data[p].num_types; q++, ctrl++) - { - mg_printf(conn, "%s{\"id\":%u,\"description\":\"%s\"}", comma, ctrl->id, ctrl->desc); - comma = ","; - } - } - - mg_printf(conn, "],\"inputDescriptors\":["); - comma = ""; - - if (core_has_set_input_descriptor()) - { - for (p = 0; p < settings->input.max_users; p++) - { - for (q = 0; q < RARCH_FIRST_CUSTOM_BIND; q++) + for (q = 0; q < system->ports.data[p].num_types; q++, ctrl++) { - const char* description = system->input_desc_btn[p][q]; - - if (description) - { - mg_printf(conn, - "%s{\"player\":%u,\"button\":\"%s\",\"description\":\"%s\"}", - comma, - p + 1, - libretro_btn_desc[q], - description - ); - - comma = ","; - } + mg_printf(conn, "%s{\"id\":%u,\"description\":\"%s\"}", comma, ctrl->id, ctrl->desc); + comma = ","; } - } - } + } - mg_printf(conn, "],\"coreOptions\":["); - runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_LIST_GET, (void*)&core_opts); - opts = core_opts->opts; + mg_printf(conn, "],\"inputDescriptors\":["); + comma = ""; - for (p = 0; p < core_opts->size; p++, opts++) - { - mg_printf(conn, "%s{\"key\":\"%s\",\"description\":\"%s\",\"values\":[", p == 0 ? "" : ",", opts->key, opts->desc); - comma = ""; + if (core_has_set_input_descriptor()) + { + for (p = 0; p < settings->input.max_users; p++) + { + for (q = 0; q < RARCH_FIRST_CUSTOM_BIND; q++) + { + const char* description = system->input_desc_btn[p][q]; - for (q = 0; q < opts->vals->size; q++) - { - mg_printf(conn, "%s\"%s\"", comma, opts->vals->elems[q].data); - comma = ","; - } + if (description) + { + mg_printf(conn, + "%s{\"player\":%u,\"button\":\"%s\",\"description\":\"%s\"}", + comma, + p + 1, + libretro_btn_desc[q], + description + ); - mg_printf(conn, "]}"); - } + comma = ","; + } + } + } + } - mg_printf(conn, "]}"); - return 1; + mg_printf(conn, "],\"coreOptions\":["); + runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_LIST_GET, (void*)&core_opts); + opts = core_opts->opts; + + for (p = 0; p < core_opts->size; p++, opts++) + { + mg_printf(conn, "%s{\"key\":\"%s\",\"description\":\"%s\",\"values\":[", p == 0 ? "" : ",", opts->key, opts->desc); + comma = ""; + + for (q = 0; q < opts->vals->size; q++) + { + mg_printf(conn, "%s\"%s\"", comma, opts->vals->elems[q].data); + comma = ","; + } + + mg_printf(conn, "]}"); + } + + mg_printf(conn, "]}"); + return 1; } /*============================================================ @@ -392,25 +394,21 @@ MMAPS static int httpserver_handle_get_mmaps(struct mg_connection* conn, void* cbdata) { - const struct mg_request_info* req = mg_get_request_info(conn); - const char* comma = ""; - rarch_system_info_t* system; - const struct retro_memory_map* mmaps; - const struct retro_memory_descriptor* mmap; unsigned id; + const char* comma = ""; + const struct retro_memory_map* mmaps = NULL; + const struct retro_memory_descriptor* mmap = NULL; + const struct mg_request_info* req = mg_get_request_info(conn); + rarch_system_info_t *system = core_system_info_get(); if (strcmp(req->request_method, "GET")) - { return httpserver_error(conn, 405, "Unimplemented method in %s: %s", __FUNCTION__, req->request_method); - } - if (!runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system)) - { + if (!system) return httpserver_error(conn, 500, "Could not get system information in %s", __FUNCTION__); - } mmaps = &system->mmaps; - mmap = mmaps->descriptors; + mmap = mmaps->descriptors; mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n"); mg_printf(conn, "["); @@ -450,42 +448,33 @@ static int httpserver_handle_get_mmaps(struct mg_connection* conn, void* cbdata) static int httpserver_handle_get_mmap(struct mg_connection* conn, void* cbdata) { - const struct mg_request_info* req = mg_get_request_info(conn); - const char* comma = ""; - rarch_system_info_t* system; - const struct retro_memory_map* mmaps; - const struct retro_memory_descriptor* mmap; size_t start, length; - const char* param; unsigned id; uLong buflen; - Bytef* buffer; + const char* comma = ""; + const char* param = NULL; + Bytef* buffer = NULL; + const struct retro_memory_map* mmaps = NULL; + const struct retro_memory_descriptor* mmap = NULL; + const struct mg_request_info* req = mg_get_request_info(conn); + rarch_system_info_t *system = core_system_info_get(); if (strcmp(req->request_method, "GET")) - { return httpserver_error(conn, 405, "Unimplemented method in %s: %s", __FUNCTION__, req->request_method); - } if (sscanf(req->request_uri, "/" MEMORY_MAP "/%u", &id) != 1) - { return httpserver_error(conn, 500, "Malformed request in %s: %s", __FUNCTION__, req->request_uri); - } - if (!runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system)) - { + if (!system) return httpserver_error(conn, 500, "Could not get system information in %s", __FUNCTION__); - } mmaps = &system->mmaps; if (id >= mmaps->num_descriptors) - { return httpserver_error(conn, 404, "Invalid memory map id in %s: %u", __FUNCTION__, id); - } - mmap = mmaps->descriptors + id; - - start = 0; + mmap = mmaps->descriptors + id; + start = 0; length = mmap->len; if (req->query_string != NULL) @@ -493,35 +482,25 @@ static int httpserver_handle_get_mmap(struct mg_connection* conn, void* cbdata) param = strstr(req->query_string, "start="); if (param != NULL) - { start = atoll(param + 6); - } param = strstr(req->query_string, "length="); if (param != NULL) - { length = atoll(param + 7); - } } if (start >= mmap->len) - { start = mmap->len - 1; - } if (length > mmap->len - start) - { length = mmap->len - start; - } buflen = compressBound(length); buffer = (Bytef*)malloc(((buflen + 3) / 4) * 5); if (buffer == NULL) - { return httpserver_error(conn, 500, "Out of memory in %s", __FUNCTION__); - } if (compress2(buffer, &buflen, (Bytef*)mmap->ptr + start, length, Z_BEST_COMPRESSION) != Z_OK) { @@ -556,17 +535,13 @@ static int httpserver_handle_get_mmap(struct mg_connection* conn, void* cbdata) static int httpserver_handle_mmaps(struct mg_connection* conn, void* cbdata) { - const struct mg_request_info* req = mg_get_request_info(conn); unsigned id; + const struct mg_request_info* req = mg_get_request_info(conn); if (sscanf(req->request_uri, "/" MEMORY_MAP "/%u", &id) == 1) - { return httpserver_handle_get_mmap(conn, cbdata); - } - else - { - return httpserver_handle_get_mmaps(conn, cbdata); - } + + return httpserver_handle_get_mmaps(conn, cbdata); } /*============================================================ @@ -575,33 +550,32 @@ HTTP SERVER int httpserver_init(unsigned port) { - char str[16]; - snprintf(str, sizeof(str), "%u", port); - str[sizeof(str) - 1] = 0; + char str[16]; - const char* options[] = - { - "listening_ports", str, - NULL, NULL - }; + snprintf(str, sizeof(str), "%u", port); + str[sizeof(str) - 1] = 0; - memset(&s_httpserver_callbacks, 0, sizeof(s_httpserver_callbacks)); - s_httpserver_ctx = mg_start(&s_httpserver_callbacks, NULL, options); + const char* options[] = + { + "listening_ports", str, + NULL, NULL + }; - if (s_httpserver_ctx == NULL) - { - return -1; - } + memset(&s_httpserver_callbacks, 0, sizeof(s_httpserver_callbacks)); + s_httpserver_ctx = mg_start(&s_httpserver_callbacks, NULL, options); - mg_set_request_handler(s_httpserver_ctx, "/" BASIC_INFO, httpserver_handle_basic_info, NULL); + if (s_httpserver_ctx == NULL) + return -1; - mg_set_request_handler(s_httpserver_ctx, "/" MEMORY_MAP, httpserver_handle_mmaps, NULL); - mg_set_request_handler(s_httpserver_ctx, "/" MEMORY_MAP "/", httpserver_handle_mmaps, NULL); + mg_set_request_handler(s_httpserver_ctx, "/" BASIC_INFO, httpserver_handle_basic_info, NULL); - return 0; + mg_set_request_handler(s_httpserver_ctx, "/" MEMORY_MAP, httpserver_handle_mmaps, NULL); + mg_set_request_handler(s_httpserver_ctx, "/" MEMORY_MAP "/", httpserver_handle_mmaps, NULL); + + return 0; } -void httpserver_destroy() +void httpserver_destroy(void) { - mg_stop(s_httpserver_ctx); + mg_stop(s_httpserver_ctx); } diff --git a/location/location_driver.c b/location/location_driver.c index 9f06d71b98..d9d7cba8b4 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -206,10 +206,8 @@ bool driver_location_get_position(double *lat, double *lon, void init_location(void) { - rarch_system_info_t *system = NULL; + rarch_system_info_t *system = core_system_info_get(); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); - /* Resource leaks will follow if location interface is initialized twice. */ if (location_data) return; @@ -230,9 +228,7 @@ void init_location(void) static void uninit_location(void) { - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (location_data && location_driver) { diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 8186d3c2c6..d24fa55730 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -443,10 +443,10 @@ static int general_push(menu_displaylist_info_t *info, unsigned id, enum menu_displaylist_ctl_state state) { struct retro_system_info *system_menu = NULL; - settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = NULL; core_info_list_t *list = NULL; menu_handle_t *menu = NULL; + settings_t *settings = config_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); @@ -454,7 +454,6 @@ static int general_push(menu_displaylist_info_t *info, core_info_get_list(&list); menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET, &system_menu); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); switch (id) { diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 1947d13b41..168fa0c555 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -933,10 +933,9 @@ static void menu_action_setting_disp_set_label_menu_disk_index( char *s2, size_t len2) { unsigned images = 0, current = 0; - rarch_system_info_t *system = NULL; struct retro_disk_control_callback *control = NULL; + rarch_system_info_t *system = core_system_info_get(); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); if (!system) return; @@ -1319,10 +1318,9 @@ static void menu_action_setting_disp_set_label_core_option_create( const char *path, char *s2, size_t len2) { - rarch_system_info_t *system = NULL; global_t *global = global_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); if (!system) return; diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 9b501d4aca..c06741016e 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1540,11 +1540,9 @@ static int generic_action_ok_shader_preset_save(const char *path, char directory[PATH_MAX_LENGTH] = {0}; char file[PATH_MAX_LENGTH] = {0}; char tmp[PATH_MAX_LENGTH] = {0}; - settings_t *settings = config_get_ptr(); - rarch_system_info_t *info = NULL; const char *core_name = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + settings_t *settings = config_get_ptr(); + rarch_system_info_t *info = core_system_info_get(); if (info) core_name = info->info.library_name; @@ -1660,11 +1658,9 @@ static int generic_action_ok_remap_file_save(const char *path, { char directory[PATH_MAX_LENGTH] = {0}; char file[PATH_MAX_LENGTH] = {0}; - settings_t *settings = config_get_ptr(); - rarch_system_info_t *info = NULL; const char *core_name = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + settings_t *settings = config_get_ptr(); + rarch_system_info_t *info = core_system_info_get(); if (info) core_name = info->info.library_name; diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 374d19cb71..af2a76b80f 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -704,30 +704,21 @@ static size_t mui_list_get_size(void *data, enum menu_list_type type) static int mui_get_core_title(char *s, size_t len) { - struct retro_system_info *system = NULL; - rarch_system_info_t *info = NULL; + struct retro_system_info*system= NULL; settings_t *settings = config_get_ptr(); - const char *core_name = NULL; - const char *core_version = NULL; - - menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET, - &system); - - core_name = system->library_name; - core_version = system->library_version; + rarch_system_info_t *info = core_system_info_get(); + const char *core_name = system->library_name; + const char *core_version = system->library_version; if (!settings->menu.core_enable) return -1; - if (runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info)) + if (info) { - if (info) - { - if (string_is_empty(core_name)) - core_name = info->info.library_name; - if (!core_version) - core_version = info->info.library_version; - } + if (string_is_empty(core_name)) + core_name = info->info.library_name; + if (!core_version) + core_version = info->info.library_version; } if (string_is_empty(core_name)) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index e0f409dab7..430553aa89 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -2531,9 +2531,7 @@ static int menu_displaylist_parse_load_content_settings( if (!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) { - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); menu_entries_append_enum(info->list, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RESUME_CONTENT), @@ -2949,9 +2947,9 @@ static int menu_displaylist_parse_options_remappings( menu_displaylist_info_t *info) { unsigned p, retro_id; - rarch_system_info_t *system = NULL; menu_handle_t *menu = NULL; settings_t *settings = config_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return -1; @@ -2988,36 +2986,34 @@ static int menu_displaylist_parse_options_remappings( MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME, MENU_SETTING_ACTION, 0, 0); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + if (!system) + return 0; - if (system) + for (p = 0; p < settings->input.max_users; p++) { - for (p = 0; p < settings->input.max_users; p++) + for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND + 4; retro_id++) { - for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND + 4; retro_id++) - { - char desc_label[64] = {0}; - unsigned user = p + 1; - unsigned desc_offset = retro_id; - const char *description = NULL; + char desc_label[64] = {0}; + unsigned user = p + 1; + unsigned desc_offset = retro_id; + const char *description = NULL; - if (desc_offset >= RARCH_FIRST_CUSTOM_BIND) - desc_offset = RARCH_FIRST_CUSTOM_BIND - + (desc_offset - RARCH_FIRST_CUSTOM_BIND) * 2; - - description = system->input_desc_btn[p][desc_offset]; + if (desc_offset >= RARCH_FIRST_CUSTOM_BIND) + desc_offset = RARCH_FIRST_CUSTOM_BIND + + (desc_offset - RARCH_FIRST_CUSTOM_BIND) * 2; - if (!description) - continue; + description = system->input_desc_btn[p][desc_offset]; - snprintf(desc_label, sizeof(desc_label), - "%s %u %s : ", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), - user, description); - menu_entries_append_enum(info->list, desc_label, "", - MSG_UNKNOWN, - MENU_SETTINGS_INPUT_DESC_BEGIN + - (p * (RARCH_FIRST_CUSTOM_BIND + 4)) + retro_id, 0, 0); - } + if (!description) + continue; + + snprintf(desc_label, sizeof(desc_label), + "%s %u %s : ", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), + user, description); + menu_entries_append_enum(info->list, desc_label, "", + MSG_UNKNOWN, + MENU_SETTINGS_INPUT_DESC_BEGIN + + (p * (RARCH_FIRST_CUSTOM_BIND + 4)) + retro_id, 0, 0); } } @@ -4195,8 +4191,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) return true; case DISPLAYLIST_MAIN_MENU: { - rarch_system_info_t *system = NULL; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) menu_displaylist_parse_settings_enum(menu, info, diff --git a/menu/menu_entries.c b/menu/menu_entries.c index a44d7c1a69..83a91f9e54 100644 --- a/menu/menu_entries.c +++ b/menu/menu_entries.c @@ -440,19 +440,18 @@ int menu_entries_get_title(char *s, size_t len) * (shown at the top of the UI). */ int menu_entries_get_core_title(char *s, size_t len) { - struct retro_system_info *system = NULL; - rarch_system_info_t *info = NULL; - settings_t *settings = config_get_ptr(); + struct retro_system_info*system= NULL; const char *core_name = NULL; const char *core_version = NULL; + settings_t *settings = config_get_ptr(); + rarch_system_info_t *info = core_system_info_get(); - menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET, - &system); - - core_name = system->library_name; - core_version = system->library_version; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + if (menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET, &system) + && system) + { + core_name = system->library_name; + core_version = system->library_version; + } if (!settings->menu.core_enable) return -1; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 3fe3b6d53a..7313932dc5 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -340,17 +340,16 @@ static void setting_get_string_representation_uint_libretro_device(void *data, unsigned index_offset; const struct retro_controller_description *desc = NULL; const char *name = NULL; - rarch_system_info_t *system = NULL; rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); + rarch_system_info_t *system = core_system_info_get(); if (!setting) return; index_offset = setting_get_index_offset(setting); - if (runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system) - && system) + if (system) { if (index_offset < system->ports.size) desc = libretro_find_controller_description( @@ -958,9 +957,9 @@ static int setting_action_start_libretro_device_type(void *data) unsigned index_offset, current_device; unsigned devices[128], types = 0, port = 0; const struct retro_controller_info *desc = NULL; - rarch_system_info_t *system = NULL; settings_t *settings = config_get_ptr(); rarch_setting_t *setting = (rarch_setting_t*)data; + rarch_system_info_t *system = core_system_info_get(); if (setting_generic_action_start_default(setting) != 0) return -1; @@ -971,8 +970,7 @@ static int setting_action_start_libretro_device_type(void *data) devices[types++] = RETRO_DEVICE_NONE; devices[types++] = RETRO_DEVICE_JOYPAD; - if (runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system) - && system) + if (system) { /* Only push RETRO_DEVICE_ANALOG as default if we use an * older core which doesn't use SET_CONTROLLER_INFO. */ @@ -1064,7 +1062,7 @@ static int setting_action_left_libretro_device_type( const struct retro_controller_info *desc = NULL; rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = NULL; + rarch_system_info_t *system = core_system_info_get(); if (!setting) return -1; @@ -1074,8 +1072,6 @@ static int setting_action_left_libretro_device_type( devices[types++] = RETRO_DEVICE_NONE; devices[types++] = RETRO_DEVICE_JOYPAD; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); - if (system) { /* Only push RETRO_DEVICE_ANALOG as default if we use an @@ -1132,7 +1128,7 @@ static int setting_action_right_libretro_device_type( const struct retro_controller_info *desc = NULL; rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); - rarch_system_info_t *system = NULL; + rarch_system_info_t *system = core_system_info_get(); if (!setting) return -1; @@ -1142,8 +1138,7 @@ static int setting_action_right_libretro_device_type( devices[types++] = RETRO_DEVICE_NONE; devices[types++] = RETRO_DEVICE_JOYPAD; - if (runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system) - && system) + if (system) { /* Only push RETRO_DEVICE_ANALOG as default if we use an * older core which doesn't use SET_CONTROLLER_INFO. */ @@ -1666,8 +1661,8 @@ void general_write_handler(void *data) break; case MENU_ENUM_LABEL_VIDEO_ROTATION: { - rarch_system_info_t *system = NULL; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); + if (system) video_driver_set_rotation( (*setting->value.target.unsigned_integer + @@ -1917,17 +1912,14 @@ static bool setting_append_list_input_player_options( static char buffer[MAX_USERS][13+2+1]; static char group_lbl[MAX_USERS][PATH_MAX_LENGTH]; unsigned i; - rarch_setting_group_info_t group_info = {0}; - rarch_setting_group_info_t subgroup_info = {0}; - settings_t *settings = config_get_ptr(); - const char *temp_value = NULL; + rarch_setting_group_info_t group_info = {0}; + rarch_setting_group_info_t subgroup_info = {0}; + settings_t *settings = config_get_ptr(); const struct retro_keybind* const defaults = (user == 0) ? retro_keybinds_1 : retro_keybinds_rest; - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); - - temp_value =msg_hash_to_str((enum msg_hash_enums)(MENU_ENUM_LABEL_INPUT_USER_1_BINDS + user)); + rarch_system_info_t *system = core_system_info_get(); + const char *temp_value = msg_hash_to_str((enum msg_hash_enums) + (MENU_ENUM_LABEL_INPUT_USER_1_BINDS + user)); snprintf(buffer[user], sizeof(buffer[user]), "%s %u", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1); diff --git a/network/netplay/netplay_common.c b/network/netplay/netplay_common.c index dba2eef948..f9cf05127c 100644 --- a/network/netplay/netplay_common.c +++ b/network/netplay/netplay_common.c @@ -170,16 +170,14 @@ uint32_t netplay_impl_magic(void) retro_ctx_api_info_t api_info; unsigned api; uint32_t res = 0; - rarch_system_info_t *info = NULL; const char *lib = NULL; const char *ver = PACKAGE_VERSION; + rarch_system_info_t *info = core_system_info_get(); core_api_version(&api_info); api = api_info.version; - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); - if (info) lib = info->info.library_name; diff --git a/retroarch.c b/retroarch.c index 6233ac8fa9..68f384662f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -413,9 +413,7 @@ static void retroarch_set_paths_redirect(void) bool check_global_library_name_hash = false; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); - rarch_system_info_t *info = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info); + rarch_system_info_t *info = core_system_info_get(); if (!global) return; @@ -1088,9 +1086,7 @@ static void retroarch_parse_input(int argc, char *argv[]) static void retroarch_init_savefile_paths(void) { global_t *global = global_get_ptr(); - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); command_event(CMD_EVENT_SAVEFILES_DEINIT, NULL); @@ -1199,10 +1195,8 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir) char config_directory[PATH_MAX_LENGTH] = {0}; const char *core_name = NULL; const char *game_name = NULL; - rarch_system_info_t *system = NULL; global_t *global = global_get_ptr(); - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (system) core_name = system->info.library_name; diff --git a/runloop.c b/runloop.c index 5d3dbc6f3f..4b32bbf765 100644 --- a/runloop.c +++ b/runloop.c @@ -75,12 +75,6 @@ #include "verbosity.h" -#ifdef HAVE_ZLIB -#define DEFAULT_EXT "zip" -#else -#define DEFAULT_EXT "" -#endif - #define runloop_cmd_triggered(cmd, id) BIT64_GET(cmd->state[2].state, id) #define runloop_cmd_press(cmd, id) BIT64_GET(cmd->state[0].state, id) @@ -106,7 +100,6 @@ typedef struct event_cmd_state static struct rarch_dir_list runloop_shader_dir; static char runloop_fullpath[PATH_MAX_LENGTH]; static char runloop_default_shader_preset[PATH_MAX_LENGTH]; -static rarch_system_info_t runloop_system; static unsigned runloop_pending_windowed_scale; static struct retro_frame_time_callback runloop_frame_time; static retro_keyboard_event_t runloop_key_event = NULL; @@ -756,6 +749,7 @@ static bool runloop_is_frame_count_end(void) return runloop_max_frames && (*frame_count >= runloop_max_frames); } + bool runloop_ctl(enum runloop_ctl_state state, void *data) { @@ -767,19 +761,8 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) case RUNLOOP_CTL_SHADER_DIR_INIT: return shader_dir_init(&runloop_shader_dir); case RUNLOOP_CTL_SYSTEM_INFO_INIT: - core_get_system_info(&runloop_system.info); - - if (!runloop_system.info.library_name) - runloop_system.info.library_name = msg_hash_to_str(MSG_UNKNOWN); - if (!runloop_system.info.library_version) - runloop_system.info.library_version = "v0"; - + core_system_info_init(); video_driver_set_title_buf(); - - strlcpy(runloop_system.valid_extensions, - runloop_system.info.valid_extensions ? - runloop_system.info.valid_extensions : DEFAULT_EXT, - sizeof(runloop_system.valid_extensions)); break; case RUNLOOP_CTL_GET_CORE_OPTION_SIZE: { @@ -799,37 +782,12 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) *coreopts = runloop_core_options; } break; - case RUNLOOP_CTL_SYSTEM_INFO_GET: - { - rarch_system_info_t **system = (rarch_system_info_t**)data; - if (!system) - return false; - *system = &runloop_system; - } - break; case RUNLOOP_CTL_SYSTEM_INFO_FREE: - - /* No longer valid. */ - if (runloop_system.subsystem.data) - free(runloop_system.subsystem.data); - runloop_system.subsystem.data = NULL; - runloop_system.subsystem.size = 0; - - if (runloop_system.ports.data) - free(runloop_system.ports.data); - runloop_system.ports.data = NULL; - runloop_system.ports.size = 0; - - if (runloop_system.mmaps.descriptors) - free((void *)runloop_system.mmaps.descriptors); - runloop_system.mmaps.descriptors = NULL; - runloop_system.mmaps.num_descriptors = 0; + core_system_info_free(); runloop_key_event = NULL; runloop_frontend_key_event = NULL; - audio_driver_unset_callback(); - memset(&runloop_system, 0, sizeof(rarch_system_info_t)); break; case RUNLOOP_CTL_SET_FRAME_TIME_LAST: runloop_frame_time_last_enable = true; diff --git a/runloop.h b/runloop.h index 138e7b2623..70f763268c 100644 --- a/runloop.h +++ b/runloop.h @@ -127,7 +127,6 @@ enum runloop_ctl_state RUNLOOP_CTL_SHADER_DIR_INIT, /* System info */ - RUNLOOP_CTL_SYSTEM_INFO_GET, RUNLOOP_CTL_SYSTEM_INFO_INIT, RUNLOOP_CTL_SYSTEM_INFO_FREE, diff --git a/tasks/task_content.c b/tasks/task_content.c index 91c5c6f1a2..8ef01d5462 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1134,10 +1134,8 @@ static bool load_content_from_compressed_archive( char new_basedir[PATH_MAX_LENGTH] = {0}; ssize_t new_path_len = 0; bool ret = false; - rarch_system_info_t *sys_info= NULL; settings_t *settings = config_get_ptr(); - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sys_info); + rarch_system_info_t *sys_info = core_system_info_get(); if (sys_info && sys_info->info.block_extract) return true; @@ -1457,10 +1455,8 @@ static bool content_file_init(struct string_list *temporary_content) struct string_list* additional_path_allocs = NULL; struct string_list *content = NULL; const struct retro_subsystem_info *special = NULL; - rarch_system_info_t *system = NULL; global_t *global = global_get_ptr(); - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + rarch_system_info_t *system = core_system_info_get(); if (!string_is_empty(global->subsystem)) { @@ -1668,9 +1664,8 @@ static bool task_load_content(content_ctx_info_t *content_info, { char tmp[PATH_MAX_LENGTH] = {0}; struct retro_system_info *info = NULL; - rarch_system_info_t *system = NULL; + rarch_system_info_t *system = core_system_info_get(); - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); if (system) info = &system->info;