Memory callback system - simplify and remove now unused methods

This commit is contained in:
adelikat 2019-11-05 20:01:58 -06:00
parent 558171d949
commit 40ac534f51
2 changed files with 31 additions and 54 deletions

View File

@ -186,14 +186,9 @@ namespace BizHawk.Emulation.Common
public int PlayerNumber(string buttonName) public int PlayerNumber(string buttonName)
{ {
var match = PlayerRegex.Match(buttonName); var match = PlayerRegex.Match(buttonName);
if (match.Success) return match.Success
{ ? int.Parse(match.Groups[1].Value)
return int.Parse(match.Groups[1].Value); : 0;
}
else
{
return 0;
}
} }
private static readonly Regex PlayerRegex = new Regex("^P(\\d+) "); private static readonly Regex PlayerRegex = new Regex("^P(\\d+) ");

View File

@ -33,9 +33,6 @@ namespace BizHawk.Emulation.Common
private readonly ObservableCollection<IMemoryCallback> _writes = new ObservableCollection<IMemoryCallback>(); private readonly ObservableCollection<IMemoryCallback> _writes = new ObservableCollection<IMemoryCallback>();
private readonly ObservableCollection<IMemoryCallback> _execs = new ObservableCollection<IMemoryCallback>(); private readonly ObservableCollection<IMemoryCallback> _execs = new ObservableCollection<IMemoryCallback>();
private bool _hasReads;
private bool _hasWrites;
private bool _hasExecutes;
private bool _hasAny; private bool _hasAny;
public bool ExecuteCallbacksAvailable { get; } public bool ExecuteCallbacksAvailable { get; }
@ -81,56 +78,41 @@ namespace BizHawk.Emulation.Common
public void CallMemoryCallbacks(uint addr, uint value, uint flags, string scope) public void CallMemoryCallbacks(uint addr, uint value, uint flags, string scope)
{ {
if (!_hasAny) return; if (!_hasAny)
if (_hasReads)
{ {
if((flags & (uint)MemoryCallbackFlags.AccessRead)!=0) return;
Call(_reads, addr, value, flags, scope);
} }
if (_hasWrites) if (HasReads)
{ {
if((flags & (uint)MemoryCallbackFlags.AccessWrite)!=0) if ((flags & (uint) MemoryCallbackFlags.AccessRead) != 0)
Call(_writes, addr, value, flags, scope);
}
if (_hasExecutes)
{
if((flags & (uint)MemoryCallbackFlags.AccessExecute)!=0)
Call(_execs, addr, value, flags, scope);
}
}
public void CallReads(uint addr, uint value, uint flags, string scope)
{
if (_hasReads)
{ {
Call(_reads, addr, value, flags, scope); Call(_reads, addr, value, flags, scope);
} }
} }
public void CallWrites(uint addr, uint value, uint flags, string scope) if (HasWrites)
{ {
if (_hasWrites) if ((flags & (uint) MemoryCallbackFlags.AccessWrite) != 0)
{ {
Call(_writes, addr, value, flags, scope); Call(_writes, addr, value, flags, scope);
} }
} }
public void CallExecutes(uint addr, uint value, uint flags, string scope) if (HasExecutes)
{ {
if (_hasExecutes) if ((flags & (uint) MemoryCallbackFlags.AccessExecute) != 0)
{ {
Call(_execs, addr, value, flags, scope); Call(_execs, addr, value, flags, scope);
} }
} }
}
public bool HasReads => _hasReads; public bool HasReads { get; private set; }
public bool HasWrites => _hasWrites; public bool HasWrites { get; private set; }
public bool HasExecutes => _hasExecutes; public bool HasExecutes { get; private set; }
public bool HasReadsForScope(string scope) public bool HasReadsForScope(string scope)
{ {
@ -149,16 +131,16 @@ namespace BizHawk.Emulation.Common
private bool UpdateHasVariables() private bool UpdateHasVariables()
{ {
bool hadReads = _hasReads; bool hadReads = HasReads;
bool hadWrites = _hasWrites; bool hadWrites = HasWrites;
bool hadExecutes = _hasExecutes; bool hadExecutes = HasExecutes;
_hasReads = _reads.Count > 0; HasReads = _reads.Count > 0;
_hasWrites = _writes.Count > 0; HasWrites = _writes.Count > 0;
_hasExecutes = _execs.Count > 0; HasExecutes = _execs.Count > 0;
_hasAny = _hasReads || _hasWrites || _hasExecutes; _hasAny = HasReads || HasWrites || HasExecutes;
return (_hasReads != hadReads || _hasWrites != hadWrites || _hasExecutes != hadExecutes); return (HasReads != hadReads || HasWrites != hadWrites || HasExecutes != hadExecutes);
} }
private int RemoveInternal(MemoryCallbackDelegate action) private int RemoveInternal(MemoryCallbackDelegate action)