cge_nes 0.1.0

Cycle-accurate NES (Nintendo Entertainment System) emulator library: CPU, PPU, cartridge, input, and iNES ROM loading.
Documentation
//! Gamepad state management module
//!
//! Provides types for representing and managing NES gamepad button states.

#![allow(missing_docs)]

use bitflags::bitflags;

bitflags! {
    /// Represents the current pressed state of all gamepad buttons
    ///
    /// Each bit corresponds to a button's state:
    /// - 1: Button is pressed
    /// - 0: Button is released
    #[derive(Default, PartialEq, Eq, Copy, Clone, Debug)]
    pub struct GamepadButtonsPressedFlags: u8 {
        const A =         0b00000001;
        const B =         0b00000010;
        const SELECT =    0b00000100;
        const START =     0b00001000;
        const UP =        0b00010000;
        const DOWN =      0b00100000;
        const LEFT =      0b01000000;
        const RIGHT =     0b10000000;
    }
}

/// Represents the complete state of a gamepad at a point in time
#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
pub struct GamepadState {
    /// The current state of all buttons
    pub buttons_pressed: GamepadButtonsPressedFlags,
}

impl GamepadState {
    /// Creates a new GamepadState with the specified button states
    ///
    /// # Arguments
    /// * `buttons_pressed` - Flags indicating which buttons are currently pressed
    pub fn new(buttons_pressed: GamepadButtonsPressedFlags) -> Self {
        Self { buttons_pressed }
    }
}