From 9ea6e09fdc87f8173b0f4db023398d1d61a2082d Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 3 Aug 2019 17:41:39 -0400 Subject: [PATCH] Tweak JVS coin count APIs This makes things more consistent with the button/analog APIs. --- board/io3.c | 6 +++--- board/io3.h | 2 +- chunihook/jvs.c | 16 ++++++++++++---- chuniio/chuniio.c | 8 ++++++-- chuniio/chuniio.h | 2 +- divahook/jvs.c | 14 ++++++++++---- divaio/divaio.c | 8 ++++++-- divaio/divaio.h | 2 +- idzhook/jvs.c | 14 ++++++++++---- idzio/idzio.c | 4 ++-- idzio/idzio.h | 2 +- 11 files changed, 53 insertions(+), 25 deletions(-) diff --git a/board/io3.c b/board/io3.c index ee566b7..0a4fc80 100644 --- a/board/io3.c +++ b/board/io3.c @@ -459,10 +459,10 @@ static HRESULT io3_cmd_read_coin( /* Write slot detail */ for (i = 0 ; i < req.nslots ; i++) { + ncoins = 0; + if (io3->ops->read_coin_counter != NULL) { - ncoins = io3->ops->read_coin_counter(io3->ops_ctx, i); - } else { - ncoins = 0; + io3->ops->read_coin_counter(io3->ops_ctx, i, &ncoins); } hr = iobuf_write_be16(resp_buf, ncoins); diff --git a/board/io3.h b/board/io3.h index 4bae608..efe98d1 100644 --- a/board/io3.h +++ b/board/io3.h @@ -18,7 +18,7 @@ struct io3_ops { void (*write_gpio)(void *ctx, uint32_t state); void (*read_switches)(void *ctx, struct io3_switch_state *out); void (*read_analogs)(void *ctx, uint16_t *analogs, uint8_t nanalogs); - uint16_t (*read_coin_counter)(void *ctx, uint8_t slot_no); + void (*read_coin_counter)(void *ctx, uint8_t slot_no, uint16_t *out); }; struct io3 { diff --git a/chunihook/jvs.c b/chunihook/jvs.c index 055f743..a78d902 100644 --- a/chunihook/jvs.c +++ b/chunihook/jvs.c @@ -21,7 +21,10 @@ struct chunithm_jvs_ir_mask { }; static void chunithm_jvs_read_switches(void *ctx, struct io3_switch_state *out); -static uint16_t chunithm_jvs_read_coin_counter(void *ctx, uint8_t slot_no); +static void chunithm_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out); static const struct io3_ops chunithm_jvs_io3_ops = { .read_switches = chunithm_jvs_read_switches, @@ -81,11 +84,16 @@ static void chunithm_jvs_read_switches(void *ctx, struct io3_switch_state *out) } } -static uint16_t chunithm_jvs_read_coin_counter(void *ctx, uint8_t slot_no) +static void chunithm_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out) { + assert(out != NULL); + if (slot_no > 0) { - return 0; + return; } - return chuni_io_jvs_read_coin_counter(); + chuni_io_jvs_read_coin_counter(out); } diff --git a/chuniio/chuniio.c b/chuniio/chuniio.c index 5ef79ed..7d61648 100644 --- a/chuniio/chuniio.c +++ b/chuniio/chuniio.c @@ -23,8 +23,12 @@ HRESULT chuni_io_init(void) return S_OK; } -uint16_t chuni_io_jvs_read_coin_counter(void) +void chuni_io_jvs_read_coin_counter(uint16_t *out) { + if (out == NULL) { + return; + } + if (GetAsyncKeyState('3')) { if (!chuni_io_coin) { chuni_io_coin = true; @@ -34,7 +38,7 @@ uint16_t chuni_io_jvs_read_coin_counter(void) chuni_io_coin = false; } - return chuni_io_coins; + *out = chuni_io_coins; } void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams) diff --git a/chuniio/chuniio.h b/chuniio/chuniio.h index 456c7f9..7e71a5b 100644 --- a/chuniio/chuniio.h +++ b/chuniio/chuniio.h @@ -36,7 +36,7 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams); for every coin detected by the coin acceptor mechanism. This count does not need to persist beyond the lifetime of the process. */ -uint16_t chuni_io_jvs_read_coin_counter(void); +void chuni_io_jvs_read_coin_counter(uint16_t *total); /* Set the state of the coin blocker. Parameter is true if the blocker is disengaged (i.e. coins can be inserted) and false if the blocker is engaged diff --git a/divahook/jvs.c b/divahook/jvs.c index ca6df53..688d4ba 100644 --- a/divahook/jvs.c +++ b/divahook/jvs.c @@ -15,7 +15,10 @@ #include "util/dprintf.h" static void diva_jvs_read_switches(void *ctx, struct io3_switch_state *out); -static uint16_t diva_jvs_read_coin_counter(void *ctx, uint8_t slot_no); +static void diva_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out); static const struct io3_ops diva_jvs_io3_ops = { .read_switches = diva_jvs_read_switches, @@ -73,11 +76,14 @@ static void diva_jvs_read_switches(void *ctx, struct io3_switch_state *out) } } -static uint16_t diva_jvs_read_coin_counter(void *ctx, uint8_t slot_no) +static void diva_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out) { if (slot_no > 0) { - return 0; + return; } - return diva_io_jvs_read_coin_counter(); + diva_io_jvs_read_coin_counter(out); } diff --git a/divaio/divaio.c b/divaio/divaio.c index 701a983..8fbeaa9 100644 --- a/divaio/divaio.c +++ b/divaio/divaio.c @@ -47,8 +47,12 @@ void diva_io_jvs_poll(uint8_t *opbtn_out, uint8_t *gamebtn_out) *gamebtn_out = gamebtn; } -uint16_t diva_io_jvs_read_coin_counter(void) +void diva_io_jvs_read_coin_counter(uint16_t *out) { + if (out == NULL) { + return; + } + if (GetAsyncKeyState('3')) { if (!diva_io_coin) { diva_io_coin = true; @@ -58,7 +62,7 @@ uint16_t diva_io_jvs_read_coin_counter(void) diva_io_coin = false; } - return diva_io_coins; + *out = diva_io_coins; } void diva_io_jvs_set_coin_blocker(bool open) diff --git a/divaio/divaio.h b/divaio/divaio.h index 8a78e4f..0328324 100644 --- a/divaio/divaio.h +++ b/divaio/divaio.h @@ -30,7 +30,7 @@ void diva_io_jvs_poll(uint8_t *opbtn, uint8_t *gamebtn); for every coin detected by the coin acceptor mechanism. This count does not need to persist beyond the lifetime of the process. */ -uint16_t diva_io_jvs_read_coin_counter(void); +void diva_io_jvs_read_coin_counter(uint16_t *out); /* Set the state of the coin blocker. Parameter is true if the blocker is disengaged (i.e. coins can be inserted) and false if the blocker is engaged diff --git a/idzhook/jvs.c b/idzhook/jvs.c index f43e092..073b806 100644 --- a/idzhook/jvs.c +++ b/idzhook/jvs.c @@ -20,7 +20,10 @@ static void idz_jvs_read_analogs( uint16_t *analogs, uint8_t nanalogs); static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out); -static uint16_t idz_jvs_read_coin_counter(void *ctx, uint8_t slot_no); +static void idz_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out); static const struct io3_ops idz_jvs_io3_ops = { .read_switches = idz_jvs_read_switches, @@ -150,11 +153,14 @@ static void idz_jvs_read_analogs( } } -static uint16_t idz_jvs_read_coin_counter(void *ctx, uint8_t slot_no) +static void idz_jvs_read_coin_counter( + void *ctx, + uint8_t slot_no, + uint16_t *out) { if (slot_no > 0) { - return 0; + return; } - return idz_io_jvs_read_coin_counter(); + idz_io_jvs_read_coin_counter(out); } diff --git a/idzio/idzio.c b/idzio/idzio.c index 55943ff..80df095 100644 --- a/idzio/idzio.c +++ b/idzio/idzio.c @@ -136,7 +136,7 @@ void idz_io_jvs_read_analogs(struct idz_io_analog_state *out) out->brake = xi.Gamepad.bLeftTrigger << 8; } -uint16_t idz_io_jvs_read_coin_counter(void) +void idz_io_jvs_read_coin_counter(uint16_t *out) { if (GetAsyncKeyState('3')) { if (!idz_io_coin) { @@ -147,5 +147,5 @@ uint16_t idz_io_jvs_read_coin_counter(void) idz_io_coin = false; } - return idz_io_coins; + *out = idz_io_coins; } diff --git a/idzio/idzio.h b/idzio/idzio.h index edcdafe..486fdb6 100644 --- a/idzio/idzio.h +++ b/idzio/idzio.h @@ -32,6 +32,6 @@ void idz_io_jvs_read_buttons(uint8_t *opbtn, uint8_t *gamebtn); void idz_io_jvs_read_shifter(uint8_t *gear); -uint16_t idz_io_jvs_read_coin_counter(void); +void idz_io_jvs_read_coin_counter(uint16_t *total); // TODO force feedback once that gets reverse engineered