GB MBC: Fix MBC6 bank switching

This commit is contained in:
Vicki Pfau 2018-04-17 22:44:37 -07:00
parent 84b79b1ba8
commit f23f221d49
2 changed files with 21 additions and 4 deletions

View File

@ -531,7 +531,7 @@ void _GBMBC5(struct GB* gb, uint16_t address, uint8_t value) {
void _GBMBC6(struct GB* gb, uint16_t address, uint8_t value) {
struct GBMemory* memory = &gb->memory;
int bank = value & 0x7F;
int bank = value;
switch (address >> 10) {
case 0:
switch (value) {
@ -548,9 +548,11 @@ void _GBMBC6(struct GB* gb, uint16_t address, uint8_t value) {
break;
}
break;
case 0x8:
case 0x9:
GBMBCSwitchHalfBank(gb, 0, bank);
break;
case 0xC:
case 0xD:
GBMBCSwitchHalfBank(gb, 1, bank);
break;

View File

@ -73,9 +73,20 @@ static void GBSetActiveRegion(struct LR35902Core* cpu, uint16_t address) {
case GB_REGION_CART_BANK1 + 2:
case GB_REGION_CART_BANK1 + 3:
cpu->memory.cpuLoad8 = GBFastLoad8;
cpu->memory.activeRegion = memory->romBank;
cpu->memory.activeRegionEnd = GB_BASE_VRAM;
cpu->memory.activeMask = GB_SIZE_CART_BANK0 - 1;
if (gb->memory.mbcType != GB_MBC6) {
cpu->memory.activeRegion = memory->romBank;
cpu->memory.activeRegionEnd = GB_BASE_VRAM;
cpu->memory.activeMask = GB_SIZE_CART_BANK0 - 1;
} else {
cpu->memory.activeMask = GB_SIZE_CART_HALFBANK - 1;
if (address & 0x2000) {
cpu->memory.activeRegion = memory->mbcState.mbc6.romBank1;
cpu->memory.activeRegionEnd = GB_BASE_VRAM;
} else {
cpu->memory.activeRegion = memory->romBank;
cpu->memory.activeRegionEnd = GB_BASE_CART_BANK1 + 0x2000;
}
}
break;
default:
cpu->memory.cpuLoad8 = GBLoad8;
@ -169,6 +180,10 @@ void GBMemoryReset(struct GB* gb) {
case GB_MBC1:
gb->memory.mbcState.mbc1.mode = 0;
break;
case GB_MBC6:
GBMBCSwitchHalfBank(gb, 0, 2);
GBMBCSwitchHalfBank(gb, 1, 3);
break;
default:
memset(&gb->memory.mbcState, 0, sizeof(gb->memory.mbcState));
}