BizHawk/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs

75 lines
1.6 KiB
C#
Raw Normal View History

2014-06-26 19:19:26 +00:00
using System;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public class AndAdapter : IController
{
public bool IsPressed(string button)
{
return this[button];
}
// pass floats solely from the original source
// this works in the code because SourceOr is the autofire controller
public float GetFloat(string name) { return Source.GetFloat(name); }
public IController Source { get; set; }
public IController SourceAnd { get; set; }
public ControllerDefinition Definition { get { return Source.Definition; } set { throw new InvalidOperationException(); } }
2014-06-26 19:19:26 +00:00
public bool this[string button]
{
get
{
if (Source != null && SourceAnd != null)
{
return Source[button] & SourceAnd[button];
}
return false;
}
set
{
throw new InvalidOperationException();
}
}
}
public class ORAdapter : IController
{
public bool IsPressed(string button)
{
return this[button];
}
// pass floats solely from the original source
// this works in the code because SourceOr is the autofire controller
public float GetFloat(string name) { return Source.GetFloat(name); }
public IController Source { get; set; }
public IController SourceOr { get; set; }
public ControllerDefinition Definition
{
get { return Source.Definition; }
set { throw new InvalidOperationException(); }
}
2014-06-26 19:19:26 +00:00
public bool this[string button]
{
get
{
return (Source != null ? Source[button] : false)
| (SourceOr != null ? SourceOr[button] : false);
2014-06-26 19:19:26 +00:00
}
set
{
throw new InvalidOperationException();
}
}
}
}