From f54a36ab9a72efd801cfef3fe0c86558a727adc5 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 20 Apr 2020 18:49:55 -0400 Subject: [PATCH] GBHawk: Fix cart RAM domain --- .../Nintendo/GBHawk/GBHawk.IMemoryDomains.cs | 8 +++++- .../Nintendo/GBHawk/GBHawk.IStatable.cs | 3 ++- .../Nintendo/GBHawk/Mappers/Mapper_MBC3.cs | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs index 9dc07e519d..b194879498 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs @@ -57,7 +57,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (cart_RAM != null) { - var CartRam = new MemoryDomainByteArray("CartRAM", MemoryDomain.Endian.Little, cart_RAM, true, 1); + var CartRam = new MemoryDomainDelegate( + "CartRAM", + cart_RAM.Length, + MemoryDomain.Endian.Little, + addr => cart_RAM[addr], + (addr, value) => cart_RAM[addr] = value, + 1); domains.Add(CartRam); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs index 1ccff5eea4..803cd6fec9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using BizHawk.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBHawk 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 a0bd65fb91..5651ff7a5f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs @@ -136,6 +136,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return ReadMemoryLow(addr); } + public override byte PeekMemoryHigh(ushort addr) + { + + if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) + { + if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) + { + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; + } + else + { + return 0xFF; + } + } + + if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) + { + //Console.WriteLine("reg: " + (RAM_bank - 8) + " value: " + RTC_regs_latch[RAM_bank - 8] + " cpu: " + Core.cpu.TotalExecutedCycles); + return RTC_regs_latch[RAM_bank - 8]; + } + else + { + return 0x0; + } + } + public override void WriteMemory(ushort addr, byte value) { if (addr < 0x8000)