Login
1 branch 0 tags
Ben (Desktop/Arch) Added MIT license 098069c 25 days ago 3 Commits
gb-rs / src / input.rs
#[derive(Copy, Clone, Default, Eq, PartialEq)]
pub struct Buttons(u8);

impl Buttons {
    pub const RIGHT: Self  = Self(1 << 0);
    pub const LEFT: Self   = Self(1 << 1);
    pub const UP: Self     = Self(1 << 2);
    pub const DOWN: Self   = Self(1 << 3);
    pub const A: Self      = Self(1 << 4);
    pub const B: Self      = Self(1 << 5);
    pub const SELECT: Self = Self(1 << 6);
    pub const START: Self  = Self(1 << 7);

    pub fn set(self, b: Buttons, down: bool) -> Self {
        if down {
            Self(self.0 | b.0)
        } else {
            Self(self.0 & !b.0)
        }
    }

    pub fn bitmask(self) -> u8 {
        self.0
    }
}