/* ============================================================================= PAD.C Copyright (c) 1998 by Radouan Khechane. PlayStation controller pad input functions ============================================================================= Usage: call PadInit(); as part of initialisation in main each frame (VSync loop), call PadRead(x); to return the status of controller pad x e.g. PADstatus = PadRead(x); then, test individual buttons by masking the pad status variable with the #defined constants in pad.h e.g. if (PADstatus & PADleft) // Pad x left button is pressed { // do PADleft actions here } */ /* ==================== I N C L U D E S ==================== */ #include #include "pad.h" // low-level pad buffers volatile u_char *bb0, *bb1; /* ==================== F U N C T I O N S ==================== */ /* =============== PadInit call once only in program initialisation =============== */ void PadInit (void) { GetPadBuf(&bb0, &bb1); } /* =============== PadRead returns controller pad status, call once per VSync(0) =============== */ u_long PadRead (int pad) { switch (pad) { case 1 : // contoller pad 1 return ~( *(bb0 + 3) | *(bb0 + 2) << 8 ); case 2 : // controller pad 2 return ~( *(bb1 + 3) | *(bb1 + 2) << 8 ); default : // default is controller pad 1 return ~( *(bb0 + 3) | *(bb0 + 2) << 8 ); } }