Support multiple RAM sizes for MBC7

We rely on the rom size in the cartridge header as a proxy for the RAM
size. Only 3 cartridges exist that use MBC7, Korokoro Kirby / Kirby
Tilt'n'Rumble and Command Master. Both versions of Kirby use a 256 bytes
EEPROM while Command Master uses a 512 bytes EEPROM. There does not seem
to be any other way to reliably get the EEPROM size for MBC7 cartridges.
This commit is contained in:
Fabrice de Gans 2023-04-13 14:14:06 -07:00 committed by Fabrice de Gans
parent 75b79d91f1
commit 0e29be8735
2 changed files with 14 additions and 16 deletions

View File

@ -58,10 +58,6 @@ struct VBamIoVec {
};
std::vector<VBamIoVec> g_vbamIoVecs;
// TODO: This is set to 256 bytes for compatibility with older versions. We
// should figure out how to actually get the MBC7 RAM size.
static constexpr size_t kMbc7RamSizeForSaving = k256B;
void ResetMBC3RTC() {
time(&gbDataMBC3.mapperLastTime);
struct tm* lt;
@ -472,17 +468,12 @@ bool gbInitializeRom(size_t romSize) {
HUC3_RTC_DATA_SIZE, -4,
&ResetHuc3RTC});
break;
case gbCartData::MapperType::kMbc7:
// For MBC7, we don't save the RAM data from the same location.
// TODO: Unify handling and find how to get the MBC7 RAM size.
g_vbamIoVecs.clear();
g_vbamIoVecs.push_back({&gbMemory[0xa000], kMbc7RamSizeForSaving});
break;
case gbCartData::MapperType::kNone:
case gbCartData::MapperType::kMbc1:
case gbCartData::MapperType::kMbc2:
case gbCartData::MapperType::kMbc5:
case gbCartData::MapperType::kMbc6:
case gbCartData::MapperType::kMbc7:
case gbCartData::MapperType::kHuC1:
case gbCartData::MapperType::kMmm01:
case gbCartData::MapperType::kPocketCamera:
@ -3181,13 +3172,12 @@ bool gbReadGSASnapshot(const char* fileName)
case gbCartData::MapperType::kMbc1:
case gbCartData::MapperType::kMbc3:
case gbCartData::MapperType::kMbc5:
case gbCartData::MapperType::kMbc7:
case gbCartData::MapperType::kHuC1:
FREAD_UNCHECKED(gbRam, 1, g_gbCartData.ram_size(), file);
break;
case gbCartData::MapperType::kMbc2:
case gbCartData::MapperType::kMbc7:
// TODO: Figure out how to get the RAM size for MBC7.
FREAD_UNCHECKED(&gbMemory[0xa000], 1, kMbc7RamSizeForSaving, file);
FREAD_UNCHECKED(&gbMemory[0xa000], 1, k256B, file);
break;
default:
systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE,

View File

@ -356,10 +356,18 @@ gbCartData::gbCartData(const uint8_t* romData, size_t romDataSize) {
break;
case 0x22:
// MBC7 header does not specify a RAM size so set it here.
// TODO: Figure out how to get the RAM size for MBC7. It is either
// 256 or 512 Bytes.
mapper_type_ = MapperType::kMbc7;
if (header->rom_size == 0x05) {
// Kirby Tilt 'n' Tumble / Korokoro Kirby.
ram_size_ = k256B;
} else if (header->rom_size == 0x06) {
// Command Master.
ram_size_ = k512B;
} else {
// Not a licensed MBC7 cart. Default to the larger size and hope
// for the best.
ram_size_ = k512B;
}
skip_ram = true;
has_battery_ = true;
has_rumble_ = true;