LostArtefacts / TRX

Open source re-implementation of Tomb Raider 1 (1996), along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
583 stars 36 forks source link

Sony PS Digital controller misread as analog #1284

Open fawtytoo opened 5 months ago

fawtytoo commented 5 months ago

This puzzled me for a bit. I have a Sony PS1 digital gamepad on a USB adapter. All buttons worked as expected but the D-pad did nothing. Redefining the directions had them show up as analog.

walkawayy commented 5 months ago

Hm I don't have one of those to test. Does the d-pad work properly with other games such as through Steam? Is your adapter something like this? https://www.amazon.com/Controller-Adapter-Converter-Compatible-Playstation-2/dp/B00FBM3F72

fawtytoo commented 5 months ago

Yes, that's the adapter.

I have a PS1 emulator I wrote that does use digital and analog gamepads however, it does have to be specified in the configuration file. and is not something that's auto detectable.

walkawayy commented 5 months ago

This seems like an SDL issue potentially? We use SDL for all the gamepad communication. I could try opening an issue there.

https://github.com/libsdl-org/SDL/issues

fawtytoo commented 5 months ago

You don't appear to be reading from these:

SDL_CONTROLLER_BUTTON_DPAD_UP
SDL_CONTROLLER_BUTTON_DPAD_DOWN
SDL_CONTROLLER_BUTTON_DPAD_LEFT
SDL_CONTROLLER_BUTTON_DPAD_RIGHT
fawtytoo commented 5 months ago

Personally, I've never liked using SDL's game controller API. I prefer using SDL_INIT_JOYSTICK and SDL_PollEvent and then use configuration files for different types of joysticks. I get better results that way.

walkawayy commented 5 months ago

You don't appear to be reading from these:

SDL_CONTROLLER_BUTTON_DPAD_UP
SDL_CONTROLLER_BUTTON_DPAD_DOWN
SDL_CONTROLLER_BUTTON_DPAD_LEFT
SDL_CONTROLLER_BUTTON_DPAD_RIGHT

We do use those and have no issues with official gamepads AFAIK. My guess is there's something wonky the adapter is doing. I'd suggest opening an SDL issue and seeing if anyone there has any info.

Personally, I've never liked using SDL's game controller API. I prefer using SDL_INIT_JOYSTICK and SDL_PollEvent and then use configuration files for different types of joysticks. I get better results that way.

We are still using SDL 2 but will probably upgrade to SDL 3 in the future. Maybe we can reevaluate the implementation then.

fawtytoo commented 5 months ago

The adapter simply turns the gamepad into a 14 button controller, and 4 of those buttons are the d-pad.

SDL2 can easily handle this controller using SDL_INIT_JOYSTICK, SDL_PollEvent and reading from SDL_JOYBUTTONDOWN & SDL_JOYBUTTONUP. This is how it's implemented in my PS1 emulator.

Perhaps you need a new CONTROLLER_MAP? Is there a way I can see what your code is reading to see what needs altering/adding?

fawtytoo commented 5 months ago

Is there a way I can add some sort of "debug" code to see what your code is reading from my controller and feed those results back to you?

walkawayy commented 5 months ago

Is there a way I can add some sort of "debug" code to see what your code is reading from my controller and feed those results back to you?

The code is all open source. What you are looking for is probably here: https://github.com/LostArtefacts/TR1X/blob/develop/src/specific/s_input.c

walkawayy commented 5 months ago

Is there a way I can add some sort of "debug" code to see what your code is reading from my controller and feed those results back to you?

Add LOG_DEBUG statements like you see in other places in that file. Then you can upload the TR1X.log that's created every game run. Here's some info on how to compile: https://github.com/LostArtefacts/TR1X/blob/develop/CONTRIBUTING.md