diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IMemoryDomains.cs index 13ac2d5fd9..eca129c035 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IMemoryDomains.cs @@ -36,10 +36,60 @@ namespace BizHawk.Emulation.Cores.Intellivision addr => GraphicsRom[addr], (addr, value) => GraphicsRom[addr] = value, 1), + new MemoryDomainDelegate( + "System Ram", + SystemRam.Length * 2, + MemoryDomain.Endian.Little, + addr => ReadByteFromShortArray(addr, SystemRam), + (addr, value) => WriteByteToShortArray(addr, value, SystemRam), + 1 + ), + new MemoryDomainDelegate( + "Executive Rom", + SystemRam.Length * 2, + MemoryDomain.Endian.Little, + addr => ReadByteFromShortArray(addr, ExecutiveRom), + (addr, value) => WriteByteToShortArray(addr, value, ExecutiveRom), + 1 + ) }; MemoryDomains = new MemoryDomainList(domains); (ServiceProvider as BasicServiceProvider).Register(MemoryDomains); } + + // TODO: move these to a common library and maybe add an endian parameter + // Little endian + private byte ReadByteFromShortArray(long addr, ushort[] array) + { + if (addr % 2 == 0) + { + long index = addr / 2; + return (byte)(array[index] >> 8); + + } + else + { + long index = (addr - 1) / 2; + return (byte)(array[index] & 0xFF); + } + } + + private void WriteByteToShortArray(long addr, byte value, ushort[] array) + { + if (addr % 2 == 0) + { + long index = (addr - 1) / 2; + ushort val = (ushort)((value << 8) + (array[index] & 0xFF)); + array[index] = val; + + } + else + { + long index = addr / 2; + ushort val = (ushort)((((array[index] >> 8) & 0xFF) << 8) + value); + array[index] = val; + } + } } }