add PeekWord, PeekDWord, PokeWord, and PokeDWord to the memory domain object, don't know why we never did this before. Refactored watch.cs accordingly, todo: a bazillion other places

This commit is contained in:
adelikat 2013-09-21 14:32:37 +00:00
parent 22ddfa99f8
commit 52918e9609
2 changed files with 70 additions and 46 deletions

View File

@ -118,6 +118,72 @@ namespace BizHawk
{ {
return Name; return Name;
} }
public ushort PeekWord(int addr, Endian endian)
{
switch (endian)
{
default:
case Endian.Big:
return (ushort)((PeekByte(addr) << 8) | (PeekByte(addr + 1)));
case Endian.Little:
return (ushort)((PeekByte(addr)) | (PeekByte(addr + 1) << 8));
}
}
public uint PeekDWord(int addr, Endian endian)
{
switch (endian)
{
default:
case Endian.Big:
return (uint)((PeekByte(addr) << 24)
| (PeekByte(addr + 1) << 16)
| (PeekByte(addr + 2) << 8)
| (PeekByte(addr + 3) << 0));
case Endian.Little:
return (uint)((PeekByte(addr) << 0)
| (PeekByte(addr + 1) << 8)
| (PeekByte(addr + 2) << 16)
| (PeekByte(addr + 3) << 24));
}
}
public void PokeWord(int addr, ushort val, Endian endian)
{
switch (endian)
{
default:
case Endian.Big:
PokeByte(addr + 0, (byte)(val >> 8));
PokeByte(addr + 1, (byte)(val));
break;
case Endian.Little:
PokeByte(addr + 0, (byte)(val));
PokeByte(addr + 1, (byte)(val >> 8));
break;
}
}
public void PokeDWord(int addr, uint val, Endian endian)
{
switch (endian)
{
default:
case Endian.Big:
PokeByte(addr + 0, (byte)(val >> 24));
PokeByte(addr + 1, (byte)(val >> 16));
PokeByte(addr + 2, (byte)(val >> 8));
PokeByte(addr + 3, (byte)(val));
break;
case Endian.Little:
PokeByte(addr + 0, (byte)(val));
PokeByte(addr + 1, (byte)(val >> 8));
PokeByte(addr + 2, (byte)(val >> 16));
PokeByte(addr + 3, (byte)(val >> 24));
break;
}
}
} }
public enum Endian { Big, Little, Unknown } public enum Endian { Big, Little, Unknown }

View File

@ -170,32 +170,12 @@ namespace BizHawk.MultiClient
protected ushort GetWord() protected ushort GetWord()
{ {
if (_bigEndian) return _domain.PeekWord(_address, _bigEndian ? Endian.Big : Endian.Little);
{
return (ushort)((_domain.PeekByte(_address) << 8) | (_domain.PeekByte(_address + 1)));
}
else
{
return (ushort)((_domain.PeekByte(_address)) | (_domain.PeekByte(_address + 1) << 8));
}
} }
protected uint GetDWord() protected uint GetDWord()
{ {
if (_bigEndian) return _domain.PeekDWord(_address, _bigEndian ? Endian.Big : Endian.Little);
{
return (uint)((_domain.PeekByte(_address) << 24)
| (_domain.PeekByte(_address + 1) << 16)
| (_domain.PeekByte(_address + 2) << 8)
| (_domain.PeekByte(_address + 3) << 0));
}
else
{
return (uint)((_domain.PeekByte(_address) << 0)
| (_domain.PeekByte(_address + 1) << 8)
| (_domain.PeekByte(_address + 2) << 16)
| (_domain.PeekByte(_address + 3) << 24));
}
} }
protected void PokeByte(byte val) protected void PokeByte(byte val)
@ -205,34 +185,12 @@ namespace BizHawk.MultiClient
protected void PokeWord(ushort val) protected void PokeWord(ushort val)
{ {
if (_bigEndian) _domain.PokeWord(_address, val, _bigEndian ? Endian.Big : Endian.Little);
{
_domain.PokeByte(_address + 0, (byte)(val >> 8));
_domain.PokeByte(_address + 1, (byte)(val));
}
else
{
_domain.PokeByte(_address + 0, (byte)(val));
_domain.PokeByte(_address + 1, (byte)(val >> 8));
}
} }
protected void PokeDWord(uint val) protected void PokeDWord(uint val)
{ {
if (_bigEndian) _domain.PokeDWord(_address, val, _bigEndian ? Endian.Big : Endian.Little);
{
_domain.PokeByte(_address + 0, (byte)(val >> 24));
_domain.PokeByte(_address + 1, (byte)(val >> 16));
_domain.PokeByte(_address + 2, (byte)(val >> 8));
_domain.PokeByte(_address + 3, (byte)(val));
}
else
{
_domain.PokeByte(_address + 0, (byte)(val));
_domain.PokeByte(_address + 1, (byte)(val >> 8));
_domain.PokeByte(_address + 2, (byte)(val >> 16));
_domain.PokeByte(_address + 3, (byte)(val >> 24));
}
} }
public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size, bool details) public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size, bool details)