Skip to main content

PowerPadState

Struct PowerPadState 

Source
pub struct PowerPadState { /* private fields */ }
Expand description

The NES Power Pad (a.k.a. Family Fun Fitness / Family Trainer mat) overlay.

A 12-button mat read on the player-2 port ($4017) through two 8-bit parallel-in/serial-out shift registers (a pair of 4021s), strobed by the standard $4016 controller strobe. The 12 buttons are indexed 0..=11 (matching the mat’s “1”..“12” labels); the frontend decides which physical keys map to which mat button (and any Side-A/Side-B row inversion).

Per the NESdev “Power Pad” page (and Mesen’s implementation), the button bits load into two registers and shift out LSb-first on bits 3 and 4 of each $4017 read:

  • register L (bit 3 of the read): buttons 2, 1, 5, 9, 6, 10, 11, 7;
  • register H (bit 4 of the read): buttons 4, 3, 12, 8, then four 1 bits.

(Button numbers are 1-based here, matching the mat labels; the code uses 0-based indices.) Each read shifts both registers right and feeds 1s in from the top, so post-shift reads settle to “no button”.

Implementations§

Source§

impl PowerPadState

Source

pub const fn new() -> Self

New mat with no buttons pressed.

Source

pub const fn set(&mut self, buttons: u16)

Update the live pressed-button mask (bit i = mat button i+1). While the strobe is held high the registers track the live mask (parallel load), matching the standard controller’s latch-while-strobed semantics.

Source

pub const fn write_strobe(&mut self, value: u8)

Handle a $4016 strobe write. While bit 0 is high the registers are (re)loaded from the live buttons; the falling edge leaves the latched snapshot to shift out.

Source

pub const fn read(&mut self) -> u8

Read the device byte for a $4017 access, shifting both registers. Bit 4 = the current serial-out (LSb) of register H, bit 3 = register L; each read then shifts both right (feeding 1s in from the top). The caller ORs in the open-bus upper bits. While the strobe is high the registers are continuously reloaded (reads return the first button).

Source

pub const fn peek(&self) -> u8

Side-effect-free sample of the next device byte (debugger peek).

Source

pub const fn from_parts( buttons: u16, shift_l: u8, shift_h: u8, strobe: bool, ) -> Self

Reconstruct from save-state parts. buttons is masked to the 12 mat bits, matching Self::set, so a malformed save-state cannot inject out-of-range bits.

Source

pub const fn buttons_raw(&self) -> u16

Raw live button mask (save-state).

Source

pub const fn shift_l_raw(&self) -> u8

Raw low shift register (save-state).

Source

pub const fn shift_h_raw(&self) -> u8

Raw high shift register (save-state).

Source

pub const fn strobe_raw(&self) -> bool

Raw strobe state (save-state).

Trait Implementations§

Source§

impl Clone for PowerPadState

Source§

fn clone(&self) -> PowerPadState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PowerPadState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PowerPadState

Source§

fn default() -> PowerPadState

Returns the “default value” for a type. Read more
Source§

impl Copy for PowerPadState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.