BizHawk/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.Controllers.cs

178 lines
3.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2019-05-07 13:43:36 +00:00
using System.Windows.Forms;
using BizHawk.Common.BufferExtensions;
2019-05-07 13:43:36 +00:00
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.ChannelF
{
public partial class ChannelF
{
2019-05-07 13:43:36 +00:00
public bool[] StateConsole = new bool[4];
public string[] ButtonsConsole = new string[]
{
"TIME", "MODE", "HOLD", "START"
};
public byte DataConsole
{
get
{
int w = 0;
for (int i = 0; i < 4; i++)
{
byte mask = (byte) (1 << i);
w = StateConsole[i] ? w | mask : w & ~mask;
}
return (byte)(w & 0xFF);
}
}
public bool[] StateRight = new bool[8];
public string[] ButtonsRight = new string[]
{
"Right", "Left", "Back", "Forward", "CCW", "CW", "Pull", "Push"
};
public byte DataRight
{
get
{
int w = 0;
for (int i = 0; i < 8; i++)
{
byte mask = (byte)(1 << i);
w = StateRight[i] ? w | mask : w & ~mask;
}
return (byte)(w & 0xFF);
}
}
public bool[] StateLeft = new bool[8];
public string[] ButtonsLeft = new string[]
{
"Right", "Left", "Back", "Forward", "CCW", "CW", "Pull", "Push"
};
public byte DataLeft
{
get
{
int w = 0;
for (int i = 0; i < 8; i++)
{
byte mask = (byte)(1 << i);
w = StateLeft[i] ? w | mask : w & ~mask;
}
return (byte)(w & 0xFF);
}
}
/// <summary>
/// Cycles through all the input callbacks
/// This should be done once per frame
/// </summary>
public bool PollInput()
{
bool noInput = true;
InputCallbacks.Call();
lock (this)
{
for (int i = 0; i < ButtonsConsole.Length; i++)
{
var key = ButtonsConsole[i];
bool prevState = StateConsole[i]; // CTRLConsole.Bit(i);
bool currState = _controller.IsPressed(key);
if (currState != prevState)
{
StateConsole[i] = currState;
noInput = false;
}
}
for (int i = 0; i < ButtonsRight.Length; i++)
{
var key = "P1 " + ButtonsRight[i];
bool prevState = StateRight[i];
bool currState = _controller.IsPressed(key);
if (currState != prevState)
{
StateRight[i] = currState;
noInput = false;
}
}
for (int i = 0; i < ButtonsLeft.Length; i++)
{
var key = "P2 " + ButtonsLeft[i];
bool prevState = StateLeft[i];
bool currState = _controller.IsPressed(key);
if (currState != prevState)
{
StateLeft[i] = currState;
noInput = false;
}
}
}
return noInput;
}
public ControllerDefinition ChannelFControllerDefinition
{
get
{
ControllerDefinition definition = new ControllerDefinition();
definition.Name = "ChannelF Controller";
2019-05-07 13:43:36 +00:00
string pre = "P1 ";
// sticks
2019-05-07 13:43:36 +00:00
List<string> stickR = new List<string>
{
2019-05-07 13:43:36 +00:00
// P1 (right) stick
pre + "Forward", pre + "Back", pre + "Left", pre + "Right", pre + "CCW", pre + "CW", pre + "Pull", pre + "Push"
};
2019-05-07 13:43:36 +00:00
foreach (var s in stickR)
{
definition.BoolButtons.Add(s);
2019-05-07 13:43:36 +00:00
definition.CategoryLabels[s] = "Right Controller";
}
2019-05-07 13:43:36 +00:00
pre = "P2 ";
List<string> stickL = new List<string>
{
2019-05-07 13:43:36 +00:00
// P2 (left) stick
pre + "Forward", pre + "Back", pre + "Left", pre + "Right", pre + "CCW", pre + "CW", pre + "Pull", pre + "Push"
};
2019-05-07 13:43:36 +00:00
foreach (var s in stickL)
{
definition.BoolButtons.Add(s);
2019-05-07 13:43:36 +00:00
definition.CategoryLabels[s] = "Left Controller";
}
// console
List<string> consoleButtons = new List<string>
{
"RESET", "START", "HOLD", "MODE", "TIME"
};
foreach (var s in consoleButtons)
{
definition.BoolButtons.Add(s);
definition.CategoryLabels[s] = "Console";
}
return definition;
}
}
}
}