From 702879c848e5df4b34a6ab6baea295765fdb007e Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Mon, 2 Dec 2013 12:49:36 +0000 Subject: [PATCH] core: - add autofix the device capacity value in broken header (fix bug [#1353]); --- desmume/src/NDSSystem.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 822b00c3e..c217e122f 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -399,6 +399,22 @@ bool GameInfo::loadROM(std::string fname, u32 type) if (res) { cardSize = (128 * 1024) << header.cardSize; + + if (cardSize < romsize) + { + msgbox->warn("The ROM header is invalid.\nThe device size has been increased to allow for the provided file size.\n"); + + for (u32 i = header.cardSize; i < 0xF; i++) + { + if (((128 * 1024) << i) >= romsize) + { + header.cardSize = i; + cardSize = (128 * 1024) << i; + break; + } + } + } + mask = (cardSize - 1); mask |= (mask >>1); mask |= (mask >>2);