improve cd change handling

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@731 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-08-03 22:43:39 +00:00
parent 2843d00e70
commit 35e3031aaa
5 changed files with 28 additions and 18 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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)