GB Memory: Clean up MBC1

This commit is contained in:
Jeffrey Pfau 2016-02-27 01:12:23 -08:00
parent 878c6b8a2c
commit 93a839f52a
2 changed files with 23 additions and 2 deletions

View File

@ -438,8 +438,8 @@ static void _switchBank(struct GBMemory* memory, int bank) {
size_t bankStart = bank * GB_SIZE_CART_BANK0; size_t bankStart = bank * GB_SIZE_CART_BANK0;
if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) { if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) {
mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank); mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank);
bankStart &= (GB_SIZE_CART_BANK0 - 1); bankStart &= (memory->romSize - 1);
bank /= GB_SIZE_CART_BANK0; bank = bankStart / GB_SIZE_CART_BANK0;
} }
memory->romBank = &memory->rom[bankStart]; memory->romBank = &memory->rom[bankStart];
memory->currentBank = bank; memory->currentBank = bank;
@ -496,6 +496,22 @@ void _GBMBC1(struct GBMemory* memory, uint16_t address, uint8_t value) {
} }
_switchBank(memory, bank | (memory->currentBank & 0x60)); _switchBank(memory, bank | (memory->currentBank & 0x60));
break; break;
case 0x2:
bank &= 3;
if (!memory->mbcState.mbc1.mode) {
_switchBank(memory, (bank << 5) | (memory->currentBank & 0x1F));
} else {
_switchSramBank(memory, bank);
}
break;
case 0x3:
memory->mbcState.mbc1.mode = value & 1;
if (memory->mbcState.mbc1.mode) {
_switchBank(memory, memory->currentBank & 0x1F);
} else {
_switchSramBank(memory, 0);
}
break;
default: default:
// TODO // TODO
mLOG(GB_MBC, STUB, "MBC1 unknown address: %04X:%02X", address, value); mLOG(GB_MBC, STUB, "MBC1 unknown address: %04X:%02X", address, value);

View File

@ -90,6 +90,10 @@ enum GBMBC7MachineState {
GBMBC7_STATE_WRITE = 8, GBMBC7_STATE_WRITE = 8,
}; };
struct GBMBC1State {
int mode;
};
struct GBMBC7State { struct GBMBC7State {
enum GBMBC7MachineState state; enum GBMBC7MachineState state;
uint32_t sr; uint32_t sr;
@ -101,6 +105,7 @@ struct GBMBC7State {
}; };
union GBMBCState { union GBMBCState {
struct GBMBC1State mbc1;
struct GBMBC7State mbc7; struct GBMBC7State mbc7;
}; };