From 4c8ebb205ca36321eef5b1106f3c0db7e2a49d87 Mon Sep 17 00:00:00 2001 From: neonloop Date: Fri, 20 Aug 2021 21:15:01 +0000 Subject: Adds disc control to MinUI --- Makefile | 2 +- core.c | 190 +++++++++++++++++++++++++++++++++++++-------------------------- core.h | 1 + main.c | 15 ++--- menu.c | 3 - 5 files changed, 121 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index f81993f..5cfb979 100644 --- a/Makefile +++ b/Makefile @@ -158,7 +158,7 @@ mame2003_plus_PAK_NAME = Arcade (MAME 2003-plus) pcsx_rearmed_ROM_DIR = PS pcsx_rearmed_TYPES = bin,cue,img,mdf,pbp,toc,cbn,m3u,chd -pcsx_rearmed_PAK_NAME = Sony PlayStation +pcsx_rearmed_PAK_NAME = PlayStation define pcsx_rearmed_PAK_EXTRA needs-swap diff --git a/core.c b/core.c index a259b6e..bbc9a58 100644 --- a/core.c +++ b/core.c @@ -28,11 +28,98 @@ static char config_dir[MAX_PATH]; static char save_dir[MAX_PATH]; static char system_dir[MAX_PATH]; static char temp_rom[MAX_PATH]; -static struct retro_game_info game_info; static struct retro_disk_control_ext_callback disk_control_ext; static uint32_t buttons = 0; +#define MAX_EXTENSIONS 24 + +static void core_handle_zip(const char *path, struct retro_system_info *info, struct retro_game_info *game_info, FILE** file) { + const char *extensions[MAX_EXTENSIONS] = {0}; + char *extensionstr = strdup(info->valid_extensions); + char *ext = NULL; + char *saveptr = NULL; + int index = 0; + bool haszip = false; + FILE *dest = NULL; + + if (info->valid_extensions && has_suffix_i(path, ".zip")) { + while((ext = strtok_r(index == 0 ? extensionstr : NULL, "|", &saveptr))) { + if (!strcmp(ext, "zip")) { + haszip = true; + break; + } + extensions[index++] = ext; + if (index > MAX_EXTENSIONS - 1) break; + } + + if (!haszip) { + if (!unzip_tmp(*file, extensions, temp_rom, MAX_PATH)) { + game_info->path = temp_rom; + dest = fopen(temp_rom, "r"); + if (dest) { + fclose(*file); + *file = dest; + } + } + } + } + free(extensionstr); +} + +static int core_load_game_info(const char *path, struct retro_game_info *game_info) { + struct retro_system_info info = {0}; + FILE *file = fopen(path, "rb"); + int ret = -1; + + if (!file) { + PA_ERROR("Couldn't load content: %s\n", strerror(errno)); + goto finish; + } + + PA_INFO("Loading %s\n", path); + game_info->path = path; + + current_core.retro_get_system_info(&info); + + core_handle_zip(path, &info, game_info, &file); + + fseek(file, 0, SEEK_END); + game_info->size = ftell(file); + rewind(file); + + if (!info.need_fullpath) { + void *game_data = malloc(game_info->size); + + if (!game_data) { + PA_ERROR("Couldn't allocate memory for content\n"); + goto finish; + } + + if (fread(game_data, 1, game_info->size, file) != game_info->size) { + PA_ERROR("Couldn't read file: %s\n", strerror(errno)); + goto finish; + } + + game_info->data = game_data; + } + + ret = 0; +finish: + if (file) + fclose(file); + + return ret; +} + +static void core_free_game_info(struct retro_game_info *game_info) { + if (game_info->data) { + free((void *)game_info->data); + game_info->data = NULL; + game_info->size = 0; + } +} + static void gamepak_related_name(char *buf, size_t len, const char *new_extension) { char filename[MAX_PATH]; @@ -245,12 +332,30 @@ bool disc_switch_index(unsigned index) { return ret; } +bool disc_replace_index(unsigned index, const char *content_path) { + bool ret = false; + struct retro_game_info info = {0}; + if (!disk_control_ext.replace_image_index) + return false; + + if (core_load_game_info(content_path, &info)) { + goto finish; + } + + ret = disk_control_ext.replace_image_index(index, &info); + +finish: + core_free_game_info(&info); + return ret; +} + static void set_directories(const char *core_name) { const char *home = getenv("HOME"); - char cwd[MAX_PATH]; char *dst = save_dir; int len = MAX_PATH; - +#ifndef MINUI + char cwd[MAX_PATH]; +#endif if (home != NULL) { snprintf(dst, len, "%s/.picoarch-%s/", home, core_name); mkdir(dst, 0755); @@ -537,81 +642,15 @@ int core_load(const char *corefile) { return 0; } -#define MAX_EXTENSIONS 24 - -static void core_handle_zip(const char *path, struct retro_system_info *info, struct retro_game_info *game_info, FILE** file) { - const char *extensions[MAX_EXTENSIONS] = {0}; - char *extensionstr = strdup(info->valid_extensions); - char *ext = NULL; - char *saveptr = NULL; - int index = 0; - bool haszip = false; - FILE *dest = NULL; - - if (info->valid_extensions && has_suffix_i(path, ".zip")) { - while((ext = strtok_r(index == 0 ? extensionstr : NULL, "|", &saveptr))) { - if (!strcmp(ext, "zip")) { - haszip = true; - break; - } - extensions[index++] = ext; - if (index > MAX_EXTENSIONS - 1) break; - } - - if (!haszip) { - if (!unzip_tmp(*file, extensions, temp_rom, MAX_PATH)) { - game_info->path = temp_rom; - dest = fopen(temp_rom, "r"); - if (dest) { - fclose(*file); - *file = dest; - } - } - } - } - free(extensionstr); -} - int core_load_content(const char *path) { - struct retro_system_info info = {0}; + struct retro_game_info game_info = {0}; struct retro_system_av_info av_info = {0}; - FILE *file = fopen(path, "rb"); int ret = -1; - if (!file) { - PA_ERROR("Couldn't load content: %s\n", strerror(errno)); + if (core_load_game_info(path, &game_info)) { goto finish; } - memset(&game_info, 0, sizeof(struct retro_game_info)); - - PA_INFO("Loading %s\n", path); - game_info.path = path; - - current_core.retro_get_system_info(&info); - - core_handle_zip(path, &info, &game_info, &file); - - fseek(file, 0, SEEK_END); - game_info.size = ftell(file); - rewind(file); - - if (!info.need_fullpath) { - void *game_data = malloc(game_info.size); - - if (!game_data) { - PA_ERROR("Couldn't allocate memory for content\n"); - goto finish; - } - - if (fread(game_data, 1, game_info.size, file) != game_info.size) { - PA_ERROR("Couldn't read file: %s\n", strerror(errno)); - goto finish; - } - - game_info.data = game_data; - } - if (!current_core.retro_load_game(&game_info)) { PA_ERROR("Couldn't load content\n"); goto finish; @@ -636,9 +675,7 @@ int core_load_content(const char *path) { ret = 0; finish: - if (file) - fclose(file); - + core_free_game_info(&game_info); return ret; } @@ -650,11 +687,6 @@ void core_unload(void) { current_core.initialized = false; } - if (game_info.data) { - free((void *)game_info.data); - game_info.data = NULL; - } - if (temp_rom[0]) { remove(temp_rom); temp_rom[0] = '\0'; diff --git a/core.h b/core.h index 67cf4e2..1c39d87 100644 --- a/core.h +++ b/core.h @@ -50,6 +50,7 @@ int state_write(void); unsigned disc_get_count(void); unsigned disc_get_index(void); bool disc_switch_index(unsigned index); +bool disc_replace_index(unsigned index, const char *content_path); int core_load(const char *corefile); int core_load_content(const char *path); diff --git a/main.c b/main.c index 3b9cfb0..c7b4276 100644 --- a/main.c +++ b/main.c @@ -347,19 +347,20 @@ void handle_emu_action(emu_action action) ShowMenu_t ShowMenu = (ShowMenu_t)dlsym(mmenu, "ShowMenu"); SDL_Surface *screen = SDL_GetVideoSurface(); MenuReturnStatus status = ShowMenu(content_path, state_allowed() ? save_template_path : NULL, screen, kMenuEventKeyDown); + char disc_path[256]; + ChangeDisc_t ChangeDisc = (ChangeDisc_t)dlsym(mmenu, "ChangeDisc"); - if (status==kStatusExitGame) { + if (status == kStatusExitGame) { should_quit = 1; plat_video_menu_leave(); - } - else if (status==kStatusOpenMenu) { + } else if (status == kStatusChangeDisc && ChangeDisc(disc_path)) { + disc_replace_index(0, disc_path); + } else if (status == kStatusOpenMenu) { menu_loop(); - } - else if (status>=kStatusLoadSlot) { + } else if (status >= kStatusLoadSlot) { state_slot = status - kStatusLoadSlot; state_read(); - } - else if (status>=kStatusSaveSlot) { + } else if (status >= kStatusSaveSlot) { state_slot = status - kStatusSaveSlot; state_write(); } diff --git a/menu.c b/menu.c index 2846200..f314e43 100644 --- a/menu.c +++ b/menu.c @@ -427,9 +427,6 @@ void menu_loop(void) me_enable(e_menu_main, MA_MAIN_SAVE_STATE, mmenu == NULL); me_enable(e_menu_main, MA_MAIN_LOAD_STATE, mmenu == NULL); } - if (needs_disc_ctrl) { - me_enable(e_menu_main, MA_MAIN_DISC_CTRL, mmenu == NULL); - } #endif me_loop_d(e_menu_main, &sel, NULL, NULL); -- cgit v1.2.3