Skip to content

Inconsistent gamepad button mapping for button2 in VIA joystick handling #503

Open
@mattgodbolt

Description

@mattgodbolt

Issue Description

There's an inconsistency in how button2 is mapped for joystick fire buttons in the VIA gamepad handling code (around line 679 in src/via.js).

Current Behavior

In SysVia.getJoysticks():

  • button1: Always uses pad.buttons[10] (first gamepad, FIRE1)
  • button2:
    • If 2 gamepads: Uses pad2.buttons[10] (second gamepad's FIRE1)
    • If 1 gamepad: Uses pad.buttons[11] (first gamepad's FIRE2)

Code Location

// src/via.js line ~679
button2 = button2 || (pad2 ? pad2.buttons[10].pressed : pad.buttons[11].pressed);

Expected Behavior (to be clarified)

The mapping should be consistent. Possible approaches:

  1. Option A: Always use button index 10 for both scenarios
  2. Option B: Always use button index 11 for button2 in both scenarios
  3. Option C: Current behavior is intentional and should be documented

Context

From the gamepad mapping in gamepads.js:

  • Button 10 = FIRE1
  • Button 11 = FIRE2

Impact

This inconsistency may confuse users when switching between single and dual gamepad setups, as button2 maps to different physical buttons depending on the setup.

Next Steps

  • Clarify if current behavior is intentional
  • Add documentation explaining the mapping logic
  • Consider standardizing the mapping
  • Add tests to verify intended behavior

Note: This is existing behavior, not introduced by recent changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug: incorrect behaviour in the webpage or the emulation itselfinputIssues with input, keyboard, mouse, etc

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions