Added Cursor(Protek) and Sinclair (left and right) joystick emulation. Also user can now set J1, J2, and J3 emulated joystick type through syncsettings

This commit is contained in:
Asnivor 2018-03-06 15:47:14 +00:00
parent 3cc4b94406
commit 93ae29c3a0
21 changed files with 775 additions and 68 deletions

View File

@ -256,6 +256,11 @@
<Compile Include="Computers\Commodore64\MOS\Vic.VideoProvider.cs" />
<Compile Include="Computers\Commodore64\SaveState.cs" />
<Compile Include="Computers\Commodore64\User\UserPortDevice.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\IJoystick.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\CursorJoystick.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\SinclairJoystick2.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\SinclairJoystick1.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\NullJoystick.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\SoundOuput\AY38912.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\SoundOuput\Buzzer.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Datacorder\DatacorderDevice.cs" />

View File

@ -0,0 +1,116 @@
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Cursor joystick
/// Maps to a combination of 0xf7fe and 0xeffe
/// </summary>
public class CursorJoystick : IJoystick
{
private int _joyLine;
private SpectrumBase _machine;
#region Construction
public CursorJoystick(SpectrumBase machine, int playerNumber)
{
_machine = machine;
_joyLine = 0;
_playerNumber = playerNumber;
ButtonCollection = new List<string>
{
"P" + _playerNumber + " Left",
"P" + _playerNumber + " Right",
"P" + _playerNumber + " Down",
"P" + _playerNumber + " Up",
"P" + _playerNumber + " Button",
}.ToArray();
}
private List<string> btnLookups = new List<string>
{
"Key 5", // left
"Key 8", // right
"Key 6", // down
"Key 7", // up
"Key 0", // fire
};
#endregion
#region IJoystick
public JoystickType JoyType => JoystickType.SinclairPORT1;
public string[] ButtonCollection { get; set; }
private int _playerNumber;
public int PlayerNumber
{
get { return _playerNumber; }
set { _playerNumber = value; }
}
/// <summary>
/// Sets the joystick line based on key pressed
/// </summary>
/// <param name="key"></param>
/// <param name="isPressed"></param>
public void SetJoyInput(string key, bool isPressed)
{
var pos = GetBitPos(key);
if (isPressed)
{
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], true);
}
else
{
if (_machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]))
{
// key is already pressed elswhere - leave it as is
}
else
{
// key is safe to unpress
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], false);
}
}
}
/// <summary>
/// Gets the state of a particular joystick binding
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool GetJoyInput(string key)
{
var pos = GetBitPos(key);
if (_machine == null)
return false;
var l = _machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]);
return l;
}
#endregion
/// <summary>
/// Gets the bit position of a particular joystick binding from the matrix
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public int GetBitPos(string key)
{
int index = Array.IndexOf(ButtonCollection, key);
return index;
}
}
}

View File

@ -0,0 +1,44 @@
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Represents a spectrum joystick
/// </summary>
public interface IJoystick
{
/// <summary>
/// The type of joystick
/// </summary>
JoystickType JoyType { get; }
/// <summary>
/// Array of all the possibly button press names
/// </summary>
string[] ButtonCollection { get; set; }
/// <summary>
/// The player number that this controller is currently assigned to
/// </summary>
int PlayerNumber { get; set; }
/// <summary>
/// Sets the joystick line based on key pressed
/// </summary>
/// <param name="key"></param>
/// <param name="isPressed"></param>
void SetJoyInput(string key, bool isPressed);
/// <summary>
/// Gets the state of a particular joystick binding
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
bool GetJoyInput(string key);
}
}

View File

@ -1,4 +1,5 @@
using System;
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,34 +7,42 @@ using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
public class KempstonJoystick
public class KempstonJoystick : IJoystick
{
private int _joyLine;
private SpectrumBase _machine;
public readonly string[] _bitPos = new string[]
{
"P1 Right",
"P1 Left",
"P1 Down",
"P1 Up",
"P1 Button"
};
#region Construction
/*
Active bits high
0 0 0 F U D L R
*/
public int JoyLine
{
get { return _joyLine; }
set { _joyLine = value; }
}
public KempstonJoystick(SpectrumBase machine)
public KempstonJoystick(SpectrumBase machine, int playerNumber)
{
_machine = machine;
_joyLine = 0;
_playerNumber = playerNumber;
ButtonCollection = new List<string>
{
"P" + _playerNumber + " Right",
"P" + _playerNumber + " Left",
"P" + _playerNumber + " Down",
"P" + _playerNumber + " Up",
"P" + _playerNumber + " Button",
}.ToArray();
}
#endregion
#region IJoystick
public JoystickType JoyType => JoystickType.Kempston;
public string[] ButtonCollection { get; set; }
private int _playerNumber;
public int PlayerNumber
{
get { return _playerNumber; }
set { _playerNumber = value; }
}
/// <summary>
@ -60,6 +69,18 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
var pos = GetBitPos(key);
return (_joyLine & (1 << pos)) != 0;
}
#endregion
/// <summary>
/// Active bits high
/// 0 0 0 F U D L R
/// </summary>
public int JoyLine
{
get { return _joyLine; }
set { _joyLine = value; }
}
/// <summary>
/// Gets the bit position of a particular joystick binding from the matrix
@ -68,8 +89,20 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <returns></returns>
public int GetBitPos(string key)
{
int index = Array.IndexOf(_bitPos, key);
int index = Array.IndexOf(ButtonCollection, key);
return index;
}
/*
public readonly string[] _bitPos = new string[]
{
"P1 Right",
"P1 Left",
"P1 Down",
"P1 Up",
"P1 Button"
};
*/
}
}

View File

@ -0,0 +1,107 @@
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// A null joystick object
/// </summary>
public class NullJoystick : IJoystick
{
private int _joyLine;
private SpectrumBase _machine;
#region Construction
public NullJoystick(SpectrumBase machine, int playerNumber)
{
_machine = machine;
_joyLine = 0;
_playerNumber = playerNumber;
ButtonCollection = new List<string>
{
}.ToArray();
}
#endregion
#region IJoystick
public JoystickType JoyType => JoystickType.None;
public string[] ButtonCollection { get; set; }
private int _playerNumber;
public int PlayerNumber
{
get { return _playerNumber; }
set { _playerNumber = value; }
}
/// <summary>
/// Sets the joystick line based on key pressed
/// </summary>
/// <param name="key"></param>
/// <param name="isPressed"></param>
public void SetJoyInput(string key, bool isPressed)
{
var pos = GetBitPos(key);
if (isPressed)
_joyLine |= (1 << pos);
else
_joyLine &= ~(1 << pos);
}
/// <summary>
/// Gets the state of a particular joystick binding
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool GetJoyInput(string key)
{
var pos = GetBitPos(key);
return (_joyLine & (1 << pos)) != 0;
}
#endregion
/// <summary>
/// Active bits high
/// 0 0 0 F U D L R
/// </summary>
public int JoyLine
{
get { return _joyLine; }
set { _joyLine = value; }
}
/// <summary>
/// Gets the bit position of a particular joystick binding from the matrix
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public int GetBitPos(string key)
{
int index = Array.IndexOf(ButtonCollection, key);
return index;
}
/*
public readonly string[] _bitPos = new string[]
{
"P1 Right",
"P1 Left",
"P1 Down",
"P1 Up",
"P1 Button"
};
*/
}
}

View File

@ -0,0 +1,115 @@
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Sinclair Joystick LEFT
/// Just maps to the standard keyboard and is read the same (from port 0xf7fe)
/// </summary>
public class SinclairJoystick1 : IJoystick
{
private int _joyLine;
private SpectrumBase _machine;
#region Construction
public SinclairJoystick1(SpectrumBase machine, int playerNumber)
{
_machine = machine;
_joyLine = 0;
_playerNumber = playerNumber;
ButtonCollection = new List<string>
{
"P" + _playerNumber + " Left",
"P" + _playerNumber + " Right",
"P" + _playerNumber + " Down",
"P" + _playerNumber + " Up",
"P" + _playerNumber + " Button",
}.ToArray();
}
private List<string> btnLookups = new List<string>
{
"Key 1", // left
"Key 2", // right
"Key 3", // down
"Key 4", // up
"Key 5", // fire
};
#endregion
#region IJoystick
public JoystickType JoyType => JoystickType.SinclairPORT1;
public string[] ButtonCollection { get; set; }
private int _playerNumber;
public int PlayerNumber
{
get { return _playerNumber; }
set { _playerNumber = value; }
}
/// <summary>
/// Sets the joystick line based on key pressed
/// </summary>
/// <param name="key"></param>
/// <param name="isPressed"></param>
public void SetJoyInput(string key, bool isPressed)
{
var pos = GetBitPos(key);
if (isPressed)
{
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], true);
}
else
{
if (_machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]))
{
// key is already pressed elswhere - leave it as is
}
else
{
// key is safe to unpress
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], false);
}
}
}
/// <summary>
/// Gets the state of a particular joystick binding
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool GetJoyInput(string key)
{
var pos = GetBitPos(key);
if (_machine == null)
return false;
return _machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]);
}
#endregion
/// <summary>
/// Gets the bit position of a particular joystick binding from the matrix
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public int GetBitPos(string key)
{
int index = Array.IndexOf(ButtonCollection, key);
return index;
}
}
}

View File

@ -0,0 +1,115 @@
using BizHawk.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Sinclair Joystick RIGHT
/// Just maps to the standard keyboard and is read the same (from port 0xeffe)
/// </summary>
public class SinclairJoystick2 : IJoystick
{
private int _joyLine;
private SpectrumBase _machine;
#region Construction
public SinclairJoystick2(SpectrumBase machine, int playerNumber)
{
_machine = machine;
_joyLine = 0;
_playerNumber = playerNumber;
ButtonCollection = new List<string>
{
"P" + _playerNumber + " Left",
"P" + _playerNumber + " Right",
"P" + _playerNumber + " Down",
"P" + _playerNumber + " Up",
"P" + _playerNumber + " Button",
}.ToArray();
}
private List<string> btnLookups = new List<string>
{
"Key 6", // left
"Key 7", // right
"Key 8", // down
"Key 9", // up
"Key 0", // fire
};
#endregion
#region IJoystick
public JoystickType JoyType => JoystickType.SinclairPORT1;
public string[] ButtonCollection { get; set; }
private int _playerNumber;
public int PlayerNumber
{
get { return _playerNumber; }
set { _playerNumber = value; }
}
/// <summary>
/// Sets the joystick line based on key pressed
/// </summary>
/// <param name="key"></param>
/// <param name="isPressed"></param>
public void SetJoyInput(string key, bool isPressed)
{
var pos = GetBitPos(key);
if (isPressed)
{
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], true);
}
else
{
if (_machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]))
{
// key is already pressed elswhere - leave it as is
}
else
{
// key is safe to unpress
_machine.KeyboardDevice.SetKeyStatus(btnLookups[pos], false);
}
}
}
/// <summary>
/// Gets the state of a particular joystick binding
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool GetJoyInput(string key)
{
var pos = GetBitPos(key);
if (_machine == null)
return false;
return _machine.KeyboardDevice.GetKeyStatus(btnLookups[pos]);
}
#endregion
/// <summary>
/// Gets the bit position of a particular joystick binding from the matrix
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public int GetBitPos(string key)
{
int index = Array.IndexOf(ButtonCollection, key);
return index;
}
}
}

View File

@ -1,4 +1,7 @@

using System.Collections.Generic;
using System.Linq;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
@ -37,6 +40,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
// non matrix keys
/*
foreach (string k in KeyboardDevice.NonMatrixKeys)
{
if (!k.StartsWith("Key"))
@ -46,17 +50,40 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
KeyboardDevice.SetKeyStatus(k, currState);
}
*/
// J1
foreach (string j in JoystickCollection[0].ButtonCollection)
{
bool prevState = JoystickCollection[0].GetJoyInput(j);
bool currState = Spectrum._controller.IsPressed(j);
if (currState != prevState)
JoystickCollection[0].SetJoyInput(j, currState);
}
// J2
foreach (string j in JoystickCollection[1].ButtonCollection)
{
bool prevState = JoystickCollection[1].GetJoyInput(j);
bool currState = Spectrum._controller.IsPressed(j);
if (currState != prevState)
JoystickCollection[1].SetJoyInput(j, currState);
}
// J3
foreach (string j in JoystickCollection[2].ButtonCollection)
{
bool prevState = JoystickCollection[2].GetJoyInput(j);
bool currState = Spectrum._controller.IsPressed(j);
if (currState != prevState)
JoystickCollection[2].SetJoyInput(j, currState);
}
}
// J1
foreach (string j in KempstonDevice._bitPos)
{
bool prevState = KempstonDevice.GetJoyInput(j);
bool currState = Spectrum._controller.IsPressed(j);
if (currState != prevState)
KempstonDevice.SetJoyInput(j, currState);
}
// Tape control
if (Spectrum._controller.IsPressed(Play))
@ -123,6 +150,62 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
else
pressed_PrevTape = false;
}
/// <summary>
/// Instantiates the joysticks array
/// </summary>
/// <param name="joys"></param>
protected void InitJoysticks(List<JoystickType> joys)
{
List<IJoystick> jCollection = new List<IJoystick>();
for (int i = 0; i < joys.Count(); i++)
{
jCollection.Add(InstantiateJoystick(joys[i], i + 1));
}
JoystickCollection = jCollection.ToArray();
for (int i = 0; i < JoystickCollection.Length; i++)
{
Spectrum.OSD_FireInputMessage("Joystick " + (i + 1) + ": " + JoystickCollection[i].JoyType.ToString());
}
}
/// <summary>
/// Instantiates a new IJoystick object
/// </summary>
/// <param name="type"></param>
/// <param name="playerNumber"></param>
/// <returns></returns>
public IJoystick InstantiateJoystick(JoystickType type, int playerNumber)
{
switch (type)
{
case JoystickType.Kempston:
return new KempstonJoystick(this, playerNumber);
case JoystickType.Cursor:
return new CursorJoystick(this, playerNumber);
case JoystickType.SinclairPORT1:
return new SinclairJoystick1(this, playerNumber);
case JoystickType.SinclairPORT2:
return new SinclairJoystick2(this, playerNumber);
case JoystickType.None:
return new NullJoystick(this, playerNumber);
}
return null;
}
/// <summary>
/// Returns a IJoystick object depending on the type (or null if not found)
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
protected IJoystick LocateUniqueJoystick(JoystickType type)
{
return JoystickCollection.Where(a => a.JoyType == type).FirstOrDefault();
}
}
}

View File

@ -2,6 +2,7 @@
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.Z80A;
using System;
using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
@ -72,14 +73,27 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public virtual DatacorderDevice TapeDevice { get; set; }
/// <summary>
/// The tape provider
/// Holds the currently selected joysticks
/// </summary>
//public virtual ITapeProvider TapeProvider { get; set; }
public virtual IJoystick[] JoystickCollection { get; set; }
/*
/// <summary>
/// Joystick device 1
/// </summary>
public virtual IJoystick Joystick1 { get; set; }
/// <summary>
/// Kempston joystick
/// Joystick device 2
/// </summary>
public virtual KempstonJoystick KempstonDevice { get; set; }
public virtual IJoystick Joystick2 { get; set; }
/// <summary>
/// Joystick device 3
/// </summary>
public virtual IJoystick Joystick3 { get; set; }
*/
/// <summary>
/// Signs whether the frame has ended

View File

@ -27,7 +27,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// Kempston Joystick
if ((port & 0xe0) == 0 || (port & 0x20) == 0)
{
return (byte)KempstonDevice.JoyLine;
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
}
else if (lowBitReset)
{

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files, List<JoystickType> joysticks)
{
Spectrum = spectrum;
CPU = cpu;
@ -38,7 +38,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
AYDevice.Init(44100, ULADevice.FrameLength);
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
InitJoysticks(joysticks);
//KempstonDevice = new KempstonJoystick(this);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);

View File

@ -20,8 +20,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128Plus2(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
: base(spectrum, cpu, borderType, files)
public ZX128Plus2(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files, List<JoystickType> joysticks)
: base(spectrum, cpu, borderType, files, joysticks)
{
}

View File

@ -26,7 +26,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// Kempston Joystick
if ((port & 0xe0) == 0 || (port & 0x20) == 0)
{
return (byte)KempstonDevice.JoyLine;
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
}
else if (lowBitReset)
{

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128Plus3(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
public ZX128Plus3(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files, List<JoystickType> joysticks)
{
Spectrum = spectrum;
CPU = cpu;
@ -38,7 +38,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
AYDevice.Init(44100, ULADevice.FrameLength);
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
InitJoysticks(joysticks);
//KempstonDevice = new KempstonJoystick(this);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);

View File

@ -16,8 +16,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX16(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
: base(spectrum, cpu, borderType, files)
public ZX16(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files, List<JoystickType> joysticks)
: base(spectrum, cpu, borderType, files, joysticks)
{
}

View File

@ -68,11 +68,13 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
};
var nonMatrix = new List<string>();
/*
foreach (var key in ZXSpectrum.ZXSpectrumControllerDefinition.BoolButtons)
{
if (!KeyboardMatrix.Any(s => s == key))
nonMatrix.Add(key);
}
*/
NonMatrixKeys = nonMatrix.ToArray();
LineStatus = new byte[8];

View File

@ -26,7 +26,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// Kempston Joystick
if ((port & 0xe0) == 0 || (port & 0x20) == 0)
{
return (byte)KempstonDevice.JoyLine;
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
}
else if (lowBitReset)
{

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX48(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
public ZX48(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files, List<JoystickType> joysticks)
{
Spectrum = spectrum;
CPU = cpu;
@ -29,7 +29,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
BuzzerDevice.Init(44100, ULADevice.FrameLength);
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
InitJoysticks(joysticks);
//KempstonDevice = new KempstonJoystick(this);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);

View File

@ -1,6 +1,10 @@

using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
@ -17,16 +21,40 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
definition.Name = "ZXSpectrum Controller";
// joysticks
List<string> joys = new List<string>
List<string> joys1 = new List<string>
{
// Kempston Joystick (P1)
// P1 Joystick
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
};
foreach (var s in joys)
foreach (var s in joys1)
{
definition.BoolButtons.Add(s);
definition.CategoryLabels[s] = "Kempton Joystick";
definition.CategoryLabels[s] = "Joystick 1";
}
List<string> joys2 = new List<string>
{
// P2 Joystick
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button",
};
foreach (var s in joys2)
{
definition.BoolButtons.Add(s);
definition.CategoryLabels[s] = "Joystick 2";
}
List<string> joys3 = new List<string>
{
// P3 Joystick
"P3 Up", "P3 Down", "P3 Left", "P3 Right", "P3 Button",
};
foreach (var s in joys3)
{
definition.BoolButtons.Add(s);
definition.CategoryLabels[s] = "Joystick 3";
}
// keyboard
@ -71,6 +99,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
}
/*
/// <summary>
/// Controller mapping includes all keyboard keys from the following models:
@ -101,4 +131,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
*/
}
/// <summary>
/// The possible joystick types
/// </summary>
public enum JoystickType
{
None,
Kempston,
SinclairPORT1,
SinclairPORT2,
Cursor
}
}

View File

@ -85,7 +85,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
[DisplayName("Tape Load Speed")]
[Description("Select how fast the spectrum loads the game from tape")]
[DefaultValue(TapeLoadSpeed.Accurate)]
public TapeLoadSpeed TapeLoadSpeed { get; set; }
public TapeLoadSpeed TapeLoadSpeed { get; set; }
[DisplayName("Joystick 1")]
[Description("The emulated joystick assigned to P1 (SHOULD BE UNIQUE TYPE!)")]
[DefaultValue(JoystickType.Kempston)]
public JoystickType JoystickType1 { get; set; }
[DisplayName("Joystick 2")]
[Description("The emulated joystick assigned to P2 (SHOULD BE UNIQUE TYPE!)")]
[DefaultValue(JoystickType.SinclairPORT1)]
public JoystickType JoystickType2 { get; set; }
[DisplayName("Joystick 3")]
[Description("The emulated joystick assigned to P3 (SHOULD BE UNIQUE TYPE!)")]
[DefaultValue(JoystickType.SinclairPORT2)]
public JoystickType JoystickType3 { get; set; }
public ZXSpectrumSyncSettings Clone()
{

View File

@ -39,27 +39,32 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//_file = file;
_files = files?.ToList() ?? new List<byte[]>();
List<JoystickType> joysticks = new List<JoystickType>();
joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType1);
joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType2);
joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType3);
switch (SyncSettings.MachineType)
{
case MachineType.ZXSpectrum16:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
break;
case MachineType.ZXSpectrum48:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
break;
case MachineType.ZXSpectrum128:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
break;
case MachineType.ZXSpectrum128Plus2:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
break;
case MachineType.ZXSpectrum128Plus3:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
break;
default:
throw new InvalidOperationException("Machine not yet emulated");
@ -101,7 +106,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
private readonly Z80A _cpu;
private readonly TraceBuffer _tracer;
public IController _controller;
private SpectrumBase _machine;
public SpectrumBase _machine;
private List<GameInfo> _gameInfo;
@ -112,7 +117,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//private byte[] _file;
private readonly List<byte[]> _files;
public bool DiagRom = false;
public bool DiagRom = true;
private byte[] GetFirmware(int length, params string[] names)
{
@ -158,37 +163,37 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
private void Init(MachineType machineType, BorderType borderType, TapeLoadSpeed tapeLoadSpeed, List<byte[]> files)
private void Init(MachineType machineType, BorderType borderType, TapeLoadSpeed tapeLoadSpeed, List<byte[]> files, List<JoystickType> joys)
{
// setup the emulated model based on the MachineType
switch (machineType)
{
case MachineType.ZXSpectrum16:
_machine = new ZX16(this, _cpu, borderType, files);
_machine = new ZX16(this, _cpu, borderType, files, joys);
var _systemRom16 = GetFirmware(0x4000, "48ROM");
var romData16 = RomData.InitROM(machineType, _systemRom16);
_machine.InitROM(romData16);
break;
case MachineType.ZXSpectrum48:
_machine = new ZX48(this, _cpu, borderType, files);
_machine = new ZX48(this, _cpu, borderType, files, joys);
var _systemRom = GetFirmware(0x4000, "48ROM");
var romData = RomData.InitROM(machineType, _systemRom);
_machine.InitROM(romData);
break;
case MachineType.ZXSpectrum128:
_machine = new ZX128(this, _cpu, borderType, files);
_machine = new ZX128(this, _cpu, borderType, files, joys);
var _systemRom128 = GetFirmware(0x8000, "128ROM");
var romData128 = RomData.InitROM(machineType, _systemRom128);
_machine.InitROM(romData128);
break;
case MachineType.ZXSpectrum128Plus2:
_machine = new ZX128Plus2(this, _cpu, borderType, files);
_machine = new ZX128Plus2(this, _cpu, borderType, files, joys);
var _systemRomP2 = GetFirmware(0x8000, "PLUS2ROM");
var romDataP2 = RomData.InitROM(machineType, _systemRomP2);
_machine.InitROM(romDataP2);
break;
case MachineType.ZXSpectrum128Plus3:
_machine = new ZX128Plus3(this, _cpu, borderType, files);
_machine = new ZX128Plus3(this, _cpu, borderType, files, joys);
var _systemRomP3 = GetFirmware(0x10000, "PLUS3ROM");
var romDataP3 = RomData.InitROM(machineType, _systemRomP3);
_machine.InitROM(romDataP3);