From: kub Date: Thu, 1 Aug 2024 18:27:37 +0000 (+0200) Subject: platform ps2, some support for 2nd controller X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bba99294e08fd81ef1d378cef95a2d5f3e12a629;p=picodrive.git platform ps2, some support for 2nd controller --- diff --git a/platform/ps2/in_ps2.c b/platform/ps2/in_ps2.c index e7ff02e6..463ae315 100644 --- a/platform/ps2/in_ps2.c +++ b/platform/ps2/in_ps2.c @@ -25,13 +25,12 @@ /* 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] = { @@ -53,15 +52,14 @@ static int lg2(unsigned v) 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); @@ -80,7 +78,7 @@ static unsigned int ps2_pad_read() 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 | @@ -88,12 +86,14 @@ static unsigned in_ps2_get_bits(void) 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); } @@ -112,15 +112,16 @@ in_ps2_get_key_names(const in_drv_t *drv, int *count) /* 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; } @@ -137,11 +138,12 @@ static int in_ps2_update(void *drv_data, const int *binds, int *result) 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; @@ -150,7 +152,7 @@ int in_ps2_update_keycode(void *data, int *is_down) if (diff & (1<