diff --git a/autosave.c b/autosave.c index 26129b70ed..1381a26854 100644 --- a/autosave.c +++ b/autosave.c @@ -243,7 +243,7 @@ void autosave_event_init(void) mem_info.id = type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (mem_info.size <= 0) continue; diff --git a/cheats.c b/cheats.c index a77ab4b900..af051df050 100644 --- a/cheats.c +++ b/cheats.c @@ -81,7 +81,7 @@ void cheat_manager_apply_cheats(void) if (!handle) return; - core_ctl(CORE_CTL_RETRO_CHEAT_RESET, NULL); + core_reset_cheat(); for (i = 0; i < handle->size; i++) { @@ -93,7 +93,7 @@ void cheat_manager_apply_cheats(void) cheat_info.enabled = true; cheat_info.code = handle->cheats[i].code; - core_ctl(CORE_CTL_RETRO_CHEAT_SET, &cheat_info); + core_set_cheat(&cheat_info); } } diff --git a/cheevos.c b/cheevos.c index cb83764239..8700be4e54 100644 --- a/cheevos.c +++ b/cheevos.c @@ -974,7 +974,7 @@ static const uint8_t *cheevos_get_memory(unsigned offset) mem_info.id = RETRO_MEMORY_SYSTEM_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (offset < mem_info.size) { @@ -988,7 +988,7 @@ static const uint8_t *cheevos_get_memory(unsigned offset) mem_info.size = 0; mem_info.id = RETRO_MEMORY_SAVE_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (offset < mem_info.size) { @@ -1002,7 +1002,7 @@ static const uint8_t *cheevos_get_memory(unsigned offset) mem_info.size = 0; mem_info.id = RETRO_MEMORY_VIDEO_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (offset < mem_info.size) { @@ -1016,7 +1016,7 @@ static const uint8_t *cheevos_get_memory(unsigned offset) mem_info.size = 0; mem_info.id = RETRO_MEMORY_RTC; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (offset < mem_info.size) { @@ -1983,7 +1983,7 @@ bool cheevos_load(const void *data) mem_info.size = 0; mem_info.id = RETRO_MEMORY_SYSTEM_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); memory = mem_info.size; @@ -1991,7 +1991,7 @@ bool cheevos_load(const void *data) mem_info.size = 0; mem_info.id = RETRO_MEMORY_VIDEO_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); memory += mem_info.size; @@ -1999,7 +1999,7 @@ bool cheevos_load(const void *data) mem_info.size = 0; mem_info.id = RETRO_MEMORY_RTC; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); memory += mem_info.size; @@ -2007,7 +2007,7 @@ bool cheevos_load(const void *data) mem_info.size = 0; mem_info.id = RETRO_MEMORY_SAVE_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); memory += mem_info.size; @@ -2020,7 +2020,7 @@ bool cheevos_load(const void *data) /* The the supported extensions as a hint to what method we should use. */ - core_ctl(CORE_CTL_RETRO_GET_SYSTEM_INFO, &sysinfo); + core_get_system_info(&sysinfo); for (i = 0; i < sizeof(finders) / sizeof(finders[0]); i++) { diff --git a/command_event.c b/command_event.c index 95328a43c0..02ec85914b 100644 --- a/command_event.c +++ b/command_event.c @@ -388,7 +388,7 @@ static void event_init_controllers(void) { pad.device = device; pad.port = i; - core_ctl(CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE, &pad); + core_set_controller_port_device(&pad); } } } @@ -399,8 +399,8 @@ static void event_deinit_core(bool reinit) cheevos_unload(); #endif - core_ctl(CORE_CTL_RETRO_UNLOAD_GAME, NULL); - core_ctl(CORE_CTL_RETRO_DEINIT, NULL); + core_unload_game(); + core_unload(); if (reinit) { @@ -581,7 +581,7 @@ static bool event_init_core(void *data) retro_ctx_environ_info_t info; settings_t *settings = config_get_ptr(); - if (!core_ctl(CORE_CTL_RETRO_SYMBOLS_INIT, data)) + if (!core_init_symbols(data)) return false; runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_INIT, NULL); @@ -599,7 +599,7 @@ static bool event_init_core(void *data) video_driver_set_pixel_format(RETRO_PIXEL_FORMAT_0RGB1555); info.env = rarch_environment_cb; - core_ctl(CORE_CTL_RETRO_SET_ENVIRONMENT, &info); + core_set_environment(&info); /* Auto-remap: apply remap files */ if(settings->auto_remaps_enable) @@ -608,13 +608,13 @@ static bool event_init_core(void *data) /* Per-core saves: reset redirection paths */ rarch_ctl(RARCH_CTL_SET_PATHS_REDIRECT, NULL); - if (!core_ctl(CORE_CTL_RETRO_INIT, NULL)) + if (!core_init()) return false; if (!event_init_content()) return false; - if (!core_ctl(CORE_CTL_INIT, NULL)) + if (!core_load()) return false; return true; @@ -874,7 +874,7 @@ static void event_main_state(unsigned cmd) else strlcpy(path, global->name.savestate, sizeof(path)); - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); if (info.size) { @@ -1091,7 +1091,7 @@ bool event_cmd_ctl(enum event_command cmd, void *data) #ifdef HAVE_CHEEVOS cheevos_set_cheats(); #endif - core_ctl(CORE_CTL_RETRO_RESET, NULL); + core_reset(); break; case EVENT_CMD_SAVE_STATE: #ifdef HAVE_CHEEVOS diff --git a/configuration.c b/configuration.c index 841051d8b2..992e0cdadd 100644 --- a/configuration.c +++ b/configuration.c @@ -2420,7 +2420,7 @@ void config_load(void) config_save_file(global->path.core_specific_config); /* Flush out some states that could have been set by core environment variables */ - core_ctl(CORE_CTL_UNSET_INPUT_DESCRIPTORS, NULL); + core_unset_input_descriptors(); if (!rarch_ctl(RARCH_CTL_IS_BLOCK_CONFIG_READ, NULL)) { diff --git a/content.c b/content.c index 40255786b5..dafce8b0a0 100644 --- a/content.c +++ b/content.c @@ -1017,7 +1017,7 @@ static bool content_save_state(const char *path) bool ret = false; void *data = NULL; - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); RARCH_LOG("%s: \"%s\".\n", msg_hash_to_str(MSG_SAVING_STATE), @@ -1038,7 +1038,7 @@ static bool content_save_state(const char *path) serial_info.data = data; serial_info.size = info.size; - ret = core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + ret = core_serialize(&serial_info); if (ret) ret = filestream_write_file(path, data, info.size); @@ -1108,7 +1108,7 @@ static bool content_load_state(const char *path) retro_ctx_memory_info_t mem_info; mem_info.id = blocks[i].type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); blocks[i].size = mem_info.size; } @@ -1127,7 +1127,7 @@ static bool content_load_state(const char *path) mem_info.id = blocks[i].type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); ptr = mem_info.data; if (ptr) @@ -1137,7 +1137,7 @@ static bool content_load_state(const char *path) serial_info.data_const = buf; serial_info.size = size; - ret = core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info); + ret = core_unserialize(&serial_info); /* Flush back. */ for (i = 0; i < num_blocks; i++) @@ -1149,7 +1149,7 @@ static bool content_load_state(const char *path) mem_info.id = blocks[i].type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); ptr = mem_info.data; if (ptr) @@ -1193,7 +1193,7 @@ static bool load_ram_file(void *data) mem_info.id = ram->type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (mem_info.size == 0 || !mem_info.data) return false; @@ -1239,7 +1239,7 @@ static bool save_ram_file(ram_type_t *ram) mem_info.id = ram->type; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (!mem_info.data || mem_info.size == 0) return false; @@ -1430,7 +1430,7 @@ static bool load_content( load_info.special = special; load_info.info = info; - if (!core_ctl(CORE_CTL_RETRO_LOAD_GAME, &load_info)) + if (!core_load_game(&load_info)) { RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT)); return false; diff --git a/driver.c b/driver.c index d6539af9f2..b236be464d 100644 --- a/driver.c +++ b/driver.c @@ -436,7 +436,7 @@ bool driver_ctl(enum driver_ctl_state state, void *data) #endif location_driver_ctl(RARCH_LOCATION_CTL_DESTROY, NULL); camera_driver_ctl(RARCH_CAMERA_CTL_DESTROY, NULL); - core_ctl(CORE_CTL_DEINIT, NULL); + core_uninit_libretro_callbacks(); break; case RARCH_DRIVER_CTL_UNINIT: { diff --git a/dynamic.c b/dynamic.c index 739c3500c1..db1f0adff2 100644 --- a/dynamic.c +++ b/dynamic.c @@ -514,7 +514,7 @@ void libretro_get_current_core_pathname(char *name, size_t size) if (size == 0) return; - core_ctl(CORE_CTL_RETRO_GET_SYSTEM_INFO, &info); + core_get_system_info(&info); if (info.library_name) id = info.library_name; @@ -875,7 +875,7 @@ bool rarch_environment_cb(unsigned cmd, void *data) } } - core_ctl(CORE_CTL_SET_INPUT_DESCRIPTORS, NULL); + core_set_input_descriptors(); break; } diff --git a/gfx/drivers_shader/shader_gl_cg.c b/gfx/drivers_shader/shader_gl_cg.c index 003fd28b4b..e4011d76b6 100644 --- a/gfx/drivers_shader/shader_gl_cg.c +++ b/gfx/drivers_shader/shader_gl_cg.c @@ -811,7 +811,7 @@ static bool gl_cg_load_imports(void *data) mem_info.id = memtype; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if ((memtype != -1u) && (cg->shader->variable[i].addr >= mem_info.size)) @@ -825,7 +825,7 @@ static bool gl_cg_load_imports(void *data) mem_info.size = 0; mem_info.id = RETRO_MEMORY_SYSTEM_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); tracker_info.wram = (uint8_t*)mem_info.data; tracker_info.info = cg->shader->variable; diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index eb1778c874..14d98013b7 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -853,7 +853,7 @@ static void *gl_glsl_init(void *data, const char *path) mem_info.id = RETRO_MEMORY_SYSTEM_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); info.wram = (uint8_t*)mem_info.data; info.info = glsl->shader->variable; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index a4041a6f81..5ce5c325be 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -1107,7 +1107,7 @@ static bool video_driver_cached_frame(void) if (video_driver_state.frame_cache.data != RETRO_HW_FRAME_BUFFER_VALID) info.data = video_driver_state.frame_cache.data; - core_ctl(CORE_CTL_RETRO_CTX_FRAME_CB, &info); + core_frame(&info); recording_driver_set_data_ptr(recording); @@ -1804,7 +1804,7 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) case RARCH_DISPLAY_CTL_SET_TITLE_BUF: { struct retro_system_info info; - core_ctl(CORE_CTL_RETRO_GET_SYSTEM_INFO, &info); + core_get_system_info(&info); strlcpy(video_driver_title_buf, msg_hash_to_str(MSG_PROGRAM), sizeof(video_driver_title_buf)); diff --git a/gfx/video_state_python.c b/gfx/video_state_python.c index c875a6d975..6df023816f 100644 --- a/gfx/video_state_python.c +++ b/gfx/video_state_python.c @@ -40,7 +40,7 @@ static PyObject* py_read_wram(PyObject *self, PyObject *args) mem_info.id = RETRO_MEMORY_SYSTEM_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); data = (const uint8_t*)mem_info.data; @@ -75,7 +75,7 @@ static PyObject* py_read_vram(PyObject *self, PyObject *args) mem_info.id = RETRO_MEMORY_VIDEO_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); data = (const uint8_t*)mem_info.data; diff --git a/libretro_version_1.c b/libretro_version_1.c index 438dd9f8c1..34683c4591 100644 --- a/libretro_version_1.c +++ b/libretro_version_1.c @@ -64,45 +64,11 @@ static int16_t core_input_state_poll(unsigned port, return input_state(port, device, idx, id); } -/** - * core_set_default_callbacks: - * @data : pointer to retro_callbacks object - * - * Binds the libretro callbacks to default callback functions. - **/ -static bool core_set_default_callbacks(void *data) +void core_set_input_state(retro_ctx_input_state_info_t *info) { - struct retro_callbacks *cbs = (struct retro_callbacks*)data; - - if (!cbs) - return false; - - cbs->frame_cb = video_driver_frame; - cbs->sample_cb = audio_driver_sample; - cbs->sample_batch_cb = audio_driver_sample_batch; - cbs->state_cb = core_input_state_poll; - cbs->poll_cb = input_poll; - - return true; + core.retro_set_input_state(info->cb); } -static bool core_uninit_libretro_cbs(void *data) -{ - struct retro_callbacks *cbs = (struct retro_callbacks*)data; - - if (!cbs) - return false; - - cbs->frame_cb = NULL; - cbs->sample_cb = NULL; - cbs->sample_batch_cb = NULL; - cbs->state_cb = NULL; - cbs->poll_cb = NULL; - - return true; -} - - /** * core_init_libretro_cbs: * @data : pointer to retro_callbacks object @@ -126,7 +92,7 @@ static bool core_init_libretro_cbs(void *data) core.retro_set_input_state(core_input_state_poll); core.retro_set_input_poll(core_input_state_poll_maybe); - core_ctl(CORE_CTL_SET_CBS, cbs); + core_set_default_callbacks(cbs); #ifdef HAVE_NETPLAY if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL)) @@ -154,13 +120,57 @@ static bool core_init_libretro_cbs(void *data) return true; } +/** + * core_set_default_callbacks: + * @data : pointer to retro_callbacks object + * + * Binds the libretro callbacks to default callback functions. + **/ +bool core_set_default_callbacks(void *data) +{ + struct retro_callbacks *cbs = (struct retro_callbacks*)data; + + if (!cbs) + return false; + + cbs->frame_cb = video_driver_frame; + cbs->sample_cb = audio_driver_sample; + cbs->sample_batch_cb = audio_driver_sample_batch; + cbs->state_cb = core_input_state_poll; + cbs->poll_cb = input_poll; + + return true; +} + + +bool core_deinit(void *data) +{ + struct retro_callbacks *cbs = (struct retro_callbacks*)data; + + if (!cbs) + return false; + + cbs->frame_cb = NULL; + cbs->sample_cb = NULL; + cbs->sample_batch_cb = NULL; + cbs->state_cb = NULL; + cbs->poll_cb = NULL; + + return true; +} + +bool core_uninit_libretro_callbacks(void) +{ + return core_deinit(&retro_ctx); +} + /** * core_set_rewind_callbacks: * * Sets the audio sampling callbacks based on whether or not * rewinding is currently activated. **/ -static void core_set_rewind_callbacks(void) +bool core_set_rewind_callbacks(void) { if (state_manager_frame_is_reversed()) { @@ -172,211 +182,224 @@ static void core_set_rewind_callbacks(void) core.retro_set_audio_sample(audio_driver_sample); core.retro_set_audio_sample_batch(audio_driver_sample_batch); } + return true; } -bool core_ctl(enum core_ctl_state state, void *data) +bool core_set_cheat(retro_ctx_cheat_info_t *info) { + core.retro_cheat_set(info->index, info->enabled, info->code); + return true; +} - switch (state) +bool core_reset_cheat(void) +{ + core.retro_cheat_reset(); + return true; +} + +bool core_api_version(retro_ctx_api_info_t *api) +{ + if (!api) + return false; + api->version = core.retro_api_version(); + return true; +} + +bool core_set_poll_type(unsigned *type) +{ + core_poll_type = *type; + return true; +} + +bool core_init_symbols(enum rarch_core_type *type) +{ + if (!type) + return false; + init_libretro_sym(*type, &core); + return true; +} + +bool core_set_controller_port_device(retro_ctx_controller_info_t *pad) +{ + if (!pad) + return false; + core.retro_set_controller_port_device(pad->port, pad->device); + return true; +} + +bool core_get_memory(retro_ctx_memory_info_t *info) +{ + if (!info) + return false; + info->size = core.retro_get_memory_size(info->id); + info->data = core.retro_get_memory_data(info->id); + return true; +} + +bool core_load_game(retro_ctx_load_content_info_t *load_info) +{ + if (!load_info) + return false; + + if (load_info->special) + return core.retro_load_game_special(load_info->special->id, load_info->info, load_info->content->size); + return core.retro_load_game(*load_info->content->elems[0].data ? load_info->info : NULL); +} + +bool core_get_system_info(struct retro_system_info *system) +{ + if (!system) + return false; + core.retro_get_system_info(system); + return true; +} + +bool core_unserialize(retro_ctx_serialize_info_t *info) +{ + if (!info) + return false; + if (!core.retro_unserialize(info->data_const, info->size)) + return false; + return true; +} + +bool core_serialize(retro_ctx_serialize_info_t *info) +{ + if (!info) + return false; + if (!core.retro_serialize(info->data, info->size)) + return false; + return true; +} + +bool core_serialize_size(retro_ctx_size_info_t *info) +{ + if (!info) + return false; + info->size = core.retro_serialize_size(); + return true; +} + +bool core_frame(retro_ctx_frame_info_t *info) +{ + if (!info || !retro_ctx.frame_cb) + return false; + + retro_ctx.frame_cb( + info->data, info->width, info->height, info->pitch); + return true; +} + +bool core_poll(void) +{ + if (!retro_ctx.poll_cb) + return false; + retro_ctx.poll_cb(); + return true; +} + +bool core_set_environment(retro_ctx_environ_info_t *info) +{ + if (!info) + return false; + core.retro_set_environment(info->env); + return true; +} + +bool core_get_system_av_info(struct retro_system_av_info *av_info) +{ + if (!av_info) + return false; + core.retro_get_system_av_info(av_info); + return true; +} + +bool core_reset(void) +{ + core.retro_reset(); + return true; +} + +bool core_init(void) +{ + core.retro_init(); + return true; +} + +bool core_unload(void) +{ + core.retro_deinit(); + uninit_libretro_sym(&core); + return true; +} + +bool core_unload_game(void) +{ + video_driver_ctl(RARCH_DISPLAY_CTL_DEINIT_HW_CONTEXT, NULL); + audio_driver_ctl(RARCH_AUDIO_CTL_STOP, NULL); + core.retro_unload_game(); + return true; +} + +bool core_run(void) +{ + switch (core_poll_type) { - case CORE_CTL_RETRO_CHEAT_SET: - { - retro_ctx_cheat_info_t *info = (retro_ctx_cheat_info_t*)data; - core.retro_cheat_set(info->index, info->enabled, info->code); - } + case POLL_TYPE_EARLY: + input_poll(); break; - case CORE_CTL_RETRO_CHEAT_RESET: - core.retro_cheat_reset(); - break; - case CORE_CTL_RETRO_API_VERSION: - { - retro_ctx_api_info_t *api = (retro_ctx_api_info_t*)data; - api->version = core.retro_api_version(); - } - break; - case CORE_CTL_SET_POLL_TYPE: - { - unsigned *poll_type = (unsigned*)data; - core_poll_type = *poll_type; - } - break; - case CORE_CTL_RETRO_SYMBOLS_INIT: - { - enum rarch_core_type *core_type = (enum rarch_core_type*)data; - - if (!core_type) - return false; - init_libretro_sym(*core_type, &core); - } - break; - case CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE: - { - retro_ctx_controller_info_t *pad = (retro_ctx_controller_info_t*)data; - if (!pad) - return false; - core.retro_set_controller_port_device(pad->port, pad->device); - } - break; - case CORE_CTL_RETRO_GET_MEMORY: - { - retro_ctx_memory_info_t *info = (retro_ctx_memory_info_t*)data; - if (!info) - return false; - info->size = core.retro_get_memory_size(info->id); - info->data = core.retro_get_memory_data(info->id); - } - break; - case CORE_CTL_RETRO_LOAD_GAME: - { - retro_ctx_load_content_info_t *load_info = - (retro_ctx_load_content_info_t*)data; - if (!load_info) - return false; - - if (load_info->special) - return core.retro_load_game_special(load_info->special->id, load_info->info, load_info->content->size); - return core.retro_load_game(*load_info->content->elems[0].data ? load_info->info : NULL); - } - case CORE_CTL_RETRO_GET_SYSTEM_INFO: - { - struct retro_system_info *system = (struct retro_system_info*)data; - if (!system) - return false; - core.retro_get_system_info(system); - } - break; - case CORE_CTL_RETRO_UNSERIALIZE: - { - retro_ctx_serialize_info_t *info = (retro_ctx_serialize_info_t*)data; - if (!info) - return false; - if (!core.retro_unserialize(info->data_const, info->size)) - return false; - } - break; - case CORE_CTL_RETRO_SERIALIZE: - { - retro_ctx_serialize_info_t *info = (retro_ctx_serialize_info_t*)data; - if (!info) - return false; - if (!core.retro_serialize(info->data, info->size)) - return false; - } - break; - case CORE_CTL_RETRO_SERIALIZE_SIZE: - { - retro_ctx_size_info_t *info = (retro_ctx_size_info_t *)data; - if (!info) - return false; - info->size = core.retro_serialize_size(); - } - break; - case CORE_CTL_RETRO_CTX_FRAME_CB: - { - retro_ctx_frame_info_t *info = (retro_ctx_frame_info_t*)data; - if (!info || !retro_ctx.frame_cb) - return false; - - retro_ctx.frame_cb( - info->data, info->width, info->height, info->pitch); - } - break; - case CORE_CTL_RETRO_CTX_POLL_CB: - if (!retro_ctx.poll_cb) - return false; - retro_ctx.poll_cb(); - break; - case CORE_CTL_RETRO_SET_ENVIRONMENT: - { - retro_ctx_environ_info_t *info = (retro_ctx_environ_info_t*)data; - if (!info) - return false; - core.retro_set_environment(info->env); - } - break; - case CORE_CTL_RETRO_GET_SYSTEM_AV_INFO: - { - struct retro_system_av_info *av_info = (struct retro_system_av_info*)data; - if (!av_info) - return false; - core.retro_get_system_av_info(av_info); - } - break; - case CORE_CTL_RETRO_RESET: - core.retro_reset(); - break; - case CORE_CTL_RETRO_INIT: - core.retro_init(); - break; - case CORE_CTL_RETRO_DEINIT: - core.retro_deinit(); - uninit_libretro_sym(&core); - break; - case CORE_CTL_RETRO_UNLOAD_GAME: - video_driver_ctl(RARCH_DISPLAY_CTL_DEINIT_HW_CONTEXT, NULL); - audio_driver_ctl(RARCH_AUDIO_CTL_STOP, NULL); - core.retro_unload_game(); - break; - case CORE_CTL_RETRO_RUN: - switch (core_poll_type) - { - case POLL_TYPE_EARLY: - input_poll(); - break; - case POLL_TYPE_LATE: - core_input_polled = false; - break; - } - if (core.retro_run) - core.retro_run(); - if (core_poll_type == POLL_TYPE_LATE && !core_input_polled) - input_poll(); - break; - case CORE_CTL_SET_CBS: - return core_set_default_callbacks(data); - case CORE_CTL_SET_CBS_REWIND: - core_set_rewind_callbacks(); - break; - case CORE_CTL_INIT: - { - settings_t *settings = config_get_ptr(); - core_poll_type = settings->input.poll_type_behavior; - if (!core_ctl(CORE_CTL_VERIFY_API_VERSION, NULL)) - return false; - if (!core_init_libretro_cbs(&retro_ctx)) - return false; - core_ctl(CORE_CTL_RETRO_GET_SYSTEM_AV_INFO, - video_viewport_get_system_av_info()); - runloop_ctl(RUNLOOP_CTL_SET_FRAME_LIMIT, NULL); - } - break; - case CORE_CTL_DEINIT: - return core_uninit_libretro_cbs(&retro_ctx); - case CORE_CTL_VERIFY_API_VERSION: - { - unsigned api_version = core.retro_api_version(); - RARCH_LOG("Version of libretro API: %u\n", api_version); - RARCH_LOG("Compiled against API: %u\n", RETRO_API_VERSION); - - if (api_version != RETRO_API_VERSION) - { - RARCH_WARN("%s\n", msg_hash_to_str(MSG_LIBRETRO_ABI_BREAK)); - return false; - } - } - break; - case CORE_CTL_HAS_SET_INPUT_DESCRIPTORS: - return core_has_set_input_descriptors; - case CORE_CTL_SET_INPUT_DESCRIPTORS: - core_has_set_input_descriptors = true; - break; - case CORE_CTL_UNSET_INPUT_DESCRIPTORS: - core_has_set_input_descriptors = false; - break; - case CORE_CTL_NONE: - default: + case POLL_TYPE_LATE: + core_input_polled = false; break; } + if (core.retro_run) + core.retro_run(); + if (core_poll_type == POLL_TYPE_LATE && !core_input_polled) + input_poll(); + return true; +} + +bool core_load(void) +{ + settings_t *settings = config_get_ptr(); + core_poll_type = settings->input.poll_type_behavior; + + if (!core_verify_api_version()) + return false; + if (!core_init_libretro_cbs(&retro_ctx)) + return false; + + core_get_system_av_info(video_viewport_get_system_av_info()); + runloop_ctl(RUNLOOP_CTL_SET_FRAME_LIMIT, NULL); return true; } + +bool core_verify_api_version(void) +{ + unsigned api_version = core.retro_api_version(); + RARCH_LOG("Version of libretro API: %u\n", api_version); + RARCH_LOG("Compiled against API: %u\n", RETRO_API_VERSION); + + if (api_version != RETRO_API_VERSION) + { + RARCH_WARN("%s\n", msg_hash_to_str(MSG_LIBRETRO_ABI_BREAK)); + return false; + } + return true; +} + +bool core_has_set_input_descriptor(void) +{ + return core_has_set_input_descriptors; +} + +void core_set_input_descriptors(void) +{ + core_has_set_input_descriptors = true; +} + +void core_unset_input_descriptors(void) +{ + core_has_set_input_descriptors = false; +} diff --git a/libretro_version_1.h b/libretro_version_1.h index 01799e00d7..ad7f00be5c 100644 --- a/libretro_version_1.h +++ b/libretro_version_1.h @@ -24,6 +24,7 @@ extern "C" { #include +#include "core_type.h" #include "libretro.h" enum @@ -40,83 +41,6 @@ enum POLL_TYPE_LATE }; -enum core_ctl_state -{ - CORE_CTL_NONE = 0, - - CORE_CTL_INIT, - - CORE_CTL_DEINIT, - - - CORE_CTL_SET_CBS, - - CORE_CTL_SET_CBS_REWIND, - - CORE_CTL_SET_POLL_TYPE, - - /* Runs the core for one frame. */ - CORE_CTL_RETRO_RUN, - - CORE_CTL_RETRO_INIT, - - CORE_CTL_RETRO_DEINIT, - - CORE_CTL_RETRO_UNLOAD_GAME, - - CORE_CTL_RETRO_RESET, - - CORE_CTL_RETRO_GET_SYSTEM_AV_INFO, - - CORE_CTL_RETRO_CTX_FRAME_CB, - - CORE_CTL_RETRO_CTX_POLL_CB, - - CORE_CTL_RETRO_SET_ENVIRONMENT, - - CORE_CTL_RETRO_SERIALIZE_SIZE, - - CORE_CTL_RETRO_SERIALIZE, - - CORE_CTL_RETRO_UNSERIALIZE, - - CORE_CTL_RETRO_SYMBOLS_INIT, - - CORE_CTL_RETRO_CHEAT_SET, - - CORE_CTL_RETRO_CHEAT_RESET, - - CORE_CTL_RETRO_SET_INPUT_STATE, - - CORE_CTL_RETRO_API_VERSION, - - /* Compare libretro core API version against API version - * used by RetroArch. - * - * TODO - when libretro v2 gets added, allow for switching - * between libretro version backend dynamically. - */ - CORE_CTL_VERIFY_API_VERSION, - - CORE_CTL_RETRO_GET_MEMORY, - - /* Initialize system A/V information. */ - CORE_CTL_INIT_SYSTEM_AV_INFO, - - /* Get system A/V information. */ - CORE_CTL_RETRO_GET_SYSTEM_INFO, - - CORE_CTL_RETRO_LOAD_GAME, - - CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE, - - CORE_CTL_HAS_SET_INPUT_DESCRIPTORS, - - CORE_CTL_SET_INPUT_DESCRIPTORS, - - CORE_CTL_UNSET_INPUT_DESCRIPTORS -}; - typedef struct retro_ctx_input_state_info { retro_input_state_t cb; @@ -188,7 +112,76 @@ typedef struct retro_callbacks retro_input_poll_t poll_cb; } retro_callbacks_t; -bool core_ctl(enum core_ctl_state state, void *data); +bool core_load(void); + +bool core_unload(void); + +bool core_set_default_callbacks(void *data); + +bool core_set_rewind_callbacks(void); + +bool core_set_poll_type(unsigned *type); + +/* Runs the core for one frame. */ +bool core_run(void); + +bool core_init(void); + +bool core_deinit(void *data); + +bool core_unload_game(void); + +bool core_reset(void); + +bool core_frame(retro_ctx_frame_info_t *info); + +bool core_poll(void); + +bool core_set_environment(retro_ctx_environ_info_t *info); + +bool core_serialize_size(retro_ctx_size_info_t *info); + +bool core_serialize(retro_ctx_serialize_info_t *info); + +bool core_unserialize(retro_ctx_serialize_info_t *info); + +bool core_init_symbols(enum rarch_core_type *type); + +bool core_set_cheat(retro_ctx_cheat_info_t *info); + +bool core_reset_cheat(void); + +bool core_api_version(retro_ctx_api_info_t *api); + +/* Compare libretro core API version against API version + * used by RetroArch. + * + * TODO - when libretro v2 gets added, allow for switching + * between libretro version backend dynamically. + */ +bool core_verify_api_version(void); + +bool core_get_memory(retro_ctx_memory_info_t *info); + +/* Initialize system A/V information. */ +bool core_get_system_av_info(struct retro_system_av_info *av_info); + +/* Get system A/V information. */ +bool core_get_system_info(struct retro_system_info *system); + +bool core_load_game(retro_ctx_load_content_info_t *load_info); + +bool core_set_controller_port_device(retro_ctx_controller_info_t *pad); + +bool core_has_set_input_descriptor(void); + +void core_set_input_descriptors(void); + +void core_unset_input_descriptors(void); + +bool core_uninit_libretro_callbacks(void); + +void core_set_input_state(retro_ctx_input_state_info_t *info); #ifdef __cplusplus } diff --git a/menu/menu_display.c b/menu/menu_display.c index 1b0b4c0dc1..5c7cc0a40a 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -282,7 +282,7 @@ bool menu_display_ctl(enum menu_display_ctl_state state, void *data) input_driver_ctl( RARCH_INPUT_CTL_SET_LIBRETRO_INPUT_BLOCKED, NULL); - core_ctl(CORE_CTL_RETRO_RUN, NULL); + core_run(); input_driver_ctl( RARCH_INPUT_CTL_UNSET_LIBRETRO_INPUT_BLOCKED, NULL); diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 85d0bbfdeb..28548d2835 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -2197,7 +2197,7 @@ static int menu_displaylist_parse_load_content_settings( menu_hash_to_str(MENU_LABEL_CORE_OPTIONS), MENU_SETTING_ACTION, 0, 0); - if (core_ctl(CORE_CTL_HAS_SET_INPUT_DESCRIPTORS, NULL)) + if (core_has_set_input_descriptor()) menu_entries_add(info->list, menu_hash_to_str(MENU_LABEL_VALUE_CORE_INPUT_REMAPPING_OPTIONS), menu_hash_to_str(MENU_LABEL_CORE_INPUT_REMAPPING_OPTIONS), diff --git a/menu/menu_input.c b/menu/menu_input.c index e2081f823f..9f4ceb3826 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -1288,7 +1288,7 @@ unsigned menu_input_frame_retropad(retro_input_t input, if (!menu_input) return 0; - core_ctl(CORE_CTL_RETRO_CTX_POLL_CB, NULL); + core_poll(); /* don't run anything first frame, only capture held inputs * for old_input_state. */ diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 436a4e17c1..cff7817e2f 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -2327,7 +2327,7 @@ static int setting_action_start_libretro_device_type(void *data) pad.port = port; pad.device = current_device; - core_ctl(CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE, &pad); + core_set_controller_port_device(&pad); return 0; } @@ -2488,7 +2488,7 @@ static int setting_action_left_libretro_device_type( pad.port = port; pad.device = current_device; - core_ctl(CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE, &pad); + core_set_controller_port_device(&pad); return 0; } @@ -2553,7 +2553,7 @@ static int setting_action_right_libretro_device_type( pad.port = port; pad.device = current_device; - core_ctl(CORE_CTL_RETRO_SET_CONTROLLER_PORT_DEVICE, &pad); + core_set_controller_port_device(&pad); return 0; } @@ -2915,7 +2915,7 @@ void general_write_handler(void *data) } break; case MENU_LABEL_INPUT_POLL_TYPE_BEHAVIOR: - core_ctl(CORE_CTL_SET_POLL_TYPE, setting->value.target.integer); + core_set_poll_type((unsigned int*)setting->value.target.integer); break; case MENU_LABEL_VIDEO_SCALE_INTEGER: { @@ -3408,7 +3408,7 @@ static bool setting_append_list_input_player_options( if ( settings->input.input_descriptor_label_show && (i < RARCH_FIRST_META_KEY) - && (core_ctl(CORE_CTL_HAS_SET_INPUT_DESCRIPTORS, NULL)) + && core_has_set_input_descriptor() && (i != RARCH_TURBO_ENABLE) ) { diff --git a/movie.c b/movie.c index e56f960fae..086e8bbcdb 100644 --- a/movie.c +++ b/movie.c @@ -120,13 +120,13 @@ static bool init_playback(bsv_movie_t *handle, const char *path) return false; } - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size( &info); if (info.size == state_size) { serial_info.data_const = handle->state; serial_info.size = state_size; - core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info); + core_unserialize(&serial_info); } else RARCH_WARN("Movie format seems to have a different serializer version. Will most likely fail.\n"); @@ -158,7 +158,7 @@ static bool init_record(bsv_movie_t *handle, const char *path) header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC); header[CRC_INDEX] = swap_if_big32(*content_crc_ptr); - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); state_size = info.size; @@ -180,7 +180,7 @@ static bool init_record(bsv_movie_t *handle, const char *path) serial_info.data = handle->state; serial_info.size = state_size; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); fwrite(handle->state, 1, state_size, handle->file); } @@ -289,7 +289,7 @@ static void bsv_movie_frame_rewind(bsv_movie_t *handle) serial_info.data = handle->state; serial_info.size = handle->state_size; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); fwrite(handle->state, 1, handle->state_size, handle->file); } diff --git a/netplay/netplay.c b/netplay/netplay.c index bc99c971b5..78c5b7feba 100644 --- a/netplay/netplay.c +++ b/netplay/netplay.c @@ -1030,7 +1030,7 @@ static int16_t netplay_get_spectate_input(netplay_t *netplay, bool port, input_info.cb = netplay->cbs.state_cb; - core_ctl(CORE_CTL_RETRO_SET_INPUT_STATE, &input_info); + core_set_input_state(&input_info); return netplay->cbs.state_cb(port, device, idx, id); } @@ -1103,7 +1103,7 @@ bool init_netplay(void) return false; } - core_ctl(CORE_CTL_SET_CBS, &cbs); + core_set_default_callbacks(&cbs); if (*global->netplay.server) { diff --git a/netplay/netplay_common.c b/netplay/netplay_common.c index b27f8de36b..dbdcb9e8fb 100644 --- a/netplay/netplay_common.c +++ b/netplay/netplay_common.c @@ -69,7 +69,7 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic) size_t serialize_size, header_size; uint32_t *header, bsv_header[4] = {0}; - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); serialize_size = info.size; header_size = sizeof(bsv_header) + serialize_size; @@ -88,7 +88,7 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic) serial_info.data = header + 4; serial_info.size = serialize_size; - if (serialize_size && !core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info)) + if (serialize_size && !core_serialize(&serial_info)) goto error; memcpy(header, bsv_header, sizeof(bsv_header)); @@ -132,7 +132,7 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) return false; } - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); in_state_size = swap_if_big32(header[STATE_SIZE_INDEX]); if (in_state_size != info.size) @@ -165,7 +165,7 @@ uint32_t np_impl_magic(void) const char *lib = NULL; const char *ver = PACKAGE_VERSION; - core_ctl(CORE_CTL_RETRO_API_VERSION, &api_info); + core_api_version(&api_info); api = api_info.version; @@ -204,7 +204,7 @@ bool np_send_info(netplay_t *netplay) mem_info.id = RETRO_MEMORY_SAVE_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); header[0] = htonl(*content_crc_ptr); @@ -274,7 +274,7 @@ bool np_get_info(netplay_t *netplay) mem_info.id = RETRO_MEMORY_SAVE_RAM; - core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); + core_get_memory(&mem_info); if (mem_info.size != ntohl(header[2])) { diff --git a/netplay/netplay_net.c b/netplay/netplay_net.c index 6f19a5ce22..fa64b6f880 100644 --- a/netplay/netplay_net.c +++ b/netplay/netplay_net.c @@ -28,7 +28,7 @@ static void netplay_net_pre_frame(netplay_t *netplay) serial_info.data = netplay->buffer[netplay->self_ptr].state; serial_info.size = netplay->state_size; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); netplay->can_poll = true; @@ -77,7 +77,7 @@ static void netplay_net_post_frame(netplay_t *netplay) serial_info.data_const = netplay->buffer[netplay->other_ptr].state; serial_info.size = netplay->state_size; - core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info); + core_unserialize(&serial_info); while (first || (netplay->tmp_ptr != netplay->self_ptr)) { @@ -85,12 +85,12 @@ static void netplay_net_post_frame(netplay_t *netplay) serial_info.size = netplay->state_size; serial_info.data_const = NULL; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); #if defined(HAVE_THREADS) lock_autosave(); #endif - core_ctl(CORE_CTL_RETRO_RUN, NULL); + core_run(); #if defined(HAVE_THREADS) unlock_autosave(); #endif @@ -118,7 +118,7 @@ static bool netplay_net_init_buffers(netplay_t *netplay) if (!netplay->buffer) return false; - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); netplay->state_size = info.size; diff --git a/rewind.c b/rewind.c index 22274aa35f..f1c54f0796 100644 --- a/rewind.c +++ b/rewind.c @@ -637,7 +637,7 @@ void init_rewind(void) return; } - core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info); + core_serialize_size(&info); rewind_state.size = info.size; @@ -663,7 +663,7 @@ void init_rewind(void) serial_info.data = state; serial_info.size = rewind_state.size; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); state_manager_push_do(rewind_state.state); } @@ -732,7 +732,7 @@ void state_manager_check_rewind(bool pressed) serial_info.data_const = buf; serial_info.size = rewind_state.size; - core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info); + core_unserialize(&serial_info); if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) bsv_movie_ctl(BSV_MOVIE_CTL_FRAME_REWIND, NULL); @@ -763,7 +763,7 @@ void state_manager_check_rewind(bool pressed) serial_info.data = state; serial_info.size = rewind_state.size; - core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info); + core_serialize(&serial_info); retro_perf_stop(&rewind_serialize); @@ -771,5 +771,5 @@ void state_manager_check_rewind(bool pressed) } } - core_ctl(CORE_CTL_SET_CBS_REWIND, NULL); + core_set_rewind_callbacks(); } diff --git a/runloop.c b/runloop.c index 5005cba5e9..d70d27689d 100644 --- a/runloop.c +++ b/runloop.c @@ -561,7 +561,7 @@ 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_ctl(CORE_CTL_RETRO_GET_SYSTEM_INFO, &runloop_system.info); + core_get_system_info(&runloop_system.info); if (!runloop_system.info.library_name) runloop_system.info.library_name = msg_hash_to_str(MSG_UNKNOWN); @@ -914,7 +914,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL); runloop_overrides_active = false; - core_ctl(CORE_CTL_UNSET_INPUT_DESCRIPTORS, NULL); + core_unset_input_descriptors(); global = global_get_ptr(); memset(global, 0, sizeof(struct global)); @@ -1428,7 +1428,7 @@ int runloop_iterate(unsigned *sleep_ms) if (!runloop_ctl(RUNLOOP_CTL_CHECK_STATE, &cmd)) { /* RetroArch has been paused. */ - core_ctl(CORE_CTL_RETRO_CTX_POLL_CB, NULL); + core_poll(); *sleep_ms = 10; return 1; } @@ -1462,7 +1462,7 @@ int runloop_iterate(unsigned *sleep_ms) !input_driver_ctl(RARCH_INPUT_CTL_IS_NONBLOCK_STATE, NULL)) retro_sleep(settings->video.frame_delay); - core_ctl(CORE_CTL_RETRO_RUN, NULL); + core_run(); #ifdef HAVE_CHEEVOS cheevos_test();