yes this is what I would like to know, too. I am not new to emulators, not to linux, but the emulation station 2 does a pretty good job of hiding, how it works.
As far as I found out, the retroarch.cfg does not have any input_c_btn or input_z_btn. But there is a dgenrc, which lists all the buttons that are important for a megadrive controller. I think (but I could be wrong) that the button numbers you define there, are new indices of a virtual controller.