Reading MD3 Joypad: Difference between revisions

From MegaDrive Development Wiki
Jump to navigation Jump to search
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 15: Line 15:
|'''Data'''
|'''Data'''
|-
|-
|0
|1
|{{8BitRegister
|{{8BitRegister
|?|0
|0|0
|TH|1
|TH|1
|START|1
|C|1
|A|1
|B|1
|0|1
|RIGHT|1
|0|1
|LEFT|1
|DOWN|1
|DOWN|1
|UP|1
|UP|1
}}
}}
|-
|-
|1
|0
|{{8BitRegister
|{{8BitRegister
|?|0
|0|0
|TH|1
|TH|1
|C|1
|START|1
|B|1
|A|1
|RIGHT|1
|0|1
|LEFT|1
|0|1
|DOWN|1
|DOWN|1
|UP|1
|UP|1
Line 42: Line 42:
=Code=
=Code=


<syntaxhighlight>
<syntaxhighlight lang="asm">
    move.b  #0x40, (0xA10009)       ; Set the direction
moveq #0, d0
    nop
moveq #0, d1
    nop
 
    move.b  #0x40, (0xA10003)       ; Set TH to 1
move.b  #0x40, (0xA10009) | Set direction
    nop
move.b  #0x40, (0xA10003) | TH = 1
    nop
nop
    move.b  (0xA10003), d0           ; Read C/B/RIGHT/LEFT/DOWN/UP
nop
    andi.b #0x3F, d0               ; Discard bit 6 and 7
move.b  (a0), d0 | d0.b = X | 1 | C | B | R | L | D | U |
    move.b #0x00, (0xA10003)       ; Set TH to 0
andi.b #0x3F, d0 | d0.b = 0 | 0 | C | B | R | L | D | U |
    nop
 
    nop
move.b #0x0, (0xA10003) | TH = 0
    move.b (0xA10003), d1           ; Read START/A
nop
    lsl.b   #0x2, d1                 ; Move START and A to bit 6 and 7
nop
    andi.b #0xC0, d1               ; Only keep START and A
move.b (0xA10003), d1 | d1.b = X | 0 | S | A | 0 | 0 | D | U |
    or.b   d1, d0                   ; Now d0 contain START,A,B,C,RIGHT,LEFT,DOWN,UP (active low)
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 |
</syntaxhighlight>
</syntaxhighlight>


[[Category:MegaDrive]]
[[Category:Code]]
[[Category:Code]]

Latest revision as of 11:53, 19 January 2017

Details

All the buttons can't be read at once. There is a multiplexer inside the control pad.

Reading the 3 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)
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

Code

 	moveq	#0, d0
	moveq	#0, d1

	move.b  #0x40, (0xA10009)	| Set direction
	move.b  #0x40, (0xA10003)	| TH = 1
	nop
	nop
	move.b  (a0), 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 |