BizHawk/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs

94 lines
1.8 KiB
C#
Raw Normal View History

2017-08-29 13:18:28 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
/// <summary>
/// Represents a GB add on
/// </summary>
public interface IPort
{
byte Read(IController c);
ControllerDefinition Definition { get; }
void SyncState(Serializer ser);
int PortNum { get; }
}
2017-11-19 20:16:15 +00:00
[DisplayName("Gameboy Controller")]
2017-08-29 13:18:28 +00:00
public class StandardControls : IPort
{
public StandardControls(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
2017-11-19 20:16:15 +00:00
Name = "Gameboy Controller",
2017-08-29 13:18:28 +00:00
BoolButtons = BaseDefinition
.Select(b => "P" + PortNum + " " + b)
.ToList()
};
}
public int PortNum { get; }
public ControllerDefinition Definition { get; }
public byte Read(IController c)
{
byte result = 0xFF;
2018-01-17 22:17:43 +00:00
if (c.IsPressed(Definition.BoolButtons[0]))
{
result -= 4;
}
if (c.IsPressed(Definition.BoolButtons[1]))
{
result -= 8;
}
if (c.IsPressed(Definition.BoolButtons[2]))
{
result -= 2;
}
if (c.IsPressed(Definition.BoolButtons[3]))
{
result -= 1;
}
if (c.IsPressed(Definition.BoolButtons[4]))
{
result -= 128;
}
if (c.IsPressed(Definition.BoolButtons[5]))
{
result -= 64;
}
if (c.IsPressed(Definition.BoolButtons[6]))
{
result -= 32;
}
if (c.IsPressed(Definition.BoolButtons[7]))
2017-08-29 13:18:28 +00:00
{
2018-01-17 22:17:43 +00:00
result -= 16;
2017-08-29 13:18:28 +00:00
}
return result;
}
private static readonly string[] BaseDefinition =
{
2018-01-17 14:41:59 +00:00
"Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Power"
2017-08-29 13:18:28 +00:00
};
public void SyncState(Serializer ser)
{
//nothing
}
}
}