Improved MBC1 emulation. Fixed incorrect error messages.

This commit is contained in:
Lior Halphon 2017-06-19 19:46:09 +03:00
parent abf7efcc5a
commit aefca34b39
2 changed files with 6 additions and 5 deletions

View File

@ -194,7 +194,7 @@ int GB_save_battery(GB_gameboy_t *gb, const char *path)
if (gb->mbc_ram_size == 0 && !gb->cartridge_type->has_rtc) return 0; /* Claims to have battery, but has no RAM or RTC */ if (gb->mbc_ram_size == 0 && !gb->cartridge_type->has_rtc) return 0; /* Claims to have battery, but has no RAM or RTC */
FILE *f = fopen(path, "wb"); FILE *f = fopen(path, "wb");
if (!f) { if (!f) {
GB_log(gb, "Could not open save state: %s.\n", strerror(errno)); GB_log(gb, "Could not open battery save: %s.\n", strerror(errno));
return errno; return errno;
} }

View File

@ -46,12 +46,12 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
switch (gb->cartridge_type->mbc_type) { switch (gb->cartridge_type->mbc_type) {
case GB_NO_MBC: return; case GB_NO_MBC: return;
case GB_MBC1: case GB_MBC1:
/* Todo: some obscure behaviors of MBC1 are not supported. See http://forums.nesdev.com/viewtopic.php?f=20&t=14099 */
if (gb->mbc1.mode == 0) { if (gb->mbc1.mode == 0) {
switch (gb->mbc1_wiring) { switch (gb->mbc1_wiring) {
case GB_STANDARD_MBC1_WIRING: case GB_STANDARD_MBC1_WIRING:
gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5); gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5);
gb->mbc_ram_bank = 0; gb->mbc_ram_bank = 0;
gb->mbc_rom0_bank = 0;
break; break;
case GB_MBC1M_WIRING: case GB_MBC1M_WIRING:
@ -63,8 +63,9 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
else { else {
switch (gb->mbc1_wiring) { switch (gb->mbc1_wiring) {
case GB_STANDARD_MBC1_WIRING: case GB_STANDARD_MBC1_WIRING:
gb->mbc_rom_bank = gb->mbc1.bank_low; gb->mbc_rom_bank = gb->mbc1.bank_low | (gb->mbc1.bank_high << 5);
gb->mbc_ram_bank = gb->mbc1.bank_high; gb->mbc_ram_bank = gb->mbc1.bank_high;
gb->mbc_rom0_bank = gb->mbc1.bank_high << 5;
break; break;
case GB_MBC1M_WIRING: case GB_MBC1M_WIRING:
@ -100,8 +101,8 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb)
gb->mbc_ram_bank = gb->huc3.ram_bank; gb->mbc_ram_bank = gb->huc3.ram_bank;
break; break;
} }
if (gb->mbc_rom_bank == 0 && gb->cartridge_type->mbc_type != GB_MBC5 && gb->cartridge_type->mbc_type != GB_HUC3) { if ((gb->mbc_rom_bank & 0x1F) == 0 && gb->cartridge_type->mbc_type != GB_MBC5 && gb->cartridge_type->mbc_type != GB_HUC3) {
gb->mbc_rom_bank = 1; gb->mbc_rom_bank++;
} }
} }