fix coin debouncing

This commit is contained in:
beerpsi 2024-01-02 19:11:26 +07:00
parent a1790a9a48
commit 74e8e2a122
2 changed files with 6 additions and 7 deletions

View File

@ -55,9 +55,8 @@ pub const OUTPUT_MEMORY_SIZE: usize = 240;
#[inline(always)]
pub fn jvs_poll(input: &[u8]) -> (u8, u8) {
// FN1 | FN2
let opbtn = input[3] >> 3 & 1
| input[3] >> 1 & 2;
let opbtn = input[3] >> 3 & 1 | input[3] >> 1 & 2;
// IR1-6 in order
let beams = input[3] >> 5 & 1
| input[3] >> 3 & 2

View File

@ -69,7 +69,7 @@ cfg_if::cfg_if! {
use crate::configuration::Configuration;
static COIN_COUNT: AtomicU16 = AtomicU16::new(0);
static COIN_PRESSED: AtomicBool = AtomicBool::new(false);
static mut COIN_PRESSED: bool = false;
lazy_static! {
static ref CONFIGURATION: Configuration = {
@ -182,12 +182,12 @@ pub unsafe extern "C" fn chuni_io_jvs_read_coin_counter(total: *mut u16) {
if con_impl::is_coin_button_pressed(input_shmem.as_slice())
|| GetAsyncKeyState(CONFIGURATION.coin_key as c_int) != 0
{
let coin_previously_pressed = COIN_PRESSED.fetch_xor(true, Ordering::Relaxed);
if !coin_previously_pressed {
if !COIN_PRESSED {
COIN_PRESSED = true;
COIN_COUNT.fetch_add(1, Ordering::Relaxed);
}
} else {
COIN_PRESSED.store(false, Ordering::Relaxed);
COIN_PRESSED = false;
}
*total = COIN_COUNT.load(Ordering::Relaxed);