libretro: fix arcade flash files path. ui: stop spamming dc_stop

This commit is contained in:
Flyinghead 2021-07-20 10:06:44 +02:00
parent edc6474f27
commit 4a77f847b4
8 changed files with 36 additions and 35 deletions

View File

@ -37,11 +37,14 @@ bool MemChip::Load(const std::string& file)
void MemChip::Save(const std::string& file)
{
FILE *f = nowide::fopen(file.c_str(), "wb");
if (f)
if (f == nullptr)
{
std::fwrite(data + write_protect_size, 1, size - write_protect_size, f);
std::fclose(f);
ERROR_LOG(FLASHROM, "Cannot save flash/nvmem to file '%s'", file.c_str());
return;
}
if (std::fwrite(data + write_protect_size, 1, size - write_protect_size, f) != size - write_protect_size)
ERROR_LOG(FLASHROM, "Failed or truncated write to flash file '%s'", file.c_str());
std::fclose(f);
}
bool MemChip::Load(const std::string &prefix, const std::string &names_ro, const std::string &title)

View File

@ -16,6 +16,7 @@
#include "reios/reios.h"
#include "hw/bba/bba.h"
#include "cfg/option.h"
#include "oslib/oslib.h"
MemChip *sys_rom;
MemChip *sys_nvmem;
@ -172,12 +173,12 @@ static bool nvmem_load()
if (settings.platform.system == DC_PLATFORM_DREAMCAST)
rc = sys_nvmem->Load(getRomPrefix(), "%nvmem.bin", "nvram");
else
rc = sys_nvmem->Load(get_game_save_prefix() + ".nvmem");
rc = sys_nvmem->Load(hostfs::getArcadeFlashPath() + ".nvmem");
if (!rc)
INFO_LOG(FLASHROM, "flash/nvmem is missing, will create new file...");
if (settings.platform.system == DC_PLATFORM_ATOMISWAVE)
sys_rom->Load(get_game_save_prefix() + ".nvmem2");
sys_rom->Load(hostfs::getArcadeFlashPath() + ".nvmem2");
return true;
}
@ -201,9 +202,9 @@ void SaveRomFiles()
if (settings.platform.system == DC_PLATFORM_DREAMCAST)
sys_nvmem->Save(getRomPrefix(), "nvmem.bin", "nvmem");
else
sys_nvmem->Save(get_game_save_prefix() + ".nvmem");
sys_nvmem->Save(hostfs::getArcadeFlashPath() + ".nvmem");
if (settings.platform.system == DC_PLATFORM_ATOMISWAVE)
sys_rom->Save(get_game_save_prefix() + ".nvmem2");
sys_rom->Save(hostfs::getArcadeFlashPath() + ".nvmem2");
}
bool LoadHle()

View File

@ -34,7 +34,7 @@ void load_naomi_eeprom()
if (!EEPROM_loaded)
{
EEPROM_loaded = true;
std::string eeprom_file = hostfs::getJvsEepromPath();
std::string eeprom_file = hostfs::getArcadeFlashPath() + ".eeprom";
FILE* f = nowide::fopen(eeprom_file.c_str(), "rb");
if (f)
{
@ -974,7 +974,7 @@ void maple_naomi_jamma::handle_86_subcommand()
//printState(Command,buffer_in,buffer_in_len);
memcpy(EEPROM + address, dma_buffer_in + 4, size);
std::string eeprom_file = hostfs::getJvsEepromPath();
std::string eeprom_file = hostfs::getArcadeFlashPath() + ".eeprom";
FILE* f = nowide::fopen(eeprom_file.c_str(), "wb");
if (f)
{

View File

@ -34,10 +34,10 @@ std::string getVmuPath(const std::string& port)
return apath;
}
std::string getJvsEepromPath()
std::string getArcadeFlashPath()
{
std::string nvmemSuffix = cfgLoadStr("net", "nvmem", "");
return get_game_save_prefix() + nvmemSuffix + ".eeprom";
return get_game_save_prefix() + nvmemSuffix;
}
std::string findFlash(const std::string& prefix, const std::string& names)

View File

@ -26,7 +26,8 @@ u32 static INLINE bitscanrev(u32 v)
namespace hostfs
{
std::string getVmuPath(const std::string& port);
std::string getJvsEepromPath();
std::string getArcadeFlashPath();
std::string findFlash(const std::string& prefix, const std::string& names);
std::string getFlashSavePath(const std::string& prefix, const std::string& name);

View File

@ -434,7 +434,8 @@ static void gui_start_game(const std::string& path)
static void gui_display_commands()
{
dc_stop();
if (dc_is_running())
dc_stop();
display_vmus();

View File

@ -102,10 +102,7 @@ constexpr char slash = path_default_slash_c();
#include "libretro_core_options.h"
#include "vmu_xhair.h"
static char save_dir[PATH_MAX];
char eeprom_file[PATH_MAX];
char nvmem_file[PATH_MAX]; // TODO
char nvmem_file2[PATH_MAX]; // AtomisWave
std::string arcadeFlashPath;
static bool boot_to_bios;
static bool devices_need_refresh = false;
@ -1634,26 +1631,24 @@ bool retro_load_game(const struct retro_game_info *game)
if (settings.platform.system != DC_PLATFORM_DREAMCAST)
{
if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) {
char g_save_dir[PATH_MAX];
strncpy(g_save_dir, dir, sizeof(g_save_dir));
if(strcmp(g_save_dir,g_roms_dir) != 0)
snprintf(save_dir, sizeof(save_dir), "%s%creicast%c", g_save_dir, slash, slash);
else
strncpy(save_dir, g_roms_dir, sizeof(save_dir));
if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir)
&& dir != nullptr
&& strcmp(dir, g_roms_dir) != 0)
{
static char save_dir[PATH_MAX];
snprintf(save_dir, sizeof(save_dir), "%s%creicast%c", dir, slash, slash);
struct stat buf;
if (stat(save_dir, &buf) < 0)
{
DEBUG_LOG(BOOT, "Creating dir: %s", save_dir);
path_mkdir(save_dir);
}
arcadeFlashPath = std::string(save_dir) + g_base_name;
} else {
strncpy(save_dir, g_roms_dir, sizeof(save_dir));
arcadeFlashPath = std::string(g_roms_dir) + g_base_name;
}
INFO_LOG(BOOT, "Setting save dir to %s", save_dir);
snprintf(eeprom_file, sizeof(eeprom_file), "%s%s.eeprom", save_dir, g_base_name);
snprintf(nvmem_file, sizeof(nvmem_file), "%s%s.nvmem", save_dir, g_base_name);
snprintf(nvmem_file2, sizeof(nvmem_file2), "%s%s.nvmem2", save_dir, g_base_name);
INFO_LOG(BOOT, "Setting flash base path to %s", arcadeFlashPath.c_str());
}
config::ScreenStretching = 100;
@ -1683,15 +1678,15 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
void retro_unload_game()
{
INFO_LOG(COMMON, "Flycast unloading game");
frontend_clear_thread_waits_cb(1, nullptr);
dc_stop();
frontend_clear_thread_waits_cb(0, nullptr);
free(game_data);
game_data = nullptr;
disk_paths.clear();
disk_labels.clear();
blankVmus();
frontend_clear_thread_waits_cb(1, nullptr);
dc_stop();
frontend_clear_thread_waits_cb(0, nullptr);
dc_term_emulator();
}

View File

@ -22,11 +22,11 @@
const char *retro_get_system_directory();
extern char eeprom_file[PATH_MAX];
extern char game_dir_no_slash[1024];
extern char vmu_dir_no_slash[PATH_MAX];
extern char content_name[PATH_MAX];
extern unsigned per_content_vmus;
extern std::string arcadeFlashPath;
namespace hostfs
{
@ -48,9 +48,9 @@ std::string getVmuPath(const std::string& port)
}
}
std::string getJvsEepromPath()
std::string getArcadeFlashPath()
{
return eeprom_file;
return arcadeFlashPath;
}
std::string findFlash(const std::string& prefix, const std::string& names_ro)