From e831c2d6cb20394e0b7cc2f86c5e7d751d542685 Mon Sep 17 00:00:00 2001 From: skidau Date: Wed, 25 Mar 2015 11:01:50 +0000 Subject: [PATCH] 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 --- src/Util.cpp | 14 ++++----- src/Util.h | 2 +- src/win32/MainWnd.cpp | 3 ++ src/win32/MainWndOptions.cpp | 56 ++++++++++++++---------------------- 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/src/Util.cpp b/src/Util.cpp index 25f3df4b..8bbff3df 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -634,10 +634,10 @@ 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); + u32 *p = (u32 *)&rom[0]; + u32 *end = (u32 *)(&rom[0] + size); int saveType = 0; int flashSize = 0x10000; bool rtcFound = false; @@ -648,22 +648,22 @@ void utilGBAFindSave(const u8 *data, const int size) if(d == 0x52504545) { if(memcmp(p, "EEPROM_", 7) == 0) { if(saveType == 0) - saveType = 3; + saveType = 1; } } else if (d == 0x4D415253) { if(memcmp(p, "SRAM_", 5) == 0) { if(saveType == 0) - saveType = 1; + saveType = 2; } } else if (d == 0x53414C46) { if(memcmp(p, "FLASH1M_", 8) == 0) { if(saveType == 0) { - saveType = 2; + saveType = 3; flashSize = 0x20000; } } else if(memcmp(p, "FLASH", 5) == 0) { if(saveType == 0) { - saveType = 2; + saveType = 3; flashSize = 0x10000; } } diff --git a/src/Util.h b/src/Util.h index 1292b85f..1f66428a 100644 --- a/src/Util.h +++ b/src/Util.h @@ -39,7 +39,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 ); diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 38bc0fdf..977fb751 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -521,6 +521,9 @@ bool MainWnd::FileRun() rtcEnable(theApp.winRtcEnable); cpuSaveType = theApp.winSaveType; + if (cpuSaveType == 0) + utilGBAFindSave(theApp.romSize); + GetModuleFileName(NULL, tempName, 2048); char *p = strrchr(tempName, '\\'); diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index 14070623..0fa6da87 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -797,44 +797,32 @@ void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI* pCmdUI) void MainWnd::OnOptionsEmulatorSavetypeDetectNow() { if( theApp.cartridgeType != IMAGE_GBA ) return; + const int address_max = theApp.romSize - 10; char temp[11]; temp[10] = '\0'; CString answer( _T( "This cartridge has probably no backup media." ) ); - const u32 EEPR = 'E' | ( 'E' << 8 ) | ( 'P' << 16 ) | ( 'R' << 24 ); - const u32 SRAM = 'S' | ( 'R' << 8 ) | ( 'A' << 16 ) | ( 'M' << 24 ); - const u32 FLAS = 'F' | ( 'L' << 8 ) | ( 'A' << 16 ) | ( 'S' << 24 ); - - for( int address = 0; address < address_max; address += 4 ) { - const u32 check = *((u32*)&rom[address]); - - if( EEPR == check ) { - memcpy( temp, &rom[address], 10 ); - if( 0 == strncmp( temp, "EEPROM_V", 8 ) ) { - answer = _T( "This cartridge uses EEPROM." ); - break; - } - } - - if( SRAM == check ) { - memcpy( temp, &rom[address], 10 ); - if( ( 0 == strncmp( temp, "SRAM_V", 6 ) ) || ( 0 == strncmp( temp, "SRAM_F_V", 8 ) ) ) { - answer = _T( "This cartridge uses SRAM." ); - 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; - } - } + utilGBAFindSave(theApp.romSize); + switch (cpuSaveType) + { + case 0: + answer = _T("This cartridge has probably no backup media."); + break; + case 1: + answer = _T( "This cartridge uses SRAM." ); + break; + case 2: + if (flashSize == 0x10000) + answer = _T( "This cartridge uses FLASH (64 KiB)." ); + else if (flashSize = 0x20000) + answer = _T( "This cartridge uses FLASH (128 KiB)." ); + break; + case 3: + answer = _T("This cartridge uses EEPROM."); + break; + default: + answer = _T("This cartridge has probably no backup media."); + break; } MessageBox( answer );