diff --git a/core/hw/holly/sb_mem.cpp b/core/hw/holly/sb_mem.cpp index 72c906cc2..fa8151bc4 100644 --- a/core/hw/holly/sb_mem.cpp +++ b/core/hw/holly/sb_mem.cpp @@ -39,35 +39,8 @@ static std::string getRomPrefix() } } -static bool nvmemOptional() +static bool nvmem_load(const string& root) { - return settings.platform.system != DC_PLATFORM_DREAMCAST; -} - -bool LoadRomFiles(const string& root) -{ - bool rom_loaded = false; - if (settings.platform.system != DC_PLATFORM_ATOMISWAVE) - { - if (!sys_rom->Load(root, getRomPrefix(), "%boot.bin;%boot.bin.bin;%bios.bin;%bios.bin.bin", "bootrom")) - { - if (settings.platform.system == DC_PLATFORM_DREAMCAST && !settings.bios.UseReios) - { - // Dreamcast absolutely needs a BIOS - msgboxf("Unable to find bios in %s. Exiting...", MBX_ICONERROR, root.c_str()); - return false; - } - } - else - { - bios_loaded = true; - rom_loaded = true; - } - } - else - { - rom_loaded = true; - } bool rc; if (settings.platform.system == DC_PLATFORM_DREAMCAST) rc = sys_nvmem->Load(root, getRomPrefix(), "%nvmem.bin;%flash_wb.bin;%flash.bin;%flash.bin.bin", "nvram"); @@ -75,11 +48,11 @@ bool LoadRomFiles(const string& root) rc = sys_nvmem->Load(get_game_save_prefix() + ".nvmem"); if (!rc) INFO_LOG(FLASHROM, "flash/nvmem is missing, will create new file..."); - + if (settings.platform.system == DC_PLATFORM_DREAMCAST) { static_cast(sys_nvmem)->Validate(); - + // overwrite factory flash settings if (settings.dreamcast.region <= 2) { @@ -96,11 +69,11 @@ bool LoadRomFiles(const string& root) sys_nvmem->data[0x1a004] = '0' + settings.dreamcast.broadcast; sys_nvmem->data[0x1a0a4] = '0' + settings.dreamcast.broadcast; } - + // overwrite user settings struct flash_syscfg_block syscfg; int res = static_cast(sys_nvmem)->ReadBlock(FLASH_PT_USER, FLASH_USER_SYSCFG, &syscfg); - + if (!res) { // write out default settings @@ -116,15 +89,38 @@ bool LoadRomFiles(const string& root) syscfg.time_hi = time >> 16; if (settings.dreamcast.language <= 5) syscfg.lang = settings.dreamcast.language; - + if (static_cast(sys_nvmem)->WriteBlock(FLASH_PT_USER, FLASH_USER_SYSCFG, &syscfg) != 1) WARN_LOG(FLASHROM, "Failed to save time and language to flash RAM"); } - + if (settings.platform.system == DC_PLATFORM_ATOMISWAVE) sys_rom->Load(get_game_save_prefix() + ".nvmem2"); + + return true; +} - return rom_loaded; +bool LoadRomFiles(const string& root) +{ + if (settings.platform.system != DC_PLATFORM_ATOMISWAVE) + { + if (!sys_rom->Load(root, getRomPrefix(), "%boot.bin;%boot.bin.bin;%bios.bin;%bios.bin.bin", "bootrom")) + { + if (settings.platform.system == DC_PLATFORM_DREAMCAST) + { + // Dreamcast absolutely needs a BIOS + msgboxf("Unable to find bios in %s. Exiting...", MBX_ICONERROR, root.c_str()); + return false; + } + } + else + { + bios_loaded = true; + } + } + nvmem_load(root); + + return true; } void SaveRomFiles(const string& root) @@ -137,8 +133,11 @@ void SaveRomFiles(const string& root) sys_rom->Save(get_game_save_prefix() + ".nvmem2"); } -bool HleInit() +bool LoadHle(const string& root) { + if (!nvmem_load(root)) + WARN_LOG(FLASHROM, "No nvmem loaded\n"); + return reios_init(sys_rom->data, sys_nvmem); } diff --git a/core/hw/sh4/sh4_mem.h b/core/hw/sh4/sh4_mem.h index 29271dc10..9fe5886bb 100644 --- a/core/hw/sh4/sh4_mem.h +++ b/core/hw/sh4/sh4_mem.h @@ -100,4 +100,4 @@ u32 GetRamPageFromAddress(u32 RamAddress); bool LoadRomFiles(const string& root); void SaveRomFiles(const string& root); -bool HleInit(); +bool LoadHle(const string& root); diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 706106d00..e884137a6 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -461,21 +461,19 @@ void dc_start_game(const char *path) LoadSettings(false); std::string data_path = get_readonly_data_path(DATA_PATH); - if (!LoadRomFiles(data_path)) + if ((settings.platform.system == DC_PLATFORM_DREAMCAST && settings.bios.UseReios) + || !LoadRomFiles(data_path)) { if (settings.platform.system == DC_PLATFORM_DREAMCAST) { - if (settings.bios.UseReios) - { - if (!HleInit()) - throw ReicastException("Failed to initialize HLE BIOS"); + if (!LoadHle(data_path)) + throw ReicastException("Failed to initialize HLE BIOS"); - NOTICE_LOG(BOOT, "Did not load BIOS, using reios"); - } - else - { - throw ReicastException("Cannot find BIOS files in " + data_path); - } + NOTICE_LOG(BOOT, "Did not load BIOS, using reios"); + } + else + { + throw ReicastException("Cannot find BIOS files in " + data_path); } }