XMypuK / zx-dream

Sinclair ZX Spectrum emulator in JavaScript
https://zx.researcher.su
MIT License
36 stars 9 forks source link

Add support for hardware controllers #1

Open Korb opened 1 month ago

Korb commented 1 month ago

Currently, the web app's Settings tab contains only the following settings:

Please add the ability to use the hardware game controllers present in the system (Xbox Controller, PlayStation Controller, Nintendo Switch, Generic Controller, and Steam Controller).

XMypuK commented 1 week ago

Implemented in e551dfce4d0105c35cbe7ebcd74061ae4fda335b. Thanks

Korb commented 1 week ago

When I connected a working Xbox Wireless Controller, the web app settings showed non-clickable text "Gamepads", "Device" and "Map", and nothing more:

2024-10-18_18-31-53

For example, the game's main menu offers:

  1. Kempston
  2. Sinclair
  3. Protek
  4. A.G.F.
  5. Fuller
  6. Keyboard

Up — E, O, 7 Down — F, K, 6 Left — M, X, 5 Right — Symbol, Shift, C, 8 Fire — N, V, B, O (0?)

What actions should the player take in order to use the controller in the game in this case?

Mozilla Firefox 132.0b8 (64-bit) Microsoft Windows 10.0.19045.5011 Xbox driver 10.0.19041.3636 (2023-10-19)

XMypuK commented 1 week ago

Did you press any buttons on the controller while the focus was on the browser window?

XMypuK commented 1 week ago

Should be something like that: image

Korb commented 1 week ago

Did you press any buttons on the controller while the focus was on the browser window?

Sure. I tried the key mapping mode in Renegade, but the app only accepts keyboard key presses, not controller buttons or stick movements. The controller works fine on Steam-games.

Have a look, maybe the Using the Gamepad API article on MDN is useful?

XMypuK commented 1 week ago

Thanks. Yes, I've read this article.

Just tried it in Firefox 131.0.3 under Windows 11. It works. image

I have Xbox Wireless Controller either. I do not have any dedicated driver installed for it though. It's just a generic driver. Probably, I'll have a chance to test it with other configurations later.

Korb commented 1 week ago

Chrome 129.0.6668.59 (Official Build) (64-bit):

2024-10-18_19-23-47

Available matching options:

  1. Kempston
  2. Sinclair 1
  3. Sinclair 2
  4. Cursor
  5. QAOPM
  6. QAOPSpace

Cursor

A = 0 (zero) B = N/A X = N/A Y = N/A LB = 5 (five) LSB = N/A LS◀ = 5 (five) LS🔼 = 7 (seven) LS▶ = 8 (eight) LS🔽 = 6 (six) LT = N/A RB = 8 (eight) RSB = N/A RS◀ = N/A RS🔼 = N/A RS▶ = N/A RS🔽 = N/A RT = N/A D-pad◀ = 5 (five) D-pad🔼 = 7 (seven) D-pad▶ = 8 (eight) D-pad🔽 = 6 (six)

QAOPM

A = M B = N/A X = N/A Y = N/A LB = O (letter) LSB = N/A LS◀ = O (letter) LS🔼 = Q LS▶ = O (letter) LS🔽 = A LT = N/A RB = P RSB = N/A RS◀ = N/A RS🔼 = N/A RS▶ = N/A RS🔽 = N/A RT = N/A D-pad◀ = O (letter) D-pad🔼 = Q D-pad▶ = P D-pad🔽 = A

QAOPSpace

A = BR / Space B = N/A X = N/A Y = N/A LB = O (letter) LSB = N/A LS◀ = O (letter) LS🔼 = Q LS▶ = O (letter) LS🔽 = A LT = N/A RB = P RSB = N/A RS◀ = N/A RS🔼 = N/A RS▶ = N/A RS🔽 = N/A RT = N/A D-pad◀ = O (letter) D-pad🔼 = Q D-pad▶ = P D-pad🔽 = A

If we fix the Mozilla Firefox incompatibility and QAOPM/QAOPSpace bugs, could we create a separate issue for custom controller remapping (rather than the fixed one as it is now)? The possibility of playing Elite with a controller was recently mentioned here, and the idea seems viable. Of course, with the ability to export and import mapping profiles.

XMypuK commented 6 days ago

I have fixed QAOPM/QAOPSpace layouts. Thanks you.

Speaking of Mozilla Firefox, I didn't figure out why it might not work. I checked a few configurations and browsers behaved strange sometimes. For example, I created a page with minimal code for checking connected gamepads. It detects my gamepad only every other time I refresh the page in Firefox/Win11. This behavior changes if I, for instance, open developer tools or just a new tab in the browser. However, the same page works stably in Firefox/Win10. Futhermore, the emulator itself, which contains similar code, works well in both these configurations for me. I'll continue to test different environments. If I find the root of the problem and it can be solved with client code, I'll do it.

As for custom remapping, I was going to implement it. However, at the moment, I just don't have much time for development. When it becomes easier, I'll get to it.