From 879f76d703520810bc04e2ef9bfd3c7f52833bc0 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Mon, 21 Feb 2011 15:23:30 +0000 Subject: [PATCH] Implement PokeAddress on the Watch class, refactor Ram Poke to use this method. DWord poke implemented now. --- BizHawk.MultiClient/tools/RamPoke.cs | 34 +++-------------------- BizHawk.MultiClient/tools/RamWatch.cs | 2 +- BizHawk.MultiClient/tools/Watch.cs | 40 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/BizHawk.MultiClient/tools/RamPoke.cs b/BizHawk.MultiClient/tools/RamPoke.cs index a9bd00d617..627dcbac54 100644 --- a/BizHawk.MultiClient/tools/RamPoke.cs +++ b/BizHawk.MultiClient/tools/RamPoke.cs @@ -92,7 +92,7 @@ namespace BizHawk.MultiClient { //Put user settings in the watch file - if (InputValidate.IsValidHexNumber(AddressBox.Text)) //TODO: also validate it is within a valid memory address range! + if (InputValidate.IsValidHexNumber(AddressBox.Text)) watch.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); else { @@ -162,36 +162,10 @@ namespace BizHawk.MultiClient } break; default: - return; - } - - //TODO: Try/Catch this? Seems destined for failures - - switch (watch.type) - { - case atype.BYTE: - Global.Emulator.MainMemory.PokeByte(watch.address, (byte)watch.value); - break; - case atype.WORD: - if (watch.bigendian) - { - Global.Emulator.MainMemory.PokeByte(watch.address, (byte)(watch.value / 256)); - Global.Emulator.MainMemory.PokeByte(watch.address + 1, (byte)(watch.value % 256)); - } - else - { - Global.Emulator.MainMemory.PokeByte(watch.address + 1, (byte)(watch.value / 256)); - Global.Emulator.MainMemory.PokeByte(watch.address, (byte)(watch.value % 256)); - } - break; - case atype.DWORD: - //TODO - break; - default: - break; + return; } - - + watch.PokeAddress(Global.Emulator.MainMemory); + //TODO: format value based on watch.type OutputLabel.Text = watch.value.ToString() + " written to " + String.Format("{0:X}", watch.address); } diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index dda0bc2bb0..9febb0adc3 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -853,4 +853,4 @@ namespace BizHawk.MultiClient e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;string[] filePaths = (string[]) e.Data.GetData(DataFormats.FileDrop); } } -} +} \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/Watch.cs b/BizHawk.MultiClient/tools/Watch.cs index ce32032efa..d2732beb0a 100644 --- a/BizHawk.MultiClient/tools/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch.cs @@ -162,6 +162,43 @@ namespace BizHawk.MultiClient } } + private void PokeByte(MemoryDomain domain) + { + domain.PokeByte(address, (byte)value); + } + + private void PokeWord(MemoryDomain domain) + { + if (bigendian) + { + domain.PokeByte(address, (byte)(value / 256)); + domain.PokeByte(address + 1, (byte)(value % 256)); + } + else + { + domain.PokeByte(address + 1, (byte)(value / 256)); + domain.PokeByte(address, (byte)(value % 256)); + } + } + + private void PokeDWord(MemoryDomain domain) + { + if (bigendian) + { + domain.PokeByte(address, (byte)(value << 6)); + domain.PokeByte(address + 1, (byte)(value << 4)); + domain.PokeByte(address + 2, (byte)(value << 2)); + domain.PokeByte(address + 3, (byte)(value)); + } + else + { + domain.PokeByte(address + 1, (byte)(value << 6)); + domain.PokeByte(address, (byte)(value << 4)); + domain.PokeByte(address + 3, (byte)(value << 2)); + domain.PokeByte(address + 2, (byte)(value)); + } + } + public void PokeAddress(MemoryDomain domain) { if (type == atype.SEPARATOR) @@ -170,10 +207,13 @@ namespace BizHawk.MultiClient switch (type) { case atype.BYTE: + PokeByte(domain); break; case atype.WORD: + PokeWord(domain); break; case atype.DWORD: + PokeDWord(domain); break; } }