Reading the Sega Mega Drive / Genesis control pads

Haku

Senior Member
Reading the Sega Mega Drive (Genesis) & Amiga CD32 controllers

In the process of turning a Zeemote JS1 bluetooth games controller into a box that allows you to plug old ZX Spectrum / Sega / Amiga games controllers it to control games such as those on console emulators on your Android phone/tablet, I discovered that not all joysticks & joypads with the standard DB9 connector are wired the same.

There's a main standard pinout which applies to most sticks/pads. All controllers outputs are pulled to ground when triggered.



Few sticks/pads have 2 fire buttons such as the Sega Master System so only the first fire button is used, but the Mega Drive (Genesis) has a 3 button pad as standard and a 6 button one for even more control with fighting games etc.



The 3 & 6 button Sega pads use a different pin for power and the main power becomes the select signal to trigger the controller to output the extra button states:



Using the information on these pages http://www.msarnoff.org/gen2usb/ & http://segaretro.org/Six_Button_Control_Pad_(Mega_Drive) I wrote code that allows a Picaxe to read all the Sega pad buttons which also detects wether a Sega Mega Drive / Genesis 3 or 6 button compatable controller is connected:

Code:
' Read Sega Mega Drive (Genesis) 3-button & 6-button joypads
'
'
' Joystick pinout: (looking at joystick DB9 plug)
'
'    5 4 3 2 1
'     9 8 7 6
'
' 1 -    Up / Z
' 2 -  Down / Y
' 3 -  Left / Y 
' 4 - Right / Mode
' 5 - +5v
' 6 -     B / A
' 7 - Select line
' 8 - Ground
' 9 -     C / Start
'
'
' Must run at 16mhz or faster to read 6-button pad.
' Button inputs must have pullup resistors or use internal pullup.
' Might not work with standard joysticks that have autofire or
'  other circuitry in them because their +5V line is DB9 pin 7
'  which is toggled to read the Sega pads.

#picaxe 20m2
#no_data

symbol DB9_1=pinc.3
symbol DB9_2=pinc.2
symbol DB9_3=pinc.1
symbol DB9_4=pinc.0
symbol DB9_6=pinb.6
symbol DB9_9=pinb.7
symbol DB9_7=b.5

symbol jup=b10
symbol jdown=b11
symbol jleft=b12
symbol jright=b13
symbol ja=b14
symbol jb=b15
symbol jc=b16
symbol jx=b17
symbol jy=b18
symbol jz=b19
symbol jstart=b20
symbol jmode=b21

setfreq m32

pullup on
pullup %0000111111000000

high DB9_7

do
 gosub ReadSegaGamepad
 sertxd("u=",#jup," d=",#jdown," l=",#jleft," r=",#jright," a=",#ja," b=",#jb," c=",#jc," x=",#jx," y=",#jy," z=",#jz," start=",#jstart," mode=",#jmode,cr,lf)
loop


ReadSegaGamepad:

 ' Read the standard buttons most controllers use
 jup=1-DB9_1
 jdown=1-DB9_2
 jleft=1-DB9_3
 jright=1-DB9_4
 jb=1-DB9_6
 jc=1-DB9_9
 
 low DB9_7

 ' Check to see if Sega joypad detected
 if DB9_3=0 and DB9_4=0 then
 
  ' Read in extra buttons on 3-button controller
  ja=1-DB9_6
  jstart=1-DB9_9

  ' Attempt to read in extra buttons on 6-button controller
  high DB9_7
  low DB9_7
  high DB9_7
  low DB9_7
  high DB9_7
 
  jx=1-DB9_3
  jy=1-DB9_2
  jz=1-DB9_1
  jmode=1-DB9_4

  low DB9_7
 endif

 high DB9_7
return
I also have an Amiga CD32 in a box somewhere which the controller pad also has the same connector type and extra buttons but uses a different shift method to read the extra buttons. I might have a stab at reading that pad too.

Lastly, just to confuse things further, the ZX Spectrum +2 & +3 have different pinout configurations for the joysticks, this was a move to attempt to sell you a whole new set of joysticks when you upgraded from the first generations of Spectrums, however adaptor cables quickly appeared and some joysticks came with two connectors so they would work on all Spectrums.
 
Last edited:

Haku

Senior Member
Using help from this page http://atariage.com/forums/topic/126083-amiga-cd32-joypad-or-modding-a-sega-one/ I did the code for reading Amiga CD32 joypads, tested & working on these two which are the 3rd party Competition Pro with autofire switches and the original CD32 controller:



The wiring is almost identical to the universal pinout:



If you don't put pin 5 high to start the internal shift register then pin 6 goes low when the red 'fire' button is pressed and pin 9 goes low when the blue 'fire' button is pressed, all other buttons are inactive, allowing it to still work as a 2-fire-button controller on almost any system with the DB9 joystick port.

Code:
' Read Amiga CD32 joypads
'
'
' Joystick pinout: (looking at joystick DB9 plug)
'
'    5 4 3 2 1
'     9 8 7 6
'
' 1 - Up
' 2 - Down
' 3 - Left 
' 4 - Right
' 5 - LOAD/SHIFT
' 6 - CLK
' 7 - +5v
' 8 - Ground
' 9 - DATA
'
'
' Code tested at up to 32mhz without problems.

#picaxe 20m2
#no_data

symbol DB9_1=pinc.3
symbol DB9_2=pinc.2
symbol DB9_3=pinc.1
symbol DB9_4=pinc.0
symbol DB9_5=b.5
symbol DB9_6=b.6
symbol DB9_9=pinb.7

symbol jup=b10
symbol jdown=b11
symbol jleft=b12
symbol jright=b13
symbol jblue=b14
symbol jred=b15
symbol jyellow=b16
symbol jgreen=b17
symbol jtopleft=b18
symbol jtopright=b19
symbol jpause=b20

setfreq m8

pullup on
pullup %0000111110000000

do
 gosub ReadCD32Joypad
 sertxd("u=",#jup," d=",#jdown," l=",#jleft," r=",#jright," blu=",#jblue," red=",#jred," yel=",#jyellow," grn=",#jgreen," TL=",#jtopleft," TR=",#jtopright," paus=",#jpause,cr,lf)
loop


ReadCD32Joypad:
 jup=1-DB9_1
 jdown=1-DB9_2
 jleft=1-DB9_3
 jright=1-DB9_4

 'load button states into controller memory
 high DB9_5
 low DB9_5

 'read button states
 jblue=1-DB9_9:high DB9_6:low DB9_6
 jred=1-DB9_9:high DB9_6:low DB9_6
 jyellow=1-DB9_9:high DB9_6:low DB9_6
 jgreen=1-DB9_9:high DB9_6:low DB9_6
 jtopright=1-DB9_9:high DB9_6:low DB9_6
 jtopleft=1-DB9_9:high DB9_6:low DB9_6
 jpause=1-DB9_9

return
It was almost easier than expected to write it, there's not much the Picaxe has to actually do :)
 
Top