mirror of https://github.com/mgba-emu/mgba.git
GB MBC: Fix initialization and swapping
This commit is contained in:
parent
362c572009
commit
3d77a9d922
19
src/gb/gb.c
19
src/gb/gb.c
|
@ -124,7 +124,7 @@ bool GBLoadROM(struct GB* gb, struct VFile* vf) {
|
|||
gb->memory.romBase = gb->memory.rom;
|
||||
gb->memory.romSize = gb->pristineRomSize;
|
||||
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
|
||||
GBMBCSwitchBank(gb, gb->memory.currentBank);
|
||||
GBMBCInit(gb);
|
||||
|
||||
if (gb->cpu) {
|
||||
struct LR35902Core* cpu = gb->cpu;
|
||||
|
@ -135,12 +135,6 @@ bool GBLoadROM(struct GB* gb, struct VFile* vf) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GBLoadSave(struct GB* gb, struct VFile* vf) {
|
||||
gb->sramVf = vf;
|
||||
gb->sramRealVf = vf;
|
||||
return vf;
|
||||
}
|
||||
|
||||
static void GBSramDeinit(struct GB* gb) {
|
||||
if (gb->sramVf) {
|
||||
gb->sramVf->unmap(gb->sramVf, gb->memory.sram, gb->sramSize);
|
||||
|
@ -154,6 +148,16 @@ static void GBSramDeinit(struct GB* gb) {
|
|||
gb->memory.sram = 0;
|
||||
}
|
||||
|
||||
bool GBLoadSave(struct GB* gb, struct VFile* vf) {
|
||||
GBSramDeinit(gb);
|
||||
gb->sramVf = vf;
|
||||
gb->sramRealVf = vf;
|
||||
if (gb->sramSize) {
|
||||
GBResizeSram(gb, gb->sramSize);
|
||||
}
|
||||
return vf;
|
||||
}
|
||||
|
||||
void GBResizeSram(struct GB* gb, size_t size) {
|
||||
if (gb->memory.sram && size <= gb->sramSize) {
|
||||
return;
|
||||
|
@ -280,6 +284,7 @@ void GBUnloadROM(struct GB* gb) {
|
|||
gb->romVf = NULL;
|
||||
}
|
||||
gb->memory.rom = NULL;
|
||||
gb->memory.mbcType = GB_MBC_AUTODETECT;
|
||||
gb->isPristine = false;
|
||||
|
||||
GBSavedataUnmask(gb);
|
||||
|
|
|
@ -204,6 +204,14 @@ void GBMBCInit(struct GB* gb) {
|
|||
break;
|
||||
}
|
||||
|
||||
gb->memory.currentBank = 1;
|
||||
gb->memory.sramCurrentBank = 0;
|
||||
gb->memory.sramAccess = false;
|
||||
gb->memory.rtcAccess = false;
|
||||
gb->memory.activeRtcReg = 0;
|
||||
gb->memory.rtcLatched = false;
|
||||
memset(&gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
||||
|
||||
GBResizeSram(gb, gb->sramSize);
|
||||
|
||||
if (gb->memory.mbcType == GB_MBC3_RTC) {
|
||||
|
|
|
@ -158,12 +158,6 @@ void GBMemoryReset(struct GB* gb) {
|
|||
gb->memory.hdmaEvent.callback = _GBMemoryHDMAService;
|
||||
gb->memory.hdmaEvent.priority = 0x41;
|
||||
|
||||
gb->memory.sramAccess = false;
|
||||
gb->memory.rtcAccess = false;
|
||||
gb->memory.activeRtcReg = 0;
|
||||
gb->memory.rtcLatched = false;
|
||||
memset(&gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
||||
|
||||
memset(&gb->memory.hram, 0, sizeof(gb->memory.hram));
|
||||
switch (gb->memory.mbcType) {
|
||||
case GB_MBC1:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <mgba/internal/gb/overrides.h>
|
||||
|
||||
#include <mgba/internal/gb/gb.h>
|
||||
#include <mgba/internal/gb/mbc.h>
|
||||
|
||||
#include <mgba-util/configuration.h>
|
||||
#include <mgba-util/crc32.h>
|
||||
|
@ -102,6 +103,7 @@ void GBOverrideApply(struct GB* gb, const struct GBCartridgeOverride* override)
|
|||
|
||||
if (override->mbc != GB_MBC_AUTODETECT) {
|
||||
gb->memory.mbcType = override->mbc;
|
||||
GBMBCInit(gb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue