Author Topic: Generating input bindings via translation from SDL2  (Read 14781 times)

Offline digitalwatches

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
Generating input bindings via translation from SDL2
« on: March 01, 2024, 02:30:00 AM »
Hey folks, not sure if this kind of question is welcome here, but here goes:

I'm writing some tooling intended to integrate with FBNeo (among other things) and was wondering if anyone here could help me out with the translation convention of the input bindings so that they could be generated from an external tool

Specifically, I'm interested in how SDL2 bindings translate to the hex code that's mapped to per-game config files, e.g.

input  "P1 Coin"          switch 0x4087

I've cloned the repo and am digging through it, but I figured it was worth asking here in case someone knew off-hand and could save me some effort

Specifically, I'd like to understand how SDL2 inputs from joysticks are translated into these hex values. I assume that it's something like a signature derived from the fields one could also read as an SDL_Event in c, e.g. there's some translation of an event with the properties: {which: 0, axis: 2, value: -1} and a hex code like the one above. (Or, similar for states, if it's checking device states rather than using the event polling subsystem)

The code for handling inputs and saving config files seems pretty spread out over the codebase, so I think it would be adequate for my purposes to point to which files and functions relate to this translation

Thanks for your time
« Last Edit: March 01, 2024, 02:33:02 AM by digitalwatches »

Offline digitalwatches

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Generating input bindings via translation from SDL2
« Reply #1 on: March 01, 2024, 02:48:00 AM »
O, this is promising:

Within

src/burner/sdl/sdl2_gui_ingame.cpp

The function

int GetNewKeyButtonJoyToMap()

seems to be what I'm looking for. If this turns out to be all I need, I guess I'm just posting the answer here for posterity, but if I'm on the wrong track or someone wants to add more about this I'm still all ears

Offline digitalwatches

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Generating input bindings via translation from SDL2
« Reply #2 on: March 01, 2024, 02:56:38 AM »
Okay, assuming this works, I have an additional question

The tooling I'm making intends to provide an overlay that remaps inputs. I'm wondering if there's a way to hook into a running FBNeo instance to make it update its configs

Like when you update the config from the GUI menu, the game instantly recognizes the new mappings. Would that happen if the mappings were changed in the config file from an external process? Would the emulator need to reload the game? Restart entirely? Is there a way to induce whatever the minimal necessary reset is by sending signals to the process without killing the process? If not, is there a way to do something like save state, kill the emulator, reload the emulator with the same rom and load that savestate via e.g. command line options or macros that could be scripted?


Offline dink

  • Administrator
  • *****
  • Posts: 5060
  • Karma: +451/-1
  • pie? I nearly bought one!
Re: Generating input bindings via translation from SDL2
« Reply #3 on: March 01, 2024, 09:30:31 AM »
Hi,
I'm sure you already have this figured out, but the input id
stuff is also in src/intf/input/inp_interface.cpp
0x0000 = keyboard
0x4000 = mouse
0x8000 = joystick

Regarding editing inputs from an external process, that's tricky but it could be done
a number of ways.  Thinking back to the 90's here, but, I'd create a named pipe (or
some sort of external semaphore, depending on os), and when it's ticked, it'll have
fbn reload the config.  (of course, you'd have to add that feature to fbn)

best regards,
- dink