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 { /// /// Represents a GB add on /// public interface IPort { byte Read(IController c); ControllerDefinition Definition { get; } void SyncState(Serializer ser); int PortNum { get; } } [DisplayName("Gameboy Controller")] public class StandardControls : IPort { public StandardControls(int portNum) { PortNum = portNum; Definition = new ControllerDefinition { Name = "Gameboy Controller", 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", "Power" }; public void SyncState(Serializer ser) { //nothing } } }