Skip to main content

SnesMouseState

Struct SnesMouseState 

Source
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 moving

After 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

Source

pub const fn new() -> Self

New mouse at rest (no movement, buttons up, low sensitivity).

Source

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.

Source

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.

Source

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.

Source

pub const fn peek(&self) -> u8

Side-effect-free sample of the next D0 bit (debugger peek).

Source

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.

Source

pub const fn dx_raw(&self) -> i16

Raw delta-X (save-state).

Source

pub const fn dy_raw(&self) -> i16

Raw delta-Y (save-state).

Source

pub const fn left_raw(&self) -> bool

Raw left button (save-state).

Source

pub const fn right_raw(&self) -> bool

Raw right button (save-state).

Source

pub const fn sensitivity_raw(&self) -> u8

Raw sensitivity (save-state).

Source

pub const fn shift_raw(&self) -> u32

Raw shift register (save-state).

Source

pub const fn read_count_raw(&self) -> u8

Raw read counter (save-state).

Source

pub const fn strobe_raw(&self) -> bool

Raw strobe state (save-state).

Trait Implementations§

Source§

impl Clone for SnesMouseState

Source§

fn clone(&self) -> SnesMouseState

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 SnesMouseState

Source§

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

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

impl Default for SnesMouseState

Source§

fn default() -> SnesMouseState

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

impl Copy for SnesMouseState

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.