pub struct FamilyKeyboardState { /* private fields */ }Expand description
The Famicom Family BASIC keyboard overlay state.
Per the NESdev “Family BASIC Keyboard” page, the keyboard is a 9 x 8
switch matrix (with the data-recorder lines unused here) read through the
expansion port but software-visible on $4017. The protocol:
$4016write — bit 0 (the “column” select; 0 selects the low 4 keys of the current row, 1 selects the high 4) and bit 1 (a clock; a 0->1 transition advances to the next row). Bit 2 enables the keyboard matrix; when bit 2 is 0 the matrix is disabled and$4017reads1s. Writing bit 1 = 0 while bit 2 = 1 resets the row counter to 0.$4017read — bits 4..1 carry the four key switches of the currently selected (row, column-half), active-low (0 = pressed). There are 9 rows x 2 halves = 18 selectable groups of 4 keys = 72 key positions.
We model the live pressed state as a 72-bit key bitmap ([u8; 9], one byte
per row: low nibble = column-half 0, high nibble = column-half 1) and the
row counter + column select per the write protocol. Determinism holds: it is
a pure function of the writes + the live key bitmap.
Implementations§
Source§impl FamilyKeyboardState
impl FamilyKeyboardState
Sourcepub const fn set_keys(&mut self, keys: [u8; 9])
pub const fn set_keys(&mut self, keys: [u8; 9])
Set the full pressed-key bitmap (one byte per matrix row; low nibble = column-half 0, high nibble = column-half 1). The frontend builds this from host keys via its key map.
Sourcepub const fn set_key(&mut self, index: usize, pressed: bool)
pub const fn set_key(&mut self, index: usize, pressed: bool)
Set one key by linear index (0..72) — index = row * 8 + bit, matching
the matrix layout (bit 0..=3 = column-half 0, 4..=7 = column-half 1).
Out-of-range indices are ignored.
Sourcepub const fn write_strobe(&mut self, value: u8)
pub const fn write_strobe(&mut self, value: u8)
Handle a $4016 write: latch column select (bit 0), advance the row on a
clock (bit 1) rising edge, set the matrix-enable (bit 2). A clock low
while enabled resets the row counter to 0.
Sourcepub const fn read(&self) -> u8
pub const fn read(&self) -> u8
Read the device byte for a $4017 access. The four selected key switches
are returned on bits 4..1, active-low (0 = pressed). When the matrix
is disabled, all four bits read 1 (no keys). The caller ORs in the
open-bus upper bits.
Sourcepub const fn peek(&self) -> u8
pub const fn peek(&self) -> u8
Side-effect-free sample of the device byte (debugger peek) — identical to
Self::read (the keyboard read has no side effects).
Sourcepub const fn from_parts(
keys: [u8; 9],
row: u8,
column: bool,
enabled: bool,
clock: bool,
) -> Self
pub const fn from_parts( keys: [u8; 9], row: u8, column: bool, enabled: bool, clock: bool, ) -> Self
Reconstruct from save-state parts.
Sourcepub const fn column_raw(&self) -> bool
pub const fn column_raw(&self) -> bool
Raw column select (save-state).
Sourcepub const fn enabled_raw(&self) -> bool
pub const fn enabled_raw(&self) -> bool
Raw matrix-enable (save-state).
Trait Implementations§
Source§impl Clone for FamilyKeyboardState
impl Clone for FamilyKeyboardState
Source§fn clone(&self) -> FamilyKeyboardState
fn clone(&self) -> FamilyKeyboardState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more