diff options
author | StapleButter <thetotalworm@gmail.com> | 2018-12-11 19:47:03 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2018-12-11 19:47:03 +0100 |
commit | f03828f7b95f18bc4a0b3794a39df1fb9aae1a10 (patch) | |
tree | b8dabbf3c3efa4a5da35c449cb1da108a30a90c5 /src | |
parent | e2f3c293609c7e0c8d7c5b29afe343e1187842fa (diff) |
add code that searches into romlist.bin
Diffstat (limited to 'src')
-rw-r--r-- | src/NDSCart.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 5be1fff..730d320 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -1064,6 +1064,63 @@ void ApplyDLDIPatch() } +bool ReadROMParams(u32* params) +{ + // format for romlist.bin: + // [CRC32] [ROM size] [save type] [reserved] + // list must be sorted by CRC + + FILE* f = fopen("romlist.bin", "rb"); + if (!f) return false; + + fseek(f, 0, SEEK_END); + u32 len = (u32)ftell(f); + u32 maxlen = len; + len >>= 4; // 16 bytes per entry + + u32 offset = 0; + u32 chk_size = len >> 1; + for (;;) + { + u32 crc = 0; + fseek(f, offset + (chk_size << 4), SEEK_SET); + fread(&crc, 4, 1, f); + + printf("chk_size=%d, crc=%08X, wanted=%08X, offset=%08X\n", chk_size, crc, CartCRC, offset); + + if (crc == CartCRC) + { + fread(params, 4, 3, f); + fclose(f); + return true; + } + else + { + if (crc < CartCRC) + { + if (chk_size == 0) + offset += 0x10; + else + offset += (chk_size << 4); + } + else if (chk_size == 0) + { + fclose(f); + return false; + } + + chk_size >>= 1; + } + + if (offset >= maxlen) + { + fclose(f); + return false; + } + } +} + + bool LoadROM(const char* path, const char* sram, bool direct) { // TODO: streaming mode? for really big ROMs or systems with limited RAM @@ -1099,6 +1156,15 @@ 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(romparams)) + { + // set defaults + printf("ROM entry not found\n"); + } + else + printf("ROM entry: %08X %08X %08X\n", romparams[0], romparams[1], romparams[2]); + // generate a ROM ID // note: most games don't check the actual value // it just has to stay the same throughout gameplay |