pub struct SnesMouseState { /* private fields */ }Expand description
The (Hyperkin / Nintendo) mouse overlay state — the SNES-style serial mouse
as wired to an NES $4016/$4017 port (D0 serial-out).
Per the NESdev “Mouse” page (the SNES mouse, the canonical serial mouse
reused on the NES), a strobe latches a fixed-format 32-bit report that is
then shifted out MSb-first on D0 (one bit per port read):
bits 31..28 : signature 0b0001 (device id nibble)
bits 27..26 : 00
bits 25..24 : sensitivity (00 low / 01 medium / 10 high; cycled by pressing
both buttons on real hardware — we expose it as a field)
bit 23 : left button (1 = pressed)
bit 22 : right button (1 = pressed)
bits 21..16 : 0
bits 15..8 : Y movement — bit 15 = direction sign (1 = up/-), bits 14..8 =
magnitude (0..127); 0 when not moving
bits 7..0 : X movement — bit 7 = direction sign (1 = left/-), bits 6..0 =
magnitude (0..127); 0 when not movingAfter the 32 real bits are shifted out, further reads return 1 (the open
serial line idles high), matching the standard controller’s post-sequence
behavior. Like the standard controller, while the strobe is held high the
report is continuously re-latched, so reads return the first (signature) bit.
Implementations§
Source§impl SnesMouseState
impl SnesMouseState
Sourcepub const fn set(
&mut self,
dx: i16,
dy: i16,
left: bool,
right: bool,
sensitivity: u8,
)
pub const fn set( &mut self, dx: i16, dy: i16, left: bool, right: bool, sensitivity: u8, )
Update the live movement + button + sensitivity state. Takes effect on the next latch (strobe), matching the standard controller semantics.
Sourcepub const fn write_strobe(&mut self, value: u8)
pub const fn write_strobe(&mut self, value: u8)
Handle a $4016 strobe write. On a high level the 32-bit report is
(re)latched from the live state; the read counter resets.
Sourcepub const fn read(&mut self) -> u8
pub const fn read(&mut self) -> u8
Read the device byte for a port access, shifting out one MSb-first bit on
D0. After 32 bits the line idles high (1 on D0). While the strobe is
held high the report is continuously re-latched (reads return bit 31).
The caller ORs in the open-bus upper bits.
Sourcepub const fn from_parts(
dx: i16,
dy: i16,
left: bool,
right: bool,
sensitivity: u8,
shift: u32,
read_count: u8,
strobe: bool,
) -> Self
pub const fn from_parts( dx: i16, dy: i16, left: bool, right: bool, sensitivity: u8, shift: u32, read_count: u8, strobe: bool, ) -> Self
Reconstruct from save-state parts.
Sourcepub const fn sensitivity_raw(&self) -> u8
pub const fn sensitivity_raw(&self) -> u8
Raw sensitivity (save-state).
Sourcepub const fn read_count_raw(&self) -> u8
pub const fn read_count_raw(&self) -> u8
Raw read counter (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 SnesMouseState
impl Clone for SnesMouseState
Source§fn clone(&self) -> SnesMouseState
fn clone(&self) -> SnesMouseState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more