@felleg I've just read your method to configure the controller for a specific console and I think it's not a good approach. Your configs/megadrive/retroarch.cfg is ignoring the global configs/all/retroarch.cfg.
My suggestion is:
recover the default configs/megadrive/retroarch.cfg (check if you have a retroarch.cfg.rp-dist on the same directory, that's the default config).
configure your Hori controller in emulationstation like a SNES controller (square = Y; triangle = X, circle = A, etc.)
You need to define if you want to use your Hori controller for player1 or 2, and make sure you'll always use it as that player (if you change, you need to remap). And then use the
Core Input Remapping when running a megadrive game and use the following scheme:
MegaDrive = RetroPad
B = A
A = B
C = R2
Y = X
X = Y
Z = R
after remap, select
Save Core Remap File.