Reading MD6 Joypad

From MegaDrive Development Wiki
Revision as of 17:59, 8 February 2013 by ElBarto (talk | contribs) (→‎Code)
Jump to navigation Jump to search

Details

As the 3 buttons pad, all the buttons can't be read at once. There is a multiplexer inside the control pad.

Reading the 6 buttons pad consist of 5 steps :

  • Set the direction of pin 6 to output and all others to input.
  • Set TH (pin6) to 1.
  • Read the first part of the buttons (UP,DOWN,LEFT,RIGHT,B,C)
  • Switch the outputs in the control pad by setting TH (pin6) to 0.
  • Read the second part of the buttons (A,START)
  • Switch the outputs in the control pad by setting TH (pin6) to 1.
  • Switch the outputs in the control pad by setting TH (pin6) to 0.
  • Switch the outputs in the control pad by setting TH (pin6) to 1.
  • Read the extra buttons (X,Y,Z,MODE)


TH State Data
1
Bit 7 6 5 4 3 2 1 0
Def 0 THCBRIGHTLEFTDOWNUP
0
Bit 7 6 5 4 3 2 1 0
Def 0 THSTARTA00DOWNUP
1
Bit 7 6 5 4 3 2 1 0
Def 0 THCBRIGHTLEFTDOWNUP
0
Bit 7 6 5 4 3 2 1 0
Def 0 THSTARTA0000
1
Bit 7 6 5 4 3 2 1 0
Def 0 THCBXYZMODE
0
Bit 7 6 5 4 3 2 1 0
Def 0 THSTARTA1111

Code

	moveq	#0, d0
	moveq	#0, d1

	move.b  #0x40, (0xA10009)	| Set direction
	move.b  #0x40, (0xA10003)	| TH = 1
	nop
	nop
	move.b  (0xA10003), d0		| d0.b = X | 1 | C | B | R | L | D | U |
	andi.b	#0x3F, d0		| d0.b = 0 | 0 | C | B | R | L | D | U |

	move.b	#0x0, (0xA10003)	| TH = 0
	nop
	nop
	move.b	(0xA10003), d1		| d1.b = X | 0 | S | A | 0 | 0 | D | U |
	andi.b	#0x30, d1		| d1.b = 0 | 0 | S | A | 0 | 0 | 0 | 0 |
	lsl.b	#0x2, d1		| d1.b = S | A | 0 | 0 | D | U | 0 | 0 |
	or.b	d1, d0			| d0.b = S | A | C | B | R | L | D | U |

	move.b  #0x40, (0xA10003)	| TH = 1
	nop
	nop
	move.b	#0x0, (0xA10003)	| TH = 0
	nop
	nop
	move.b	#0x40, (0xA10003)	| TH = 1
	nop
	nop
	move.b	(0xA10003), d1		| d1.b = X | X | X | X | M | X | Y | Z
	move.b  #0x0, (0xA10003)	| TH = 0

	andi.w	#0xF, d1		| d1.b = 0 | 0 | 0 | 0 | M | X | Y | Z
	lsl.w	#0x8, d1		| d1.w = 0 | 0 | 0 | 0 | M | X | Y | Z | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
	or.w	d1, d0			| d0.w = 0 | 0 | 0 | 0 | M | X | Y | Z | S | A | C | B | R | L | D | U |