Here is two bits of arduino code that work for 3 and 6 button MD joypads separately. They need to be combined but I have never found the time.
When a 6 button joystick is connected the joystick reports that both U and D are pressed simultaneously so you can look for this to change between the 2 bits of code for a 3 button a 6 button.
The way to implement this together is, by default polling for a 3 button dpad quickly as the 3 button dpad used dumb logic. After every pulse, check for both U and D being pressed simultaneously. If that is detected then you know a 6 button controller is connected, so you start polling for a 6 button dpad, slightly more slowly than a 3 button because a 6 button dpad uses an IC to detect the select state and send the correct signals and polling to quickly can reset the IC.
If you combine that code with a simple pcb like those for the PS or SNES it should be easy. I just can't find the time.