GB MBC: Ensure SRAM size is properly updated if GBMBCInit is called again
This commit is contained in:
parent
84704502bd
commit
50a314913f
@ -87,6 +87,7 @@ static void GBInit(void* cpu, struct mCPUComponent* component) {
|
|||||||
gb->isPristine = false;
|
gb->isPristine = false;
|
||||||
gb->pristineRomSize = 0;
|
gb->pristineRomSize = 0;
|
||||||
gb->yankedRomSize = 0;
|
gb->yankedRomSize = 0;
|
||||||
|
gb->sramSize = 0;
|
||||||
|
|
||||||
memset(&gb->gbx, 0, sizeof(gb->gbx));
|
memset(&gb->gbx, 0, sizeof(gb->gbx));
|
||||||
|
|
||||||
|
35
src/gb/mbc.c
35
src/gb/mbc.c
@ -274,6 +274,7 @@ void GBMBCSwitchSramHalfBank(struct GB* gb, int half, int bank) {
|
|||||||
|
|
||||||
void GBMBCInit(struct GB* gb) {
|
void GBMBCInit(struct GB* gb) {
|
||||||
const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
|
const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
|
||||||
|
size_t sramSize = 0;
|
||||||
if (gb->memory.rom && gb->memory.romSize) {
|
if (gb->memory.rom && gb->memory.romSize) {
|
||||||
if (gb->memory.romSize >= 0x8000) {
|
if (gb->memory.romSize >= 0x8000) {
|
||||||
const struct GBCartridge* cartFooter = (const struct GBCartridge*) &gb->memory.rom[gb->memory.romSize - 0x7F00];
|
const struct GBCartridge* cartFooter = (const struct GBCartridge*) &gb->memory.rom[gb->memory.romSize - 0x7F00];
|
||||||
@ -282,25 +283,25 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gb->gbx.romSize) {
|
if (gb->gbx.romSize) {
|
||||||
gb->sramSize = gb->gbx.ramSize;
|
sramSize = gb->gbx.ramSize;
|
||||||
gb->memory.mbcType = gb->gbx.mbc;
|
gb->memory.mbcType = gb->gbx.mbc;
|
||||||
} else {
|
} else {
|
||||||
switch (cart->ramSize) {
|
switch (cart->ramSize) {
|
||||||
case 0:
|
case 0:
|
||||||
gb->sramSize = 0;
|
sramSize = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 2:
|
case 2:
|
||||||
gb->sramSize = 0x2000;
|
sramSize = 0x2000;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
gb->sramSize = 0x8000;
|
sramSize = 0x8000;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
gb->sramSize = 0x20000;
|
sramSize = 0x20000;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
gb->sramSize = 0x10000;
|
sramSize = 0x10000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,7 +400,7 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
gb->memory.mbcWrite = _GBMBC2;
|
gb->memory.mbcWrite = _GBMBC2;
|
||||||
gb->memory.mbcRead = _GBMBC2Read;
|
gb->memory.mbcRead = _GBMBC2Read;
|
||||||
gb->memory.directSramAccess = false;
|
gb->memory.directSramAccess = false;
|
||||||
gb->sramSize = 0x100;
|
sramSize = 0x100;
|
||||||
break;
|
break;
|
||||||
case GB_MBC3:
|
case GB_MBC3:
|
||||||
gb->memory.mbcWrite = _GBMBC3;
|
gb->memory.mbcWrite = _GBMBC3;
|
||||||
@ -414,15 +415,15 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
gb->memory.mbcWrite = _GBMBC6;
|
gb->memory.mbcWrite = _GBMBC6;
|
||||||
gb->memory.mbcRead = _GBMBC6Read;
|
gb->memory.mbcRead = _GBMBC6Read;
|
||||||
gb->memory.directSramAccess = false;
|
gb->memory.directSramAccess = false;
|
||||||
if (!gb->sramSize) {
|
if (!sramSize) {
|
||||||
gb->sramSize = GB_SIZE_EXTERNAL_RAM; // Force minimum size for convenience
|
sramSize = GB_SIZE_EXTERNAL_RAM; // Force minimum size for convenience
|
||||||
}
|
}
|
||||||
gb->sramSize += GB_SIZE_MBC6_FLASH; // Flash is concatenated at the end
|
sramSize += GB_SIZE_MBC6_FLASH; // Flash is concatenated at the end
|
||||||
break;
|
break;
|
||||||
case GB_MBC7:
|
case GB_MBC7:
|
||||||
gb->memory.mbcWrite = _GBMBC7;
|
gb->memory.mbcWrite = _GBMBC7;
|
||||||
gb->memory.mbcRead = _GBMBC7Read;
|
gb->memory.mbcRead = _GBMBC7Read;
|
||||||
gb->sramSize = 0x100;
|
sramSize = 0x100;
|
||||||
break;
|
break;
|
||||||
case GB_MMM01:
|
case GB_MMM01:
|
||||||
gb->memory.mbcWrite = _GBMMM01;
|
gb->memory.mbcWrite = _GBMMM01;
|
||||||
@ -440,7 +441,7 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
gb->memory.mbcState.tama5.rtcAlarmPage[GBTAMA6_RTC_PAGE] = 1;
|
gb->memory.mbcState.tama5.rtcAlarmPage[GBTAMA6_RTC_PAGE] = 1;
|
||||||
gb->memory.mbcState.tama5.rtcFreePage0[GBTAMA6_RTC_PAGE] = 2;
|
gb->memory.mbcState.tama5.rtcFreePage0[GBTAMA6_RTC_PAGE] = 2;
|
||||||
gb->memory.mbcState.tama5.rtcFreePage1[GBTAMA6_RTC_PAGE] = 3;
|
gb->memory.mbcState.tama5.rtcFreePage1[GBTAMA6_RTC_PAGE] = 3;
|
||||||
gb->sramSize = 0x20;
|
sramSize = 0x20;
|
||||||
break;
|
break;
|
||||||
case GB_MBC3_RTC:
|
case GB_MBC3_RTC:
|
||||||
memset(gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
memset(gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
||||||
@ -452,8 +453,8 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
case GB_POCKETCAM:
|
case GB_POCKETCAM:
|
||||||
gb->memory.mbcWrite = _GBPocketCam;
|
gb->memory.mbcWrite = _GBPocketCam;
|
||||||
gb->memory.mbcRead = _GBPocketCamRead;
|
gb->memory.mbcRead = _GBPocketCamRead;
|
||||||
if (!gb->sramSize) {
|
if (!sramSize) {
|
||||||
gb->sramSize = GB_SIZE_EXTERNAL_RAM; // Force minimum size for convenience
|
sramSize = GB_SIZE_EXTERNAL_RAM; // Force minimum size for convenience
|
||||||
}
|
}
|
||||||
if (gb->memory.cam && gb->memory.cam->startRequestImage) {
|
if (gb->memory.cam && gb->memory.cam->startRequestImage) {
|
||||||
gb->memory.cam->startRequestImage(gb->memory.cam, GBCAM_WIDTH, GBCAM_HEIGHT, mCOLOR_ANY);
|
gb->memory.cam->startRequestImage(gb->memory.cam, GBCAM_WIDTH, GBCAM_HEIGHT, mCOLOR_ANY);
|
||||||
@ -508,7 +509,7 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
gb->memory.mbcReadBank1 = true;
|
gb->memory.mbcReadBank1 = true;
|
||||||
gb->memory.mbcReadHigh = true;
|
gb->memory.mbcReadHigh = true;
|
||||||
gb->memory.mbcWriteHigh = true;
|
gb->memory.mbcWriteHigh = true;
|
||||||
if (gb->sramSize) {
|
if (sramSize) {
|
||||||
gb->memory.sramAccess = true;
|
gb->memory.sramAccess = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -516,7 +517,7 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
gb->memory.mbcWrite = _GBSintax;
|
gb->memory.mbcWrite = _GBSintax;
|
||||||
gb->memory.mbcRead = _GBSintaxRead;
|
gb->memory.mbcRead = _GBSintaxRead;
|
||||||
gb->memory.mbcReadBank1 = true;
|
gb->memory.mbcReadBank1 = true;
|
||||||
if (gb->sramSize) {
|
if (sramSize) {
|
||||||
gb->memory.sramAccess = true;
|
gb->memory.sramAccess = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -539,7 +540,7 @@ void GBMBCInit(struct GB* gb) {
|
|||||||
}
|
}
|
||||||
memset(&gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
memset(&gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));
|
||||||
|
|
||||||
GBResizeSram(gb, gb->sramSize);
|
GBResizeSram(gb, sramSize);
|
||||||
|
|
||||||
if (gb->memory.mbcType == GB_MBC3_RTC) {
|
if (gb->memory.mbcType == GB_MBC3_RTC) {
|
||||||
GBMBCRTCRead(gb);
|
GBMBCRTCRead(gb);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user