embed romlist.bin

This commit is contained in:
Arisotura 2020-05-30 00:28:21 +02:00
parent 88823f66cb
commit c45068da0e
6 changed files with 6829 additions and 69 deletions

View File

@ -37,7 +37,3 @@ add_subdirectory(src)
if (BUILD_QT_SDL)
add_subdirectory(src/frontend/qt_sdl)
endif()
configure_file(
${CMAKE_SOURCE_DIR}/romlist.bin
${CMAKE_BINARY_DIR}/romlist.bin COPYONLY)

Binary file not shown.

View File

@ -27,6 +27,7 @@ add_library(core STATIC
NDSCart.cpp
OpenGLSupport.cpp
Platform.h
ROMList.h
RTC.cpp
Savestate.cpp
SPI.cpp

View File

@ -23,6 +23,7 @@
#include "ARM.h"
#include "CRC32.h"
#include "Platform.h"
#include "ROMList.h"
namespace NDSCart_SRAM
@ -808,34 +809,21 @@ void ApplyDLDIPatch()
}
bool ReadROMParams(u32 gamecode, u32* params)
bool ReadROMParams(u32 gamecode, ROMListEntry* params)
{
// format for romlist.bin:
// [gamecode] [ROM size] [save type] [reserved]
// list must be sorted by gamecode
FILE* f = Platform::OpenDataFile("romlist.bin");
if (!f) return false;
fseek(f, 0, SEEK_END);
u32 len = (u32)ftell(f);
u32 maxlen = len;
len >>= 4; // 16 bytes per entry
u32 len = sizeof(ROMList) / sizeof(ROMListEntry);
u32 offset = 0;
u32 chk_size = len >> 1;
for (;;)
{
u32 key = 0;
fseek(f, offset + (chk_size << 4), SEEK_SET);
fread(&key, 4, 1, f);
printf("chk_size=%d, key=%08X, wanted=%08X, offset=%08X\n", chk_size, key, gamecode, offset);
ROMListEntry* curentry = &ROMList[offset + chk_size];
key = curentry->GameCode;
if (key == gamecode)
{
fread(params, 4, 3, f);
fclose(f);
memcpy(params, curentry, sizeof(ROMListEntry));
return true;
}
else
@ -843,22 +831,20 @@ bool ReadROMParams(u32 gamecode, u32* params)
if (key < gamecode)
{
if (chk_size == 0)
offset += 0x10;
offset++;
else
offset += (chk_size << 4);
offset += chk_size;
}
else if (chk_size == 0)
{
fclose(f);
return false;
}
chk_size >>= 1;
}
if (offset >= maxlen)
if (offset >= len)
{
fclose(f);
return false;
}
}
@ -936,22 +922,23 @@ bool LoadROM(const char* path, const char* sram, bool direct)
CartCRC = CRC32(CartROM, CartROMSize);
printf("ROM CRC32: %08X\n", CartCRC);
u32 romparams[3];
if (!ReadROMParams(gamecode, romparams))
ROMListEntry romparams;
if (!ReadROMParams(gamecode, &romparams))
{
// set defaults
printf("ROM entry not found\n");
romparams[0] = CartROMSize;
romparams.GameCode = gamecode;
romparams.ROMSize = CartROMSize;
if (*(u32*)&CartROM[0x20] < 0x4000)
romparams[1] = 0; // no saveRAM for homebrew
romparams.SaveMemType = 0; // no saveRAM for homebrew
else
romparams[1] = 2; // assume EEPROM 64k (TODO FIXME)
romparams.SaveMemType = 2; // assume EEPROM 64k (TODO FIXME)
}
else
printf("ROM entry: %08X %08X %08X\n", romparams[0], romparams[1], romparams[2]);
printf("ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType);
if (romparams[0] != len) printf("!! bad ROM size %d (expected %d) rounded to %d\n", len, romparams[0], CartROMSize);
if (romparams.ROMSize != len) printf("!! bad ROM size %d (expected %d) rounded to %d\n", len, romparams.ROMSize, CartROMSize);
// generate a ROM ID
// note: most games don't check the actual value
@ -963,7 +950,7 @@ bool LoadROM(const char* path, const char* sram, bool direct)
else
CartID |= (0x100 - (CartROMSize >> 28)) << 8;
if (romparams[1] == 8)
if (romparams.SaveMemType == 8)
CartID |= 0x08000000; // NAND flag
printf("Cart ID: %08X\n", CartID);
@ -1018,7 +1005,7 @@ bool LoadROM(const char* path, const char* sram, bool direct)
// save
printf("Save file: %s\n", sram);
NDSCart_SRAM::LoadSave(sram, romparams[1]);
NDSCart_SRAM::LoadSave(sram, romparams.SaveMemType);
return true;
}

6809
src/ROMList.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1900,39 +1900,6 @@ int main(int argc, char** argv)
SANITIZE(Config::ScreenSizing, 0, 3);
#undef SANITIZE
// TODO: this should be checked before running anything
#if 0
{
const char* romlist_missing = "Save memory type detection will not work correctly.\n\n"
"You should use the latest version of romlist.bin (provided in melonDS release packages).";
#if !defined(UNIX_PORTABLE) && !defined(__WIN32__)
std::string missingstr = std::string(romlist_missing) +
"\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise "
"melonDS will search for it in the current working directory.";
const char* romlist_missing_text = missingstr.c_str();
#else
const char* romlist_missing_text = romlist_missing;
#endif
FILE* f = Platform::OpenDataFile("romlist.bin");
if (f)
{
u32 data;
fread(&data, 4, 1, f);
fclose(f);
if ((data >> 24) == 0) // old CRC-based list
{
uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text);
}
}
else
{
uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text);
}
}
#endif
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);