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
1bits.
(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
impl PowerPadState
Sourcepub const fn set(&mut self, buttons: u16)
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.
Sourcepub const fn write_strobe(&mut self, value: u8)
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.
Sourcepub const fn read(&mut self) -> u8
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).
Sourcepub const fn peek(&self) -> u8
pub const fn peek(&self) -> u8
Side-effect-free sample of the next device byte (debugger peek).
Sourcepub const fn from_parts(
buttons: u16,
shift_l: u8,
shift_h: u8,
strobe: bool,
) -> Self
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.
Raw live button mask (save-state).
Sourcepub const fn shift_l_raw(&self) -> u8
pub const fn shift_l_raw(&self) -> u8
Raw low shift register (save-state).
Sourcepub const fn shift_h_raw(&self) -> u8
pub const fn shift_h_raw(&self) -> u8
Raw high shift register (save-state).
Sourcepub const fn strobe_raw(&self) -> bool
pub const fn strobe_raw(&self) -> bool
Raw strobe state (save-state).
Trait Implementations§
Source§impl Clone for PowerPadState
impl Clone for PowerPadState
Source§fn clone(&self) -> PowerPadState
fn clone(&self) -> PowerPadState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more