From d5c9f320956f433bdd41c2e6b0977c92689279a9 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 15 Sep 2019 16:19:48 -0400 Subject: [PATCH] GB3x: update saveram and memory domains --- .../GBHawkLink3x.IMemoryDomains.cs | 53 +++++++++++++++++++ .../GBHawkLink3x/GBHawkLink3x.ISaveRam.cs | 44 ++++++++++----- 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IMemoryDomains.cs index 33b36df759..940f1524e4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IMemoryDomains.cs @@ -20,6 +20,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x addr => L.RAM[addr], (addr, value) => L.RAM[addr] = value, 1), + new MemoryDomainDelegate( + "Main RAM C", + C.RAM.Length, + MemoryDomain.Endian.Little, + addr => C.RAM[addr], + (addr, value) => C.RAM[addr] = value, + 1), new MemoryDomainDelegate( "Main RAM R", R.RAM.Length, @@ -34,6 +41,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x addr => L.ZP_RAM[addr], (addr, value) => L.ZP_RAM[addr] = value, 1), + new MemoryDomainDelegate( + "Zero Page RAM C", + C.ZP_RAM.Length, + MemoryDomain.Endian.Little, + addr => C.ZP_RAM[addr], + (addr, value) => C.ZP_RAM[addr] = value, + 1), new MemoryDomainDelegate( "Zero Page RAM R", R.ZP_RAM.Length, @@ -48,6 +62,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x addr => PeekSystemBusL(addr), (addr, value) => PokeSystemBusL(addr, value), 1), + new MemoryDomainDelegate( + "System Bus C", + 0X10000, + MemoryDomain.Endian.Little, + addr => PeekSystemBusC(addr), + (addr, value) => PokeSystemBusC(addr, value), + 1), new MemoryDomainDelegate( "System Bus R", 0X10000, @@ -62,6 +83,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x addr => L._rom[addr], (addr, value) => L._rom[addr] = value, 1), + new MemoryDomainDelegate( + "ROM C", + C._rom.Length, + MemoryDomain.Endian.Little, + addr => C._rom[addr], + (addr, value) => C._rom[addr] = value, + 1), new MemoryDomainDelegate( "ROM R", R._rom.Length, @@ -76,6 +104,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x addr => L.VRAM[addr], (addr, value) => L.VRAM[addr] = value, 1), + new MemoryDomainDelegate( + "VRAM C", + C.VRAM.Length, + MemoryDomain.Endian.Little, + addr => C.VRAM[addr], + (addr, value) => C.VRAM[addr] = value, + 1), new MemoryDomainDelegate( "VRAM R", R.VRAM.Length, @@ -91,6 +126,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x domains.Add(CartRamL); } + if (C.cart_RAM != null) + { + var CartRamC = new MemoryDomainByteArray("Cart RAM C", MemoryDomain.Endian.Little, C.cart_RAM, true, 1); + domains.Add(CartRamC); + } + if (R.cart_RAM != null) { var CartRamR = new MemoryDomainByteArray("Cart RAM R", MemoryDomain.Endian.Little, R.cart_RAM, true, 1); @@ -107,6 +148,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x return L.PeekMemory(addr2); } + private byte PeekSystemBusC(long addr) + { + ushort addr2 = (ushort)(addr & 0xFFFF); + return C.PeekMemory(addr2); + } + private byte PeekSystemBusR(long addr) { ushort addr2 = (ushort)(addr & 0xFFFF); @@ -119,6 +166,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x L.WriteMemory(addr2, value); } + private void PokeSystemBusC(long addr, byte value) + { + ushort addr2 = (ushort)(addr & 0xFFFF); + C.WriteMemory(addr2, value); + } + private void PokeSystemBusR(long addr, byte value) { ushort addr2 = (ushort)(addr & 0xFFFF); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISaveRam.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISaveRam.cs index 3b40a8dfb3..17d9d3ce31 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISaveRam.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISaveRam.cs @@ -7,10 +7,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x { public byte[] CloneSaveRam() { - if ((L.cart_RAM != null) || (R.cart_RAM != null)) + if ((L.cart_RAM != null) || (C.cart_RAM != null) || (R.cart_RAM != null)) { int Len1 = 0; int Len2 = 0; + int Len3 = 0; int index = 0; if (L.cart_RAM != null) @@ -18,12 +19,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x Len1 = L.cart_RAM.Length; } - if (R.cart_RAM != null) + if (C.cart_RAM != null) { - Len2 = R.cart_RAM.Length; + Len2 = C.cart_RAM.Length; } - byte[] temp = new byte[Len1 + Len2]; + if (R.cart_RAM != null) + { + Len3 = R.cart_RAM.Length; + } + + byte[] temp = new byte[Len1 + Len2 + Len3]; if (L.cart_RAM != null) { @@ -34,6 +40,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x } } + if (C.cart_RAM != null) + { + for (int i = 0; i < C.cart_RAM.Length; i++) + { + temp[index] = C.cart_RAM[i]; + index++; + } + } + if (R.cart_RAM != null) { for (int i = 0; i < L.cart_RAM.Length; i++) @@ -53,18 +68,23 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x public void StoreSaveRam(byte[] data) { - if ((L.cart_RAM != null) && (R.cart_RAM == null)) + int temp = 0; + + if (L.cart_RAM != null) { - Buffer.BlockCopy(data, 0, L.cart_RAM, 0, L.cart_RAM.Length); + Buffer.BlockCopy(data, temp, L.cart_RAM, 0, L.cart_RAM.Length); + temp += L.cart_RAM.Length; } - else if ((R.cart_RAM != null) && (L.cart_RAM == null)) + + if (C.cart_RAM != null) { - Buffer.BlockCopy(data, 0, R.cart_RAM, 0, R.cart_RAM.Length); + Buffer.BlockCopy(data, temp, C.cart_RAM, 0, C.cart_RAM.Length); + temp += C.cart_RAM.Length; } - else if ((R.cart_RAM != null) && (L.cart_RAM != null)) + + if (R.cart_RAM != null) { - Buffer.BlockCopy(data, 0, L.cart_RAM, 0, L.cart_RAM.Length); - Buffer.BlockCopy(data, L.cart_RAM.Length, R.cart_RAM, 0, R.cart_RAM.Length); + Buffer.BlockCopy(data, temp, R.cart_RAM, 0, R.cart_RAM.Length); } Console.WriteLine("loading SRAM here"); @@ -74,7 +94,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x { get { - return (L.has_bat || R.has_bat) & Link3xSyncSettings.Use_SRAM; + return (L.has_bat || C.has_bat || R.has_bat) & Link3xSyncSettings.Use_SRAM; } } }