naomi,aw: embed default flash for some games

Needed to configure network on first run.
This commit is contained in:
Flyinghead 2023-03-27 16:57:48 +02:00
parent fb4229c4ae
commit d76982bbeb
17 changed files with 126 additions and 6 deletions

View File

@ -922,6 +922,19 @@ target_sources(${PROJECT_NAME} PRIVATE
core/hw/sh4/sh4_sched.h
core/hw/sh4/storeq.cpp)
cmrc_add_resources(flycast-resources
WHENCE resources
resources/flash/gunsur2.nvmem.zip
resources/flash/otrigger.nvmem.zip
resources/flash/wldkicks.nvmem.zip # free play
resources/flash/wldkicksj.nvmem.zip # free play
resources/flash/wldkicksu.nvmem.zip # free play
resources/flash/f355.nvmem.zip # printer on
resources/flash/f355twin.nvmem.zip
resources/flash/f355twn2.nvmem.zip
resources/flash/dirtypig.nvmem.zip # 4 players
resources/flash/dirtypig.nvmem2.zip)
cmrc_add_resources(flycast-resources
fonts/printer_ascii8x16.bin
fonts/printer_ascii12x24.bin

View File

@ -88,3 +88,23 @@ u32 ZipArchiveFile::Read(void* buffer, u32 length)
{
return zip_fread(zip_file, buffer, length);
}
bool ZipArchive::Open(const void *data, size_t size)
{
zip_error_t error;
zip_source_t *source = zip_source_buffer_create(data, size, 0, &error);
if (source == nullptr)
return false;
zip = zip_open_from_source(source, 0, NULL);
if (zip == nullptr)
zip_source_free(source);
return zip != nullptr;
}
ArchiveFile *ZipArchive::OpenFirstFile()
{
zip_file *zipFile = zip_fopen_index(zip, 0, 0);
if (zipFile == nullptr)
return nullptr;
return new ZipArchiveFile(zipFile);
}

View File

@ -32,6 +32,9 @@ public:
ArchiveFile* OpenFile(const char* name) override;
ArchiveFile* OpenFileByCrc(u32 crc) override;
bool Open(const void *data, size_t size);
ArchiveFile *OpenFirstFile();
private:
bool Open(const char* path) override;

View File

@ -33,6 +33,12 @@ bool MemChip::Load(const std::string& file)
return false;
}
void MemChip::Load(const u8 *data, size_t size)
{
verify(size == this->size - write_protect_size);
memcpy(this->data + write_protect_size, data, this->size - write_protect_size);
}
void WritableChip::Save(const std::string& file)
{
FILE *f = nowide::fopen(file.c_str(), "wb");

View File

@ -64,6 +64,7 @@ public:
virtual bool Reload() { return true; }
bool Load(const std::string &prefix, const std::string &names_ro,
const std::string &title);
void Load(const u8 *data, size_t size);
void digest(u8 md5Digest[16]);
virtual void Reset() {}
@ -82,6 +83,8 @@ public:
bool Reload() override
{
if (load_filename.empty())
return false;
return Load(this->load_filename);
}
void Save(const std::string& file);

View File

@ -22,6 +22,9 @@
#include "hw/aica/aica_if.h"
#include "reios/reios.h"
#include "oslib/oslib.h"
#include "archive/ZipArchive.h"
#include <cmrc/cmrc.hpp>
CMRC_DECLARE(flycast);
extern bool bios_loaded;
@ -193,13 +196,81 @@ static void fixUpDCFlash()
}
}
static std::unique_ptr<u8[]> loadFlashResource(const std::string& name, size_t& size)
{
try {
cmrc::embedded_filesystem fs = cmrc::flycast::get_filesystem();
std::string fname = "flash/" + name + ".zip";
if (fs.exists(fname))
{
cmrc::file zipFile = fs.open(fname);
ZipArchive zip;
if (zip.Open(zipFile.cbegin(), zipFile.size()))
{
std::unique_ptr<ArchiveFile> flashFile;
flashFile.reset(zip.OpenFirstFile());
if (flashFile != nullptr)
{
std::unique_ptr<u8[]> buffer = std::make_unique<u8[]>(size);
size = flashFile->Read(buffer.get(), size);
return buffer;
}
}
}
else
{
cmrc::file flashFile = fs.open("flash/" + name);
size = flashFile.size();
std::unique_ptr<u8[]> buffer = std::make_unique<u8[]>(size);
return buffer;
}
DEBUG_LOG(FLASHROM, "Default flash not found");
} catch (const std::system_error& e) {
DEBUG_LOG(FLASHROM, "Default flash not found: %s", e.what());
}
size = 0;
return nullptr;
}
static void loadDefaultAWBiosFlash()
{
std::string flashName = get_game_basename() + ".nvmem2";
size_t lastindex = get_last_slash_pos(flashName);
if (lastindex != std::string::npos)
flashName = flashName.substr(lastindex + 1);
size_t size = settings.platform.bios_size / 2;
std::unique_ptr<u8[]> buffer = loadFlashResource(flashName, size);
if (buffer)
sys_rom->Load(buffer.get(), size);
}
static bool loadFlash()
{
bool rc = true;
if (settings.platform.isConsole())
rc = sys_nvmem->Load(getRomPrefix(), "%nvmem.bin", "nvram");
else if (!settings.naomi.slave)
{
rc = sys_nvmem->Load(hostfs::getArcadeFlashPath() + ".nvmem");
if (!rc)
{
std::string flashName = get_game_basename() + ".nvmem";
size_t lastindex = get_last_slash_pos(flashName);
if (lastindex != std::string::npos)
flashName = flashName.substr(lastindex + 1);
size_t size = settings.platform.flash_size;
std::unique_ptr<u8[]> buffer = loadFlashResource(flashName, size);
if (buffer)
{
sys_nvmem->Load(buffer.get(), size);
rc = true;
}
}
}
if (!rc)
INFO_LOG(FLASHROM, "flash/nvmem is missing, will create new file...");
fixUpDCFlash();
@ -208,7 +279,10 @@ static bool loadFlash()
if (settings.platform.isAtomiswave())
{
sys_rom->Load(hostfs::getArcadeFlashPath() + ".nvmem2");
rc = sys_rom->Load(hostfs::getArcadeFlashPath() + ".nvmem2");
// TODO default AW .nvmem2
if (!rc)
loadDefaultAWBiosFlash();
if (config::GGPOEnable)
sys_nvmem->digest(settings.network.md5.nvmem2);
}
@ -281,10 +355,14 @@ u8 *getBiosData()
{
return sys_rom->data;
}
void reloadAWBios()
{
if (settings.platform.isAtomiswave())
sys_rom->Reload();
if (!settings.platform.isAtomiswave())
return;
if (sys_rom->Reload())
return;
loadDefaultAWBiosFlash();
}
void init()

View File

@ -307,7 +307,6 @@ void SetNaomiNetworkConfig(int node)
}
else if (gameId == " BIOHAZARD GUN SURVIVOR2")
{
// FIXME need default flash
write_naomi_flash(0x21c, node == 0 ? 0 : 1); // CPU ID - 1
write_naomi_flash(0x22a, node == -1 ? 0 : 1); // comm link on
}
@ -317,7 +316,6 @@ void SetNaomiNetworkConfig(int node)
}
else if (gameId == "OUTTRIGGER JAPAN")
{
// FIXME need default flash
write_naomi_flash(0x21a, node == -1 ? 0 : 1); // network on
write_naomi_flash(0x21b, node); // node id
}
@ -349,7 +347,6 @@ void SetNaomiNetworkConfig(int node)
}
else if (gameId == "WORLD KICKS")
{
// FIXME need default flash
write_naomi_flash(0x224, node == -1 ? 0 : 1); // network on
write_naomi_flash(0x220, node == 0 ? 0 : 1); // node id
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.