Improved MMM01 emulation, fixes #447

This commit is contained in:
Lior Halphon 2022-07-02 21:03:26 +03:00
parent 887a8104f5
commit 7071032288
2 changed files with 10 additions and 10 deletions

View File

@ -107,10 +107,10 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
if (gb->mmm01.locked) {
if (gb->mmm01.multiplex_mode) {
gb->mbc_rom0_bank = (gb->mmm01.rom_bank_low & (gb->mmm01.rom_bank_mask << 1)) |
((gb->mmm01.rom_bank_low & (gb->mmm01.mbc1_mode? -1 : gb->mmm01.ram_bank_mask)) << 5) |
((gb->mmm01.mbc1_mode? 0 : gb->mmm01.ram_bank_low) << 5) |
(gb->mmm01.rom_bank_high << 7);
gb->mbc_rom_bank = gb->mmm01.rom_bank_low |
(gb->mmm01.rom_bank_low << 5) |
(gb->mmm01.ram_bank_low << 5) |
(gb->mmm01.rom_bank_high << 7);
gb->mbc_ram_bank = gb->mmm01.rom_bank_mid | (gb->mmm01.ram_bank_high << 2);
}
@ -125,7 +125,7 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
gb->mbc_ram_bank = gb->mmm01.ram_bank_low | (gb->mmm01.ram_bank_high << 2);
}
else {
gb->mbc_ram_bank = (gb->mmm01.ram_bank_low & gb->mmm01.ram_bank_mask) | (gb->mmm01.ram_bank_high << 2);
gb->mbc_ram_bank = gb->mmm01.ram_bank_low | (gb->mmm01.ram_bank_high << 2);
}
}
if (gb->mbc_rom_bank == gb->mbc_rom0_bank) {
@ -256,6 +256,7 @@ void GB_reset_mbc(GB_gameboy_t *gb)
if (gb->cartridge_type->mbc_type == GB_MMM01) {
gb->mbc_rom_bank = -1;
gb->mbc_rom0_bank = -2;
gb->mmm01.ram_bank_mask = -1;
}
else if (gb->cartridge_type->mbc_type == GB_MBC5 ||
gb->cartridge_type->mbc_type == GB_CAMERA) {

View File

@ -859,15 +859,12 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
case 0x2000: case 0x3000:
if (!gb->mmm01.locked) {
gb->mmm01.rom_bank_mid = value >> 5;
gb->mmm01.rom_bank_low = value;
}
else {
gb->mmm01.rom_bank_low &= (gb->mmm01.rom_bank_mask << 1);
gb->mmm01.rom_bank_low |= ~(gb->mmm01.rom_bank_mask << 1) & value;
}
break;
case 0x4000: case 0x5000:
gb->mmm01.ram_bank_low = value;
gb->mmm01.ram_bank_low = value | ~gb->mmm01.ram_bank_mask;
if (!gb->mmm01.locked) {
gb->mmm01.ram_bank_high = value >> 2;
gb->mmm01.rom_bank_high = value >> 4;
@ -875,7 +872,9 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
}
break;
case 0x6000: case 0x7000:
gb->mmm01.mbc1_mode = (value & 1) && !gb->mmm01.mbc1_mode_disable;
if (!gb->mmm01.mbc1_mode_disable) {
gb->mmm01.mbc1_mode = (value & 1);
}
if (!gb->mmm01.locked) {
gb->mmm01.rom_bank_mask = value >> 2;
gb->mmm01.multiplex_mode = value & 0x40;