68 lines
1.3 KiB
C#
68 lines
1.3 KiB
C#
![]() |
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; }
|
|||
|
}
|
|||
|
|
|||
|
[DisplayName("Standard controls")]
|
|||
|
public class StandardControls : IPort
|
|||
|
{
|
|||
|
public StandardControls(int portNum)
|
|||
|
{
|
|||
|
PortNum = portNum;
|
|||
|
Definition = new ControllerDefinition
|
|||
|
{
|
|||
|
Name = "Game Boy",
|
|||
|
BoolButtons = BaseDefinition
|
|||
|
.Select(b => "P" + PortNum + " " + b)
|
|||
|
.ToList()
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public int PortNum { get; }
|
|||
|
|
|||
|
public ControllerDefinition Definition { get; }
|
|||
|
|
|||
|
public byte Read(IController c)
|
|||
|
{
|
|||
|
byte result = 0xFF;
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
if (c.IsPressed(Definition.BoolButtons[i]))
|
|||
|
{
|
|||
|
result -= (byte)(1 << i);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
private static readonly string[] BaseDefinition =
|
|||
|
{
|
|||
|
"Right", "Left", "Up", "Down", "A", "B", "Select", "Start"
|
|||
|
};
|
|||
|
|
|||
|
public void SyncState(Serializer ser)
|
|||
|
{
|
|||
|
//nothing
|
|||
|
}
|
|||
|
}
|
|||
|
}
|