From 652c52635067b47a0d6960c6600a0056cdc8906d Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 16 May 2020 01:06:25 +0800 Subject: [PATCH] Optimized home dir detection. --- menu.cpp | 6 +++--- support/sharpmz/sharpmz.cpp | 38 ++++++++++++++++++------------------- support/st/st_tos.cpp | 2 +- user_io.cpp | 31 ++++++++++++++++++------------ user_io.h | 2 +- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/menu.cpp b/menu.cpp index 86aac4e..7d1e790 100644 --- a/menu.cpp +++ b/menu.cpp @@ -338,7 +338,7 @@ static void SelectFile(const char* path, const char* pFileExt, unsigned char Opt } else { - const char *home = HomeDir((is_pce() && !strncasecmp(pFileExt, "CUE", 3)) ? PCECD_DIR : NULL); + const char *home = user_io_get_core_path((is_pce() && !strncasecmp(pFileExt, "CUE", 3)) ? PCECD_DIR : NULL, 1); home_dir = strrchr(home, '/'); if (home_dir) home_dir++; @@ -1193,7 +1193,7 @@ void HandleUI(void) /******************************************************************/ case MENU_ARCHIE_MAIN1: - OsdSetTitle(user_io_get_core_name(), OSD_ARROW_RIGHT | OSD_ARROW_LEFT); + OsdSetTitle(CoreName, OSD_ARROW_RIGHT | OSD_ARROW_LEFT); m = 0; menumask = 0x3ff; @@ -1365,7 +1365,7 @@ void HandleUI(void) menumask = 0; p = user_io_get_core_name(); if (!p[0]) OsdCoreNameSet("8BIT"); - else OsdCoreNameSet(p); + else OsdCoreNameSet(p); if(!page) OsdSetTitle(OsdCoreNameGet()); else OsdSetTitle(title); diff --git a/support/sharpmz/sharpmz.cpp b/support/sharpmz/sharpmz.cpp index 6b08c57..36d4d44 100644 --- a/support/sharpmz/sharpmz.cpp +++ b/support/sharpmz/sharpmz.cpp @@ -7,8 +7,8 @@ // This module is an extension to the MiSTer control program. It adds extensions to // the menu system and additional I/O control specific to the Sharp MZ series // emulation. -// -// Credits: +// +// Credits: // Copyright: (c) 2018 Philip Smart // // History: July 2018 - Initial module written. @@ -144,7 +144,7 @@ int sharpmz_reset_config(short setStatus) // Set the configuration registers to a known defualt. config.system_reg[REGISTER_MODEL] = 0x03; // MZ-80A config.system_reg[REGISTER_DISPLAY] = 0x00; // Mono 40x25 - config.system_reg[REGISTER_DISPLAY2] = 0x78 | 0x00; // GRAM base addr | VGA Mode. + config.system_reg[REGISTER_DISPLAY2] = 0x78 | 0x00; // GRAM base addr | VGA Mode. config.system_reg[REGISTER_DISPLAY3] = 0x00; // Status screen buffer. config.system_reg[REGISTER_CPU] = 0x00; // CPU speed. config.system_reg[REGISTER_AUDIO] = 0x00; // Audio - sound output. @@ -435,7 +435,7 @@ void sharpmz_poll(void) { sharpmz_save_tape_from_cmt((const char *)0); } - + // Reset the timer. time = GetTimer(0); } @@ -479,7 +479,7 @@ char *sharpmz_pop_filename(void) tapeQueue.queue[i-1] = tapeQueue.queue[i]; } tapeQueue.queue[MAX_TAPE_QUEUE-1] = NULL; - + } // Return filename. @@ -583,7 +583,7 @@ void sharpmz_clear_filelist(void) sharpmz_debugf("Cleared Tape Queue."); } -// Return fast tape status bits. Bit 0,1 of system_reg, 0 = Off, 1 = 2x, 2 = 4x, 3 = 16x +// Return fast tape status bits. Bit 0,1 of system_reg, 0 = Off, 1 = 2x, 2 = 4x, 3 = 16x // int sharpmz_get_fasttape(void) { @@ -656,7 +656,7 @@ void sharpmz_set_fasttape(short mode, short setStatus) } -// Return Ascii Mapping of header filename bits. Bit 0,1 of system_reg, 0 = Off, 1 = FROMMZ, 2 = TOMZ, 3 = BOTH +// Return Ascii Mapping of header filename bits. Bit 0,1 of system_reg, 0 = Off, 1 = FROMMZ, 2 = TOMZ, 3 = BOTH // int sharpmz_get_cmt_ascii_mapping(void) { @@ -899,7 +899,7 @@ const char *sharpmz_get_gram_base_addr_string(void) void sharpmz_set_gram_base_addr(short addr, short setStatus) { config.system_reg[REGISTER_DISPLAY2] &= ~(0x1f << 3); - config.system_reg[REGISTER_DISPLAY2] |= addr << 3; + config.system_reg[REGISTER_DISPLAY2] |= addr << 3; if(setStatus) sharpmz_set_config_register(REGISTER_DISPLAY, config.system_reg[REGISTER_DISPLAY]); @@ -2216,7 +2216,7 @@ short sharpmz_load_tape_to_ram(const char *tapeFile, unsigned char dstCMT) sharpmz_debugf("Register (%02x) = %02x", i, sharpmz_read_config_register(i)); } #endif - + // Success. // return(0); @@ -2402,7 +2402,7 @@ void sharpmz_ui(int idleState, int idle2State, int system subItem = 0; *menumask = 0; - OsdSetTitle(user_io_get_core_name(), 0); + OsdSetTitle(CoreName, 0); OsdWrite(menuItem++, " Main Menu", 0, 0); OsdWrite(menuItem++, "", 0, 0); @@ -2529,7 +2529,7 @@ void sharpmz_ui(int idleState, int idle2State, int system if(right) select = true; break; #endif - + case 4: // System *menustate = systemState; #ifdef __SHARPMZ_DEBUG__ @@ -2541,7 +2541,7 @@ void sharpmz_ui(int idleState, int idle2State, int system if(right) select = true; break; - case 5: // Boot Reset + case 5: // Boot Reset if(select) { sharpmz_set_boot_reset(); @@ -2643,7 +2643,7 @@ void sharpmz_ui(int idleState, int idle2State, int system OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); *menumask = (*menumask << 1) | 1; } - + for (; menuItem < 15; menuItem++) { OsdWrite(menuItem, "", 0, 0); @@ -2804,7 +2804,7 @@ void sharpmz_ui(int idleState, int idle2State, int system *menumask = 0x01; // Exit. *parentstate = *menustate; menuItem = 0; - + // Limit number of items in queue, makes no sense to have too many and we run out of display space. // if(tapeQueue.elements < MAX_TAPE_QUEUE && !fail) @@ -3341,7 +3341,7 @@ void sharpmz_ui(int idleState, int idle2State, int system //strcat(sBuf, sharpmz_get_scandoubler_fx_string()); //OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); //*menumask = (*menumask << 1) | 1; - + for (; menuItem < 15; menuItem++) { OsdWrite(menuItem, "", 0, 0); @@ -3445,7 +3445,7 @@ void sharpmz_ui(int idleState, int idle2State, int system { OsdSetTitle("Memory Dump", OSD_ARROW_LEFT); } - + OsdWrite(menuItem++, "", 0, 0); strcpy(sBuf, " Select Memory Bank: "); @@ -3490,7 +3490,7 @@ void sharpmz_ui(int idleState, int idle2State, int system strcat(sBuf, sharpmz_get_debug_leds_string()); OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); *menumask = (*menumask << 1) | 1; - + // Display the LED menu only when enabled. // if(sharpmz_get_debug_leds()) @@ -3499,12 +3499,12 @@ void sharpmz_ui(int idleState, int idle2State, int system strcat(sBuf, sharpmz_get_debug_leds_smpfreq_string()); OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); *menumask = (*menumask << 1) | 1; - + strcpy(sBuf, " Signal Block: "); strcat(sBuf, sharpmz_get_debug_leds_bank_string()); OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); *menumask = (*menumask << 1) | 1; - + strcpy(sBuf, " Bank: "); strcat(sBuf, sharpmz_get_debug_leds_subbank_string()); OsdWrite(menuItem++, sBuf, *menusub == subItem++, 0); diff --git a/support/st/st_tos.cpp b/support/st/st_tos.cpp index 636157b..0bdab7f 100644 --- a/support/st/st_tos.cpp +++ b/support/st/st_tos.cpp @@ -570,7 +570,7 @@ void tos_config_load(int slot) // set default values config.system_ctrl = TOS_MEMCONFIG_1M | TOS_CONTROL_VIDEO_COLOR | TOS_CONTROL_BORDER; - strcpy(config.tos_img, user_io_get_core_path()); + strcpy(config.tos_img, HomeDir()); strcat(config.tos_img, "/TOS.IMG"); // try to load config diff --git a/user_io.cpp b/user_io.cpp index 0a97682..f96da08 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -156,14 +156,19 @@ char *user_io_get_core_name() return core_name; } -char *user_io_get_core_path(const char *suffix) +char *user_io_get_core_path(const char *suffix, int recheck) { - static char tmp[1024]; + static char old_name[256] = {}; + static char tmp[1024] = {}; - if (suffix) strcpy(tmp, suffix); - else strcpy(tmp, !strcasecmp(core_name, "minimig") ? "Amiga" : core_name); + if (!suffix) suffix = (!strcasecmp(core_name, "minimig")) ? "Amiga" : core_name; + if (recheck || strcmp(old_name, suffix) || !tmp[0]) + { + strcpy(old_name, suffix); + strcpy(tmp, suffix); + prefixGameDir(tmp, sizeof(tmp)); + } - prefixGameDir(tmp, sizeof(tmp)); return tmp; } @@ -845,6 +850,8 @@ void user_io_init(const char *path, const char *xml) } else { + const char *home = HomeDir(); + if (!strlen(path) || !user_io_file_tx(path, 0, 0, 0, 1)) { if (!is_cpc()) @@ -852,13 +859,13 @@ void user_io_init(const char *path, const char *xml) // check for multipart rom for (char i = 0; i < 4; i++) { - sprintf(mainpath, "%s/boot%d.rom", user_io_get_core_path(), i); + sprintf(mainpath, "%s/boot%d.rom", home, i); user_io_file_tx(mainpath, i << 6); } } // legacy style of rom - sprintf(mainpath, "%s/boot.rom", user_io_get_core_path()); + sprintf(mainpath, "%s/boot.rom", home); if (!user_io_file_tx(mainpath)) { strcpy(name + strlen(name) - 3, "ROM"); @@ -882,13 +889,13 @@ void user_io_init(const char *path, const char *xml) for (int m = 0; m < 3; m++) { const char *model = !m ? "" : (m == 1) ? "0" : "1"; - sprintf(mainpath, "%s/boot%s.eZZ", user_io_get_core_path(), model); + sprintf(mainpath, "%s/boot%s.eZZ", home, model); user_io_file_tx(mainpath, 0x40 * (m + 1), 0, 1); - sprintf(mainpath, "%s/boot%s.eZ0", user_io_get_core_path(), model); + sprintf(mainpath, "%s/boot%s.eZ0", home, model); user_io_file_tx(mainpath, 0x40 * (m + 1), 0, 1); for (int i = 0; i < 256; i++) { - sprintf(mainpath, "%s/boot%s.e%02X", user_io_get_core_path(), model, i); + sprintf(mainpath, "%s/boot%s.e%02X", home, model, i); user_io_file_tx(mainpath, 0x40 * (m + 1), 0, 1); } } @@ -897,7 +904,7 @@ void user_io_init(const char *path, const char *xml) // check if vhd present for (char i = 0; i < 4; i++) { - sprintf(mainpath, "%s/boot%d.vhd", user_io_get_core_path(), i); + sprintf(mainpath, "%s/boot%d.vhd", home, i); if (FileExists(mainpath)) { user_io_set_index(i << 6); @@ -905,7 +912,7 @@ void user_io_init(const char *path, const char *xml) } } - sprintf(mainpath, "%s/boot.vhd", user_io_get_core_path()); + sprintf(mainpath, "%s/boot.vhd", home); if (FileExists(mainpath)) { user_io_set_index(0); diff --git a/user_io.h b/user_io.h index b0c2934..04c13db 100644 --- a/user_io.h +++ b/user_io.h @@ -201,7 +201,7 @@ uint32_t user_io_get_file_crc(); int user_io_file_mount(const char *name, unsigned char index = 0, char pre = 0); 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 *suffix = NULL); +char *user_io_get_core_path(const char *suffix = NULL, int recheck = 0); const char *user_io_get_core_name_ex(); void user_io_name_override(const char* name); char has_menu();