From 35e3031aaab69be3703de3b6ce0cfa64aae5ece8 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 3 Aug 2009 22:43:39 +0000 Subject: [PATCH] improve cd change handling git-svn-id: file:///home/notaz/opt/svn/PicoDrive@731 be3aeb3a-fb24-0410-a615-afba39da0efa --- pico/cd/cd_sys.c | 2 +- pico/pico.h | 2 +- platform/common/emu.c | 27 +++++++++++++++++++++++---- platform/common/emu.h | 2 +- platform/common/menu.c | 13 ++----------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/pico/cd/cd_sys.c b/pico/cd/cd_sys.c index 319f4f1..32a9425 100644 --- a/pico/cd/cd_sys.c +++ b/pico/cd/cd_sys.c @@ -196,7 +196,7 @@ PICO_INTERNAL void Reset_CD(void) } -int Insert_CD(char *cdimg_name, int type) +int Insert_CD(const char *cdimg_name, int type) { int ret = 1; diff --git a/pico/pico.h b/pico/pico.h index fb067b8..c3ada59 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -121,7 +121,7 @@ void PicoCDBufferFree(void); void PicoCDBufferFlush(void); // cd/cd_sys.c -int Insert_CD(char *cdimg_name, int type); +int Insert_CD(const char *cdimg_name, int type); void Stop_CD(void); // releases all resources taken when CD game was started. // Cart.c diff --git a/platform/common/emu.c b/platform/common/emu.c index cee9f2d..7de2aa9 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -80,9 +80,9 @@ static int try_rfn_cut(char *fname) return 0; } -static void get_ext(char *file, char *ext) +static void get_ext(const char *file, char *ext) { - char *p; + const char *p; p = file + strlen(file) - 4; if (p < file) p = file; @@ -177,12 +177,13 @@ static unsigned char id_header[0x100]; /* checks if fname points to valid MegaCD image * if so, checks for suitable BIOS */ -int emu_cd_check(int *pregion, char *fname_in) +static int emu_cd_check(int *pregion, const char *fname_in) { + const char *fname = fname_in; unsigned char buf[32]; pm_file *cd_f; int region = 4; // 1: Japan, 4: US, 8: Europe - char ext[5], *fname = fname_in; + char ext[5]; cue_track_type type = CT_UNKNOWN; cue_data_t *cue_data = NULL; @@ -531,6 +532,24 @@ fail: return 0; } +int emu_swap_cd(const char *fname) +{ + cd_img_type cd_type; + int ret = -1; + + cd_type = emu_cd_check(NULL, fname); + if (cd_type != CIT_NOT_CD) + ret = Insert_CD(fname, cd_type); + if (ret != 0) { + me_update_msg("Load failed, invalid CD image?"); + return 0; + } + + strncpy(rom_fname_loaded, fname, sizeof(rom_fname_loaded)-1); + rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0; + return 1; +} + static void romfname_ext(char *dst, const char *prefix, const char *ext) { char *p; diff --git a/platform/common/emu.h b/platform/common/emu.h index ecd9ba1..192d268 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -102,6 +102,7 @@ void emu_finish(void); void emu_loop(void); int emu_reload_rom(char *rom_fname); +int emu_swap_cd(const char *fname); int emu_save_load_game(int load, int sram); void emu_reset_game(void); @@ -122,7 +123,6 @@ void emu_make_path(char *buff, const char *end, int size); void emu_update_input(void); void emu_get_game_name(char *str150); void emu_set_fastforward(int set_on); -int emu_cd_check(int *pregion, char *fname_in); void emu_status_msg(const char *format, ...); #ifdef __cplusplus diff --git a/platform/common/menu.c b/platform/common/menu.c index 5fc2a57..44fb5c8 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -1968,24 +1968,14 @@ void menu_loop(void) static int mh_tray_load_cd(menu_id id, int keys) { - cd_img_type cd_type; char *ret_name; - int ret = -1; ret_name = romsel_run(); if (ret_name == NULL) return 0; - cd_type = emu_cd_check(NULL, ret_name); - if (cd_type != CIT_NOT_CD) - ret = Insert_CD(ret_name, cd_type); - if (ret != 0) { - me_update_msg("Load failed, invalid CD image?"); - return 0; - } - engineState = PGS_RestartRun; - return 1; + return emu_swap_cd(ret_name); } static int mh_tray_nothing(menu_id id, int keys) @@ -2001,6 +1991,7 @@ static menu_entry e_menu_tray[] = mee_label (""), mee_handler("Load CD image", mh_tray_load_cd), mee_handler("Insert nothing", mh_tray_nothing), + mee_end, }; int menu_loop_tray(void) -- 2.39.2