Mouse

Optional package adding SNES SFM1 Mouse support

To link mouse support in a project, simply add Mouse to libsfx_packages in the project makefile.

Makefile

# Use packages
libsfx_packages := Mouse

The mouse package adds mouse polling to the regular automatic joypad polling.  By default the driver will look for a mouse in port 1.  This is configurable with the SFX_MOUSE variable∶

libSFX.cfg

SFX_MOUSE = MOUSE1 | MOUSE2

Mouse read-out data is stored in MOUSE_data structs with the following members∶

.struct MOUSE_data
    status          .byte
    sensitivity     .byte
    buttons_cont    .byte
    buttons_trig    .byte
    delta_x         .byte
    delta_y         .byte
    cursor_x        .word
    cursor_y        .word
.endstruct

Possible status values:
.define MOUSE_status_nc         $00 ;Mouse not connected
.define MOUSE_status_ok         $01 ;Mouse connected and working
.define MOUSE_status_error      $80 ;Hardware error

Button presses are stored in the follwing bits of buttons_cont/buttons_trig:
Bit
7         Right button
6         Left button

The driver updates all members during each VBlank interval at zero page locations SFX_mouse1 and SFX_mouse2.  The data can be addressed like this∶

;Load cursor vertical position
lda     z:SFX_mouse1+MOUSE_data::cursor_y

The ‘sensitivity’ member is used to set the mouse acceleration curve.

;Set normal mouse sensitivty
lda     #MOUSE_sensitivity_normal
sta     SFX_mouse1+MOUSE_data::sensitivity

;Possible values
.define MOUSE_sensitivity_slow    0
.define MOUSE_sensitivity_normal  1
.define MOUSE_sensitivity_fast    2

All other members are read-only.

If no mouse is detected and SFX_JOY is set for the port, the driver automatically falls back to joypad input.  D-pad input is then mapped to delta and cursor, and the A/X buttons is mapped to the left/right buttons.

The driver can optionally be “hugged” by special strings that – I suppose – some emulators rely on to automatically enable mouse input.  Real hardware (and consequently, real emulators) doesn’t care.

libSFX.cfg

SFX_MOUSE_STRINGS = ENABLE