Compatible USB gamepad or joystick for MiST

https://github.com/mist-devel/mist-board/wiki

Moderators: Mug UK, Zorro 2, Greenious, spiny, Moderator Team

NML32
Captain Atari
Captain Atari
Posts: 357
Joined: Tue Mar 11, 2014 1:54 am
Location: USA/Florida

Re: Compatible USB gamepad or joystick for MiST

Postby NML32 » Sat Jun 13, 2015 3:33 am

Newsdee wrote:It's called like that because on analog joysticks for flight sims there is a "POV hat" that is essentially a mini digital joystick.

USB HID assumes that all controllers are joysticks and expects an X and Y (analog) axis value for directions. It then expects a series of buttons, and optionally it allows representing a POV hat as a separate structure. Digital gamepads / joysticks usually map themselves to analog X/Y axis (giving a fixed value). But a few controllers like the Qanba do not use analog at all, and instead map directions to the POV hat.

The feature that Till added allowed these devices to work with the MiST, but originally the override was total (i.e. the analog stick was ignored). I just tweaked it a bit so that both inputs work together, allowing you to use either if a controller has both.


Thanks :)

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Sun Jun 14, 2015 2:23 pm

I've released a new firmware that adds a couple of enhancements to USB joysticks:
https://mist-board.googlecode.com/svn/t ... _r1142.upg

  • OSD can now be controlled by USB gamepad
  • When OSD is closed, you can use special button combinations to enter some keyboard keys.
When OSD is open, you can use these commands:
  • Button 1: choose / enter menu
  • Button 2: cancel / return to previous menu
  • Up/Down/Left/Right: Navigate
  • Button 3 + Up/Down: PageUp / PageDown
When OSD is closed these shortcuts are available:
  • Button 4 + Button 1: press Enter key
  • Button 4 + Button 2: press Space bar
  • Button 4 + Button 3: F12 (open OSD)

If you run into any issues or if you don't like this feature, you can disable it via the mist.ini file by setting:

Code: Select all

joystick_disable_shortcuts=0

User avatar
MasterOfGizmo
Atari God
Atari God
Posts: 1026
Joined: Fri Feb 08, 2013 12:15 pm
Contact:

Re: Compatible USB gamepad or joystick for MiST

Postby MasterOfGizmo » Tue Jun 16, 2015 7:11 pm

I've added another mist.ini option related to this (no binary firmware released yet, just the source code). The new option allows to remap joystick buttons:

Code: Select all

joystick_button_remap=<vid>,<pid>,<offset>,<button>


This maps the bit at <offset> in the report sent by device with <vid>/<pid> to button <button>. I'll explain this in more detail in the Wiki. But this for example:

Code: Select all

joystick_button_remap=0e8f,0008,42,0
joystick_button_remap=0e8f,0008,43,1


Swaps the top and right button on my wireless usb gamepad and makes the rightmost button the primary fire button. This allows you to share values to adjust certain gamepads. It's pretty similar to many adjustments that have already been hardcoded into the firmware. But this doesn't require you to update the firmware. Instead it's sufficient to place a few magic lines in the mist.ini
MIST board, FPGA based Atari STE and more: https://github.com/mist-devel/mist-board/wiki

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Tue Jun 16, 2015 9:51 pm

Ah, fantastic. Actually I'm making some more changes to the mapping so that instead of using offsets we can map with a 16-bit wide mask per button / direction. This new config support will be a good example on how to make it configurable.

One problem I came across with the current method is that I can't map across two offsets, i.e. if I want to make 2 "physical" buttons map to the same "virtual" button, but they require a different offset. The offsets can also change per device so we need to run HID capture to figure out the mapping. With the new approach I'd abstract the physical offset away, and we just map e.g. "button 1" to one or more buttons (e.g. "A" + "START"), or even to a direction ("Up" for jump). In principle it would also allow mapping directions to buttons, if we wanted to.

I still need to get it running to confirm this idea works, but I think I can handle up to 12 physical buttons for various purposes (including keyboard commands).

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Thu Jun 18, 2015 4:06 pm

I've commited my changes with the new mapping logic. I'll tweak it a bit more before building a binary, but should be good enough to give you an idea on how the new mapping works.

The approach is similar to how Window's recognizes gamepads, allowing users to map by checking Windows' gamepad properties for information.
We recognize up to 12 physical buttons generically, and then use 16-bit masks perform the mapping:

Code: Select all

                if( vid == 0x0F30 && pid == 0x1012) {
                    // mapping for Qanba Q4RAF
                    mapping[btn_off+1]  = JOY_A;
                    mapping[btn_off+2]  = JOY_B;
                    mapping[btn_off+4]  = JOY_A;
                    mapping[btn_off+3]  = JOY_B;                   
                    mapping[btn_off+6]  = JOY_SELECT;
                    mapping[btn_off+8]  = JOY_SELECT;
                    mapping[btn_off+10] = JOY_START;       
                    use_default=0;
                }


btn_off is calculated such that the +X is exactly the button number in Windows properties.
Because we use masks, it's possible to map one button to several (e.g. JOY_SELECT | JOY_START).

Next step would be to move my mappings to this method, then make it configurable by the INI...

User avatar
farvardin
Captain Atari
Captain Atari
Posts: 351
Joined: Fri Jan 01, 2010 5:50 pm
Location: France
Contact:

Re: Compatible USB gamepad or joystick for MiST

Postby farvardin » Tue Jun 30, 2015 8:08 pm

Newsdee wrote:If you run into any issues or if you don't like this feature, you can disable it via the mist.ini file by setting:

Code: Select all

joystick_disable_shortcuts=0


thank you for this. As explained before, I liked this feature but on some cores it wasn't working as expected (probably because of my gamepad), like for the st core, and also on the amstrad core (slowdown). I also noticed on the amstrad core, on the previous firmware, I couldn't change the menu screen (couldn't go left or right, only up/down and select). With latest firmware, the keyboard on the amstrad core could only work when I unplugged my gamepad (not only on the OSD)... So the option to disable it is appreciated ;)

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Tue Jun 30, 2015 10:46 pm

I fixed a bug that prevented going right in the OSD, so it is possible to change cores now.

For the rest I think the problem is the custom mapping can interfere with the keyboard. I'll try with the Amstrad core, thanks.

User avatar
farvardin
Captain Atari
Captain Atari
Posts: 351
Joined: Fri Jan 01, 2010 5:50 pm
Location: France
Contact:

Re: Compatible USB gamepad or joystick for MiST

Postby farvardin » Sat Jul 04, 2015 8:02 am

it seems it affects also the MSX core.

I've added

Code: Select all

[mist]
joystick_ignore_osd=1


but it's quite the same, with this option I can't use the gamepad to control OSD, but when the gamepad is connected then I can't type in the MSX os, either the keystroke are working badly, or I can't even enter some keys (like enter). If I unplug the gamepad, it's working again. This behavior wasn't happening with previous firmwares (and either way the latest firmware doesn't affect the Amiga core for example, my gamepad works fine with the keyboard).

Maybe the msx core needs to be updated. On the other hand, it's not very stable, if I do nothing and I've launched the mm file manager, it tends to crash itself without reason.

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Sat Jul 04, 2015 8:41 am

I've made an update to prevent the new stuff from activating if there's no joy2key mapping in the INI.
Give it a try, it should fix the issues with cores when you don't use any special config.

To fix it properly I'll need to have a closer look at how the keyboard is handed internally in the MiST firmware...

jerome777
Atariator
Atariator
Posts: 17
Joined: Mon Sep 29, 2014 2:17 pm

Re: Compatible USB gamepad or joystick for MiST

Postby jerome777 » Sun Jul 05, 2015 9:59 pm

Wow, really great idea that allows us to use only a USB gamepad and so,
we can avoid plugging in a keyboard+mouse combo.
Thanks to you guys, the MiST becomes each day more fun and enjoyable.

A few remarks though :
With the Amstrad core (it's the way this computer works), the joystick movements or pressing on the buttons
send key events. For example, if you try directly after boot, the directions display arrows, the button 1 sends X, the the button 2 sends Z.

I've tried with the iBuffalo SNES pad and :
When pressing START + A (button 1), it sends not only ENTER but X + ENTER.
Same thing for START + B (button 2) or START + X (button 3), it sends not only SPACE but SPACE + Z (" Z").
If you keep pressing START, and if at the same time you keep a key pressed on a USB keyboard (wireless or not),
the key pressing does only output one character, and not continuously (a problem in the polling ?). This occurs only with START.

The mouse emulation is great with SELECT for the directions, but with SELECT + L or SELECT + R, I can't get any mouse click
with Amiga, ST, or Archimedes cores.
All these with firmware_150704_r1201.upg, without mist.ini

Thanks anyway Newsdee for your work.

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Mon Jul 06, 2015 1:13 am

jerome777 wrote:The mouse emulation is great with SELECT for the directions, but with SELECT + L or SELECT + R, I can't get any mouse click with Amiga, ST, or Archimedes cores. All these with firmware_150704_r1201.upg, without mist.ini

Perhaps your "physical" L and R buttons aren't being mapped to the "internal" MiST L and R? It definitely works on those cores with the iBuffalo SNES pad since it's what I use :wink:

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Mon Jul 06, 2015 1:35 am

jerome777 wrote:it sends not only ENTER but X + ENTER.

That's by design: we don't suppress gamepad buttons when sending key presses. Is it a problem for a game? I'd expect games to ignore unrecognized keys or joystick buttons (but maybe you are using command line)

jerome777 wrote:If you keep pressing START, and if at the same time you keep a key pressed on a USB keyboard (wireless or not), the key pressing does only output one character, and not continuously (a problem in the polling ?). This occurs only with START.

Yes, I think this happens more widely than with just START. The problem is the gamepad makes the MiST think the keyboard has no keys pressed. I need to upgrade the MiST keyboard handling to fix that, but haven't found a nice way to do it yet.

DrChaos
Atari freak
Atari freak
Posts: 64
Joined: Sun Feb 08, 2015 11:21 pm

Re: Compatible USB gamepad or joystick for MiST

Postby DrChaos » Mon Jul 06, 2015 7:34 am

Hi,

I really like this thread, although my MiST is still not back, so I can't test it. Is it possible to map the joystick directions as well? I am asking because this would enable to use encoder which are designed for MAME, for example for use in a Arcade cabinet. Usually these are configured to use keyboard inputs, so this would allow easy switching.



Edit: Sorry - for some reason I mixed up the threads and missed the USBMapping Docs, which answers this question. I will test when my mist is back!
Maybe a link from the DocIni to the mapping would help to avoid such dumb questions ;)

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Mon Jul 06, 2015 10:09 am

If i'm not mistaken the MaME case is a bit different, because you'd need to map the keyboard input from e.g. an I-Pac 2/4 board into the MiST's joystick input. In other words the opposite of what we're doing :D

But the good news is that there is some support of this already (before my changes) by preasing Num Lock to make the keyboard act as joystick. I haven't tried it yet with my I-Pac board, though, and it would ignore the "shortcuts" defined at the joystick level.

jerome777
Atariator
Atariator
Posts: 17
Joined: Mon Sep 29, 2014 2:17 pm

Re: Compatible USB gamepad or joystick for MiST

Postby jerome777 » Mon Jul 06, 2015 10:40 am

Newsdee wrote:
jerome777 wrote:The mouse emulation is great with SELECT for the directions, but with SELECT + L or SELECT + R, I can't get any mouse click with Amiga, ST, or Archimedes cores. All these with firmware_150704_r1201.upg, without mist.ini

Perhaps your "physical" L and R buttons aren't being mapped to the "internal" MiST L and R? It definitely works on those cores with the iBuffalo SNES pad since it's what I use :wink:

Really strange, I think I've got the same USB gamepad as yours, VID is 0x0583 and PID is 0x2060, BSGP801 is written on the back, the only difference is this :
- Buffalo is written on mine : http://www.amazon.com/gp/product/B002B9XB0E
- iBuffalo is written on yours : http://i.imgur.com/CUBgkJK.jpg

But it's apparently the same brand, so just a cosmetic change.
Did you put something in your mist.ini for the mouse emulation, I should probably try to add a mist.ini ?

Newsdee wrote:That's by design: we don't suppress gamepad buttons when sending key presses. Is it a problem for a game? I'd expect games to ignore unrecognized keys or joystick buttons (but maybe you are using command line)

No, no problem for a game until now, that was just a remark. If it's by design, that's great.
I assume it also sends a key event for START or SELECT, but the Amstrad CPC doesn't display something, as it doesn't manage more for than 2 joystick buttons.

Newsdee wrote:Yes, I think this happens more widely than with just START. The problem is the gamepad makes the MiST think the keyboard has no keys pressed. I need to upgrade the MiST keyboard handling to fix that, but haven't found a nice way to do it yet.

I tried with SELECT and the other buttons, and did not notice this problem (always with the Amstrad core), only with START.
That's not very annoying either.

DrChaos
Atari freak
Atari freak
Posts: 64
Joined: Sun Feb 08, 2015 11:21 pm

Re: Compatible USB gamepad or joystick for MiST

Postby DrChaos » Mon Jul 06, 2015 1:16 pm

Newsdee wrote:If i'm not mistaken the MaME case is a bit different, because you'd need to map the keyboard input from e.g. an I-Pac 2/4 board into the MiST's joystick input. In other words the opposite of what we're doing :D

But the good news is that there is some support of this already (before my changes) by preasing Num Lock to make the keyboard act as joystick. I haven't tried it yet with my I-Pac board, though, and it would ignore the "shortcuts" defined at the joystick level.


Yes, of course, I was not thinking it through. Would it be possible in general to map a Keyboard event to Joystick? I assumed that, because the documentation says that there is a hex code for the joystick directions. Are these treated differently?

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Mon Jul 06, 2015 2:40 pm

jerome777 wrote:I think I've got the same USB gamepad as yours, VID is 0x0583 and PID is 0x2060, BSGP801 is written on the back

You shouldn't need a mist.ini because I've added the mapping inside the firmware (for that VID/PID combo); but perhaps there's been a change in how the buttons are wired. You can check this with Windows, and if that's the problem use the mist.ini to provide custom mapping. The wiki has detailed instructions on how to do it: http://code.google.com/p/mist-board/wik ... ickMapping

jerome777 wrote:I assume it also sends a key event for START or SELECT, but the Amstrad CPC doesn't display something, as it doesn't manage more for than 2 joystick buttons

Not exactly. What happens is that the original hardware mapped the joystick to keys (same as speccy and c64). START and SELECT are completely ignored as the original hardware lacked the buttons... unless you decide to map them to keys via mist config of course (in which case the core thinks it's the keyboard that is pressed).

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Mon Jul 06, 2015 2:51 pm

DrChaos wrote:Would it be possible in general to map a Keyboard event to Joystick? I assumed that, because the documentation says that there is a hex code for the joystick directions. Are these treated differently?

The hex code used for directions and buttons are not USB key scancodes, but a bitmask for a 16-bit word representing the current state of 4 directions + 12 buttons. In binary, each button or direction is 0 if idle and 1 if pressed. This makes it very flexible because you can map 1 physical button to any combination of the 16 items, and separately assign any combination of the 16 items to a keyboard key.

Custom mapping keyboard to joystick is not possible yet. I think we can just use the "MAME standard" keys which the I-PAC and other boards provide by default, and just have a mist.ini entry to turn the feature on. Ideally I'll need to do some changes to allow it to also control the keyboard shortcuts, but I'd need to work out how to handle some border cases (e.g. prevent sending "left" twice if I map left to joystick then joystick to left key...).

DrChaos
Atari freak
Atari freak
Posts: 64
Joined: Sun Feb 08, 2015 11:21 pm

Re: Compatible USB gamepad or joystick for MiST

Postby DrChaos » Mon Jul 06, 2015 8:51 pm

OK, thanks for your explanation, I think I got it now.
Of course it would be great for some (few) people to have standrad MAME encoder support. However, in my case I could look for a JVS-PAC with PS3 firmware, which will then act as a Joystick as far as I understood, so don't worry about it.
Thanks !

jerome777
Atariator
Atariator
Posts: 17
Joined: Mon Sep 29, 2014 2:17 pm

Re: Compatible USB gamepad or joystick for MiST

Postby jerome777 » Wed Jul 08, 2015 9:05 pm

Newsdee wrote:You shouldn't need a mist.ini because I've added the mapping inside the firmware (for that VID/PID combo); but perhaps there's been a change in how the buttons are wired. You can check this with Windows, and if that's the problem use the mist.ini to provide custom mapping. The wiki has detailed instructions on how to do it: http://code.google.com/p/mist-board/wik ... ickMapping


Thanks for the wiki link for the mapping, i checked with Windows, and got exactly the same mapping as yours :
A : 1, B : 2, X : 3, Y : 4
L : 5, R : 6
SELECT : 7, START : 8

In fact, I was mistaken by the picture on Amazon, and I have also a iBuffalo with the same packaging as yours.
So I was wondering what was the problem, I suspected the core I use to boot (NES core as it's very quick) but no,
that was really the missing mist.ini the problem.
I added the r1195 version of mist.ini (but should have added the 1197) : https://code.google.com/p/mist-board/so ... 195&r=1195
and L and R work now.

So it seems that without the proper mist.ini, the mappings related to L and R are lacking in the firmware (mouse clicks with SELECT, and ESC and F1 with START).
Could you give a try and rename temporarily your mist.ini on your SD card to confirm that it is the source of the problem ?

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Sat Jul 11, 2015 4:15 pm

Yes you're right, when I tried without the .ini I saw the problem.
I've updated the firmware to fix it; thanks for pointing it out.

mahen
Captain Atari
Captain Atari
Posts: 192
Joined: Mon Aug 26, 2013 3:11 pm
Location: France

Re: Compatible USB gamepad or joystick for MiST

Postby mahen » Fri Jul 24, 2015 8:20 am

Woohoo, mapping keyboard and mouse to the gamepad is super awesome, thanks a lot !!

Would it be possible to use the mouse emulation constantly, without having to keep "select" pressed ? (a combination to enable/disable it)

Thanks again, that's pretty cool !

I'm using the Retrolink SNES controller, anyone else using it here ? With default settings, it does recognize the select/start buttons properly. I'll try to map the shifts keys, space bar, enter, the "down" arrow for flippers and the "up" direction to a button :) I think I have the right number of buttons !

I'll share my settings if I find the time to do it !
Amiga user since 1993 ;-)

User avatar
Newsdee
Atari God
Atari God
Posts: 1041
Joined: Fri Sep 19, 2014 8:40 am

Re: Compatible USB gamepad or joystick for MiST

Postby Newsdee » Fri Jul 24, 2015 8:30 am

How about having it always on, maybe with an option to go back to current behavior in the .ini?

mahen
Captain Atari
Captain Atari
Posts: 192
Joined: Mon Aug 26, 2013 3:11 pm
Location: France

Re: Compatible USB gamepad or joystick for MiST

Postby mahen » Fri Jul 24, 2015 8:47 am

Well, it's not an option as the mouse correponds to the 2nd player joystick too.
Amiga user since 1993 ;-)

User avatar
Paradroyd
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Sep 10, 2013 10:50 pm
Contact:

Re: Compatible USB gamepad or joystick for MiST

Postby Paradroyd » Fri Jul 24, 2015 2:56 pm

Newsdee wrote:...Custom mapping keyboard to joystick is not possible yet. I think we can just use the "MAME standard" keys which the I-PAC and other boards provide by default, and just have a mist.ini entry to turn the feature on. Ideally I'll need to do some changes to allow it to also control the keyboard shortcuts, but I'd need to work out how to handle some border cases (e.g. prevent sending "left" twice if I map left to joystick then joystick to left key...).


This would be really useful. It would be nice to be able to map physical controller buttons to "SPACE", "RETURN" and a few others for games like Hybris (one of my favorite SHMUPs on the Amiga), as it uses these keys for smart bombs and alternate ship configurations, etc.
- Paradroyd
@paradroyd on twitter


Return to “MiST”

Who is online

Users browsing this forum: No registered users and 1 guest