diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs index a5e72555a9..bac3d10f71 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using BizHawk.Emulation.Common; @@ -7,12 +8,13 @@ namespace BizHawk.Emulation.Cores.Calculators { public partial class TI83 { + private IMemoryDomains _memoryDomains; + private readonly Dictionary _byteArrayDomains = new Dictionary(); + private bool _memoryDomainsInit = false; + private void SetupMemoryDomains() { - var domains = new List - { - MemoryDomain.FromByteArray("Main RAM", MemoryDomain.Endian.Little, _ram) - }; + var domains = new List(); var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => @@ -30,10 +32,31 @@ namespace BizHawk.Emulation.Cores.Calculators domains.Add(systemBusDomain); - _memoryDomains = new MemoryDomainList(domains); + SyncAllByteArrayDomains(); + + _memoryDomains = new MemoryDomainList(_byteArrayDomains.Values.Concat(domains).ToList()); (ServiceProvider as BasicServiceProvider).Register(_memoryDomains); + + _memoryDomainsInit = true; } - private IMemoryDomains _memoryDomains; + private void SyncAllByteArrayDomains() + { + SyncByteArrayDomain("Main RAM", _ram); + } + + private void SyncByteArrayDomain(string name, byte[] data) + { + if (_memoryDomainsInit) + { + var m = _byteArrayDomains[name]; + m.Data = data; + } + else + { + var m = new MemoryDomainByteArray(name, MemoryDomain.Endian.Little, data, true, 1); + _byteArrayDomains.Add(name, m); + } + } } } diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs index 2eb6f0277a..b63f2ac4fa 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs @@ -76,6 +76,11 @@ namespace BizHawk.Emulation.Cores.Calculators ser.Sync("LagCount", ref _lagCount); ser.Sync("IsLag", ref _isLag); ser.EndSection(); + + if (ser.IsReader) + { + SyncAllByteArrayDomains(); + } } } }