/** * rarch_main_init: * @argc : Count of (commandline) arguments. * @argv : (Commandline) arguments. * * Initializes the program. * * Returns: 0 on success, otherwise 1 if there was an error. **/ int rarch_main_init(int argc, char *argv[]) { int sjlj_ret; global_t *global = global_get_ptr(); init_state(); if ((sjlj_ret = setjmp(global->error_sjlj_context)) > 0) { RARCH_ERR("Fatal error received in: \"%s\"\n", global->error_string); return sjlj_ret; } global->inited.error = true; global->log_file = stderr; parse_input(argc, argv); if (global->verbosity) { char str[PATH_MAX_LENGTH] = {0}; RARCH_LOG_OUTPUT("=== Build ======================================="); rarch_info_get_capabilities(RARCH_CAPABILITIES_CPU, str, sizeof(str)); fprintf(stderr, "%s", str); fprintf(stderr, "Built: %s\n", __DATE__); RARCH_LOG_OUTPUT("Version: %s\n", PACKAGE_VERSION); #ifdef HAVE_GIT_VERSION RARCH_LOG_OUTPUT("Git: %s\n", rarch_git_version); #endif RARCH_LOG_OUTPUT("=================================================\n"); } rarch_ctl(RARCH_ACTION_STATE_VALIDATE_CPU_FEATURES, NULL); config_load(); { settings_t *settings = config_get_ptr(); if (settings && (settings->multimedia.builtin_mediaplayer_enable || settings->multimedia.builtin_imageviewer_enable)) { switch (rarch_path_is_media_type(global->path.fullpath)) { case RARCH_CONTENT_MOVIE: case RARCH_CONTENT_MUSIC: if (settings->multimedia.builtin_mediaplayer_enable) { #ifdef HAVE_FFMPEG global->has_set.libretro = false; global->inited.core.type = CORE_TYPE_FFMPEG; #endif } break; #ifdef HAVE_IMAGEVIEWER case RARCH_CONTENT_IMAGE: if (settings->multimedia.builtin_imageviewer_enable) { global->has_set.libretro = false; global->inited.core.type = CORE_TYPE_IMAGEVIEWER; } break; #endif default: break; } } } init_libretro_sym(global->inited.core.type); rarch_system_info_init(); init_drivers_pre(); if (!event_command(EVENT_CMD_CORE_INIT)) goto error; event_command(EVENT_CMD_DRIVERS_INIT); event_command(EVENT_CMD_COMMAND_INIT); event_command(EVENT_CMD_REWIND_INIT); event_command(EVENT_CMD_CONTROLLERS_INIT); event_command(EVENT_CMD_RECORD_INIT); event_command(EVENT_CMD_CHEATS_INIT); event_command(EVENT_CMD_REMAPPING_INIT); event_command(EVENT_CMD_SAVEFILES_INIT); #if defined(GEKKO) && defined(HW_RVL) { settings_t *settings = config_get_ptr(); if (settings) { event_command(EVENT_CMD_VIDEO_SET_ASPECT_RATIO); video_driver_set_aspect_ratio(settings->video.aspect_ratio_idx); } unsigned width = 0, height = 0; (void)width; (void)height; width = global->console.screen.resolutions.width; height = global->console.screen.resolutions.height; video_driver_set_video_mode(width, height, true); char msg[PATH_MAX_LENGTH] = {0}; snprintf(msg, sizeof(msg),"Resolution: %dx%d",width, height); rarch_main_msg_queue_push(msg, 1, 100, true); } #endif global->inited.error = false; global->inited.main = true; return 0; error: event_command(EVENT_CMD_CORE_DEINIT); global->inited.main = false; return 1; }
int main(int argc, char *argv[]) { #ifdef HAVE_SYSUTILS RARCH_LOG("Registering system utility callback...\n"); cellSysutilRegisterCallback(0, callback_sysutil_exit, NULL); #endif #ifdef HAVE_SYSMODULES cellSysmoduleLoadModule(CELL_SYSMODULE_IO); cellSysmoduleLoadModule(CELL_SYSMODULE_FS); cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_GAME); cellSysmoduleLoadModule(CELL_SYSMODULE_AVCONF_EXT); cellSysmoduleLoadModule(CELL_SYSMODULE_PNGDEC); cellSysmoduleLoadModule(CELL_SYSMODULE_JPGDEC); cellSysmoduleLoadModule(CELL_SYSMODULE_NET); cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_NP); #endif sys_net_initialize_network(); #ifdef HAVE_LOGGER logger_init(); #endif sceNpInit(NP_POOL_SIZE, np_pool); rarch_main_clear_state(); get_environment_settings(argc, argv); config_set_defaults(); char full_path[1024], tmp_path[1024]; snprintf(full_path, sizeof(full_path), "%s/%s/CORE.SELF", usrDirPath, EMULATOR_CORE_DIR); snprintf(tmp_path, sizeof(tmp_path), "%s/%s/", usrDirPath, EMULATOR_CORE_DIR); bool find_libretro_file = rarch_configure_libretro_core(full_path, tmp_path, LIBRETRO_DIR_PATH, SYS_CONFIG_FILE, ".SELF"); set_default_settings(); rarch_config_load(SYS_CONFIG_FILE, LIBRETRO_DIR_PATH, ".SELF", find_libretro_file); init_libretro_sym(); #if(CELL_SDK_VERSION > 0x340000) if (g_console.screenshots_enable) { #ifdef HAVE_SYSMODULES cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_SCREENSHOT); #endif #ifdef HAVE_SYSUTILS CellScreenShotSetParam screenshot_param = {0, 0, 0, 0}; screenshot_param.photo_title = "RetroArch PS3"; screenshot_param.game_title = "RetroArch PS3"; cellScreenShotSetParameter (&screenshot_param); cellScreenShotEnable(); #endif } #ifdef HAVE_SYSUTILS if (g_console.custom_bgm_enable) cellSysutilEnableBgmPlayback(); #endif #endif video_gl.start(); input_ps3.init(); #ifdef HAVE_OSKUTIL oskutil_init(&g_console.oskutil_handle, 0); #endif rarch_input_set_default_keybind_names_for_emulator(); menu_init(); switch(g_console.external_launcher_support) { case EXTERN_LAUNCHER_SALAMANDER: g_console.mode_switch = MODE_MENU; break; #ifdef HAVE_MULTIMAN case EXTERN_LAUNCHER_MULTIMAN: RARCH_LOG("Started from multiMAN, will auto-start game.\n"); strlcpy(g_console.rom_path, argv[1], sizeof(g_console.rom_path)); rarch_settings_change(S_START_RARCH); rarch_startup(SYS_CONFIG_FILE); break; #endif default: break; } begin_loop: if(g_console.mode_switch == MODE_EMULATION) { bool repeat = false; input_ps3.poll(NULL); rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); do{ repeat = rarch_main_iterate(); }while(repeat && !g_console.frame_advance_enable); } else if(g_console.mode_switch == MODE_MENU) { menu_loop(); rarch_startup(SYS_CONFIG_FILE); } else goto begin_shutdown; goto begin_loop; begin_shutdown: if(path_file_exists(SYS_CONFIG_FILE)) rarch_config_save(SYS_CONFIG_FILE); if(g_console.emulator_initialized) rarch_main_deinit(); input_ps3.free(NULL); video_gl.stop(); menu_free(); #ifdef HAVE_OSKUTIL if(g_console.oskutil_handle.is_running) oskutil_unload(&g_console.oskutil_handle); #endif #ifdef HAVE_LOGGER logger_shutdown(); #endif #ifdef HAVE_SYSMODULES if(g_console.screenshots_enable) cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_SCREENSHOT); cellSysmoduleUnloadModule(CELL_SYSMODULE_JPGDEC); cellSysmoduleUnloadModule(CELL_SYSMODULE_PNGDEC); cellSysmoduleUnloadModule(CELL_SYSMODULE_AVCONF_EXT); cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_GAME); #endif #ifdef HAVE_HDD_CACHE_PARTITION int ret = cellSysCacheClear(); if(ret != CELL_SYSCACHE_RET_OK_CLEARED) { RARCH_ERR("System cache partition could not be cleared on exit.\n"); } #endif rarch_exec(); return 1; }
bool core_ctl(enum core_ctl_state state, void *data) { static bool has_set_input_descriptors = false; static struct retro_callbacks retro_ctx; switch (state) { 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); } 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 retro_set_default_callbacks(data); case CORE_CTL_SET_CBS_REWIND: retro_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 (!retro_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 retro_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 has_set_input_descriptors; case CORE_CTL_SET_INPUT_DESCRIPTORS: has_set_input_descriptors = true; break; case CORE_CTL_UNSET_INPUT_DESCRIPTORS: has_set_input_descriptors = false; break; case CORE_CTL_NONE: default: break; } return true; }
int rarch_main(int argc, char *argv[]) { system_init(); rarch_main_clear_state(); verbose_log_init(); get_environment_settings(argc, argv); config_load(); init_libretro_sym(); rarch_init_system_info(); global_init_drivers(); #ifdef HAVE_LIBRETRO_MANAGEMENT char core_exe_path[PATH_MAX]; char path_prefix[PATH_MAX]; const char *extension = DEFAULT_EXE_EXT; char slash; #if defined(_WIN32) slash = '\\'; #else slash = '/'; #endif snprintf(path_prefix, sizeof(path_prefix), "%s%c", default_paths.core_dir, slash); snprintf(core_exe_path, sizeof(core_exe_path), "%sCORE%s", path_prefix, extension); if (path_file_exists(core_exe_path)) { RARCH_LOG("core_exe_path: %s\n", core_exe_path); if (install_libretro_core(core_exe_path, path_prefix, extension)) { RARCH_LOG("New default libretro core saved to config file: %s.\n", g_settings.libretro); config_save_file(g_extern.config_path); } } #endif init_libretro_sym(); system_post_init(); menu_init(); system_process_args(argc, argv); begin_loop: if(g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { driver.input->poll(NULL); if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_start_func(); while(rarch_main_iterate()); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_stop_func(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT)) { if(g_extern.main_is_init) rarch_main_deinit(); struct rarch_main_wrap args = {0}; args.verbose = g_extern.verbose; args.sram_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE)) ? g_extern.console.main_wrap.default_sram_dir : NULL; args.state_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE)) ? g_extern.console.main_wrap.default_savestate_dir : NULL; args.rom_path = g_extern.fullpath; args.libretro_path = g_settings.libretro; if (path_file_exists(g_extern.config_path)) args.config_path = g_extern.config_path; else args.config_path = NULL; if (rarch_main_init_wrap(&args) == 0) { RARCH_LOG("rarch_main_init succeeded.\n"); g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); } else { RARCH_ERR("rarch_main_init failed.\n"); g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); menu_settings_msg(S_MSG_ROM_LOADING_ERROR, 180); } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT); } else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT); while (menu_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else goto begin_shutdown; goto begin_loop; begin_shutdown: config_save_file(g_extern.config_path); system_deinit_save(); if(g_extern.main_is_init) rarch_main_deinit(); menu_free(); global_uninit_drivers(); #ifdef PERF_TEST rarch_perf_log(); #endif system_deinit(); if (g_extern.lifecycle_mode_state & (1ULL << MODE_EXITSPAWN)) system_exitspawn(); return 1; }