diff --git a/BizHawk.Emulation/Interfaces/IEmulator.cs b/BizHawk.Emulation/Interfaces/IEmulator.cs index df8ac833b3..da58d93620 100644 --- a/BizHawk.Emulation/Interfaces/IEmulator.cs +++ b/BizHawk.Emulation/Interfaces/IEmulator.cs @@ -118,6 +118,72 @@ namespace BizHawk { 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 } diff --git a/BizHawk.MultiClient/tools/Watch/Watch.cs b/BizHawk.MultiClient/tools/Watch/Watch.cs index 8c01a7b7c6..21c6f3e421 100644 --- a/BizHawk.MultiClient/tools/Watch/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch/Watch.cs @@ -170,32 +170,12 @@ namespace BizHawk.MultiClient protected ushort GetWord() { - if (_bigEndian) - { - return (ushort)((_domain.PeekByte(_address) << 8) | (_domain.PeekByte(_address + 1))); - } - else - { - return (ushort)((_domain.PeekByte(_address)) | (_domain.PeekByte(_address + 1) << 8)); - } + return _domain.PeekWord(_address, _bigEndian ? Endian.Big : Endian.Little); } protected uint GetDWord() { - if (_bigEndian) - { - 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)); - } + return _domain.PeekDWord(_address, _bigEndian ? Endian.Big : Endian.Little); } protected void PokeByte(byte val) @@ -205,34 +185,12 @@ namespace BizHawk.MultiClient protected void PokeWord(ushort val) { - if (_bigEndian) - { - _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)); - } + _domain.PokeWord(_address, val, _bigEndian ? Endian.Big : Endian.Little); } protected void PokeDWord(uint val) { - if (_bigEndian) - { - _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)); - } + _domain.PokeDWord(_address, val, _bigEndian ? Endian.Big : Endian.Little); } public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size, bool details)