Difference between revisions of "Sega Mega Drive/Control pad inputs"

From Sega Retro

Line 49: Line 49:
 
nop
 
nop
 
move.b ($A10003).l,d1
 
move.b ($A10003).l,d1
 +
move.b #0,($A10003).l ; TH to 0
 
andi.w #$F,d1 ; d1 = 0000MXYZ
 
andi.w #$F,d1 ; d1 = 0000MXYZ
 
lsl.w #8,d1 ; d1 = 0000MXYZ00000000
 
lsl.w #8,d1 ; d1 = 0000MXYZ00000000

Revision as of 20:24, 11 July 2018

Control pad inputs are received through the Sega Mega Drive's two 9-pin ports on the front of the console.

3 button control pads

Reading 3 button control pads consists of the following steps:

  • Set TH pin to output and all others to input.
  • Set TH pin to 1.
  • Read inputs for UpDownLeftRightBC
  • Set TH pin to 0.
  • Read inputs for A START 

The following code will perform this function for control pad #1:

moveq	#$40,d0
move.b	d0,($A10009).l	; TH pin to output, others to input
move.b	d0,($A10003).l	; TH to 1
nop
nop
move.b	($A10003).l,d0
andi.b	#$3F,d0		; d0 = 00CBRLDU
moveq	#0,d1
move.b	#0,($A10003).l	; TH to 0
nop
nop
move.b	($A10003).l,d1
andi.b	#$30,d1		; d1 = 00SA0000
lsl.b	#2,d1		; d1 = SA000000
or.b	d1,d0		; d0 = SACBRLDU

This leaves the current state of control pad #1 in the register d0. To do the same with pad #2, replace $A10009 with $A1000B and $A10003 with $A10005.

6 button control pads

Reading 6 button control pads is the same as reading 3 button pads, with an additional step for XYZ MODE .

The following code assumes the code for a 3 button pad has already run:

moveq	#0,d1
move.b	#$40,($A10003).l ; TH to 1
nop
nop
move.b	#0,($A10003).l	; TH to 0
nop
nop
move.b	#$40,($A10003).l ; TH to 1
nop
nop
move.b	($A10003).l,d1
move.b	#0,($A10003).l	; TH to 0
andi.w	#$F,d1		; d1 = 0000MXYZ
lsl.w	#8,d1		; d1 = 0000MXYZ00000000
or.w	d1,d0		; d0 = 0000MXYZSACBRLDU