NES - Round 1 of Hook up NES cheats for system bus (i.e. game genie codes now work)

This commit is contained in:
adelikat 2012-09-01 14:13:36 +00:00
parent f21429b996
commit 9b7404b059
5 changed files with 76 additions and 28 deletions

View File

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

View File

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

View File

@ -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()

View File

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

View File

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