Re-enable the save type auto-detect code instead of enabling all save types.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@1245 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
skidau 2015-03-25 11:01:50 +00:00
parent b56e1edc45
commit e831c2d6cb
4 changed files with 33 additions and 42 deletions

View File

@ -634,10 +634,10 @@ long utilGzMemTell(gzFile file)
return memtell(file); return memtell(file);
} }
void utilGBAFindSave(const u8 *data, const int size) void utilGBAFindSave(const int size)
{ {
u32 *p = (u32 *)data; u32 *p = (u32 *)&rom[0];
u32 *end = (u32 *)(data + size); u32 *end = (u32 *)(&rom[0] + size);
int saveType = 0; int saveType = 0;
int flashSize = 0x10000; int flashSize = 0x10000;
bool rtcFound = false; bool rtcFound = false;
@ -648,22 +648,22 @@ void utilGBAFindSave(const u8 *data, const int size)
if(d == 0x52504545) { if(d == 0x52504545) {
if(memcmp(p, "EEPROM_", 7) == 0) { if(memcmp(p, "EEPROM_", 7) == 0) {
if(saveType == 0) if(saveType == 0)
saveType = 3; saveType = 1;
} }
} else if (d == 0x4D415253) { } else if (d == 0x4D415253) {
if(memcmp(p, "SRAM_", 5) == 0) { if(memcmp(p, "SRAM_", 5) == 0) {
if(saveType == 0) if(saveType == 0)
saveType = 1; saveType = 2;
} }
} else if (d == 0x53414C46) { } else if (d == 0x53414C46) {
if(memcmp(p, "FLASH1M_", 8) == 0) { if(memcmp(p, "FLASH1M_", 8) == 0) {
if(saveType == 0) { if(saveType == 0) {
saveType = 2; saveType = 3;
flashSize = 0x20000; flashSize = 0x20000;
} }
} else if(memcmp(p, "FLASH", 5) == 0) { } else if(memcmp(p, "FLASH", 5) == 0) {
if(saveType == 0) { if(saveType == 0) {
saveType = 2; saveType = 3;
flashSize = 0x10000; flashSize = 0x10000;
} }
} }

View File

@ -39,7 +39,7 @@ int utilGzRead(gzFile file, voidp buffer, unsigned int len);
int utilGzClose(gzFile file); int utilGzClose(gzFile file);
z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence); z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence);
long utilGzMemTell(gzFile file); long utilGzMemTell(gzFile file);
void utilGBAFindSave(const u8 *, const int); void utilGBAFindSave(const int);
void utilUpdateSystemColorMaps(bool lcd = false); void utilUpdateSystemColorMaps(bool lcd = false);
bool utilFileExists( const char *filename ); bool utilFileExists( const char *filename );

View File

@ -521,6 +521,9 @@ bool MainWnd::FileRun()
rtcEnable(theApp.winRtcEnable); rtcEnable(theApp.winRtcEnable);
cpuSaveType = theApp.winSaveType; cpuSaveType = theApp.winSaveType;
if (cpuSaveType == 0)
utilGBAFindSave(theApp.romSize);
GetModuleFileName(NULL, tempName, 2048); GetModuleFileName(NULL, tempName, 2048);
char *p = strrchr(tempName, '\\'); char *p = strrchr(tempName, '\\');

View File

@ -797,44 +797,32 @@ void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI* pCmdUI)
void MainWnd::OnOptionsEmulatorSavetypeDetectNow() void MainWnd::OnOptionsEmulatorSavetypeDetectNow()
{ {
if( theApp.cartridgeType != IMAGE_GBA ) return; if( theApp.cartridgeType != IMAGE_GBA ) return;
const int address_max = theApp.romSize - 10; const int address_max = theApp.romSize - 10;
char temp[11]; temp[10] = '\0'; char temp[11]; temp[10] = '\0';
CString answer( _T( "This cartridge has probably no backup media." ) ); CString answer( _T( "This cartridge has probably no backup media." ) );
const u32 EEPR = 'E' | ( 'E' << 8 ) | ( 'P' << 16 ) | ( 'R' << 24 ); utilGBAFindSave(theApp.romSize);
const u32 SRAM = 'S' | ( 'R' << 8 ) | ( 'A' << 16 ) | ( 'M' << 24 ); switch (cpuSaveType)
const u32 FLAS = 'F' | ( 'L' << 8 ) | ( 'A' << 16 ) | ( 'S' << 24 ); {
case 0:
for( int address = 0; address < address_max; address += 4 ) { answer = _T("This cartridge has probably no backup media.");
const u32 check = *((u32*)&rom[address]); break;
case 1:
if( EEPR == check ) { answer = _T( "This cartridge uses SRAM." );
memcpy( temp, &rom[address], 10 ); break;
if( 0 == strncmp( temp, "EEPROM_V", 8 ) ) { case 2:
answer = _T( "This cartridge uses EEPROM." ); if (flashSize == 0x10000)
break; answer = _T( "This cartridge uses FLASH (64 KiB)." );
} else if (flashSize = 0x20000)
} answer = _T( "This cartridge uses FLASH (128 KiB)." );
break;
if( SRAM == check ) { case 3:
memcpy( temp, &rom[address], 10 ); answer = _T("This cartridge uses EEPROM.");
if( ( 0 == strncmp( temp, "SRAM_V", 6 ) ) || ( 0 == strncmp( temp, "SRAM_F_V", 8 ) ) ) { break;
answer = _T( "This cartridge uses SRAM." ); default:
break; answer = _T("This cartridge has probably no backup media.");
} break;
}
if( FLAS == check ) {
memcpy( temp, &rom[address], 10 );
if( ( 0 == strncmp( temp, "FLASH_V", 7 ) ) || ( 0 == strncmp( temp, "FLASH512_V", 10 ) ) ) {
answer = _T( "This cartridge uses FLASH (64 KiB)." );
break;
}
if( 0 == strncmp( temp, "FLASH1M_V", 9 ) ) {
answer = _T( "This cartridge uses FLASH (128 KiB)." );
break;
}
}
} }
MessageBox( answer ); MessageBox( answer );