Reading MD3 Joypad: Difference between revisions

From MegaDrive Development Wiki
Jump to navigation Jump to search
(Created page with "=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 t...")
 
mNo edit summary
Line 59: Line 59:
     or.b    d1, d0                  ; Now d0 contain START,A,B,C,RIGHT,LEFT,DOWN,UP (active low)
     or.b    d1, d0                  ; Now d0 contain START,A,B,C,RIGHT,LEFT,DOWN,UP (active low)
</syntaxhighlight>
</syntaxhighlight>
[[Category:MegaDrive]]

Revision as of 14:27, 20 March 2012

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
0
Bit 7 6 5 4 3 2 1 0
Def ? THSTARTA00DOWNUP
1
Bit 7 6 5 4 3 2 1 0
Def ? THCBRIGHTLEFTDOWNUP

Code

    move.b  #0x40, (0xA10009)        ; Set the direction
    nop
    nop
    move.b  #0x40, (0xA10003)        ; Set TH to 1
    nop
    nop
    move.b  (0xA10003), d0           ; Read C/B/RIGHT/LEFT/DOWN/UP
    andi.b  #0x3F, d0                ; Discard bit 6 and 7
    move.b  #0x00, (0xA10003)        ; Set TH to 0
    nop
    nop
    move.b  (0xA10003), d1           ; Read START/A
    lsl.b   #0x2, d1                 ; Move START and A to bit 6 and 7
    andi.b  #0xC0, d1                ; Only keep START and A
    or.b    d1, d0                   ; Now d0 contain START,A,B,C,RIGHT,LEFT,DOWN,UP (active low)