Skip to content

Commit

Permalink
multiplayer working with default button mapping and USB joystick for …
Browse files Browse the repository at this point in the history
…player 2
  • Loading branch information
valentecaio committed Jul 18, 2020
1 parent 02d2886 commit 53cdc9b
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 137 deletions.
4 changes: 2 additions & 2 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ int SaveState(const char *file) {
|| mdecFreeze(f, FREEZE_SAVE) )
goto error;

if (freeze_rw(f, FREEZE_SAVE, &player_controller[0], sizeof(struct ps1_controller)))
if (freeze_rw(f, FREEZE_SAVE, &controllers[0], sizeof(struct ps1_controller)))
goto error;

if (SaveFuncs.close(f)) {
Expand Down Expand Up @@ -900,7 +900,7 @@ int LoadState(const char *file) {
mdecFreeze(f, FREEZE_LOAD) )
goto error;

if (freeze_rw(f, FREEZE_LOAD, &player_controller[0], sizeof(struct ps1_controller)))
if (freeze_rw(f, FREEZE_LOAD, &controllers[0], sizeof(struct ps1_controller)))
{
goto error;
}
Expand Down
46 changes: 23 additions & 23 deletions src/pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ unsigned char PAD1_poll(unsigned char value) {
// Don't enable Analog/Vibration for a Digital or DualAnalog controller
CurCmd = value;
g.CurByte1++;
if (player_controller[0].pad_controllertype != PSE_PAD_TYPE_ANALOGPAD) {
if (controllers[0].pad_controllertype != PSE_PAD_TYPE_ANALOGPAD) {
CurCmd = CMD_READ_DATA_AND_VIBRATE;
}
g.CmdLen1 = 8;
Expand All @@ -116,7 +116,7 @@ unsigned char PAD1_poll(unsigned char value) {
return 0xF3;
case CMD_QUERY_MODEL_AND_MODE:
buf = stdmodel;
buf[4] = player_controller[0].pad_mode;
buf[4] = controllers[0].pad_mode;
return 0xF3;
case CMD_QUERY_ACT:
buf = unk46;
Expand All @@ -131,7 +131,7 @@ unsigned char PAD1_poll(unsigned char value) {
buf = unk4d;
return 0xF3;
case CMD_CONFIG_MODE:
if (player_controller[0].configmode) {
if (controllers[0].configmode) {
buf = stdcfg;
return 0xF3;
}
Expand All @@ -147,18 +147,18 @@ unsigned char PAD1_poll(unsigned char value) {
* and Dualshock features won't work.
* */

if (player_controller[0].pad_mode == 1) {
buf[4] = player_controller[0].joy_right_ax0;
buf[5] = player_controller[0].joy_right_ax1;
buf[6] = player_controller[0].joy_left_ax0;
buf[7] = player_controller[0].joy_left_ax1;
if (controllers[0].pad_mode == 1) {
buf[4] = controllers[0].joy_right_ax0;
buf[5] = controllers[0].joy_right_ax1;
buf[6] = controllers[0].joy_left_ax0;
buf[7] = controllers[0].joy_left_ax1;
}
else
{
g.CmdLen1 = 4;
}

return player_controller[0].id;
return controllers[0].id;
}
}

Expand All @@ -168,12 +168,12 @@ unsigned char PAD1_poll(unsigned char value) {
if (g.CurByte1 == 2) {
switch (CurCmd) {
case CMD_CONFIG_MODE:
player_controller[0].configmode = value;
controllers[0].configmode = value;
break;

case CMD_SET_MODE_AND_LOCK:
player_controller[0].pad_mode = value;
player_controller[0].id = value ? 0x73 : 0x41;
controllers[0].pad_mode = value;
controllers[0].id = value ? 0x73 : 0x41;
break;

case CMD_QUERY_ACT:
Expand Down Expand Up @@ -205,25 +205,25 @@ unsigned char PAD1_poll(unsigned char value) {
}
}

if (player_controller[0].pad_controllertype == PSE_PAD_TYPE_ANALOGPAD)
if (controllers[0].pad_controllertype == PSE_PAD_TYPE_ANALOGPAD)
{
switch (CurCmd) {
case CMD_READ_DATA_AND_VIBRATE:
if (g.CurByte1 == player_controller[0].Vib[0]) {
player_controller[0].VibF[0] = value;
if (g.CurByte1 == controllers[0].Vib[0]) {
controllers[0].VibF[0] = value;
#ifdef RUMBLE
if (player_controller[0].VibF[0] != 0) {
if (controllers[0].VibF[0] != 0) {
Shake_Play(device, id_shake_level[3]);
}
#endif

}

if (g.CurByte1 == player_controller[0].Vib[1]) {
player_controller[0].VibF[1] = value;
if (g.CurByte1 == controllers[0].Vib[1]) {
controllers[0].VibF[1] = value;

#ifdef RUMBLE
if (player_controller[0].VibF[1] != 0) {
if (controllers[0].VibF[1] != 0) {
Shake_Play(device, id_shake_level[value>>4]);
}
#endif
Expand All @@ -232,13 +232,13 @@ unsigned char PAD1_poll(unsigned char value) {
break;
case CMD_VIBRATION_TOGGLE:
for (uint8_t i = 0; i < 2; i++) {
if (player_controller[0].Vib[i] == g.CurByte1)
if (controllers[0].Vib[i] == g.CurByte1)
buf[g.CurByte1] = 0;
}
if (value < 2) {
player_controller[0].Vib[value] = g.CurByte1;
if ((player_controller[0].id & 0x0f) < (g.CurByte1 - 1) / 2) {
player_controller[0].id = (player_controller[0].id & 0xf0) + (g.CurByte1 - 1) / 2;
controllers[0].Vib[value] = g.CurByte1;
if ((controllers[0].id & 0x0f) < (g.CurByte1 - 1) / 2) {
controllers[0].id = (controllers[0].id & 0xf0) + (g.CurByte1 - 1) / 2;
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_lib/plugin_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,5 @@ static void pl_stats_update(void)
(unsigned int)(pl_data.cpu_cur + 0.5f),
(unsigned int)(pl_data.fps_cur + 0.5f),
pl_data.sinfo.pal ? 50 : 60,
player_controller[0].pad_mode?"A":"D");
controllers[0].pad_mode?"A":"D");
}
11 changes: 8 additions & 3 deletions src/port/sdl/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static unsigned int key_read(void)
default: break;
}
break;

case SDL_KEYUP:
switch(event.key.keysym.sym) {
case SDLK_UP: ret &= ~KEY_UP; break;
Expand All @@ -105,6 +106,11 @@ static unsigned int key_read(void)
default: break;
}
break;

case SDL_JOYBUTTONDOWN:
// external joysticks
ret |= KEY_B; break;

default: break;
}
}
Expand Down Expand Up @@ -1205,18 +1211,17 @@ static char* AnalogArrow_show()
return buf;
}

extern void Set_Controller_Mode();
extern void Set_Controller_Mode(uint_fast8_t js);
static int Analog_Mode_alter(u32 keys)
{

if (keys & KEY_RIGHT) {
Config.AnalogMode++;
if (Config.AnalogMode > 3) Config.AnalogMode = 3;
} else if (keys & KEY_LEFT) {
Config.AnalogMode--;
if (Config.AnalogMode < 1) Config.AnalogMode = 0;
}
Set_Controller_Mode();
Set_Controller_Mode(0);
return 0;
}

Expand Down
Loading

0 comments on commit 53cdc9b

Please sign in to comment.