feat: expose controller port device API for EmulatorJS#38
Open
chrisallenlane wants to merge 1 commit intoEmulatorJS:v1.22.2from
Open
feat: expose controller port device API for EmulatorJS#38chrisallenlane wants to merge 1 commit intoEmulatorJS:v1.22.2from
chrisallenlane wants to merge 1 commit intoEmulatorJS:v1.22.2from
Conversation
Add two new WASM-exported functions to allow EmulatorJS to query available controller device types per port and change them at runtime: - ejs_get_controller_port_info(): serializes the controller info reported by cores via RETRO_ENVIRONMENT_SET_CONTROLLER_INFO into a string that JavaScript can parse. - ejs_set_controller_port_device(port, device): thin wrapper around core_set_controller_port_device() to allow changing a port's device type (e.g. switching from Joypad to Super Scope) from JavaScript. Also adds RETRO_DEVICE_LIGHTGUN handling to the EmulatorJS input driver, mapping mouse position to lightgun screen coordinates and mouse buttons to lightgun buttons (trigger, cursor, turbo, start, select). This enables lightgun support for SNES Super Scope, Justifier, NES Zapper, PSX GunCon, and other lightgun peripherals across all supported cores. Closes EmulatorJS/EmulatorJS#677 Related: EmulatorJS/EmulatorJS#272, EmulatorJS/EmulatorJS#816, EmulatorJS/EmulatorJS#1117 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This looks good to me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Body
Hi, all.
Over the weekend I embedded EmulatorJS in a project, and realized that lightgun support was not implemented. This is one of two PRs that implements it. (You can see it working now in the linked project - I've applied these patches there already.)
I am a software engineer, but I am not a C programmer, so please take a close look at this one. That said, the I've robustly tested the changes (meaning: I've beaten Battleclash and Metal Combat: Falcon's Revenge several times today, lol), and I've encountered no issues.
I hope this is helpful. I'm happy to answer any questions.
Summary
This adds two new WASM-exported functions and lightgun input handling to enable EmulatorJS to support controller port device switching at runtime -- most notably, lightgun peripherals like the SNES Super Scope.
Currently, EmulatorJS has no way to change a port's device type (e.g. from Joypad to Super Scope). The core reports available device types via
RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, andcore_set_controller_port_device()exists internally, but neither is exposed to JavaScript. This means lightgun games are unplayable across all systems.Changes
runloop.c-- Two new functions inside#ifdef EMULATORJS:ejs_get_controller_port_info()-- Serializes the controller info already stored insys_info->ports(reported by the core viaSET_CONTROLLER_INFO) into a parseableport:deviceId:description\nstring. Follows the same pattern asget_core_options().ejs_set_controller_port_device(port, device)-- Thin wrapper aroundcore_set_controller_port_device().input/drivers/emulatorjs_input.c-- AddedRETRO_DEVICE_LIGHTGUNcase torwebinput_input_state():LIGHTGUN_SCREEN_X/Yvia existing viewport translationrwebinput_get_capabilities()Makefile.emulatorjs-- Added both new functions toEXPORTED_FUNCTIONS.Testing
Tested with snes9x core running SNES Super Scope games (Battle Clash, Metal Combat: Falcon's Revenge, Super Scope 6). Crosshair tracks mouse, fire/cursor/turbo buttons work correctly, device type persists across settings changes.
Related issues
Companion PR
The EmulatorJS JavaScript UI changes that consume these new exports will be submitted as a separate PR to EmulatorJS/EmulatorJS.