From 9af7b8abd81d6c9435901ef330e16a0ea3715e69 Mon Sep 17 00:00:00 2001 From: akiroz Date: Thu, 27 Jan 2022 04:08:27 +0800 Subject: [PATCH] fix coin key handling --- src/main.zig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1fbcc1a..e994426 100644 --- a/src/main.zig +++ b/src/main.zig @@ -164,15 +164,14 @@ export fn chuni_io_jvs_poll(opbtn: ?[*]u8, beams: ?[*]u8) void { beams.?.* |= usb_in[3] & 0b111111; } -var coin_depressed = false; +var coin_conter: c_ushort = 0; +var coin_prev_depressed = false; export fn chuni_io_jvs_read_coin_counter(total: ?*c_ushort) void { if(total == null) return; - if(GetAsyncKeyState(cfg.?.coin_key) == 0) { - coin_depressed = false; - } else if(!coin_depressed) { - coin_depressed = true; - total.?.* += 1; - } + const coin_depressed = GetAsyncKeyState(cfg.?.coin_key) != 0; + if(coin_depressed and !coin_prev_depressed) coin_conter += 1; + coin_prev_depressed = coin_depressed; + total.?.* = coin_conter; } export fn chuni_io_slider_init() HRESULT {