# PAD_Read

## C Specification

      #include <nitro/pad.h>

      u16 PAD_Read( void );

## Description

Gets the information for pressed keys/buttons

The key/button information is the logical sum of the following values:

`PAD_BUTTON_A` | Button A is being pressed
`PAD_BUTTON_B` | Button B is being pressed
`PAD_BUTTON_SELECT` | SELECT Button is being pressed
`PAD_BUTTON_START` | START Button is being pressed
`PAD_KEY_RIGHT` | + Control Pad Right key is being pressed
`PAD_KEY_LEFT` | + Control Pad Left key is being pressed
`PAD_KEY_UP` | + Control Pad Up key is being pressed
`PAD_KEY_DOWN` | + Control Pad Down key is being pressed
`PAD_BUTTON_R` | Button R is being pressed
`PAD_BUTTON_L` | Button L is being pressed
`PAD_BUTTON_X` | Button X is being pressed
`PAD_BUTTON_Y` | Button Y is being pressed
`PAD_BUTTON_DEBUG` | DEBUG Button is being pressed.

The X and Y buttons can read from ARM9 because ARM7 checks a generic port and writes in a shared region. Therefore, if the ARM7 read module is not operating, X and Y buttons cannot read.

`PAD_BUTTON_MASK` is defined as the logical sum of all buttons (`PAD_BUTTON_`...), and `PAD_PLUS_KEY_MASK` is defined as the logical sum of all keys (`PAD_KEY_`...).

Only the sum of X, Y, and `DEBUG` buttons read by ARM7 will be defined as `PAD_RCNTPORT_MASK`. Sums of other buttons are defined as `PAD_KEYPORT_MASK`.

D
e
b
u
g

N
/
A

Y

X

L

R

D
o
w
n

U
p

L
e
f
t

R
i
g
h
t

S
t
a
r
t

S
e
l
e
c
t

B

A

Value

`PAD_BUTTON_MASK` | `1` | `0` | `1` | `1` | `1` | `1` | `0` | `0` | `0` | `0` | `1` | `1` | `1` | `1` | `0x2F0F`
`PAD_PLUS_KEY_MASK` | `0` | `0` | `0` | `0` | `0` | `0` | `1` | `1` | `1` | `1` | `0` | `0` | `0` | `0` | `0x00F0`
`PAD_ALL_MASK` | `1` | `0` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `0x2FFF`
`PAD_RCNPORT_MASK` | `1` | `0` | `1` | `1` | `0` | `0` | `0` | `0` | `0` | `0` | `0` | `0` | `0` | `0` | `0x2C00`
`PAD_KEYPORT_MASK` | `0` | `0` | `0` | `0` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `1` | `0x03FF`

> Example:

>     u16 padData = PAD_Read();
>     if ( padData & PAD_BUTTON_A )
>       {
>       OS_Printf( "you're pushing the A-BUTTON\n" );
>       }
>     if ( padData & PAD_PLUS_KEY_MASK )
>       {
>       OS_Printf( "you're pressing one of the +Control Pad Keys\n" );
>       }

`PAD_Read()` reads the `KEYINPUT IO` register internally, aligns with the value from the `RCNT` register of the generic port that ARM7 acquired, and returns a value with the Key/Button mask `PAD_ALL_MASK` applied.

## Arguments

None

## Return Values

Current key information

## Revision History

08/06/2004 Deleted `PAD_SetIrq` and `PAD_ClearIrq` from See Also
04/13/2004 Added `DEBUG` button
02/19/2004 Added X, Y buttons
12/01/2003 Initial Version