diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 5071b676..734b4110 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -58,6 +58,10 @@ struct VBamIoVec { }; std::vector 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; @@ -470,10 +474,9 @@ bool gbInitializeRom(size_t romSize) { break; case gbCartData::MapperType::kMbc7: // For MBC7, we don't save the RAM data from the same location. - // TODO: Unify handling. + // TODO: Unify handling and find how to get the MBC7 RAM size. g_vbamIoVecs.clear(); - g_vbamIoVecs.push_back({&gbMemory[0xa000], - g_gbCartData.ram_size()}); + g_vbamIoVecs.push_back({&gbMemory[0xa000], kMbc7RamSizeForSaving}); break; case gbCartData::MapperType::kNone: case gbCartData::MapperType::kMbc1: @@ -3183,7 +3186,8 @@ bool gbReadGSASnapshot(const char* fileName) break; case gbCartData::MapperType::kMbc2: case gbCartData::MapperType::kMbc7: - FREAD_UNCHECKED(&gbMemory[0xa000], 1, 256, file); + // TODO: Figure out how to get the RAM size for MBC7. + FREAD_UNCHECKED(&gbMemory[0xa000], 1, kMbc7RamSizeForSaving, file); break; default: systemMessage(MSG_UNSUPPORTED_SNAPSHOT_FILE, @@ -4951,12 +4955,9 @@ bool gbApplyPatch(const char* patchName) { return false; } - size_t newSize = size; - if (newSize != g_gbCartData.rom_size()) { - return gbInitializeRom(newSize); - } - - return true; + // We should re-parse the header every time in case a patch has changed the + // ROM header. + return gbInitializeRom(size); } #endif // __LIBRETRO__ diff --git a/src/gb/gbCartData.cpp b/src/gb/gbCartData.cpp index 6b247877..bf44c4cf 100644 --- a/src/gb/gbCartData.cpp +++ b/src/gb/gbCartData.cpp @@ -356,8 +356,10 @@ 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; - ram_size_ = k256B; + ram_size_ = k512B; skip_ram = true; has_battery_ = true; has_rumble_ = true;