diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index a033f081b7..be8eaa21cf 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -275,15 +275,31 @@ namespace BizHawk.Emulation.Consoles.Nintendo //handle breakpoints and stuff. //the idea is that each core can implement its own watch class on an address which will track all the different kinds of monitors and breakpoints and etc. //but since freeze is a common case, it was implemented through its own mechanisms - //if (sysbus_watch[addr] != null) - //{ - // sysbus_watch[addr].Sync(); - // ret = sysbus_watch[addr].ApplyGameGenie(ret); - //} + if (sysbus_watch[addr] != null) + { + sysbus_watch[addr].Sync(); + ret = sysbus_watch[addr].ApplyGameGenie(ret); + } return ret; } + public void ApplyGameGenie(int addr, byte value, byte? compare) + { + if (addr < sysbus_watch.Length) + { + GetWatch(NESWatch.EDomain.Sysbus, addr).SetGameGenie(compare, value); + } + } + + public void RemoveGameGenie(int addr) + { + if (addr < sysbus_watch.Length) + { + GetWatch(NESWatch.EDomain.Sysbus, addr).RemoveGameGenie(); + } + } + public void WriteMemory(ushort addr, byte value) { if (addr < 0x0800) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 5494e5072d..510ea790e5 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -58,6 +58,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo { Sysbus } + public NESWatch(NES nes, EDomain domain, int address) { Address = address; @@ -85,20 +86,37 @@ namespace BizHawk.Emulation.Consoles.Nintendo else watches[Address] = this; } - public void SetGameGenie(int check, int replace) + public void SetGameGenie(byte? compare, byte value) { flags |= EFlags.GameGenie; - gg_check = check; - gg_replace = replace; + Compare = compare; + Value = value; Sync(); } - public bool HasGameGenie { get { return (flags & EFlags.GameGenie) != 0; } } + public bool HasGameGenie + { + get + { + return (flags & EFlags.GameGenie) != 0; + } + } + public byte ApplyGameGenie(byte curr) { - if (!HasGameGenie) return curr; - if (curr == gg_check || gg_check == -1) { Console.WriteLine("applied game genie"); return (byte)gg_replace; } - else return curr; + if (!HasGameGenie) + { + return curr; + } + else if (curr == Compare || Compare == null) + { + Console.WriteLine("applied game genie"); + return (byte)Value; + } + else + { + return curr; + } } public void RemoveGameGenie() @@ -107,7 +125,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo Sync(); } - int gg_check, gg_replace; + byte? Compare; + byte Value; NESWatch[] watches; } @@ -314,10 +333,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo var OAMdoman = new MemoryDomain("OAM", 64 * 4, Endian.Unknown, addr => ppu.OAM[addr & (64 * 4 - 1)], (addr, value) => ppu.OAM[addr & (64 * 4 - 1)] = value); - //demo a game genie code - GetWatch(NESWatch.EDomain.Sysbus, 0xB424).SetGameGenie(-1, 0x10); - GetWatch(NESWatch.EDomain.Sysbus, 0xB424).RemoveGameGenie(); - domains.Add(RAM); domains.Add(SystemBus); domains.Add(PPUBus); diff --git a/BizHawk.MultiClient/tools/Cheat.cs b/BizHawk.MultiClient/tools/Cheat.cs index 0965a3ed0f..05b0ebb118 100644 --- a/BizHawk.MultiClient/tools/Cheat.cs +++ b/BizHawk.MultiClient/tools/Cheat.cs @@ -1,4 +1,5 @@ using BizHawk.MultiClient; +using BizHawk.Emulation.Consoles.Nintendo; namespace BizHawk.MultiClient { @@ -51,7 +52,14 @@ namespace BizHawk.MultiClient public void Enable() { enabled = true; - MemoryPulse.Add(domain, address, value, compare); + if (Global.Emulator is NES) + { + (Global.Emulator as NES).ApplyGameGenie(address, value, compare); + } + else + { + MemoryPulse.Add(domain, address, value, compare); + } } public void Disable() diff --git a/BizHawk.MultiClient/tools/CheatList.cs b/BizHawk.MultiClient/tools/CheatList.cs index f56bed8142..8146b117c4 100644 --- a/BizHawk.MultiClient/tools/CheatList.cs +++ b/BizHawk.MultiClient/tools/CheatList.cs @@ -54,17 +54,21 @@ namespace BizHawk.MultiClient s = s.Substring(y, s.Length - y); //Enabled y = int.Parse(s[0].ToString()); - try - { + //try + //{ if (y == 0) + { c.Disable(); + } else + { c.Enable(); - } - catch - { - NotSupportedError(); - } + } + //} + //catch + //{ + // NotSupportedError(); + //} y = s.IndexOf('\t') + 1; s = s.Substring(y, s.Length - y); //Name @@ -97,7 +101,9 @@ namespace BizHawk.MultiClient for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++) { if (Global.Emulator.MemoryDomains[x].Name == name) + { return Global.Emulator.MemoryDomains[x]; + } } return Global.Emulator.MemoryDomains[0]; } diff --git a/BizHawk.MultiClient/tools/Cheats.cs b/BizHawk.MultiClient/tools/Cheats.cs index 1fd039ddf9..78f6255603 100644 --- a/BizHawk.MultiClient/tools/Cheats.cs +++ b/BizHawk.MultiClient/tools/Cheats.cs @@ -564,12 +564,15 @@ namespace BizHawk.MultiClient c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: validation c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber)); c.domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex]; - try { + try + { c.Enable(); - } - catch { + } + catch + { Global.CheatList.NotSupportedError(); } + return c; }