Confusion about input handling

I am writing a libretro version for the AppleWin emulator and I am a bit confused on how to handle input.

I am currently calling RETRO_ENVIRONMENT_SET_CONTROLLER_INFO

passing a { "Nintendo DS", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) }

Then I am not sure what the role of retro_set_controller_port_device is and I am totally ignoring. It would log something like Plugging device 1 into port 0.

Afterwards I can call input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, ...) and it works.

In all of this, it is not clear what port, device, index and id exactly refer to. Everything being an unsigned and a #define does not help.

Now I tried to change RETRO_DEVICE_JOYPAD to RETRO_DEVICE_ANALOG and nothing really changed. I still see Plugging device 1 into port 0.

Even after I changed in retroarch the device type, the call back is still for device 1.

I seem to understand that the 1 in retro_set_controller_port_device means the same 1 as in #define RETRO_DEVICE_JOYPAD 1?

A lot of confusion in my head at the moment. A lot of examples are out there but they are very complicated and probably do a lot more that I need so I am not sure I should follow them.

If I could understand the real meaning of port, device, that would help.

Cheers.

I would like to be able to handle 1 and only 1 retropad, either with analog input or without.

Is there anything I need to do, or is this already the default situation in a core?

hey, sorry for not responding to this earlier. Let me get some more eyes on it.

input_state_cb is used to read a single button for a port, so no matter what the device is it will always use that to read the buttons.

  • port is the libretro input port, so usually player 1, player 2, player 3, player 4, basically the physical port connected to an input device
  • device is the emulated device, say in PSX case, PS1 gamepad vs dualshock.

So when you change input devices in the controls menu it always plugs device X into port Y.

If you don’t do anything other than reading input devices you will get retropad and retropad w/analog in all devices, you will be able to read the buttons and the analogs depending on what you select there.

If you want to specialize further you can create “custom input devices” For instance in beetle psx:

#define RETRO_DEVICE_PS_CONTROLLER         RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
#define RETRO_DEVICE_PS_DUALSHOCK          RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)
#define RETRO_DEVICE_PS_ANALOG             RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0)

all of these are specializations of either RETRO_DEVICE_JOYPAD or RETRO_DEVICE_ANALOG and may have different button labels and functions internally depending on what you select

retro_set_controller_port_device is called by the frontend and it would set one of these “Controllers” on any of the ports.

Then you can set the controller descriptions like this:

static const struct retro_controller_description input_device_types[ INPUT_DEVICE_TYPES_COUNT ] =
{
   { "PlayStation Controller", RETRO_DEVICE_JOYPAD },
   { "DualShock", RETRO_DEVICE_PS_DUALSHOCK },
   { "Analog Controller", RETRO_DEVICE_PS_ANALOG },
   { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK },
   { "Guncon / G-Con 45", RETRO_DEVICE_PS_GUNCON },
   { "Justifier", RETRO_DEVICE_PS_JUSTIFIER },
   { "Mouse", RETRO_DEVICE_PS_MOUSE },
   { "neGcon", RETRO_DEVICE_PS_NEGCON },
   { NULL, 0 },
};

Hope it clears up a bit

2 Likes

I am getting there but I have still a question. I looked at beetle_psx and as you say this definition appears #define RETRO_DEVICE_PS_DUALSHOCK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)

Where is the description of what this variant of the standard analog device is?

If I do something similar in my core I always get

[WARN] Input device ID 5 is unknown to this libretro implementation. Using RETRO_DEVICE_JOYPAD.

I’ve tried the beetle psx core too and the same warning is logged.

To me it looks like the core creates a new joypad type, but then nowhere can I see how it is defined, nor retroarch seems to offer me the possibility to create one.

I can only attach the standard RETRO_DEVICE_JOYPAD and RETRO_DEVICE_ANALOG.

Post on our Discord in #programming instead. There will be more of an opportunity to respond to these kinds of issues in real-time.

I tried to follow this https://www.retroarch.com/?page=discord

But I failed

  1. there is no Update Core Info Files
  2. there is no Settings -> Privacy

in my retroarch. Maybe because I compiled it myself?

And on the website of discord, one needs an invite to join a group.

Heh, those instructions are to enable discord’s “rich presence” function inside RetroArch. To use the discord chat application, just follow this link to use the web app: https://discord.com/invite/27Xxm2h