stardot / b-em

An opensource BBC Micro emulator for Win32 and Linux
http://stardot.org.uk/forums/viewtopic.php?f=4&t=10823
GNU General Public License v2.0
112 stars 57 forks source link

360 game pad doesn't work properly #134

Open richard-broadhurst opened 3 years ago

richard-broadhurst commented 3 years ago

Nothing pressed gives no buttons and ADVAL(1),(2) &7FF7, &7ff7, same for left thumb stick full left or full up, right gives &fff0,&7ff7 and down &7ff7,&fff0. Any direction on the dpad gives fire 1 ADVAL(0)and3=1, all four fire buttons and shoulder and start/select give 1.

The left thumb stick, should map to adval 1,2 and maybe the dpad too. right thumb stick could be adval 3,4 or 1,2 again. fire 2 would be better as fire 2 and if there is a second stick plugged in, it could have A=2 and B=1.

Alternatively, some kind of user config.

The old b-em works fine, apart from only supporting a single fire button.

richard-broadhurst commented 3 years ago

Maybe all I need is to know how to configure allegro joysticks, but it doesn't seem great and I can't find the docs!

I've just found the .cfg ... [joymap X Box One Standard] joystick=Microsoft X-Box One S pad stick0axis0adc=1 stick0axis0scale=-1 stick0axis1adc=2 stick0axis1scale=-1 stick1axis0adc=0 stick1axis1adc=4 stick2axis0adc=3 stick2axis1adc=0 stick0axis0nkey=A stick0axis0pkey=S ... debugger state: The 360 controller that it was using   Name Value Type
jsptr 0x0b37f860 {js_name=0x01e97314 "XInput Joystick 0" js_id=b-em.exe!0x01e96f98 {...} num_stick=4 ...} joystick_map_t *
  ▶ js_name 0x01e97314 "XInput Joystick 0" const char *
  js_id b-em.exe!0x01e96f98 {...} ALLEGRO_JOYSTICK *
  num_stick 4 int
  ▶ js_sticks 0x0026fb50 {num_axes=2 axes_map=0x0b654448 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t *
  num_butn 14 int
  ▶ js_btns 0x0b68ee88 {js_button=1 js_key=0 } js_btn_map_t *
jsptr->js_sticks,4 0x0026fb50 {{num_axes=2 axes_map=0x0b654448 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} }, {num_axes=...}, ...} js_stick_t[4]
  ◢ [0] {num_axes=2 axes_map=0x0b654448 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 2 int
  ◢ axes_map 0x0b654448 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 1 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
  ◢ [1] {num_axes=2 axes_map=0x0b654498 {js_adc_chan=3 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 2 int
  ◢ axes_map 0x0b654498 {js_adc_chan=3 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 3 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
  ◢ [2] {num_axes=1 axes_map=0x0993ec48 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 1 int
  ◢ axes_map 0x0993ec48 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 0 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
  ◢ [3] {num_axes=1 axes_map=0x0993ec88 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 1 int
  ◢ axes_map 0x0993ec88 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 0 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
jsptr->js_btns,14 0x0b68ee88 {{js_button=1 js_key=0 }, {js_button=1 js_key=0 }, {js_button=1 js_key=0 }, {js_button=1 ...}, ...} js_btn_map_t[14]
  ▶ [0] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [1] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [2] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [3] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [4] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [5] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [6] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [7] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [8] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [9] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [10] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [11] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [12] {js_button=1 js_key=0 } js_btn_map_t
  ▶ [13] {js_button=1 js_key=0 } js_btn_map_t

The PS3 one that I didn't try:

  Name Value Type
jsptr 0x0b37f878 {js_name=0x01e9374c "呓䍉⁋A䷍眎꾄ט￾￿撔眊ᶜ痆4쀀൵甸Ȓᶩ痆۴" js_id=...} joystick_map_t *
  ▶ js_name 0x01e9374c "呓䍉⁋A䷍眎꾄ט￾￿撔眊ᶜ痆4쀀൵甸Ȓᶩ痆۴" const char *
  js_id b-em.exe!0x01e93380 {...} ALLEGRO_JOYSTICK *
  num_stick 3 int
  ▶ js_sticks 0x0b37f8c0 {num_axes=3 axes_map=0x0b37f920 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t *
  num_butn 13 int
  ▶ js_btns 0x0b6a9a80 {js_button=2 js_key=0 } js_btn_map_t *
jsptr->js_sticks,3 0x0b37f8c0 {{num_axes=3 axes_map=0x0b37f920 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} }, {num_axes=...}, ...} js_stick_t[3]
  ◢ [0] {num_axes=3 axes_map=0x0b37f920 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 3 int
  ◢ axes_map 0x0b37f920 {js_adc_chan=1 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 1 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
  ◢ [1] {num_axes=1 axes_map=0x0993ecc8 {js_adc_chan=3 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 1 int
  ◢ axes_map 0x0993ecc8 {js_adc_chan=3 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 3 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
  ◢ [2] {num_axes=2 axes_map=0x0b6544e8 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} } js_stick_t
  num_axes 2 int
  ◢ axes_map 0x0b6544e8 {js_adc_chan=0 js_scale=1.00000000 js_nkey=0 ...} js_axis_map_t *
  js_adc_chan 0 int
  js_scale 1.00000000 float
  js_nkey 0 int
  js_pkey 0 int
jsptr->js_btns,13 0x0b6a9a80 {{js_button=2 js_key=0 }, {js_button=2 js_key=0 }, {js_button=2 js_key=0 }, {js_button=2 ...}, ...} js_btn_map_t[13]
  ▶ [0] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [1] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [2] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [3] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [4] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [5] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [6] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [7] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [8] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [9] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [10] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [11] {js_button=2 js_key=0 } js_btn_map_t
  ▶ [12] {js_button=2 js_key=0 } js_btn_map_t
SteveFosdick commented 3 years ago

Does this documentation help? https://github.com/stardot/b-em/wiki/Joysticks

SteveFosdick commented 3 years ago

Also, check out the jstest program (jstest.c) which should help to work out which stick and axis numbers correspond to which actual sticks on the controller.

richard-broadhurst commented 3 years ago

I apologize, I searched with google and in github, but didn't think of the WIKI! "The current map can be chosen from the Settings menu and then selecting Joystick.", there is no Joystick option under settings for me, Without attaching a debugger, how would a normal user find out the joystick names? For example, it looks like allegro has chosen: 1st stick "XInput Joystick 0" 2nd stick "呓��A�眎꾄ט￾￿撔眊ᶜ痆4쀀൵甸Ȓᶩ痆۴" I have replaced the xbox one section with: [joymap XInput Joystick 0] joystick=Microsoft X-Box 360 pad stick0axis0adc=1 stick0axis0scale=-1 stick0axis1adc=2 stick0axis1scale=-1 stick2axis0adc=3 stick2axis0scale=1 stick2axis1adc=4 stick2axis1scale=1 button0btn=0 button1btn=1 button1btn=2 But still all buttons and dpad are button 1 and all buttons on the PS3 controller are button 2 (the ps3 stick does nothing) and the 360 sticks only work from centred to max!

richard-broadhurst commented 3 years ago

The axis only moving half way seems to be a simple bug here: void adc_poll() { uint32_t val = (uint32_t)(joyaxes[adc_status & 3] 32760.0) + 32760; . . . The cast happens first, casting any negative number to -1, then 32760 is added, giving 32759. I don't remember this being what C used to do, so maybe it is a 2019 compiler thing. . . . I have just realised that the included .vcxproj is for 2015, but I only had 6/97/2005/2008/2010/2012/2013 and 2019 and it wouldn't build with the others due to allegro linking issues. Still, changing this cast should work for all compilers. void adc_poll() { uint32_t val = (uint32_t)(joyaxes[adc_status & 3] 32760.0 + 32760); I still have the buttons to sort and how to identify the PS3 joystick. Is it possible to have multiple sections and is it possible to have a default if the name isn't found.

richard-broadhurst commented 3 years ago

Apologies again for not reading the WIKI properly for button mapping! Do you think that it would make sense with two joysticks attached to connect the buttons to the first one as described for a single stick and then to make the buttons on the second stick with fire 1 and 2 swapped, so first button is fire 2 and second is fire 1?

richard-broadhurst commented 3 years ago

Something else that I probably missed in the docs is that the b-em.cfg used isn't the one that shipped with it, but one in AppData/Roaming... which explains why I don't have a joystick menu as it only appears if there is at least one joymap in the .cfg - maybe could be if there is at least one joystick attached?

richard-broadhurst commented 3 years ago

I still can't use the axis on the PS3 controller, despite them coming through fine in allegro and can't add a section for it as the name seems to include unicode characters.

SteveFosdick commented 3 years ago

Thanks, Richard. I am not going to have much time to spend on this today as real work is intervening - to do with NHS vaccination centres.

It may be possible to put the unicode names in - the config file may be in UTF-8. That doesn't make it easy, though. I did try to make it work reasonably by default but that doesn't seem to have worked. You're more of the expert on joysticks than I am and it also helps to have several types to try as I only have the one Xbox controller. Thanks for what you're doing and I'll help where I can.

So having the buttons swapped on the 2nd stick so one stick could generate both or two people could be generating fire presses with two different sticks seems very sensible.

SteveFosdick commented 3 years ago

That casting bug: my guess is that I didn't put a cast in at all. That's valid C but VS, being a C++ compiler, complains. Someone put the cast in to silence the compiler but didn't test it.

richard-broadhurst commented 3 years ago

I don't think that it is a unicode string, that was just what the text viewer thought. It seems to be 60+ mostly negative values. So, please don't spend time on unicode support.

I've been looking at the code and it looks like it should probably be picking up the two joysticks anyway, but the stick on the second joystick doesn't seem to be being connected even though the buttons sort of are. If the second stick is ticked, its buttons work, but if it isn't, only button 1 works. Maybe it just needs a sample config for two working joysticks as it the code seems to have most of the functionality.