minimally fix nes CDL which was broken 3 years ago

This commit is contained in:
zeromus 2020-08-28 19:02:21 -04:00
parent 56082ddf44
commit f89840234d
3 changed files with 28 additions and 15 deletions

View File

@ -50,6 +50,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
void SyncState(Serializer ser); void SyncState(Serializer ser);
bool IrqSignal { get; } bool IrqSignal { get; }
NES.CDLog_MapResults MapMemory(ushort addr, bool write);
//mixes the board's custom audio into the supplied sample buffer //mixes the board's custom audio into the supplied sample buffer
void ApplyCustomAudio(short[] samples); void ApplyCustomAudio(short[] samples);

View File

@ -38,6 +38,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//this is set to true when SyncState is called, so that we know the base class SyncState was used //this is set to true when SyncState is called, so that we know the base class SyncState was used
public bool SyncStateFlag; public bool SyncStateFlag;
public virtual NES.CDLog_MapResults MapMemory(ushort addr, bool write)
{
NES.CDLog_MapResults ret = new NES.CDLog_MapResults();
ret.Type = NES.CDLog_AddrType.None;
if (addr < 0x2000)
{
ret.Type = NES.CDLog_AddrType.MainRAM;
ret.Address = addr & 0x7FF;
}
return ret;
}
public virtual void SyncState(Serializer ser) public virtual void SyncState(Serializer ser)
{ {
ser.Sync(nameof(_vram), ref _vram, true); ser.Sync(nameof(_vram), ref _vram, true);

View File

@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
} }
private enum CDLog_AddrType public enum CDLog_AddrType
{ {
None, None,
ROM, ROM,
@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
} }
[Flags] [Flags]
private enum CDLog_Flags public enum CDLog_Flags
{ {
ExecFirst = 0x01, ExecFirst = 0x01,
ExecOperand = 0x02, ExecOperand = 0x02,
@ -57,30 +57,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
} }
#pragma warning disable CS0649 #pragma warning disable CS0649
private struct CDLog_MapResults public struct CDLog_MapResults
{ {
public CDLog_AddrType Type; public CDLog_AddrType Type;
public int Address; public int Address;
} }
private delegate CDLog_MapResults MapMemoryDelegate(ushort addr, bool write); private delegate CDLog_MapResults MpMemoryDelegate(ushort addr, bool write);
private MapMemoryDelegate MapMemory;
#pragma warning restore CS0649 #pragma warning restore CS0649
private ICodeDataLog CDL; private ICodeDataLog CDL;
private void RunCDL(ushort address, CDLog_Flags flags) private void RunCDL(ushort address, CDLog_Flags flags)
{ {
if (MapMemory != null)
{ CDLog_MapResults results = Board.MapMemory(address, false);
CDLog_MapResults results = MapMemory(address, false);
switch (results.Type) switch (results.Type)
{ {
case CDLog_AddrType.None: break; case CDLog_AddrType.None: break;
case CDLog_AddrType.MainRAM: CDL["Main RAM"][results.Address] |= (byte)flags; break; case CDLog_AddrType.MainRAM: CDL["RAM"][results.Address] |= (byte)flags; break;
case CDLog_AddrType.SaveRAM: CDL["Save RAM"][results.Address] |= (byte)flags; break; case CDLog_AddrType.SaveRAM: CDL["Save RAM"][results.Address] |= (byte)flags; break;
} }
} }
}
/// <summary> /// <summary>
/// A wrapper for FetchMemory which inserts CDL logic /// A wrapper for FetchMemory which inserts CDL logic