From: notaz Date: Mon, 3 Aug 2009 22:43:39 +0000 (+0000) Subject: improve cd change handling X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b8796e2a8aae2d41aeec2be4d385b4905c8c19b;p=libpicofe.git improve cd change handling git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@731 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/common/emu.c b/common/emu.c index cee9f2d..7de2aa9 100644 --- a/common/emu.c +++ b/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/common/emu.h b/common/emu.h index ecd9ba1..192d268 100644 --- a/common/emu.h +++ b/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/common/menu.c b/common/menu.c index 5fc2a57..44fb5c8 100644 --- a/common/menu.c +++ b/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)