Skip to content

Commit

Permalink
add code to detect save type (as done in rev 1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Sep 3, 2015
1 parent c8cfa32 commit 9fbc689
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
2 changes: 2 additions & 0 deletions EmulatorFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ namespace VBA10
{
delete [] data.ROM;
}
//try to auto detect save type
utilGBAFindSave(romSize);

// read from vba-over.ini
Map<String ^, ROMConfig> ^configs = romConfigs;
Expand Down
94 changes: 49 additions & 45 deletions VBAM/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,52 +487,56 @@ long utilGzMemTell(gzFile file)
return memtell(file);
}

void utilGBAFindSave(const u8 *data, const int size)
void utilGBAFindSave(const int size)
{
u32 *p = (u32 *)data;
u32 *end = (u32 *)(data + size);
int saveType = 0;
int flashSize = 0x10000;
bool rtcFound = false;

while(p < end) {
u32 d = READ32LE(p);

if(d == 0x52504545) {
if(memcmp(p, "EEPROM_", 7) == 0) {
if(saveType == 0)
saveType = 3;
}
} else if (d == 0x4D415253) {
if(memcmp(p, "SRAM_", 5) == 0) {
if(saveType == 0)
saveType = 1;
}
} else if (d == 0x53414C46) {
if(memcmp(p, "FLASH1M_", 8) == 0) {
if(saveType == 0) {
saveType = 2;
flashSize = 0x20000;
}
} else if(memcmp(p, "FLASH", 5) == 0) {
if(saveType == 0) {
saveType = 2;
flashSize = 0x10000;
}
}
} else if (d == 0x52494953) {
if(memcmp(p, "SIIRTC_V", 8) == 0)
rtcFound = true;
}
p++;
}
// if no matches found, then set it to NONE
if(saveType == 0) {
saveType = 5;
}
rtcEnable(rtcFound);
cpuSaveType = saveType;
flashSetSize(flashSize);
u32 *p = (u32 *)&rom[0];
u32 *end = (u32 *)(&rom[0] + size);
int saveType = 0;
int flashSize = 0x10000;
bool rtcFound = false;

while (p < end) {
u32 d = READ32LE(p);

if (d == 0x52504545) {
if (memcmp(p, "EEPROM_", 7) == 0) {
if (saveType == 0)
saveType = 1;
}
}
else if (d == 0x4D415253) {
if (memcmp(p, "SRAM_", 5) == 0) {
if (saveType == 0)
saveType = 2;
}
}
else if (d == 0x53414C46) {
if (memcmp(p, "FLASH1M_", 8) == 0) {
if (saveType == 0) {
saveType = 3;
flashSize = 0x20000;
}
}
else if (memcmp(p, "FLASH", 5) == 0) {
if (saveType == 0) {
saveType = 3;
flashSize = 0x10000;
}
}
}
else if (d == 0x52494953) {
if (memcmp(p, "SIIRTC_V", 8) == 0)
rtcFound = true;
}
p++;
}
// if no matches found, then set it to NONE
if (saveType == 0) {
saveType = 5;
}
rtcEnable(rtcFound);
cpuSaveType = saveType;
flashSetSize(flashSize);
}

void utilUpdateSystemColorMaps(bool lcd)
Expand Down
2 changes: 1 addition & 1 deletion VBAM/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int utilGzRead(gzFile file, voidp buffer, unsigned int len);
int utilGzClose(gzFile file);
z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence);
long utilGzMemTell(gzFile file);
void utilGBAFindSave(const u8 *, const int);
void utilGBAFindSave(const int);
void utilUpdateSystemColorMaps(bool lcd = false);
bool utilFileExists( const char *filename );

Expand Down
1 change: 0 additions & 1 deletion VBAM/gba/GBAinline.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//r1225, don't use r1226 because Dragon Ball Z cannot run even when we change Savetype to EEPROM
#ifndef GBAINLINE_H
#define GBAINLINE_H

Expand Down

0 comments on commit 9fbc689

Please sign in to comment.