GBA: Fix crash when new size is larger than rom size after soft-patching
This commit is contained in:
parent
9e1a63af0b
commit
b50d48458f
|
@ -458,6 +458,23 @@ variable_desc saveGameStruct[] = {
|
||||||
|
|
||||||
static int romSize = SIZE_ROM;
|
static int romSize = SIZE_ROM;
|
||||||
|
|
||||||
|
void gbaUpdateRomSize(int size)
|
||||||
|
{
|
||||||
|
// Only change memory block if new size is larger
|
||||||
|
if (size > romSize) {
|
||||||
|
romSize = size;
|
||||||
|
|
||||||
|
uint8_t* tmp = (uint8_t*)realloc(rom, SIZE_ROM);
|
||||||
|
rom = tmp;
|
||||||
|
|
||||||
|
uint16_t* temp = (uint16_t*)(rom + ((romSize + 1) & ~1));
|
||||||
|
for (int i = (romSize + 1) & ~1; i < SIZE_ROM; i += 2) {
|
||||||
|
WRITE16LE(temp, (i >> 1) & 0xFFFF);
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PROFILING
|
#ifdef PROFILING
|
||||||
void cpuProfil(profile_segment* seg)
|
void cpuProfil(profile_segment* seg)
|
||||||
{
|
{
|
||||||
|
@ -1506,7 +1523,7 @@ int CPULoadRom(const char* szFile)
|
||||||
|
|
||||||
uint16_t* temp = (uint16_t*)(rom + ((romSize + 1) & ~1));
|
uint16_t* temp = (uint16_t*)(rom + ((romSize + 1) & ~1));
|
||||||
int i;
|
int i;
|
||||||
for (i = (romSize + 1) & ~1; i < romSize; i += 2) {
|
for (i = (romSize + 1) & ~1; i < SIZE_ROM; i += 2) {
|
||||||
WRITE16LE(temp, (i >> 1) & 0xFFFF);
|
WRITE16LE(temp, (i >> 1) & 0xFFFF);
|
||||||
temp++;
|
temp++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,9 @@ const char* GetSaveDotCodeFile();
|
||||||
void SetLoadDotCodeFile(const char* szFile);
|
void SetLoadDotCodeFile(const char* szFile);
|
||||||
void SetSaveDotCodeFile(const char* szFile);
|
void SetSaveDotCodeFile(const char* szFile);
|
||||||
|
|
||||||
|
// Updates romSize and realloc rom pointer if needed after soft-patching
|
||||||
|
void gbaUpdateRomSize(int size);
|
||||||
|
|
||||||
extern struct EmulatedSystem GBASystem;
|
extern struct EmulatedSystem GBASystem;
|
||||||
|
|
||||||
#define R13_IRQ 18
|
#define R13_IRQ 18
|
||||||
|
|
|
@ -223,6 +223,8 @@ void GameArea::LoadGame(const wxString& name)
|
||||||
int size = 0x2000000 < rom_size ? 0x2000000 : rom_size;
|
int size = 0x2000000 < rom_size ? 0x2000000 : rom_size;
|
||||||
applyPatch(pfn.GetFullPath().mb_str(), &rom, &size);
|
applyPatch(pfn.GetFullPath().mb_str(), &rom, &size);
|
||||||
// that means we no longer really know rom_size either <sigh>
|
// that means we no longer really know rom_size either <sigh>
|
||||||
|
|
||||||
|
gbaUpdateRomSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileConfig* cfg = wxGetApp().overrides;
|
wxFileConfig* cfg = wxGetApp().overrides;
|
||||||
|
|
Loading…
Reference in New Issue