2011-08-03 03:00:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2011-08-07 01:16:55 +00:00
|
|
|
|
namespace BizHawk.MultiClient
|
2011-08-03 03:00:19 +00:00
|
|
|
|
{
|
2011-08-07 01:16:55 +00:00
|
|
|
|
public static class MemoryPulse
|
|
|
|
|
{
|
|
|
|
|
public class MemoryPulseEntry
|
|
|
|
|
{
|
|
|
|
|
public int address;
|
|
|
|
|
public byte value;
|
2012-08-31 11:59:14 +00:00
|
|
|
|
public byte? compare;
|
2011-08-07 01:16:55 +00:00
|
|
|
|
public MemoryDomain domain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<MemoryPulseEntry> entries = new List<MemoryPulseEntry>();
|
|
|
|
|
|
|
|
|
|
public static void Pulse()
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in entries)
|
|
|
|
|
{
|
2012-08-31 11:59:14 +00:00
|
|
|
|
if (entry.compare.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (entry.domain.PeekByte(entry.address) == entry.compare)
|
|
|
|
|
{
|
|
|
|
|
entry.domain.PokeByte(entry.address, entry.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entry.domain.PokeByte(entry.address, entry.value);
|
|
|
|
|
}
|
2011-08-07 01:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 11:59:14 +00:00
|
|
|
|
public static void Add(MemoryDomain domain, int address, byte value, byte? compare = null)
|
2011-08-07 01:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
entries.RemoveAll(o => o.domain == domain && o.address == address);
|
|
|
|
|
|
|
|
|
|
var entry = new MemoryPulseEntry { address = address, value = value, domain = domain };
|
|
|
|
|
entries.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 11:59:14 +00:00
|
|
|
|
public static MemoryPulseEntry Query(MemoryDomain domain, int address, byte? compare = null)
|
2011-08-07 01:16:55 +00:00
|
|
|
|
{
|
2012-08-31 11:59:14 +00:00
|
|
|
|
if (compare.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return entries.Find(o => o.domain == domain && o.address == address && o.compare == compare);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return entries.Find(o => o.domain == domain && o.address == address);
|
|
|
|
|
}
|
2011-08-07 01:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Remove(MemoryDomain domain, int address)
|
|
|
|
|
{
|
|
|
|
|
entries.RemoveAll(o => o.domain == domain && o.address == address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IList<MemoryPulseEntry> GetEntries()
|
|
|
|
|
{
|
|
|
|
|
return entries.AsReadOnly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clear()
|
|
|
|
|
{
|
|
|
|
|
entries.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-03 03:00:19 +00:00
|
|
|
|
}
|