/* note: in_ps2 handles combos (if 2 btns have the same bind,
* both must be pressed for action to happen) */
-static int in_ps2_combo_keys = 0;
-static int in_ps2_combo_acts = 0;
+static int in_ps2_combo_keys[2];
+static int in_ps2_combo_acts[2];
static void *padBuf[2][4];
static uint32_t padConnected[2][4]; // 2 ports, 4 slots
static uint32_t padOpen[2][4];
-static uint32_t maxslot[2];
static const char *in_ps2_keys[IN_PS2_NBUTTONS] = {
return r;
}
-static unsigned int ps2_pad_read()
+static unsigned int ps2_pad_read(int pad)
{
unsigned int paddata;
struct padButtonStatus buttons;
int32_t ret, port, slot;
-
// Using for now port 0, slot 0
- port = 0;
+ port = pad;
slot = 0;
ret = padRead(port, slot, &buttons);
return paddata;
}
-static unsigned in_ps2_get_bits(void)
+static unsigned in_ps2_get_bits(int pad)
{
unsigned mask =
PAD_UP|PAD_DOWN|PAD_LEFT|PAD_RIGHT |
PAD_L1|PAD_R1|PAD_SELECT|PAD_START;
// PS2_NUB_UP|PS2_NUB_DOWN|PS2_NUB_LEFT|PS2_NUB_RIGHT |
- return ps2_pad_read() & mask;
+ return ps2_pad_read(pad) & mask;
}
static void in_ps2_probe(const in_drv_t *drv)
{
- in_register(IN_PS2_PREFIX "PS2 pad", -1, NULL,
+ in_register(IN_PS2_PREFIX "PS2 pad 1", -1, (void *)0,
+ IN_PS2_NBUTTONS, in_ps2_keys, 1);
+ in_register(IN_PS2_PREFIX "PS2 pad 2", -1, (void *)1,
IN_PS2_NBUTTONS, in_ps2_keys, 1);
}
/* ORs result with pressed buttons */
static int in_ps2_update(void *drv_data, const int *binds, int *result)
{
+ int pad = (int)drv_data & 1;
int type_start = 0;
int i, t;
unsigned keys;
- keys = in_ps2_get_bits();
+ keys = in_ps2_get_bits(pad);
- if (keys & in_ps2_combo_keys) {
+ if (keys & in_ps2_combo_keys[pad]) {
result[IN_BINDTYPE_EMU] = in_combos_do(keys, binds, IN_PS2_NBUTTONS,
- in_ps2_combo_keys, in_ps2_combo_acts);
+ in_ps2_combo_keys[pad], in_ps2_combo_acts[pad]);
type_start = IN_BINDTYPE_PLAYER12;
}
int in_ps2_update_keycode(void *data, int *is_down)
{
- static unsigned old_val = 0;
+ static unsigned old_val[2] = { 0, 0 };
+ int pad = (int)data & 1;
unsigned val, diff, i;
- val = in_ps2_get_bits();
- diff = val ^ old_val;
+ val = in_ps2_get_bits(pad);
+ diff = val ^ old_val[pad];
if (diff == 0)
return -1;
if (diff & (1<<i))
break;
- old_val ^= 1 << i;
+ old_val[pad] ^= 1 << i;
if (is_down)
*is_down = !!(val & (1<<i));
int pbtn;
} key_pbtn_map[] =
{
- { PAD_UP, PBTN_UP },
+ { PAD_UP, PBTN_UP },
{ PAD_DOWN, PBTN_DOWN },
{ PAD_LEFT, PBTN_LEFT },
{ PAD_RIGHT, PBTN_RIGHT },
/* remove binds of missing keys, count remaining ones */
static int in_ps2_clean_binds(void *drv_data, int *binds, int *def_binds)
{
+ int pad = (int)drv_data & 1;
int i, count = 0;
for (i = 0; i < IN_PS2_NBUTTONS; i++) {
}
}
- in_combos_find(binds, IN_PS2_NBUTTONS, &in_ps2_combo_keys, &in_ps2_combo_acts);
+ in_combos_find(binds, IN_PS2_NBUTTONS, &in_ps2_combo_keys[pad], &in_ps2_combo_acts[pad]);
return count;
}
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
key_pbtn_map[i].key = lg2(key_pbtn_map[i].key);
- in_ps2_combo_keys = in_ps2_combo_acts = 0;
+ memset(in_ps2_combo_keys, 0, sizeof(in_ps2_combo_keys));
+ memset(in_ps2_combo_acts, 0, sizeof(in_ps2_combo_acts));
/* fill keys array, converting key bitmasks to bit numbers */
in_ps2_keys[lg2(PAD_UP)] = "Up";