Intellivision - add System Ram and Executive Rom memory domains

This commit is contained in:
adelikat 2017-02-05 09:49:54 -06:00
parent c739755e9b
commit 35c4df9256
1 changed files with 50 additions and 0 deletions

View File

@ -36,10 +36,60 @@ namespace BizHawk.Emulation.Cores.Intellivision
addr => GraphicsRom[addr], addr => GraphicsRom[addr],
(addr, value) => GraphicsRom[addr] = value, (addr, value) => GraphicsRom[addr] = value,
1), 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); MemoryDomains = new MemoryDomainList(domains);
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(MemoryDomains); (ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(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;
}
}
} }
} }