From 014a6524220a7dfa4ffb96d6780371544facc51e Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 18 Mar 2018 16:06:48 -0400 Subject: [PATCH] GBHawk: Implement SaveRam fixes 1147 --- .../Nintendo/GBHawk/GBHawk.IMemoryDomains.cs | 8 +- .../Nintendo/GBHawk/GBHawk.ISaveRam.cs | 7 +- .../Consoles/Nintendo/GBHawk/GBHawk.cs | 75 ++++++++----------- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs index 375abbd592..b336e091fe 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IMemoryDomains.cs @@ -41,9 +41,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk MemoryDomain.Endian.Little, addr => _rom[addr], (addr, value) => ZP_RAM[addr] = value, - 1) + 1), }; + if (cart_RAM != null) + { + var CartRam = new MemoryDomainByteArray("Cart RAM", MemoryDomain.Endian.Little, cart_RAM, true, 1); + domains.Add(CartRam); + } + MemoryDomains = new MemoryDomainList(domains); (ServiceProvider as BasicServiceProvider).Register(MemoryDomains); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISaveRam.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISaveRam.cs index d1fa270c30..8e9c0ddbe8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISaveRam.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISaveRam.cs @@ -7,19 +7,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { public byte[] CloneSaveRam() { - return (byte[])_sram.Clone(); + return (byte[])cart_RAM.Clone(); } public void StoreSaveRam(byte[] data) { - Buffer.BlockCopy(data, 0, _sram, 0, data.Length); + Buffer.BlockCopy(data, 0, cart_RAM, 0, data.Length); + Console.WriteLine("loading SRAM here"); } public bool SaveRamModified { get { - return false; + return has_bat & _syncSettings.Use_SRAM; } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index 02660d1f7f..1caa711336 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -44,11 +44,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public byte[] OAM = new byte[0xA0]; public readonly byte[] _rom; - public readonly byte[] _bios; - public readonly byte[] _sram = new byte[2048]; + public readonly byte[] _bios; public readonly byte[] header = new byte[0x50]; public byte[] cart_RAM; + public bool has_bat; private int _frame = 0; @@ -250,39 +250,39 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk switch (header[0x47]) { - case 0x0: mapper = new MapperDefault(); mppr = "NROM"; break; - case 0x1: mapper = new MapperMBC1(); mppr = "MBC1"; break; - case 0x2: mapper = new MapperMBC1(); mppr = "MBC1"; break; - case 0x3: mapper = new MapperMBC1(); mppr = "MBC1"; break; - case 0x5: mapper = new MapperMBC2(); mppr = "MBC2"; break; - case 0x6: mapper = new MapperMBC2(); mppr = "MBC2"; break; - case 0x8: mapper = new MapperDefault(); mppr = "NROM"; break; - case 0x9: mapper = new MapperDefault(); mppr = "NROM"; break; - case 0xB: mapper = new MapperMMM01(); mppr = "MMM01"; break; - case 0xC: mapper = new MapperMMM01(); mppr = "MMM01"; break; - case 0xD: mapper = new MapperMMM01(); mppr = "MMM01"; break; - case 0xF: mapper = new MapperMBC3(); mppr = "MBC3"; break; - case 0x10: mapper = new MapperMBC3(); mppr = "MBC3"; break; - case 0x11: mapper = new MapperMBC3(); mppr = "MBC3"; break; - case 0x12: mapper = new MapperMBC3(); mppr = "MBC3"; break; - case 0x13: mapper = new MapperMBC3(); mppr = "MBC3"; break; - case 0x19: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x1A: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x1B: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x1C: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x1D: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x1E: mapper = new MapperMBC5(); mppr = "MBC5"; break; - case 0x20: mapper = new MapperMBC6(); mppr = "MBC6"; break; - case 0x22: mapper = new MapperMBC7(); mppr = "MBC7"; break; - case 0xFC: mapper = new MapperCamera(); mppr = "CAM"; break; - case 0xFD: mapper = new MapperTAMA5(); mppr = "TAMA5"; break; - case 0xFE: mapper = new MapperHuC3(); mppr = "HuC3"; break; - case 0xFF: mapper = new MapperHuC1(); mppr = "HuC1"; break; + case 0x0: mapper = new MapperDefault(); mppr = "NROM"; break; + case 0x1: mapper = new MapperMBC1(); mppr = "MBC1"; break; + case 0x2: mapper = new MapperMBC1(); mppr = "MBC1"; break; + case 0x3: mapper = new MapperMBC1(); mppr = "MBC1"; has_bat = true; break; + case 0x5: mapper = new MapperMBC2(); mppr = "MBC2"; break; + case 0x6: mapper = new MapperMBC2(); mppr = "MBC2"; has_bat = true; break; + case 0x8: mapper = new MapperDefault(); mppr = "NROM"; break; + case 0x9: mapper = new MapperDefault(); mppr = "NROM"; has_bat = true; break; + case 0xB: mapper = new MapperMMM01(); mppr = "MMM01"; break; + case 0xC: mapper = new MapperMMM01(); mppr = "MMM01"; break; + case 0xD: mapper = new MapperMMM01(); mppr = "MMM01"; has_bat = true; break; + case 0xF: mapper = new MapperMBC3(); mppr = "MBC3"; has_bat = true; break; + case 0x10: mapper = new MapperMBC3(); mppr = "MBC3"; has_bat = true; break; + case 0x11: mapper = new MapperMBC3(); mppr = "MBC3"; break; + case 0x12: mapper = new MapperMBC3(); mppr = "MBC3"; break; + case 0x13: mapper = new MapperMBC3(); mppr = "MBC3"; has_bat = true; break; + case 0x19: mapper = new MapperMBC5(); mppr = "MBC5"; break; + case 0x1A: mapper = new MapperMBC5(); mppr = "MBC5"; has_bat = true; break; + case 0x1B: mapper = new MapperMBC5(); mppr = "MBC5"; break; + case 0x1C: mapper = new MapperMBC5(); mppr = "MBC5"; break; + case 0x1D: mapper = new MapperMBC5(); mppr = "MBC5"; break; + case 0x1E: mapper = new MapperMBC5(); mppr = "MBC5"; has_bat = true; break; + case 0x20: mapper = new MapperMBC6(); mppr = "MBC6"; break; + case 0x22: mapper = new MapperMBC7(); mppr = "MBC7"; has_bat = true; break; + case 0xFC: mapper = new MapperCamera(); mppr = "CAM"; break; + case 0xFD: mapper = new MapperTAMA5(); mppr = "TAMA5"; break; + case 0xFE: mapper = new MapperHuC3(); mppr = "HuC3"; break; + case 0xFF: mapper = new MapperHuC1(); mppr = "HuC1"; break; // Bootleg mappers // NOTE: Sachen mapper selection does not account for scrambling, so if another bootleg mapper // identifies itself as 0x31, this will need to be modified - case 0x31: mapper = new MapperSachen2(); mppr = "Schn2"; break; + case 0x31: mapper = new MapperSachen2(); mppr = "Schn2"; break; case 0x4: case 0x7: @@ -299,8 +299,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // mapper not implemented Console.WriteLine(header[0x47]); throw new Exception("Mapper not implemented"); - break; - } // special case for multi cart mappers @@ -357,16 +355,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Console.Write("RAM: "); Console.WriteLine(cart_RAM.Length); - if (_syncSettings.Use_SRAM) + for (int i = 0; i < cart_RAM.Length; i++) { - // load cartRAM here - } - else - { - for (int i = 0; i < cart_RAM.Length; i++) - { - cart_RAM[i] = 0xFF; - } + cart_RAM[i] = 0xFF; } }