Joypad port.

Summary
Joypad port.
joyportI/O port.
I/O port bit mask.
IO_CD_MASKCD-ROM base unit sense bit.
IO_COUNTRY_MASKCountry detection.
IO_JOYPAD_MASKJoypad port pin.
2-buttons Joypad Bitfield.
IO_JOYPAD_IBit in the joyport for button I (SEL=0).
IO_JOYPAD_IIBit in the joyport for button II (SEL=0).
IO_JOYPAD_SELBit in the joyport for the Select button (SEL=0).
IO_JOYPAD_RUNBit in the joyport for the RUN button (SEL=0).
IO_JOYPAD_UPBit in the joyport for the up direction on the D-PAD (SEL=1).
IO_JOYPAD_RIGHTBit in the joyport for the right direction on the D-PAD (SEL=1).
IO_JOYPAD_DOWNBit in the joyport for the down direction on the D-PAD (SEL=1).
IO_JOYPAD_LEFTBit in the joyport for the left direction on the D-PAD (SEL=1).
6-buttons Joypad Bitfield.
IO_JOYPAD_IIIBit in the joyport for button III on a 6-button joypad.
IO_JOYPAD_IVBit in the joyport for button IV on a 6-button joypad.
IO_JOYPAD_VBit in the joyport for button V on a 6-button joypad.
IO_JOYPAD_VIBit in the joyport for button VI on a 6-button joypad.
JOYPAD_IBit in the joypad for button I.
JOYPAD_IIBit in the joypad for button II.
JOYPAD_IIIBit in the joypad for button III.
JOYPAD_IVBit in the joypad for button IV.
JOYPAD_VIBit in the joypad for button VI.
JOYPAD_VIBit in the joypad for button VI.
JOYPAD_SELBit in the joypad for the Select button.
JOYPAD_RUNBit in the joypad for the RUN button.
JOYPAD_UPBit in the joypad for the up direction.
JOYPAD_RIGHTBit in the joypad for the right direction.
JOYPAD_DOWNBit in the joypad for the down direction..
JOYPAD_LEFTBit in the joypad for the left direction.
joypadThis array holds the values for 5 2-buttons joypads.
joytrgDelta joypad values for 5 2-buttons joypads.
joyoldPrevious 5 joypads values.
joypad_6This array contains the values for buttons III, IV, V and VI of 5 6-buttons joypads.
joytrgDelta joypad values of 5 6-buttons joypads.
joyoldPrevious 5 6-buttons joypad values.
joypad_delay9 cycles delay before reading data after SEL line update.
joypad_reset_multitapReset multitap to the first joypad.
joypad_pollRead joypad state.

joyport

joyport = $1000

I/O port.

The joypad port uses a 8-pin connector.

pin 1Vcc
pin 2D0
pin 3D1
pin 4D2
pin 5D3
pin 6SEL
pin 7CLR
pin 8GND

Reading joyport returns the states of states of pins 2,3,4 and 5 as long as the following informations :

bit 7CD-ROM base unit presence (IO_CD_MASK)
bit 6Country detection (IO_COUNTRY_MASK)
bit 5Unused (always 1)
bit 4Unused (always 1)
bit 3Joypad port 5 (D3)
bit 2Joypad port 4 (D2)
bit 1Joypad port 3 (D1)
bit 0Joypad port 2 (D0)

Writing bit 0 and 1 of the joyport will update pin 6 and 7 states.

bit 1Joypad port 7 (CLR)
bit 0Joypad port 6 (SEL)

I/O port bit mask.

IO_CD_MASK

IO_CD_MASK = %10000000

CD-ROM base unit sense bit.

This bit is set to 0 if a CD-ROM is attached and 1 otherwise.

IO_COUNTRY_MASK

IO_COUNTRY_MASK = %01000000

Country detection.

This bit is set to 1 for Japanses models (PC-Engine, CoreGrafx, ...) and is set to 0 for US models (TurboGrafx 16).

IO_JOYPAD_MASK

IO_JOYPAD_MASK = %00001111

Joypad port pin.

The first 4 bits of the joyport returns the states of the joypad port pins 2,3,4 and 5.  Nevertheless the standard 2-button controller has a 4-way directional pad and and 4 buttons (Select, Run, I and II).  The SEL line of the I/O port selects whether the directions of the buttons state are returned when D3-D0 are read.  When SEL is high, the directions are returned, and buttons are returned when it is low.  Note that the state of D3-DO is inverted.  0 means that a button is pressed and 1 otherwise.

     SEL = 0      SEL = 1
D3 | Run        | Left      |
D2 | Select     | Right     |
D1 | I          | Down      |
D0 | II         | Up        |

Unconnected controllers always return $0f in D3-DO.

Multitap/Turbo tap

This device lets you connect 5 controllers to the joypad port.  Each joypad is read sequentially.  A transition from zero-to-one on the SEL while holding CLR to zero will switch to the next controller.  The sequence is reset by holding SEL to 1 while doing a zero-to one transition on CLR.  Note that once all 5 controllers have been read, the multitap will return $00 for D3-D0 until the sequence is reset again.

2-buttons Joypad Bitfield.

IO_JOYPAD_I

IO_JOYPAD_I = %00000001

Bit in the joyport for button I (SEL=0).

IO_JOYPAD_II

IO_JOYPAD_II = %00000010

Bit in the joyport for button II (SEL=0).

IO_JOYPAD_SEL

IO_JOYPAD_SEL = %00000100

Bit in the joyport for the Select button (SEL=0).

IO_JOYPAD_RUN

IO_JOYPAD_RUN = %00001000

Bit in the joyport for the RUN button (SEL=0).

IO_JOYPAD_UP

IO_JOYPAD_UP = %00000001

Bit in the joyport for the up direction on the D-PAD (SEL=1).

IO_JOYPAD_RIGHT

IO_JOYPAD_RIGHT = %00000010

Bit in the joyport for the right direction on the D-PAD (SEL=1).

IO_JOYPAD_DOWN

IO_JOYPAD_DOWN = %00000100

Bit in the joyport for the down direction on the D-PAD (SEL=1).

IO_JOYPAD_LEFT

IO_JOYPAD_LEFT = %00001000

Bit in the joyport for the left direction on the D-PAD (SEL=1).

6-buttons Joypad Bitfield.

IO_JOYPAD_III

IO_JOYPAD_III = %00000001

Bit in the joyport for button III on a 6-button joypad.

IO_JOYPAD_IV

IO_JOYPAD_IV = %00000010

Bit in the joyport for button IV on a 6-button joypad.

IO_JOYPAD_V

IO_JOYPAD_V = %00000100

Bit in the joyport for button V on a 6-button joypad.

IO_JOYPAD_VI

IO_JOYPAD_VI = %00001000

Bit in the joyport for button VI on a 6-button joypad.

JOYPAD_I

JOYPAD_I = IO_JOYPAD_I

Bit in the joypad for button I.

JOYPAD_II

JOYPAD_II = IO_JOYPAD_II

Bit in the joypad for button II.

JOYPAD_III

JOYPAD_III = IO_JOYPAD_III

Bit in the joypad for button III.

JOYPAD_IV

JOYPAD_IV = IO_JOYPAD_IV

Bit in the joypad for button IV.

JOYPAD_VI

Bit in the joypad for button VI.

JOYPAD_VI

JOYPAD_VI = IO_JOYPAD_VI

Bit in the joypad for button VI.

JOYPAD_SEL

JOYPAD_SEL = IO_JOYPAD_SEL

Bit in the joypad for the Select button.

JOYPAD_RUN

JOYPAD_RUN = IO_JOYPAD_RUN

Bit in the joypad for the RUN button.

JOYPAD_UP

Bit in the joypad for the up direction.

JOYPAD_RIGHT

Bit in the joypad for the right direction.

JOYPAD_DOWN

Bit in the joypad for the down direction..

JOYPAD_LEFT

Bit in the joypad for the left direction.

joypad

joypad .ds 5

This array holds the values for 5 2-buttons joypads.

joytrg

joytrg .ds 5

Delta joypad values for 5 2-buttons joypads.

joyold

joyold .ds 5

Previous 5 joypads values.

joypad_6

joypad_6 .ds 5

This array contains the values for buttons III, IV, V and VI of 5 6-buttons joypads.

joytrg

joytrg_6 .ds 5

Delta joypad values of 5 6-buttons joypads.

joyold

joyold_6 .ds 5

Previous 5 6-buttons joypad values.

joypad_delay

9 cycles delay before reading data after SEL line update.

This delay is performed after changing the SEL line before reading data.  This ensures the multiplexer is ready and returns the right data.

joypad_reset_multitap

Reset multitap to the first joypad.

joypad_poll

Read joypad state.

joyport = $1000
I/O port.
IO_CD_MASK = %10000000
CD-ROM base unit sense bit.
IO_COUNTRY_MASK = %01000000
Country detection.
IO_JOYPAD_MASK = %00001111
Joypad port pin.
IO_JOYPAD_I = %00000001
Bit in the joyport for button I (SEL=0).
IO_JOYPAD_II = %00000010
Bit in the joyport for button II (SEL=0).
IO_JOYPAD_SEL = %00000100
Bit in the joyport for the Select button (SEL=0).
IO_JOYPAD_RUN = %00001000
Bit in the joyport for the RUN button (SEL=0).
IO_JOYPAD_UP = %00000001
Bit in the joyport for the up direction on the D-PAD (SEL=1).
IO_JOYPAD_RIGHT = %00000010
Bit in the joyport for the right direction on the D-PAD (SEL=1).
IO_JOYPAD_DOWN = %00000100
Bit in the joyport for the down direction on the D-PAD (SEL=1).
IO_JOYPAD_LEFT = %00001000
Bit in the joyport for the left direction on the D-PAD (SEL=1).
IO_JOYPAD_III = %00000001
Bit in the joyport for button III on a 6-button joypad.
IO_JOYPAD_IV = %00000010
Bit in the joyport for button IV on a 6-button joypad.
IO_JOYPAD_V = %00000100
Bit in the joyport for button V on a 6-button joypad.
IO_JOYPAD_VI = %00001000
Bit in the joyport for button VI on a 6-button joypad.
JOYPAD_I = IO_JOYPAD_I
Bit in the joypad for button I.
JOYPAD_II = IO_JOYPAD_II
Bit in the joypad for button II.
JOYPAD_III = IO_JOYPAD_III
Bit in the joypad for button III.
JOYPAD_IV = IO_JOYPAD_IV
Bit in the joypad for button IV.
JOYPAD_VI = IO_JOYPAD_VI
Bit in the joypad for button VI.
JOYPAD_SEL = IO_JOYPAD_SEL
Bit in the joypad for the Select button.
JOYPAD_RUN = IO_JOYPAD_RUN
Bit in the joypad for the RUN button.
joypad .ds 5
This array holds the values for 5 2-buttons joypads.
joytrg .ds 5
Delta joypad values for 5 2-buttons joypads.
joyold .ds 5
Previous 5 joypads values.
joypad_6 .ds 5
This array contains the values for buttons III, IV, V and VI of 5 6-buttons joypads.
Close