Hi, if you are using a usb gamepad this guide should help you: https://www.petrockblock.com/2013/12/02/retropie-autoconfig-functionality/

If you are using a wireless gamepad such as an Xbox 360 pad or a PS3 pad have a look at the RetroPie-Setup wiki: https://github.com/retropie/RetroPie-Setup/wiki

Regarding the Mega Drive emulator the roms need to be in .smd or .bin format and need to be placed in /home/pi/RetroPie/roms/megadrive

Hope this helps!