libpsxsave/test.cpp

85 lines
2.7 KiB
C++
Raw Normal View History

2010-08-10 13:40:01 +00:00
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
#include "memcard.h"
char* decode_sjis( char* sjis ) {
return sjis;
}
int main( int argc, char * argv[] )
{
char* filename;
char buffer[256];
string name;
string code;
map<string, string> games;
if( argc > 1 ) {
filename = argv[1];
} else {
cout << "No filename provided, exiting.\n";
return 1;
}
fstream db;
db.open( "db", ios::in );
while( !db.eof() ) {
db.getline( buffer, 256 );
code = buffer;
int offset = code.find( ";" );
if( offset > 0 ) {
name = code.substr( offset + 1 );
code = code.substr( 0, offset );
games[code] = name;
}
}
db.close();
MemoryCard *memCard = new MemoryCard();
memCard->loadFile( filename );
if( argc > 2 ) {
cout << "Loading MCS (" << argv[2] << ")\n";
memCard->loadMCS( argv[2], 4 );
}
DirectoryBlock *directory = (DirectoryBlock*)memCard->getBlock(0);
cout << "Loaded " << games.size() << " unique entries from the game database.\n";
cout << "================================================================================\n";
cout << "Initial block\n";
cout << "================================================================================\n";
cout << "ID Frame\n";
cout << "--------------------------------------------------------------------------------\n";
printf( "ID: %s\n", directory->IDFrame()->id() );
printf( "XOR Valid: %s\n", directory->IDFrame()->getXOR() ? "Yes" : "No" );
printf( "Block Valid: %s\n", directory->IDFrame()->isValid() ? "Yes" : "No" );
for( int i = 1; i < 16; i++ ) {
cout << "================================================================================\n";
cout << "Block " << i << "\n";
cout << "================================================================================\n";
SaveHeaderFrame *h = ( ( (InitialBlock*)memCard->getBlock( i ) )->Header() );
DirectoryFrame *dir = directory->Directory( i - 1 );
printf( "Type: %d\n", dir->blockType() );
printf( "Size: %d\n", dir->size() );
printf( "Next Block: %d\n", dir->nextBlock() );
printf( "Territory: %s\n", dir->territoryCode() );
printf( "License: %s (%s)\n", dir->licenseCode(), games[dir->licenseCode()].c_str() );
printf( "Save: %s\n", dir->saveCode() );
printf( "XOR Valid: %s\n", dir->getXOR() ? "Yes" : "No" );
switch( dir->blockType() ) {
case 81:
cout << "--------------------------------------------------------------------------------\n";
printf( "Magic Number: %s\n", h->magicNumber() );
printf( "Icon Display Type: %d\n", h->iconDisplayType() );
printf( "Blocks Used: %d\n", h->blocksUsed() );
printf( "SJIS Save Title: %s\n", decode_sjis( h->SJISSaveTitle() ) );
break;
}
}
return 0;
}