Skip to content

Instantly share code, notes, and snippets.

@boomlinde
Created October 4, 2021 21:53
Show Gist options
  • Save boomlinde/3108517639b70d772275f8499c908ff5 to your computer and use it in GitHub Desktop.
Save boomlinde/3108517639b70d772275f8499c908ff5 to your computer and use it in GitHub Desktop.
import sys
mist = {
'right': 0x01, 'left': 0x02, 'down': 0x04, 'up': 0x08,
'a': 0x10, 'b': 0x20, 'select': 0x40, 'start': 0x80,
'x': 0x100, 'y': 0x200, 'l': 0x400, 'r': 0x800,
'l2': 0x1000, 'r2': 0x2000, 'l3': 0x4000, 'r3': 0x8000,
}
cpsgames = [
'dino', 'sf2', 'punisher', 'knights', 'ffight', 'varth',
]
controllers = [
{
'name': 'Retro-Bit Official Sega Genesis USB Controller 8-Button Arcade Pad',
'buttons': (
'right', 'left', 'down', 'up',
'y', 'b', 'a', 'x', 'l', 'r', 'z', 'c', 'mode', 'start'
),
'vid': 0x0f0d,
'pid': 0x00c1,
'mappings': {
'default': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'b', 'b': 'a', 'x': 'y', 'y': 'x',
'l': 'l', 'r': 'r', 'start': 'start', 'mode': 'select',
},
'genesis': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'a', 'b': 'b', 'c': 'select', 'x': 'x', 'y': 'y', 'z': 'l',
'start': 'start', 'mode': 'r',
},
'snes': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'b', 'b': 'a', 'x': 'y', 'y': 'x',
'l': 'l', 'r': 'r', 'start': 'start', 'mode': 'select',
},
'nes': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'b', 'b': 'a', 'start': 'start', 'mode': 'select',
},
'cps': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'a', 'b': 'b', 'c': 'select', 'x': 'start', 'y': 'x',
'z': 'y', 'mode': 'r', 'start': 'l'
},
'ecofghtr': {
'right': 'right', 'left': 'left', 'down': 'down', 'up': 'up',
'a': 'a', 'b': 'b', 'c': 'select', 'x': 'start', 'y': 'x',
'z': 'y', 'mode': 'r', 'start': 'l', 'l': 'a', 'r': 'select',
},
},
},
]
def mapctrl(mapping, button):
return '%x' % mist.get(mapping.get(button, ''), 0)
if __name__ == '__main__':
if len(sys.argv) == 1:
for i, c in enumerate(controllers):
print '%d:\t%s (%04x,%04x %s)' % (i, c['name'], c['vid'], c['pid'], ', '.join(c['buttons']))
sys.exit(0)
c = controllers[int(sys.argv[1])]
mappings = c['mappings']
for m in mappings:
a = [m]
if m == 'cps':
a = cpsgames
for x in a:
if x != 'default':
print '[%s]' % x
out = ['%04x' % c['vid'], '%04x' % c['pid']] + [
mapctrl(mappings[m], button)
for button in c['buttons']
]
print 'joystick_remap=' + ','.join(out)
@boomlinde
Copy link
Author

$ python2 mist.py

to list numbered controllers

$ python2 mist.py 0

to output mapping config for the MiST for controller 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment