Research / Megadrive Programming / I/O ports



$A10003Port A data
$A10005Port B data
$A10007Port C data
$A10009Port A control
$A1000BPort B control
$A1000DPort C control
$A1000FPort A TxData
$A10011Port A RxData
$A10013Port A serial control
$A10015Port B TxData
$A10017Port B RxData
$A10019Port B serial control
$A1001BPort C TxData
$A1001DPort C RxData
$A1001FPort C serial control

Reading even addresses returns the same as odd ones so you can use both $A10000 and $A10001.

$a10001 - version register

Reading version register returns a byte:

Bit 7 - Export bit. 1 if export (USA, Europe, etc.), 0 if domestic (Japan)

Bit 6 - Video type. 1 if PAL, 0 if NTSC

Bit 5 - 0 if Sega CD connected, 1 if not connected

Bit 4 - Unused (always 0)

Bits 3-0 - 0 - MegaDrive 1 / Genesis 1, 1 - newer. Newer have additional security hardware.

$a10003-7 - data registers

Reading a data register returns the state of all pins:

Bit 7 - Unused

Bit 6 - TH pin

Bit 5 - TR pin

Bit 4 - TL pin

Bit 3 - Data 3 pin

Bit 2 - Data 2 pin

Bit 1 - Data 1 pin

Bit 0 - Data 0 pin

Reading joypads

Here's the code:


lea ($FFFFFFF0).w,a0 ;where the joypad states will be written
lea ($A10003).l,a1 ;first joypad data port
bsr.s joypad_read ;do the first joypad
addq.w #2,a1 ;do the second joypad
move.b #0,(a1) ;set the first part
nop ;let the hardware parts act
move.b (a1),d0 ;move the lower byte to d0
lsl.b #2,d0 ;shift some stuff
andi.b #$C0,d0 ;exclude some dirty stuff
move.b #$40,(a1) ;set the second part
nop ;the delay
move.b (a1),d1 ;move the upper byte to d1
andi.b #$3F,d1 ;exclude some dirty stuff
or.b d1,d0 ;or d0 with d1
not.b d0 ;not d0
move.b (a0),d1 ;move the previous joypad state
eor.b d0,d1 ;eor previous state with current state
;(we get holded joypad state in d1)
move.b d0,(a0)+ ;move the pressed state to ram
and.b d0,d1 ;and stuff
move.b d1,(a0)+ ;move the holded state to ram

After executing that code you will have:

$FFFFF0 - Current pressed state of joypad 1

$FFFFF1 - Current holded state of joypad 1

$FFFFF2 - Current pressed state of joypad 2

$FFFFF3 - Current holded state of joypad 2

The joypad output format:

Bit 7 - Start

Bit 6 - A button

Bit 5 - C button

Bit 4 - B button

Bit 3 - Right

Bit 2 - Left

Bit 1 - Down

Bit 0 - Up

Back | Printer friendly
<< 3. Genesis security | 5. VDP >>

© 2004, 2005 drx, Don't copy without permission yadda yadda yadda.