Merge branch 'pceperipherals'

This commit is contained in:
adelikat 2017-07-20 08:11:51 -05:00
commit db6858f2fe
9 changed files with 333 additions and 185 deletions

View File

@ -28,52 +28,63 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PCEControllerConfig));
this.CancelBtn = new System.Windows.Forms.Button();
this.OkBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// CancelBtn
//
this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.Location = new System.Drawing.Point(235, 145);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.TabIndex = 3;
this.CancelBtn.Text = "&Cancel";
this.CancelBtn.UseVisualStyleBackColor = true;
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
//
// OkBtn
//
this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.OkBtn.Location = new System.Drawing.Point(169, 145);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.TabIndex = 2;
this.OkBtn.Text = "&OK";
this.OkBtn.UseVisualStyleBackColor = true;
this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click);
//
// PCEControllerConfig
//
this.AcceptButton = this.OkBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CancelBtn;
this.ClientSize = new System.Drawing.Size(307, 180);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.OkBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PCEControllerConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Controller Settings";
this.Load += new System.EventHandler(this.PCEControllerConfig_Load);
this.ResumeLayout(false);
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PCEControllerConfig));
this.CancelBtn = new System.Windows.Forms.Button();
this.OkBtn = new System.Windows.Forms.Button();
this.ControllerPropertyGrid = new System.Windows.Forms.PropertyGrid();
this.SuspendLayout();
//
// CancelBtn
//
this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.Location = new System.Drawing.Point(235, 203);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.TabIndex = 3;
this.CancelBtn.Text = "&Cancel";
this.CancelBtn.UseVisualStyleBackColor = true;
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
//
// OkBtn
//
this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.OkBtn.Location = new System.Drawing.Point(169, 203);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.TabIndex = 2;
this.OkBtn.Text = "&OK";
this.OkBtn.UseVisualStyleBackColor = true;
this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click);
//
// ControllerPropertyGrid
//
this.ControllerPropertyGrid.Location = new System.Drawing.Point(12, 12);
this.ControllerPropertyGrid.Name = "ControllerPropertyGrid";
this.ControllerPropertyGrid.PropertySort = System.Windows.Forms.PropertySort.Alphabetical;
this.ControllerPropertyGrid.Size = new System.Drawing.Size(283, 181);
this.ControllerPropertyGrid.TabIndex = 4;
this.ControllerPropertyGrid.ToolbarVisible = false;
//
// PCEControllerConfig
//
this.AcceptButton = this.OkBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CancelBtn;
this.ClientSize = new System.Drawing.Size(307, 238);
this.Controls.Add(this.ControllerPropertyGrid);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.OkBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PCEControllerConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Controller Settings";
this.Load += new System.EventHandler(this.PCEControllerConfig_Load);
this.ResumeLayout(false);
}
@ -81,5 +92,6 @@
private System.Windows.Forms.Button CancelBtn;
private System.Windows.Forms.Button OkBtn;
private System.Windows.Forms.PropertyGrid ControllerPropertyGrid;
}
}

View File

@ -1,6 +1,4 @@
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Emulation.Cores.PCEngine;
@ -10,6 +8,8 @@ namespace BizHawk.Client.EmuHawk
{
public partial class PCEControllerConfig : Form
{
private PCEngine.PCESyncSettings _controllerSettings;
public PCEControllerConfig()
{
InitializeComponent();
@ -18,37 +18,13 @@ namespace BizHawk.Client.EmuHawk
private void PCEControllerConfig_Load(object sender, EventArgs e)
{
var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings();
for (int i = 0; i < 5; i++)
{
Controls.Add(new Label
{
Text = "Controller " + (i + 1),
Location = new Point(15, 15 + (i * 25))
});
Controls.Add(new CheckBox
{
Text = "Connected",
Name = "Controller" + i,
Location = new Point(135, 15 + (i * 25)),
Checked = pceSettings.Controllers[i].IsConnected
});
}
_controllerSettings = pceSettings; // Assumes only controller data is in sync settings! If there are ever more sync settings, this dialog should just become a general sync settings dialog (or both settings/sync settings)
ControllerPropertyGrid.SelectedObject = _controllerSettings;
}
private void OkBtn_Click(object sender, EventArgs e)
{
var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings();
Controls
.OfType<CheckBox>()
.OrderBy(c => c.Name)
.ToList()
.ForEach(c =>
{
var index = int.Parse(c.Name.Replace("Controller", ""));
pceSettings.Controllers[index].IsConnected = c.Checked;
});
GlobalWin.MainForm.PutCoreSyncSettings(pceSettings);
GlobalWin.MainForm.PutCoreSyncSettings(_controllerSettings);
DialogResult = DialogResult.OK;
Close();
}

View File

@ -1,7 +1,10 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.PCEngine;
namespace BizHawk.Client.EmuHawk
{
@ -13,9 +16,34 @@ namespace BizHawk.Client.EmuHawk
{
public IEnumerable<PadSchema> GetPadSchemas(IEmulator core)
{
for (var i = 0; i < core.ControllerDefinition.PlayerCount; i++)
var ss = ((PCEngine)core).GetSyncSettings();
var padSchemas = new[]
{
yield return StandardController(i + 1);
ss.Port1,
ss.Port2,
ss.Port3,
ss.Port4,
ss.Port5,
}
.Where(p => p != PceControllerType.Unplugged)
.Select((p, i) => GenerateSchemaForPort(p, i + 1))
.Where(s => s != null);
return padSchemas;
}
private static PadSchema GenerateSchemaForPort(PceControllerType type, int controller)
{
switch (type)
{
default:
MessageBox.Show($"{type} is not supported yet");
return null;
case PceControllerType.Unplugged:
return null;
case PceControllerType.GamePad:
return StandardController(controller);
}
}
@ -29,7 +57,7 @@ namespace BizHawk.Client.EmuHawk
{
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Up",
Name = $"P{controller} Up",
DisplayName = "",
Icon = Properties.Resources.BlueUp,
Location = new Point(14, 12),
@ -37,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Down",
Name = $"P{controller} Down",
DisplayName = "",
Icon = Properties.Resources.BlueDown,
Location = new Point(14, 56),
@ -45,7 +73,7 @@ namespace BizHawk.Client.EmuHawk
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Left",
Name = $"P{controller} Left",
DisplayName = "",
Icon = Properties.Resources.Back,
Location = new Point(2, 34),
@ -53,7 +81,7 @@ namespace BizHawk.Client.EmuHawk
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Right",
Name = $"P{controller} Right",
DisplayName = "",
Icon = Properties.Resources.Forward,
Location = new Point(24, 34),
@ -61,28 +89,28 @@ namespace BizHawk.Client.EmuHawk
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " B2",
Name = $"P{controller} B2",
DisplayName = "II",
Location = new Point(122, 34),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " B1",
Name = $"P{controller} B1",
DisplayName = "I",
Location = new Point(146, 34),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Select",
Name = $"P{controller} Select",
DisplayName = "s",
Location = new Point(52, 34),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Run",
Name = $"P{controller} Run",
DisplayName = "R",
Location = new Point(74, 34),
Type = PadSchema.PadInputType.Boolean

View File

@ -1008,6 +1008,7 @@
<Compile Include="Consoles\PC Engine\ADPCM.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.TurboCD.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.Populous.cs" />
<Compile Include="Consoles\PC Engine\PceControllerDeck.cs" />
<Compile Include="Consoles\PC Engine\PCEngine.ArcadeCard.cs" />
<Compile Include="Consoles\PC Engine\PCEngine.ICodeDataLogger.cs">
<DependentUpon>PCEngine.cs</DependentUpon>

View File

@ -6,7 +6,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
public IEmulatorServiceProvider ServiceProvider { get; private set; }
public ControllerDefinition ControllerDefinition => PCEngineController;
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
public void FrameAdvance(IController controller, bool render, bool rendersound)
{

View File

@ -1,4 +1,7 @@
using BizHawk.Emulation.Common;
using System.ComponentModel;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.PCEngine
{
@ -35,7 +38,6 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
bool ret = PCESyncSettings.NeedsReboot(o, _syncSettings);
_syncSettings = o;
// SetControllerButtons(); // not safe to change the controller during emulation, so instead make it a reboot event
return ret;
}
@ -62,42 +64,48 @@ namespace BizHawk.Emulation.Cores.PCEngine
public class PCESyncSettings
{
public ControllerSetting[] Controllers =
{
new ControllerSetting { IsConnected = true },
new ControllerSetting { IsConnected = false },
new ControllerSetting { IsConnected = false },
new ControllerSetting { IsConnected = false },
new ControllerSetting { IsConnected = false }
};
[DefaultValue(PceControllerType.GamePad)]
[DisplayName("Port 1 Device")]
[Description("The type of controller plugged into the first controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port1 { get; set; } = PceControllerType.GamePad;
[DefaultValue(PceControllerType.Unplugged)]
[DisplayName("Port 2 Device")]
[Description("The type of controller plugged into the second controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port2 { get; set; } = PceControllerType.Unplugged;
[DefaultValue(PceControllerType.Unplugged)]
[DisplayName("Port 3 Device")]
[Description("The type of controller plugged into the third controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port3 { get; set; } = PceControllerType.Unplugged;
[DefaultValue(PceControllerType.Unplugged)]
[DisplayName("Port 4 Device")]
[Description("The type of controller plugged into the fourth controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port4 { get; set; } = PceControllerType.Unplugged;
[DefaultValue(PceControllerType.Unplugged)]
[DisplayName("Port 5 Device")]
[Description("The type of controller plugged into the fifth controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port5 { get; set; } = PceControllerType.Unplugged;
public PCESyncSettings Clone()
{
var ret = new PCESyncSettings();
for (int i = 0; i < Controllers.Length; i++)
{
ret.Controllers[i].IsConnected = Controllers[i].IsConnected;
}
return ret;
}
public class ControllerSetting
{
public bool IsConnected { get; set; }
return (PCESyncSettings)MemberwiseClone();
}
public static bool NeedsReboot(PCESyncSettings x, PCESyncSettings y)
{
for (int i = 0; i < x.Controllers.Length; i++)
{
if (x.Controllers[i].IsConnected != y.Controllers[i].IsConnected)
{
return true;
}
}
return false;
return x.Port1 != y.Port1
|| x.Port2 != y.Port2
|| x.Port3 != y.Port3
|| x.Port4 != y.Port4
|| x.Port5 != y.Port5;
}
}
}

View File

@ -1,92 +1,41 @@
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.PCEngine
namespace BizHawk.Emulation.Cores.PCEngine
{
public partial class PCEngine
{
private readonly ControllerDefinition PCEngineController = new ControllerDefinition
{
Name = "PC Engine Controller",
BoolButtons =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Select", "P1 Run", "P1 B2", "P1 B1",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Run", "P2 B2", "P2 B1",
"P3 Up", "P3 Down", "P3 Left", "P3 Right", "P3 Select", "P3 Run", "P3 B2", "P3 B1",
"P4 Up", "P4 Down", "P4 Left", "P4 Right", "P4 Select", "P4 Run", "P4 B2", "P4 B1",
"P5 Up", "P5 Down", "P5 Left", "P5 Right", "P5 Select", "P5 Run", "P5 B2", "P5 B1"
}
};
private int _selectedController;
private byte _inputByte;
private void SetControllerButtons()
{
ControllerDefinition.BoolButtons.Clear();
ControllerDefinition.FloatControls.Clear();
for (int i = 0; i < 5; i++)
{
if (_syncSettings.Controllers[i].IsConnected)
{
ControllerDefinition.BoolButtons.AddRange(new[]
{
"P" + (i + 1) + " Up",
"P" + (i + 1) + " Down",
"P" + (i + 1) + " Left",
"P" + (i + 1) + " Right",
"P" + (i + 1) + " Select",
"P" + (i + 1) + " Run",
"P" + (i + 1) + " B1",
"P" + (i + 1) + " B2"
});
}
}
}
private int SelectedController;
private byte InputByte;
public bool SEL => (InputByte & 1) != 0;
public bool CLR => (InputByte & 2) != 0;
private bool Sel => (_inputByte & 1) != 0;
private bool Clr => (_inputByte & 2) != 0;
private void WriteInput(byte value)
{
bool prevSEL = SEL;
InputByte = value;
bool prevSel = Sel;
_inputByte = value;
if (SEL && CLR)
if (Sel && Clr)
{
SelectedController = 0;
_selectedController = 0;
}
if (CLR == false && prevSEL == false && SEL == true)
if (Clr == false && prevSel == false && Sel)
{
SelectedController = (SelectedController + 1);
_selectedController = _selectedController + 1;
}
}
private readonly PceControllerDeck _controllerDeck;
private byte ReadInput()
{
InputCallbacks.Call();
byte value = 0x3F;
int player = SelectedController + 1;
int player = _selectedController + 1;
if (player < 6)
{
_lagged = false;
if (SEL == false) // return buttons
{
if (_controller.IsPressed("P" + player + " B1")) value &= 0xFE;
if (_controller.IsPressed("P" + player + " B2")) value &= 0xFD;
if (_controller.IsPressed("P" + player + " Select")) value &= 0xFB;
if (_controller.IsPressed("P" + player + " Run")) value &= 0xF7;
}
else
{
//return directions
if (_controller.IsPressed("P" + player + " Up")) value &= 0xFE;
if (_controller.IsPressed("P" + player + " Right")) value &= 0xFD;
if (_controller.IsPressed("P" + player + " Down")) value &= 0xFB;
if (_controller.IsPressed("P" + player + " Left")) value &= 0xF7;
}
value &= _controllerDeck.Read(player, _controller, Sel);
}
if (Region == "Japan")

View File

@ -41,7 +41,13 @@ namespace BizHawk.Emulation.Cores.PCEngine
Settings = (PCESettings)settings ?? new PCESettings();
_syncSettings = (PCESyncSettings)syncSettings ?? new PCESyncSettings();
Init(game, rom);
SetControllerButtons();
_controllerDeck = new PceControllerDeck(
_syncSettings.Port1,
_syncSettings.Port2,
_syncSettings.Port3,
_syncSettings.Port4,
_syncSettings.Port5);
}
public PCEngine(CoreComm comm, GameInfo game, Disc disc, object Settings, object syncSettings)
@ -96,7 +102,13 @@ namespace BizHawk.Emulation.Cores.PCEngine
// the default RomStatusDetails don't do anything with Disc
CoreComm.RomStatusDetails = string.Format("{0}\r\nDisk partial hash:{1}", game.Name, new DiscSystem.DiscHasher(disc).OldHash());
SetControllerButtons();
_controllerDeck = new PceControllerDeck(
_syncSettings.Port1,
_syncSettings.Port2,
_syncSettings.Port3,
_syncSettings.Port4,
_syncSettings.Port5);
}
// ROM

View File

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.PCEngine
{
public enum PceControllerType
{
Unplugged,
GamePad
}
public class PceControllerDeck
{
private static readonly Type[] Implementors =
{
typeof(UnpluggedController), // Order must match PceControllerType enum values
typeof(StandardController)
};
public PceControllerDeck(
PceControllerType controller1,
PceControllerType controller2,
PceControllerType controller3,
PceControllerType controller4,
PceControllerType controller5)
{
_port1 = (IPort)Activator.CreateInstance(Implementors[(int)controller1], 1);
_port2 = (IPort)Activator.CreateInstance(Implementors[(int)controller2], 2);
_port3 = (IPort)Activator.CreateInstance(Implementors[(int)controller3], 3);
_port4 = (IPort)Activator.CreateInstance(Implementors[(int)controller4], 4);
_port5 = (IPort)Activator.CreateInstance(Implementors[(int)controller5], 5);
Definition = new ControllerDefinition
{
Name = "PC Engine Controller",
BoolButtons = _port1.Definition.BoolButtons
.Concat(_port2.Definition.BoolButtons)
.Concat(_port3.Definition.BoolButtons)
.Concat(_port4.Definition.BoolButtons)
.Concat(_port5.Definition.BoolButtons)
.ToList()
};
Definition.FloatControls.AddRange(_port1.Definition.FloatControls);
Definition.FloatControls.AddRange(_port2.Definition.FloatControls);
Definition.FloatControls.AddRange(_port3.Definition.FloatControls);
Definition.FloatControls.AddRange(_port4.Definition.FloatControls);
Definition.FloatControls.AddRange(_port5.Definition.FloatControls);
Definition.FloatRanges.AddRange(_port1.Definition.FloatRanges);
Definition.FloatRanges.AddRange(_port2.Definition.FloatRanges);
Definition.FloatRanges.AddRange(_port3.Definition.FloatRanges);
Definition.FloatRanges.AddRange(_port4.Definition.FloatRanges);
Definition.FloatRanges.AddRange(_port5.Definition.FloatRanges);
}
private readonly IPort _port1;
private readonly IPort _port2;
private readonly IPort _port3;
private readonly IPort _port4;
private readonly IPort _port5;
public byte Read(int portNum, IController c, bool sel)
{
switch (portNum)
{
default:
throw new ArgumentException($"Invalid {nameof(portNum)}: {portNum}");
case 1:
return _port1.Read(c, sel);
case 2:
return _port2.Read(c, sel);
case 3:
return _port3.Read(c, sel);
case 4:
return _port4.Read(c, sel);
case 5:
return _port5.Read(c, sel);
}
}
public ControllerDefinition Definition { get; }
}
public interface IPort
{
byte Read(IController c, bool sel);
ControllerDefinition Definition { get; }
int PortNum { get; }
}
public class UnpluggedController : IPort
{
public UnpluggedController(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
BoolButtons = new List<string>()
};
}
public byte Read(IController c, bool sel)
{
return 0x3F;
}
public ControllerDefinition Definition { get; }
public int PortNum { get; }
}
public class StandardController : IPort
{
public StandardController(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
BoolButtons = BaseDefinition
.Select(b => $"P{PortNum} " + b)
.ToList()
};
}
public ControllerDefinition Definition { get; }
public int PortNum { get; }
public byte Read(IController c, bool sel)
{
byte result = 0x3F;
if (sel == false)
{
if (c.IsPressed($"P{PortNum} B1")) result &= 0xFE;
if (c.IsPressed($"P{PortNum} B2")) result &= 0xFD;
if (c.IsPressed($"P{PortNum} Select")) result &= 0xFB;
if (c.IsPressed($"P{PortNum} Run")) result &= 0xF7;
}
else
{
if (c.IsPressed($"P{PortNum} Up")) { result &= 0xFE; }
if (c.IsPressed($"P{PortNum} Right")) { result &= 0xFD; }
if (c.IsPressed($"P{PortNum} Down")) { result &= 0xFB; }
if (c.IsPressed($"P{PortNum} Left")) { result &= 0xF7; }
}
return result;
}
private static readonly string[] BaseDefinition =
{
"Up", "Down", "Left", "Right", "Select", "Run", "B2", "B1"
};
}
}