Implement PokeAddress on the Watch class, refactor Ram Poke to use this method. DWord poke implemented now.

This commit is contained in:
andres.delikat 2011-02-21 15:23:30 +00:00
parent 89eb17a468
commit 879f76d703
3 changed files with 45 additions and 31 deletions

View File

@ -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);
}

View File

@ -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);
}
}
}
}

View File

@ -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;
}
}