Advertisement
Gemini

control.c

Jun 8th, 2011
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.83 KB | None | 0 0
  1. /* ---------------------------------------------------------------------------
  2.  * - (C) Sony Computer Entertainment. All Rights Reserved.
  3.  * -
  4.  * - Project:   Movie Player V2.0  
  5.  * -
  6.  * - Name:      control.c
  7.  * -
  8.  * - Author:    Vince Diesi
  9.  * -
  10.  * - Date:      13th Feb 1996
  11.  * -
  12.  * - Description:
  13.  * - ------------
  14.  * - Controller functions. Only supports the standard controller.
  15.  * ---------------------------------------------------------------------------
  16.  */
  17. #include <sys/types.h>
  18. #include <kernel.h>
  19. #include <libpad.h>
  20.  
  21. #include "ctrller.h"
  22. #include "control.h"
  23.  
  24. /* ---------------------------------------------------------------------------
  25.  * - CONSTANTS
  26.  * ---------------------------------------------------------------------------
  27.  */
  28.  
  29. // Define for timing and testing functions.
  30. // #define TESTING
  31.  
  32.  
  33. // Controllers connected.
  34. #define NO_PADS         0
  35. #define PAD_ONE         1
  36. #define PAD_TWO         2
  37. #define BOTH_PADS       3
  38.  
  39. #define DS_PAD_1        0       //port id for pad 1
  40. #define DS_PAD_2        1       //port id for pad 2
  41.  
  42. /* ---------------------------------------------------------------------------
  43.  * - GLOBAL DEFINITIONS
  44.  * ---------------------------------------------------------------------------
  45.  */
  46.  
  47. static volatile short connected = 0;            // No. controllers connected.
  48. static volatile short currController = 0;       // Current active controller.
  49.  
  50. static volatile ControllerPacket buffers[2];
  51.  
  52. #define vibBuffLength   8
  53. u_char transmissionBuffer[2][vibBuffLength];    //vibration buffers for pads
  54.  
  55. /* ---------------------------------------------------------------------------
  56.  * - FUNCTION DEFINITIONS
  57.  * ---------------------------------------------------------------------------
  58.  */
  59. void InitControllers(void)
  60. {
  61. /* - Type:  PUBLIC
  62.  * -
  63.  * - Usage: Init controllers.
  64.  */
  65.     InitPAD((char *) &buffers[0], MAX_CONTROLLER_BYTES, (char *) &buffers[1], MAX_CONTROLLER_BYTES);
  66.     StartPAD();
  67.     ChangeClearPAD(0);
  68.  
  69.     VSync(0);
  70.     CheckControllers();
  71. }
  72.  
  73. /* ------------------------------------------------------------------------ */
  74. void StopControllers(void)
  75. {
  76. /* - Type:  PUBLIC
  77.  * -
  78.  * - Usage: Stop controllers.
  79.  */
  80.     StopPAD();
  81.     connected = 0;
  82.     currController = 0;
  83. }
  84.  
  85. /* ------------------------------------------------------------------------ */
  86. void CheckControllers(void)
  87. {
  88. /* - Type:  PUBLIC
  89.  * -
  90.  * - Usage: Check number of controllers connected (stored in connected).
  91.  * -        Also selects the active controller (stored in currController).
  92.  * -        Should be called in the VSyncCallback() to constantly check the
  93.  * -        controller status.
  94.  */
  95.     connected=0;
  96.  
  97.     if(GoodData(&buffers[0]) && (GetType(&buffers[0])==STD_PAD || GetType(&buffers[0])==ANALOG_PAD)) connected|=PAD_ONE;
  98.     if(GoodData(&buffers[1]) && (GetType(&buffers[1])==STD_PAD || GetType(&buffers[1])==ANALOG_PAD)) connected|=PAD_TWO;
  99.     if(connected==BOTH_PADS || connected==PAD_ONE) currController=0;
  100.     else if (connected==PAD_TWO) currController=1;
  101. }
  102.  
  103. /* ------------------------------------------------------------------------ */
  104. __inline short Pressed(short button)
  105. {
  106. /* - Type:  PUBLIC
  107.  * -
  108.  * - Param: button = (In) Button to test.
  109.  * -
  110.  * - Ret:   1 if pressed, 0 otherwise.
  111.  * -
  112.  * - Usage: Test if button has been pressed.
  113.  */
  114.     return (connected && !(buffers[currController].data.pad & button));
  115. }
  116.  
  117. __inline unsigned short GetPadValue()
  118. {
  119. /* - Type:  PUBLIC
  120.  * -
  121.  * - Param: button = (In) Button to test.
  122.  * -
  123.  * - Ret:   1 if pressed, 0 otherwise.
  124.  * -
  125.  * - Usage: Test if button has been pressed.
  126.  */
  127.     if(connected) return ~buffers[currController].data.pad;
  128.     return 0;
  129. }
  130.  
  131. /* ------------------------------------------------------------------------ */
  132. void GetStablePad(int port)
  133. {
  134.     //this is just a simple loop that keeps going till both pads are in a stable state
  135.     while (PadGetState(port)!=PadStateStable);  //loop till both pads are in a stable state
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement