From 8beb0a9ae5157e2604686ffea003aaf7fd00f9d2 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 7 Oct 2019 20:04:57 -0400 Subject: [PATCH] GBHawk: MBC3: fix RTC --- .../Nintendo/GBHawk/Mappers/Mapper_MBC3.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs index 378d156429..2cf79faa8c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs @@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (RAM_enable) { - if ((Core.cart_RAM != null) && (RAM_bank < 3)) + if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) { if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) { @@ -73,18 +73,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - if ((RAM_bank >= 8) && (RAM_bank < 0xC)) + if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) { return RTC_regs_latch[RAM_bank - 8]; } else { - return 0xFF; + return 0x0; } } else { - return 0xFF; + return 0x0; } } } @@ -103,7 +103,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (RAM_enable) { - if ((Core.cart_RAM != null) && (RAM_bank < 3)) + if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) { if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) { @@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - if ((RAM_bank >= 8) && (RAM_bank < 0xC)) + if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) { return; } @@ -141,7 +141,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (addr < 0x8000) { if (addr < 0x2000) - { + { RAM_enable = ((value & 0xA) == 0xA); } else if (addr < 0x4000) @@ -156,7 +156,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else if (addr < 0x6000) { - RAM_bank = value & 3; + RAM_bank = value; } else { @@ -175,17 +175,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (RAM_enable) { - if ((Core.cart_RAM != null) && (RAM_bank <= 3)) + if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) { if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) { Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000] = value; } } - else if ((RAM_bank >= 8) && (RAM_bank < 0xC)) + else if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) { RTC_regs[RAM_bank - 8] = value; + RTC_low_clock = RTC_timer = 0; + halt = (RTC_regs[4] & 0x40) > 0; } } @@ -219,6 +221,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk RTC_low_clock = 0; RTC_regs[0]++; + if (RTC_regs[0] > 59) { RTC_regs[0] = 0; @@ -255,7 +258,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override void SyncState(Serializer ser) { ser.Sync(nameof(ROM_bank), ref ROM_bank);