// File : fwPad.c // Author : John Wojcik ( QuietBloke ) // Created : September 2000 // Desc : 2D game framework pad manager. In addition to the standard function // to return what buttons are down these routines can return which // keys have just been pressed or released. // History : // Date Author Description // -------- --------------- ---------------------------------------- #include #include #include "fwPad.h" volatile u_char *bb0, *bb1; unsigned int padDown[2]; // Indicates a button is down unsigned int padPressed[2]; // Indicates a button has just been pressed unsigned int padReleased[2]; // Indicates a button has just been released void fwPadInit () { GetPadBuf (&bb0, &bb1 ); } void fwPadRead ( void ) { unsigned int currentstate; unsigned int tempChanged; unsigned int tempPressed; unsigned int tempReleased; int currentPad; for ( currentPad = 0; currentPad < 2; currentPad++ ) { if ( currentPad == 0 ) currentstate = ~(*(bb0+3) | *(bb0+2) << 8); else currentstate = ~(*(bb1+3) | *(bb1+2) << 8); // Mark each bit which has changed state // Exclusive OR the old and new bits tempChanged = ( currentstate ^ padDown[currentPad] ); // All bits which have changed and are currently pressed must have just been pressed tempPressed = ( tempChanged & currentstate ); // All bits which have changed but which have not been just pressed must have been just released tempReleased = ( tempPressed ^ tempChanged); // Store all our details away padDown[currentPad] = currentstate; padPressed[currentPad] = tempPressed; padReleased[currentPad] = tempReleased; } } unsigned int fwPadGetDown ( int pad ) { return padDown[pad]; } unsigned int fwPadGetPressed ( int pad ) { return padPressed[pad]; } unsigned int fwPadGetReleased ( int pad ) { return padReleased[pad]; }