Post Reply 
 
Thread Rating:
  • 33 Votes - 2.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Added tool for detecting save type
Author Message
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #1
Added tool for detecting save type
SVN895, 896

Options->Emulator->Save Type->Detect now...

I tested about 20 commercial games with that and the results always matched up with the GBAtemp release list: http://www.gbatemp.net/newgon/?dat=gba


Code:
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;
            }
        }
    }

    MessageBox( answer );
}
(This post was last modified: 08-21-2009 07:04 AM by spacy51. Edit Reason: N/A)
08-20-2009 07:15 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #2
RE: Added tool for detecting save type
would it work as an auto detect?

08-20-2009 10:50 AM
Visit this user's website Find all posts by this user Quote this message in a reply
aceloop Offline
Junior Member
**

Posts: 37
Joined: May 2008
Reputation: 0

Thanks: 0
0 thank was given in 0 posts
Post: #3
RE: Added tool for detecting save type
this is a great tool, soon ill test it with my library. Spacy have u tested firered because i remember that being problematic? and could this work with the Classic NES Series as an auto detect as Squall said?
(This post was last modified: 08-20-2009 11:50 AM by aceloop. Edit Reason: )
08-20-2009 11:46 AM
Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #4
RE: Added tool for detecting save type
GBA pokemon require a 128K save type
DBZ are slightly wierd... they use Fram, but... they aren't normal fram size... O.o

08-20-2009 12:02 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #5
RE: Added tool for detecting save type
doesn't work on KH-CoM or Iridion II

08-20-2009 03:56 PM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #6
RE: Added tool for detecting save type
Well, for MY ORIGINAL ROM of Iridion II it works by saying there is probably no backup media, which is right, because there really is none in the real thing.
08-20-2009 06:12 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #7
RE: Added tool for detecting save type
lol, Also does it for Zoids Legacy.


and all of them save fine Tongue

08-20-2009 07:05 PM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #8
RE: Added tool for detecting save type
But Iridion really doesn't save, there's even a password system in it.
08-20-2009 07:40 PM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #9
RE: Added tool for detecting save type
I found a game which uses a little different string:

Lufia - The Ruins of Lore (USA)
String is "SRAM_F_V102"
Something like that is not even documented in GBATEK. There mgiht be more games like that. Maybe I should write a tool to test all my games and see what the tool is good for.
08-21-2009 07:00 AM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #10
RE: Added tool for detecting save type
I made the detection into a command line tool and checked some ROMs with it. The tool is attached. Just drag & drop some ROMs on it and it will create a .txt file in the tool's dir with the output info.

My code is actually quite fast:
500 files -> ~56 seconds
Keep in mind this also includes the time to read every file into memory


Edit:
This forum destroys all my 7z+zip uploads by leaving out bytes at the end of the file o.o

http://spacy51.sp.funpic.de/VBA-M/gbaSaveTypeDetect/


Please tell me if a game was not detected correctly.
If everything works fine, we could use this algorithm for the VBA-M core.
(This post was last modified: 08-22-2009 08:13 AM by spacy51. Edit Reason: N/A)
08-22-2009 07:30 AM
Visit this user's website Find all posts by this user Quote this message in a reply
aceloop Offline
Junior Member
**

Posts: 37
Joined: May 2008
Reputation: 0

Thanks: 0
0 thank was given in 0 posts
Post: #11
RE: Added tool for detecting save type
spacy i tested all the popular games, and checked GBAtemp release list with the save types. All the save types where correct. ill test more later.

Code:
\Advance Wars 2 - Black Hole Rising (U).gba
Result: This cartridge uses FLASH (64 KiB).

\Advance Wars (U) (v1.1).gba
Result: This cartridge uses FLASH (64 KiB).

\Astro Boy - Omega Factor (U).gba
Result: This cartridge uses EEPROM.

\Castlevania - Aria of Sorrow (E) .gba
Result: This cartridge uses SRAM.

\Castlevania - Circle of the Moon (U).gba
Result: This cartridge uses SRAM.

\Castlevania - Harmony of Dissonance (E).gba
Result: This cartridge uses SRAM.

\Final Fantasy I & II - Dawn of Souls (E) .gba
Result: This cartridge uses SRAM.

\Final Fantasy IV Advance (E) .gba
Result: This cartridge uses SRAM.

\Final Fantasy Tactics Advance (E).gba
Result: This cartridge uses FLASH (64 KiB).

\Final Fantasy V (E).gba
Result: This cartridge uses SRAM.

\Final Fantasy VI Advance (U).gba
Result: This cartridge uses SRAM.

\Fire Emblem - The Sacred Stones (U).gba
Result: This cartridge uses SRAM.

\Fire Emblem (U).gba
Result: This cartridge uses SRAM.

\F-Zero - Maximum Velocity (UE).gba
Result: This cartridge uses SRAM.

\Golden Sun - The Lost Age (UE).gba
Result: This cartridge uses FLASH (64 KiB).

\Golden Sun (UE).gba
Result: This cartridge uses FLASH (64 KiB).

\Gunstar Super Heroes.gba
Result: This cartridge uses EEPROM.

\Harvest Moon - Friends of Mineral Town (U).gba
Result: This cartridge uses SRAM.

\Harvest Moon - More Friends of Mineral Town (U).gba
Result: This cartridge uses SRAM.

\Kingdom Hearts - Chain of Memories (U).gba
Result: This cartridge uses SRAM.

\Legend of Zelda, The - A Link to the Past & Four Swords (U).gba
Result: This cartridge uses EEPROM.

\Mario & Luigi - Superstar Saga (E).gba
Result: This cartridge uses EEPROM.

\Mario Golf - Advance Tour (U).gba
Result: This cartridge uses SRAM.

\Mario Kart - Super Circuit (U).gba
Result: This cartridge uses FLASH (64 KiB).

\Mario Tennis Power Tour (U).gba
Result: This cartridge uses SRAM.

\Metroid - Zero Mission (E).gba
Result: This cartridge uses SRAM.

\Metroid Fusion (E) .gba
Result: This cartridge uses SRAM.

\Mortal Kombat - Deadly Alliance (UE).gba
Result: This cartridge uses EEPROM.

\Mother 3 (J).gba
Result: This cartridge uses FLASH (64 KiB).

\Pokemon Emerald (U).gba
Result: This cartridge uses FLASH (128 KiB).

\Pokemon Fire Red.gba
Result: This cartridge uses FLASH (128 KiB).

\Pokemon Mystery Dungeon - Red Rescue Team.gba
Result: This cartridge uses FLASH (128 KiB).

\Pokemon Video Volume 1.gba
Result: This cartridge has probably no backup media.

\Riviera - The Promised Land (U).gba
Result: This cartridge uses SRAM.

\Sonic Advance 2 (E) .gba
Result: This cartridge uses FLASH (64 KiB).

\Sonic Advance 3 (E).gba
Result: This cartridge uses FLASH (64 KiB).

\Sonic Advance (E).gba
Result: This cartridge uses FLASH (64 KiB).

\Super Mario Advance 3 - Yoshi's Island (U).gba
Result: This cartridge uses EEPROM.

\Super Mario Advance 4 - Super Mario Bros. 3 (E) (v1.1).gba
Result: This cartridge uses FLASH (128 KiB).

\Super Mario Advance (UE).gba
Result: This cartridge uses EEPROM.

\Super Street Fighter II Turbo - Revival (E).gba
Result: This cartridge uses EEPROM.

\Tactics Ogre - The Knight of Lodis (U).gba
Result: This cartridge uses FLASH (64 KiB).

\The Legend of Zelda - The Minish Cap.gba
Result: This cartridge uses EEPROM.

\Wario Land 4 (UE).gba
Result: This cartridge uses SRAM.

\WarioWare - Twisted! (U).gba
Result: This cartridge uses SRAM.

\WarioWare, Inc. - Mega Microgames! (U).gba
Result: This cartridge uses SRAM.

\Street Fighter Alpha 3 Upper (E).gba
Result: This cartridge uses EEPROM.

\Super Mario Advance 2 - Super Mario World (U).gba
Result: This cartridge uses EEPROM.

i think, i found a little bug with svn896. when you have no game loaded its says "This cartridge has probably no backup media.". shouldnt it be like some like "no cartridge loaded"??
(This post was last modified: 08-24-2009 02:49 AM by aceloop. Edit Reason: )
08-24-2009 01:03 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #12
RE: Added tool for detecting save type
I am interested if there are mroe games that use strings I do not know of yet. These will get falsely be detected as no backup media present.
08-24-2009 02:52 AM
Visit this user's website Find all posts by this user Quote this message in a reply
aceloop Offline
Junior Member
**

Posts: 37
Joined: May 2008
Reputation: 0

Thanks: 0
0 thank was given in 0 posts
Post: #13
RE: Added tool for detecting save type
im not too sure but wouldn't the vba-over.ini floating about the net be a help? wasnt the vba-over.ini file the way of fixing save problems?
08-24-2009 03:00 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #14
RE: Added tool for detecting save type
vba-over.ini is more like a work-around if you ask me.

We wouldn#t need that if we had a better auto-detection mechanism.


vba-ove.rini might still be useful for homebrew that can not be detected right with this code.
08-24-2009 03:04 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #15
RE: Added tool for detecting save type
vba-over is for more then save types, its also for bios per rom, rtc, and mirroring to fix nes classics.

08-24-2009 03:11 AM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #16
RE: Added tool for detecting save type
Lol, I just found out VBA already has that kind of code in Util.cpp.
It also looks like a real time clock can be identified by the string: "SIIRTC_V"

However, this code is not used anywhere in VBA.

Quote:void utilGBAFindSave(const u8 *data, 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);
}
(This post was last modified: 09-05-2009 04:41 AM by spacy51. Edit Reason: )
09-05-2009 04:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 708
Joined: Mar 2008
Reputation: 4

Thanks: 0
6 thank was given in 6 posts
Post: #17
RE: Added tool for detecting save type
It probably corresponded with the enhanced detection function, that apparently didn't work right......

09-05-2009 07:18 AM
Visit this user's website Find all posts by this user Quote this message in a reply
bobthetaru Offline
Junior Member
**

Posts: 2
Joined: Mar 2010
Reputation: 0

Thanks: 0
0 thank was given in 0 posts
Post: #18
RE: Added tool for detecting save type
i dont know how to add that code to vba, but the list says tactics advance uses 64k flash, i set it to that and it still says error in backup memory when i try to save. I'll try starting a new game.. again..
Otherwise, can anyone help me get my tactics advanced roms to save?
03-09-2010 09:49 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 457
Joined: Mar 2008
Reputation: 3

Thanks: 0
1 thank was given in 1 posts
Post: #19
RE: Added tool for detecting save type
Is your save path correct?

Try to move your current save file out of it and start VBA-M without a save file.
03-09-2010 05:52 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: