Change UpdateCounter to u16

Signed-off-by: LPFaint99 <lpfaint99@gmail.com>
This commit is contained in:
LPFaint99 2012-02-06 17:49:17 -08:00
parent 0aeb94d3be
commit ebdab914cb
2 changed files with 10 additions and 11 deletions

View File

@ -240,7 +240,6 @@ GCMemcard::GCMemcard(const char *filename, bool forceCreation, bool sjis)
} }
if (BE16(bat.UpdateCounter) > BE16(bat_backup.UpdateCounter)) if (BE16(bat.UpdateCounter) > BE16(bat_backup.UpdateCounter))
{ {
PanicAlert("jere, %x, %x",BE16(bat.UpdateCounter) , BE16(bat_backup.UpdateCounter));
CurrentBat = &bat; CurrentBat = &bat;
PreviousBat = &bat_backup; PreviousBat = &bat_backup;
} }
@ -564,6 +563,7 @@ bool GCMemcard::GetDEntry(u8 index, DEntry &dest) const
dest = CurrentDir->Dir[index]; dest = CurrentDir->Dir[index];
return true; return true;
} }
u16 GCMemcard::BlockAlloc::GetNextBlock(u16 Block) const u16 GCMemcard::BlockAlloc::GetNextBlock(u16 Block) const
{ {
if ((Block < MC_FST_BLOCKS) || (Block > 4091)) if ((Block < MC_FST_BLOCKS) || (Block > 4091))
@ -667,7 +667,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, std::vector<GCMBlock> &saveBlocks)
break; break;
} }
} }
*(u16*)&UpdatedDir.UpdateCounter = BE16(BE16(UpdatedDir.UpdateCounter) + 1); UpdatedDir.UpdateCounter = BE16(BE16(UpdatedDir.UpdateCounter) + 1);
*PreviousDir = UpdatedDir; *PreviousDir = UpdatedDir;
if (PreviousDir == &dir ) if (PreviousDir == &dir )
{ {
@ -697,7 +697,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, std::vector<GCMBlock> &saveBlocks)
firstBlock = nextBlock; firstBlock = nextBlock;
} }
*(u16*)&UpdatedBat.FreeBlocks = BE16(BE16(UpdatedBat.FreeBlocks) - fileBlocks); *(u16*)&UpdatedBat.FreeBlocks = BE16(BE16(UpdatedBat.FreeBlocks) - fileBlocks);
*(u16*)&UpdatedBat.UpdateCounter = BE16(BE16(UpdatedBat.UpdateCounter) + 1); UpdatedBat.UpdateCounter = BE16(BE16(UpdatedBat.UpdateCounter) + 1);
*PreviousBat = UpdatedBat; *PreviousBat = UpdatedBat;
if (PreviousBat == &bat ) if (PreviousBat == &bat )
{ {
@ -726,7 +726,7 @@ u32 GCMemcard::RemoveFile(u8 index) //index in the directory array
BlockAlloc UpdatedBat = *CurrentBat; BlockAlloc UpdatedBat = *CurrentBat;
if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks)) if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks))
return DELETE_FAIL; return DELETE_FAIL;
*(u16*)&UpdatedBat.UpdateCounter = BE16(BE16(UpdatedBat.UpdateCounter) + 1); UpdatedBat.UpdateCounter = BE16(BE16(UpdatedBat.UpdateCounter) + 1);
*PreviousBat = UpdatedBat; *PreviousBat = UpdatedBat;
if (PreviousBat == &bat ) if (PreviousBat == &bat )
{ {
@ -762,7 +762,7 @@ u32 GCMemcard::RemoveFile(u8 index) //index in the directory array
} }
*/ */
memset(&(UpdatedDir.Dir[index]), 0xFF, DENTRY_SIZE); memset(&(UpdatedDir.Dir[index]), 0xFF, DENTRY_SIZE);
*(u16*)&UpdatedDir.UpdateCounter = BE16(BE16(UpdatedDir.UpdateCounter) + 1); UpdatedDir.UpdateCounter = BE16(BE16(UpdatedDir.UpdateCounter) + 1);
*PreviousDir = UpdatedDir; *PreviousDir = UpdatedDir;
if (PreviousDir == &dir ) if (PreviousDir == &dir )
{ {
@ -1245,13 +1245,13 @@ void GCMemcard::FormatInternal(GCMC_Header &GCP)
Directory *p_dir = GCP.dir, Directory *p_dir = GCP.dir,
*p_dir_backup = GCP.dir_backup; *p_dir_backup = GCP.dir_backup;
*(u16*)&p_dir->UpdateCounter = 0; *(u16*)&p_dir->UpdateCounter = 0;
*(u16*)&p_dir_backup->UpdateCounter = BE16(1); p_dir_backup->UpdateCounter = BE16(1);
calc_checksumsBE((u16*)p_dir, 0xFFE, &p_dir->Checksum, &p_dir->Checksum_Inv); calc_checksumsBE((u16*)p_dir, 0xFFE, &p_dir->Checksum, &p_dir->Checksum_Inv);
calc_checksumsBE((u16*)p_dir_backup, 0xFFE, &p_dir_backup->Checksum, &p_dir_backup->Checksum_Inv); calc_checksumsBE((u16*)p_dir_backup, 0xFFE, &p_dir_backup->Checksum, &p_dir_backup->Checksum_Inv);
BlockAlloc *p_bat = GCP.bat, BlockAlloc *p_bat = GCP.bat,
*p_bat_backup = GCP.bat_backup; *p_bat_backup = GCP.bat_backup;
*(u16*)&p_bat_backup->UpdateCounter = BE16(1); p_bat_backup->UpdateCounter = BE16(1);
*(u16*)&p_bat->FreeBlocks = *(u16*)&p_bat_backup->FreeBlocks = BE16(( BE16(p_hdr->SizeMb) * MBIT_TO_BLOCKS) - MC_FST_BLOCKS); *(u16*)&p_bat->FreeBlocks = *(u16*)&p_bat_backup->FreeBlocks = BE16(( BE16(p_hdr->SizeMb) * MBIT_TO_BLOCKS) - MC_FST_BLOCKS);
*(u16*)&p_bat->LastAllocated = *(u16*)&p_bat_backup->LastAllocated = BE16(4); *(u16*)&p_bat->LastAllocated = *(u16*)&p_bat_backup->LastAllocated = BE16(4);
calc_checksumsBE((u16*)p_bat+2, 0xFFE, &p_bat->Checksum, &p_bat->Checksum_Inv); calc_checksumsBE((u16*)p_bat+2, 0xFFE, &p_bat->Checksum, &p_bat->Checksum_Inv);

View File

@ -27,7 +27,6 @@
#define BE32(x) (Common::swap32(x)) #define BE32(x) (Common::swap32(x))
#define BE16(x) (Common::swap16(x)) #define BE16(x) (Common::swap16(x))
#define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8))); #define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8)));
enum enum
{ {
SLOT_A = 0, SLOT_A = 0,
@ -98,7 +97,7 @@ private:
u8 SizeMb[2]; //0x0022 2 size of memcard in Mbits u8 SizeMb[2]; //0x0022 2 size of memcard in Mbits
u16 Encoding; //0x0024 2 encoding (ASCII or japanese) u16 Encoding; //0x0024 2 encoding (ASCII or japanese)
u8 Unused1[468]; //0x0026 468 unused (0xff) u8 Unused1[468]; //0x0026 468 unused (0xff)
u8 UpdateCounter[2];//0x01fa 2 update Counter (?, probably unused) u16 UpdateCounter;//0x01fa 2 update Counter (?, probably unused)
u16 Checksum; //0x01fc 2 Additive Checksum u16 Checksum; //0x01fc 2 Additive Checksum
u16 Checksum_Inv; //0x01fe 2 Inverse Checksum u16 Checksum_Inv; //0x01fe 2 Inverse Checksum
u8 Unused2[7680]; //0x0200 0x1e00 unused (0xff) u8 Unused2[7680]; //0x0200 0x1e00 unused (0xff)
@ -152,7 +151,7 @@ private:
struct Directory { struct Directory {
DEntry Dir[DIRLEN]; //0x0000 Directory Entries (max 127) DEntry Dir[DIRLEN]; //0x0000 Directory Entries (max 127)
u8 Padding[0x3a]; u8 Padding[0x3a];
u8 UpdateCounter[2];//0x1ffa 2 update Counter u16 UpdateCounter; //0x1ffa 2 update Counter
u16 Checksum; //0x1ffc 2 Additive Checksum u16 Checksum; //0x1ffc 2 Additive Checksum
u16 Checksum_Inv; //0x1ffe 2 Inverse Checksum u16 Checksum_Inv; //0x1ffe 2 Inverse Checksum
} dir, dir_backup; } dir, dir_backup;
@ -161,7 +160,7 @@ private:
struct BlockAlloc { struct BlockAlloc {
u16 Checksum; //0x0000 2 Additive Checksum u16 Checksum; //0x0000 2 Additive Checksum
u16 Checksum_Inv; //0x0002 2 Inverse Checksum u16 Checksum_Inv; //0x0002 2 Inverse Checksum
u8 UpdateCounter[2];//0x0004 2 update Counter u16 UpdateCounter; //0x0004 2 update Counter
u8 FreeBlocks[2]; //0x0006 2 free Blocks u8 FreeBlocks[2]; //0x0006 2 free Blocks
u8 LastAllocated[2];//0x0008 2 last allocated Block u8 LastAllocated[2];//0x0008 2 last allocated Block
u16 Map[BAT_SIZE]; //0x000a 0x1ff8 Map of allocated Blocks u16 Map[BAT_SIZE]; //0x000a 0x1ff8 Map of allocated Blocks