you’ve to do with root permissions…you’ve to go on terminal (press f4) and
sudo -i
cd /opt/retropie/emulators/mame4all (mame4all folder i don't remember specifically folder)
./mame
now you choose a game and inside game press tab on keyboard and you’ve to configure buttons