From 4bd14be5f293465c673a7fd81e3fce76890b0a73 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 20 Nov 2019 17:24:25 +0800 Subject: [PATCH] megacd: some improvements in navigation. Remove old CD while mounting new one. --- menu.cpp | 35 +++++++++++++++++++++++++++++++---- support/megacd/megacd.cpp | 9 ++++----- user_io.h | 4 ++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/menu.cpp b/menu.cpp index c132190..492bbb3 100644 --- a/menu.cpp +++ b/menu.cpp @@ -1534,7 +1534,16 @@ void HandleUI(void) if (p[1] >= '0' && p[1] <= '3') drive_num = p[1] - '0'; substrcpy(ext, p, 1); while (strlen(ext) % 3) strcat(ext, " "); - SelectFile(ext, SCANO_DIR | SCANO_UMOUNT, MENU_8BIT_MAIN_IMAGE_SELECTED, MENU_8BIT_MAIN1); + if (is_megacd_core()) + { + int len = strlen(SelectedPath); + if (len > 4 && !strcasecmp(SelectedPath + len - 4, ".cue")) + { + char *p = strrchr(SelectedPath, '/'); + if (p) *p = 0; + } + } + SelectFile(ext, SCANO_DIR | SCANO_UMOUNT | (is_megacd_core() ? SCANO_NOENTER : 0), MENU_8BIT_MAIN_IMAGE_SELECTED, MENU_8BIT_MAIN1); } else if ((p[0] == 'O') || (p[0] == 'o')) { @@ -3265,9 +3274,27 @@ void HandleUI(void) if (select) { - if (flist_SelectedItem()->de.d_type == DT_DIR) + static char name[256]; + char type = flist_SelectedItem()->de.d_type; + memcpy(name, flist_SelectedItem()->de.d_name, sizeof(name)); + + if (is_megacd_core() && type == DT_DIR && strcmp(flist_SelectedItem()->de.d_name, "..")) { - changeDir(flist_SelectedItem()->de.d_name); + int len = strlen(SelectedPath); + strcat(SelectedPath, "/"); + strcat(SelectedPath, name); + int num = ScanDirectory(SelectedPath, SCANF_INIT, fs_pFileExt, 0); + if (!num) SelectedPath[len] = 0; + else + { + type = flist_SelectedItem()->de.d_type; + memcpy(name, flist_SelectedItem()->de.d_name, sizeof(name)); + } + } + + if (type == DT_DIR) + { + changeDir(name); menustate = MENU_FILE_SELECT1; } else @@ -3281,7 +3308,7 @@ void HandleUI(void) strcat(SelectedPath, "/"); } - strcat(SelectedPath, flist_SelectedItem()->de.d_name); + strcat(SelectedPath, name); menustate = fs_MenuSelect; } } diff --git a/support/megacd/megacd.cpp b/support/megacd/megacd.cpp index 201a607..d8448c9 100644 --- a/support/megacd/megacd.cpp +++ b/support/megacd/megacd.cpp @@ -130,6 +130,10 @@ void mcd_set_image(int num, const char *filename) { (void)num; + cdd.Unload(); + unloaded = 1; + cdd.status = CD_STAT_OPEN; + if (*filename) { if (cdd.Load(filename) > 0) { @@ -142,11 +146,6 @@ void mcd_set_image(int num, const char *filename) cdd.status = CD_STAT_NO_DISC; } } - else { - cdd.Unload(); - unloaded = 1; - cdd.status = CD_STAT_OPEN; - } } diff --git a/user_io.h b/user_io.h index 73f3265..fecab1b 100644 --- a/user_io.h +++ b/user_io.h @@ -73,7 +73,7 @@ #define UIO_SET_GAMMA 0x32 // Enable/disable Gamma correction #define UIO_SET_GAMCURV 0x33 // Set Gamma curve #define UIO_CD_GET 0x34 -#define UIO_CD_SET 0x35 +#define UIO_CD_SET 0x35 // codes as used by 8bit for file loading from OSD #define UIO_FILE_TX 0x53 @@ -216,7 +216,7 @@ char *user_io_make_filepath(const char *path, const char *filename); char *user_io_get_core_name(); char *user_io_get_core_path(); const char *user_io_get_core_name_ex(); -char is_megacd_core(); +char is_megacd_core(); char has_menu(); const char *get_image_name(int i);