psx - hook up non-dualshock pad types

This commit is contained in:
zeromus 2015-02-01 07:45:41 +00:00
parent 91c130a07a
commit 0c1dedbe75
7 changed files with 96 additions and 64 deletions

View File

@ -35,47 +35,13 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
{ {
public string SystemId { get { return "PSX"; } } public string SystemId { get { return "PSX"; } }
public static readonly ControllerDefinition PSXControllerDefinition = new ControllerDefinition
{
Name = "DualShock Controller",
BoolButtons =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Select", "P1 Start", "P1 Square", "P1 Triangle", "P1 Circle", "P1 Cross", "P1 L1",
"P1 R1", "P1 L2", "P1 R2", "P1 L3", "P1 R3", "P1 MODE",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Start", "P2 Square", "P2 Triangle", "P2 Circle", "P2 Cross", "P2 L1",
"P2 R1", "P2 L2", "P2 R2", "P2 L3", "P2 R3", "P2 MODE",
"Open", "Close", "Reset",
},
FloatControls =
{
"P1 LStick X", "P1 LStick Y", "P1 RStick X", "P1 RStick Y",
"P2 LStick X", "P2 LStick Y", "P2 RStick X", "P2 RStick Y",
"Disc Select",
},
FloatRanges =
{
new[] {0.0f, 128.0f, 255.0f},
new[] {255.0f, 128.0f, 0.0f},
new[] {0.0f, 128.0f, 255.0f},
new[] {255.0f, 128.0f, 0.0f},
new[] {0.0f, 128.0f, 255.0f},
new[] {255.0f, 128.0f, 0.0f},
new[] {0.0f, 128.0f, 255.0f},
new[] {255.0f, 128.0f, 0.0f},
new[] {-1f,-1f,-1f}, //this is carefully chosen so that we end up with a -1 disc by default (indicating that it's never been set)
},
};
private void SetControllerButtons() private void SetControllerButtons()
{ {
// adelikat: ARG, stupid Disc Select hack gets set from something assuming controllers, so I'm disabling this here ControllerDefinition = new ControllerDefinition();
_SyncSettings.Controllers[0].IsConnected = true; ControllerDefinition.Name = "DualShock Controller"; //this is a poopy name.
_SyncSettings.Controllers[1].IsConnected = true;
return;
ControllerDefinition.BoolButtons.Clear(); ControllerDefinition.BoolButtons.Clear();
ControllerDefinition.FloatControls.Clear(); ControllerDefinition.FloatControls.Clear();
for (int i = 0; i < _SyncSettings.Controllers.Length; i++) for (int i = 0; i < _SyncSettings.Controllers.Length; i++)
{ {
@ -356,8 +322,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
frameBuffer = new int[BufferWidth * BufferHeight]; frameBuffer = new int[BufferWidth * BufferHeight];
} }
SetControllerButtons();
if (discInterfaces.Count != 0) if (discInterfaces.Count != 0)
{ {
//start with first disc inserted and tray closed. it's a sensible default. //start with first disc inserted and tray closed. it's a sensible default.
@ -377,16 +341,24 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
OctoshockDll.shock_CloseTray(psx); OctoshockDll.shock_CloseTray(psx);
} }
//connect two dualshocks, thats all we're doing right now //setup the controller based on sync settings
SetControllerButtons();
var lookup = new Dictionary<ControllerSetting.ControllerType,OctoshockDll.ePeripheralType> {
{ ControllerSetting.ControllerType.Gamepad, OctoshockDll.ePeripheralType.Pad },
{ ControllerSetting.ControllerType.DualAnalog, OctoshockDll.ePeripheralType.DualAnalog },
{ ControllerSetting.ControllerType.DualShock, OctoshockDll.ePeripheralType.DualShock },
};
if (_SyncSettings.Controllers[0].IsConnected) if (_SyncSettings.Controllers[0].IsConnected)
{ {
OctoshockDll.shock_Peripheral_Connect(psx, 0x01, OctoshockDll.ePeripheralType.DualShock); OctoshockDll.shock_Peripheral_Connect(psx, 0x01, lookup[_SyncSettings.Controllers[0].Type]);
} }
if (_SyncSettings.Controllers[1].IsConnected) if (_SyncSettings.Controllers[1].IsConnected)
{ {
OctoshockDll.shock_Peripheral_Connect(psx, 0x02, OctoshockDll.ePeripheralType.DualShock); OctoshockDll.shock_Peripheral_Connect(psx, 0x01, lookup[_SyncSettings.Controllers[1].Type]);
} }
//do this after framebuffers and peripherals and whatever crap are setup. kind of lame, but thats how it is for now //do this after framebuffers and peripherals and whatever crap are setup. kind of lame, but thats how it is for now
@ -677,7 +649,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
} }
} }
public ControllerDefinition ControllerDefinition { get { return PSXControllerDefinition; } } public ControllerDefinition ControllerDefinition { get; private set; }
public IController Controller { get; set; } public IController Controller { get; set; }
public int Frame { get; private set; } public int Frame { get; private set; }

Binary file not shown.

View File

@ -24,6 +24,9 @@ class InputDevice_DualAnalog : public InputDevice
private: private:
//non-serialized state
IO_DualAnalog* io;
bool joystick_mode; bool joystick_mode;
bool dtr; bool dtr;
@ -74,10 +77,10 @@ void InputDevice_DualAnalog::Power(void)
void InputDevice_DualAnalog::UpdateInput(const void *data) void InputDevice_DualAnalog::UpdateInput(const void *data)
{ {
uint8 *d8 = (uint8 *)data; io = (IO_DualAnalog*)data;
buttons[0] = d8[0]; buttons[0] = io->buttons[0];
buttons[1] = d8[1]; buttons[1] = io->buttons[1];
//OCTOSHOCK EDIT - so we can set values directly //OCTOSHOCK EDIT - so we can set values directly
//for(int stick = 0; stick < 2; stick++) //for(int stick = 0; stick < 2; stick++)
@ -94,10 +97,10 @@ void InputDevice_DualAnalog::UpdateInput(const void *data)
// } // }
//} //}
axes[0][0] = d8[3]; axes[0][0] = io->right_x;
axes[0][1] = d8[4]; axes[0][1] = io->right_y;
axes[1][0] = d8[5]; axes[1][0] = io->left_x;
axes[1][1] = d8[6]; axes[1][1] = io->left_y;
//printf("%d %d %d %d\n", axes[0][0], axes[0][1], axes[1][0], axes[1][1]); //printf("%d %d %d %d\n", axes[0][0], axes[0][1], axes[1][0], axes[1][1]);
} }
@ -190,16 +193,17 @@ bool InputDevice_DualAnalog::Clock(bool TxD, int32 &dsr_pulse_delay)
transmit_buffer[4] = axes[0][1]; transmit_buffer[4] = axes[0][1];
transmit_buffer[5] = axes[1][0]; transmit_buffer[5] = axes[1][0];
transmit_buffer[6] = axes[1][1]; transmit_buffer[6] = axes[1][1];
transmit_pos = 0; transmit_pos = 0;
transmit_count = 7; transmit_count = 7;
io->active = true;
} }
else else
{ {
command_phase = -1; command_phase = -1;
transmit_buffer[1] = 0; transmit_buffer[1] = 0;
transmit_buffer[2] = 0; transmit_buffer[2] = 0;
transmit_pos = 0; transmit_pos = 0;
transmit_count = 0; transmit_count = 0;
} }
break; break;
case 2: case 2:

View File

@ -3,7 +3,16 @@
namespace MDFN_IEN_PSX namespace MDFN_IEN_PSX
{ {
InputDevice *Device_DualAnalog_Create(bool joystick_mode); InputDevice *Device_DualAnalog_Create(bool joystick_mode);
EW_PACKED(
struct IO_DualAnalog
{
u8 buttons[2];
u8 right_x, right_y;
u8 left_x, left_y;
u8 active;
});
} }
#endif #endif

View File

@ -24,6 +24,9 @@ class InputDevice_Gamepad : public InputDevice
private: private:
//non-serialized state
IO_Gamepad* io;
bool dtr; bool dtr;
uint8 buttons[2]; uint8 buttons[2];
@ -72,10 +75,10 @@ void InputDevice_Gamepad::Power(void)
void InputDevice_Gamepad::UpdateInput(const void *data) void InputDevice_Gamepad::UpdateInput(const void *data)
{ {
uint8 *d8 = (uint8 *)data; io = (IO_Gamepad*)data;
buttons[0] = d8[0]; buttons[0] = io->buttons[0];
buttons[1] = d8[1]; buttons[1] = io->buttons[1];
} }
@ -164,16 +167,17 @@ bool InputDevice_Gamepad::Clock(bool TxD, int32 &dsr_pulse_delay)
transmit_buffer[1] = 0xFF ^ buttons[0]; transmit_buffer[1] = 0xFF ^ buttons[0];
transmit_buffer[2] = 0xFF ^ buttons[1]; transmit_buffer[2] = 0xFF ^ buttons[1];
transmit_pos = 0; transmit_pos = 0;
transmit_count = 3; transmit_count = 3;
io->active = true;
} }
else else
{ {
command_phase = -1; command_phase = -1;
transmit_buffer[1] = 0; transmit_buffer[1] = 0;
transmit_buffer[2] = 0; transmit_buffer[2] = 0;
transmit_pos = 0; transmit_pos = 0;
transmit_count = 0; transmit_count = 0;
} }
break; break;

View File

@ -6,5 +6,12 @@ namespace MDFN_IEN_PSX
InputDevice *Device_Gamepad_Create(void); InputDevice *Device_Gamepad_Create(void);
EW_PACKED(
struct IO_Gamepad
{
u8 buttons[2];
u8 active;
});
} }
#endif #endif

View File

@ -29,6 +29,8 @@
#include "emuware/EW_state.h" #include "emuware/EW_state.h"
#include "input/dualshock.h" #include "input/dualshock.h"
#include "input/dualanalog.h"
#include "input/gamepad.h"
//#include <mednafen/PSFLoader.h> //#include <mednafen/PSFLoader.h>
@ -1120,6 +1122,22 @@ struct {
return ret; return ret;
break; break;
} }
case ePeripheralType_DualAnalog:
{
IO_DualAnalog* io_dualanalog = (IO_DualAnalog*)buf;
if(io_dualanalog->active) ret = SHOCK_TRUE;
if(clear) io_dualanalog->active = 0;
return ret;
break;
}
case ePeripheralType_Pad:
{
IO_Gamepad* io_gamepad = (IO_Gamepad*)buf;
if(io_gamepad->active) ret = SHOCK_TRUE;
if(clear) io_gamepad->active = 0;
return ret;
break;
}
case ePeripheralType_None: case ePeripheralType_None:
return SHOCK_NOCANDO; return SHOCK_NOCANDO;
@ -1152,6 +1170,24 @@ struct {
io_dualshock->left_y = left_y; io_dualshock->left_y = left_y;
return SHOCK_OK; return SHOCK_OK;
} }
case ePeripheralType_Pad:
{
IO_Gamepad* io_gamepad = (IO_Gamepad*)buf;
io_gamepad->buttons[0] = (buttons>>0)&0xFF;
io_gamepad->buttons[1] = (buttons>>8)&0xFF;
return SHOCK_OK;
}
case ePeripheralType_DualAnalog:
{
IO_DualAnalog* io_dualanalog = (IO_DualAnalog*)buf;
io_dualanalog->buttons[0] = (buttons>>0)&0xFF;
io_dualanalog->buttons[1] = (buttons>>8)&0xFF;
io_dualanalog->right_x = right_x;
io_dualanalog->right_y = right_y;
io_dualanalog->left_x = left_x;
io_dualanalog->left_y = left_y;
return SHOCK_OK;
}
default: default:
return SHOCK_ERROR; return SHOCK_ERROR;