/* special thanx fly to Metrowerks. */ #include #include "commondef.h" #include "joypad.h" volatile unsigned char *joystickData1, *joystickData2; void InitPads(void) { // Set-up so we can read the joysticks GetPadBuf(&joystickData1, &joystickData2); } void UpdatePads(void) { // Keep track of which buttons were not down during the last call // Current button state int currentJoy1, currentJoy2; // Take a snapshot of the joystick state currentJoy1 = 0xffff^((joystickData1[2] << 8) + joystickData1[3]); currentJoy2 = 0xffff^((joystickData2[2] << 8) + joystickData2[3]); // Mark which buttons were just depressed newlyDown1 = currentJoy1 & (~previousJoyDown1); newlyDown2 = currentJoy2 & (~previousJoyDown2); // Mark which buttons were just released newlyUp1 = (~currentJoy1) & previousJoyDown1; newlyUp2 = (~currentJoy2) & previousJoyDown2; // Keep current state for later previousJoyDown1 = currentJoy1; previousJoyDown2 = currentJoy2; } void GetButtonsState(int *joy1, int *joy2) { *joy1 = previousJoyDown1; *joy2 = previousJoyDown2; } void GetNewlyDownButtons(int *joy1, int *joy2) { *joy1 = newlyDown1; *joy2 = newlyDown2; } void GetNewlyUpButtons(int *joy1, int *joy2) { *joy1 = newlyUp1; *joy2 = newlyUp2; }