sm64pc/gamebridge/src/controller.rs

87 lines
1.9 KiB
Rust
Raw Normal View History

bitflags! {
// 0x0100 Digital Pad Right
// 0x0200 Digital Pad Left
// 0x0400 Digital Pad Down
// 0x0800 Digital Pad Up
// 0x1000 Start
// 0x2000 Z
// 0x4000 B
// 0x8000 A
pub(crate) struct HiButtons: u8 {
const NONE = 0x00;
const DPAD_RIGHT = 0x01;
const DPAD_LEFT = 0x02;
const DPAD_DOWN = 0x04;
const DPAD_UP = 0x08;
const START = 0x10;
const Z_BUTTON = 0x20;
const B_BUTTON = 0x40;
const A_BUTTON = 0x80;
}
}
impl HiButtons {
2020-05-09 00:47:36 +00:00
pub(crate) fn clear(&mut self) {
self.bits = 0;
}
}
bitflags! {
// 0x0001 C-Right
// 0x0002 C-Left
// 0x0004 C-Down
// 0x0008 C-Up
// 0x0010 R
// 0x0020 L
// 0x0040 (reserved)
// 0x0080 (reserved)
pub(crate) struct LoButtons: u8 {
const NONE = 0x00;
const C_RIGHT = 0x01;
const C_LEFT = 0x02;
const C_DOWN = 0x04;
const C_UP = 0x08;
const R_BUTTON = 0x10;
const L_BUTTON = 0x20;
}
}
impl LoButtons {
2020-05-09 00:47:36 +00:00
pub(crate) fn clear(&mut self) {
self.bits = 0;
}
}
pub(crate) fn test(st: crate::MTState) {
let mut lo: LoButtons = LoButtons::NONE;
let mut hi: HiButtons = HiButtons::NONE;
loop {
use std::{thread::sleep, time::Duration};
let one_second = Duration::new(1, 0);
hi = HiButtons::A_BUTTON | HiButtons::START;
{
println!("pressing a + start");
let mut data = st.write().unwrap();
data.controller[0] = hi.bits as u8;
data.controller[1] = lo.bits as u8;
}
sleep(one_second);
hi.clear();
lo.clear();
{
println!("releasing a + start");
let mut data = st.write().unwrap();
data.controller[0] = hi.bits as u8;
data.controller[1] = lo.bits as u8;
}
sleep(one_second);
}
}