From e737d6089360266b3d9c242e895afc613227ac43 Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Tue, 10 Nov 2020 18:06:51 -0800 Subject: [PATCH] Actually implement the coin mech in BIO2 based games Properly fixes #45 --- src/main/bio2/bi2a-iidx.h | 2 +- src/main/bio2/bi2a-sdvx.h | 2 +- src/main/bio2emu-iidx/bi2a.c | 13 +++++++++++++ src/main/sdvxhook2/bi2a.c | 21 ++++++++++++++++++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/bio2/bi2a-iidx.h b/src/main/bio2/bi2a-iidx.h index b219682..6248128 100644 --- a/src/main/bio2/bi2a-iidx.h +++ b/src/main/bio2/bi2a-iidx.h @@ -39,7 +39,7 @@ struct bi2a_iidx_state_out { uint8_t UNK2; struct bi2a_iidx_slider SLIDER4; struct bi2a_iidx_slider SLIDER5; - uint8_t UNK3; // coin mech? + uint8_t coins; // coin mech? struct bi2a_iidx_panel PANEL; uint8_t UNK4; uint8_t UNK5; diff --git a/src/main/bio2/bi2a-sdvx.h b/src/main/bio2/bi2a-sdvx.h index 502f36b..f51f521 100644 --- a/src/main/bio2/bi2a-sdvx.h +++ b/src/main/bio2/bi2a-sdvx.h @@ -36,7 +36,7 @@ struct bi2a_sdvx_state_in { uint16_t raw[8]; struct { struct bi2a_sdvx_analog analogs[4]; - uint8_t unk_1; // coin mech? + uint8_t coins; struct bi2a_sdvx_buttons1 buttons_1; struct bi2a_sdvx_buttons2 buttons_2; uint8_t unk_2[5]; diff --git a/src/main/bio2emu-iidx/bi2a.c b/src/main/bio2emu-iidx/bi2a.c index c590f29..fc66222 100644 --- a/src/main/bio2emu-iidx/bi2a.c +++ b/src/main/bio2emu-iidx/bi2a.c @@ -24,6 +24,8 @@ static void bio2_emu_bi2a_send_status( static int default_sliders[5]; static bool poll_delay; +static bool coin_latch; +static uint8_t coin_count; int get_default_slider_valid(size_t idx) { @@ -277,5 +279,16 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) body->SYSTEM.v_service = (input_sys >> IIDX_IO_SYS_SERVICE) & 1; body->SYSTEM.v_coin = (input_sys >> IIDX_IO_SYS_COIN) & 1; + if (body->SYSTEM.v_coin) { + if (!coin_latch) { + coin_latch = true; + coin_count += 1; + } + } else { + coin_latch = false; + } + + body->coins = coin_count; + ac_io_emu_response_push(emu, &resp, 0); } diff --git a/src/main/sdvxhook2/bi2a.c b/src/main/sdvxhook2/bi2a.c index 71de63b..f71230c 100644 --- a/src/main/sdvxhook2/bi2a.c +++ b/src/main/sdvxhook2/bi2a.c @@ -27,6 +27,9 @@ static bool poll_delay; static bool force_headphones_on; +static bool coin_latch; +static uint8_t coin_count; + void bio2_emu_bi2a_init( struct bio2emu_port *bio2_emu, bool disable_poll_limiter, @@ -241,10 +244,22 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) pin->analogs[0].a_val = sdvx_io_get_spinner_pos(0); pin->analogs[1].a_val = sdvx_io_get_spinner_pos(1); - pin->analogs[0].a_coin = check_pin(sys, SDVX_IO_IN_GPIO_SYS_COIN); pin->analogs[0].a_test = check_pin(sys, SDVX_IO_IN_GPIO_SYS_TEST); - pin->analogs[0].a_service = check_pin(sys, SDVX_IO_IN_GPIO_SYS_SERVICE) || - check_pin(sys, SDVX_IO_IN_GPIO_SYS_COIN); + pin->analogs[0].a_service = check_pin(sys, SDVX_IO_IN_GPIO_SYS_SERVICE); + pin->analogs[0].a_coin = check_pin(sys, SDVX_IO_IN_GPIO_SYS_COIN); + + if (pin->analogs[0].a_coin) { + if (!coin_latch) { + coin_latch = true; + coin_count += 1; + } + } else { + coin_latch = false; + } + + // this is NOT byteswapped, only the analogs are + pin->coins = coin_count; + pin->raw[0] = ac_io_u16(pin->raw[0]); pin->raw[1] = ac_io_u16(pin->raw[1]);