/************************************************************ * * * Pad.c * * * * * * Set of pad routines to present a similar interface * * to the controller pad as dtlh2500 * * * * Copyright (C) 1996 Sony Computer Entertainment Inc. * * All Rights Reserved * * * ***********************************************************/ /*************************************** Use: call PadInit(); as part of initialisation in main each frame (VSync loop), call PadRead(): puts pad status into an unsigned long variable e.g. padStatus = PadRead(); then, test individual buttons by masking the pad status variable with the #defined constants in pad.h e.g. if (padStatus & PADLleft) // Pad L left button is pressed { // do actions here } ***************************************/ #include #include "pad.h" // prototypes header static signed int accel[]= { 1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2, 4,4,4,4,4,4,4,4,4,4, 8,8,8,8,8,8,8,8,8,8, 16,16,16,16,16,16,16,16,16,16, 32,32,32,32,32, 32,32,32,32,32, 64,64,64,64,64, 64,64,64,64,64, 128,128,128,128,128,128,128,128,128,128, -1 } ; CPad::CPad( ) { static bool bDone = false ; if ( ! bDone ) { GetPadBuf(&m_bb0, &m_bb1); bDone = true ; } } /* call once per VSync(0) puts controller pad status into unsigned long integer please refer to the manuals if you want explanation of the internals of this function */ u_long CPad::getState( ) const { return( ~ ( *(m_bb0+3) | *(m_bb0+2) << 8 | *(m_bb1+3) << 16 | *(m_bb1+2) << 24) ); } CPad::operator u_long( ) const { return( ~ ( *(m_bb0+3) | *(m_bb0+2) << 8 | *(m_bb1+3) << 16 | *(m_bb1+2) << 24) ); } //virtual void CPadCompanion::servicePad( CPad& p ) { ; } CAccellPad::CAccellPad( ) { ; } //CAccellPad::~CAccellPad( ) //{ // ; //} int CAccellPad::getAccell( ) const { static u_long lastKey = 0 ; static u_long accelIndex = 0 ; u_long currentKey = ( u_long )*this ; bool bSame = currentKey == lastKey ; lastKey = currentKey ; if ( bSame ) { if ( accel[ accelIndex+1 ] != -1 ) ++accelIndex ; } else accelIndex = 0 ; return accel[ accelIndex ] ; }