Skip to content

Commit

Permalink
added warning logs to MBCs
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jul 25, 2013
1 parent af98601 commit 7c79515
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/MBC1MemoryRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ u8 MBC1MemoryRule::PerformRead(u16 address)
if ((m_pCartridge->GetRAMSize() == 1) && (address >= 0xA800))
{
// only 2KB of ram
Log("--> ** Attempting to read from non usable address %X", address);
Log("--> ** Attempting to read from invalid RAM %X", address);
}
return m_pRAMBanks[address - 0xA000];
}
Expand Down Expand Up @@ -151,7 +151,7 @@ void MBC1MemoryRule::PerformWrite(u16 address, u8 value)
if ((m_pCartridge->GetRAMSize() == 1) && (address >= 0xA800))
{
// only 2KB of ram
Log("--> ** Attempting to write on non usable address %X %X", address, value);
Log("--> ** Attempting to write on invalid RAM %X %X", address, value);
}

m_pRAMBanks[address - 0xA000] = value;
Expand Down Expand Up @@ -190,6 +190,7 @@ void MBC1MemoryRule::Reset(bool bCGB)
void MBC1MemoryRule::SaveRam(std::ofstream &file)
{
Log("MBC1MemoryRule save RAM...");
Log("MBC1MemoryRule saving %d banks...", m_pCartridge->GetRAMBankCount());

u32 ramSize = m_pCartridge->GetRAMBankCount() * 0x2000;

Expand All @@ -205,22 +206,20 @@ void MBC1MemoryRule::SaveRam(std::ofstream &file)
bool MBC1MemoryRule::LoadRam(std::ifstream &file, s32 fileSize)
{
Log("MBC1MemoryRule load RAM...");
Log("MBC1MemoryRule loading %d banks...", m_pCartridge->GetRAMBankCount());

s32 ramSize = m_pCartridge->GetRAMBankCount() * 0x2000;

if (fileSize > 0)
if ((fileSize > 0) && (fileSize != ramSize))
{
if (fileSize != ramSize)
{
Log("MBC1MemoryRule incorrect size. Expected: %d Found: %d", ramSize, fileSize);
return false;
}
Log("MBC1MemoryRule incorrect size. Expected: %d Found: %d", ramSize, fileSize);
return false;
}
else if (fileSize == 0)
{
// compatibility with old saves
u8 mode;
file.read(reinterpret_cast<char*> (&mode), 1);

Log("MBC1MemoryRule load RAM mode %d", mode);
}

Expand Down
14 changes: 11 additions & 3 deletions src/MBC2MemoryRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ u8 MBC2MemoryRule::PerformRead(u16 address)
}
else
{
Log("--> ** Attempting to read from non usable address %X", address);
Log("--> ** Attempting to read from ivalid RAM %X", address);
return 0x00;
}
}
Expand All @@ -81,6 +81,10 @@ void MBC2MemoryRule::PerformWrite(u16 address, u8 value)
{
m_bRamEnabled = (value & 0x0F) == 0x0A;
}
else
{
Log("--> ** Attempting to write on invalid register %X %X", address, value);
}
break;
}
case 0x2000:
Expand All @@ -93,12 +97,16 @@ void MBC2MemoryRule::PerformWrite(u16 address, u8 value)
m_iCurrentROMBank &= (m_pCartridge->GetROMBankCount() - 1);
m_CurrentROMAddress = m_iCurrentROMBank * 0x4000;
}
else
{
Log("--> ** Attempting to write on invalid register %X %X", address, value);
}
break;
}
case 0x4000:
case 0x6000:
{
Log("--> ** Attempting to write on non usable address %X %X", address, value);
Log("--> ** Attempting to write on invalid address %X %X", address, value);
break;
}
case 0xA000:
Expand All @@ -116,7 +124,7 @@ void MBC2MemoryRule::PerformWrite(u16 address, u8 value)
}
else
{
Log("--> ** Attempting to write on non usable address %X %X", address, value);
Log("--> ** Attempting to write on invalid RAM %X %X", address, value);
}
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/MBC5MemoryRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void MBC5MemoryRule::PerformWrite(u16 address, u8 value)
}
case 0x6000:
{
Log("--> ** Attempting to write on non usable address %X %X", address, value);
Log("--> ** Attempting to write on invalid address %X %X", address, value);
break;
}
case 0xA000:
Expand Down Expand Up @@ -140,6 +140,7 @@ void MBC5MemoryRule::Reset(bool bCGB)
void MBC5MemoryRule::SaveRam(std::ofstream & file)
{
Log("MBC5MemoryRule save RAM...");
Log("MBC5MemoryRule saving %d banks...", m_pCartridge->GetRAMBankCount());

s32 ramSize = m_pCartridge->GetRAMBankCount() * 0x2000;

Expand All @@ -155,6 +156,7 @@ void MBC5MemoryRule::SaveRam(std::ofstream & file)
bool MBC5MemoryRule::LoadRam(std::ifstream & file, s32 fileSize)
{
Log("MBC5MemoryRule load RAM...");
Log("MBC5MemoryRule loading %d banks...", m_pCartridge->GetRAMBankCount());

s32 ramSize = m_pCartridge->GetRAMBankCount() * 0x2000;

Expand Down

0 comments on commit 7c79515

Please sign in to comment.