Advertisement
Gemini

ctrller.h

Jun 8th, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.39 KB | None | 0 0
  1. /*+--------+----------+----------+----------+----------+----------+---------+*/
  2. /*                                                                           */
  3. /* (C) Sony Computer Entertainment. All Rights Reserved.                     */
  4. /*                                                                           */
  5. /* Name:   ctrller.h                                                         */                      
  6. /* Author: Allan J. Murphy                                                   */                    
  7. /* Created:   9th February 1995.                                                */                      
  8. /*                                                                           */
  9. /* Description:                                                              */            
  10. /*                                                                           */
  11. /* An attempt to build a tidy header for accessing the pads, after SCE       */
  12. /* Japan reversed the bytes in the packet buffer; and the bit organisation   */
  13. /* to 1 = not pressed, 0 = pressed (for pads at least).                      */
  14. /* This header includes macros to make it easier to deal with the raw        */
  15. /* packet data, which you have to if you are using anything other than a     */
  16. /* plain pad.                                                                */
  17. /*                                                                           */
  18. /* Updated 20/4/95 to include multi-tap data - not complete or tested.       */
  19. /* Updated 30/5/95 to include mouse data.                                    */
  20. /* Updated 31/5/95 to include negcon data.                                   */
  21. /* Updated 12/6/95 to include tested multi-tap data.                         */
  22. /*
  23. ** 20-nov-1995 (pholman)
  24. **      Added Analog Joystick
  25. **                                                                           **
  26. **+--------+----------+----------+----------+----------+----------+---------+*/
  27.  
  28. #ifndef __CTRLLER_H_
  29. #define __CTRLLER_H_
  30.  
  31. /*+--------+----------+----------+----------+----------+----------+---------+*/
  32.  
  33. /* #defines for recognising the contents of the controller packet.           */
  34.  
  35. #define BAD_TRANSMISSION         0xff       /* No pad or bad transmission. */
  36. #define NOKEY                    0xffff     /* No digital key pressed      */
  37.  
  38.  
  39. #define MAX_CONTROLLER_BYTES    34          /* Size of the biggest packet  */
  40.                                             /* you can possibly have.      */
  41.  
  42. #define STD_PAD_DATA            1           /* Defines for the amount of   */
  43. #define MOUSE_DATA              2           /* data controllers return.    */  
  44. #define NEGCON_DATA             3
  45. #define ANALOG_JOY_DATA         8
  46. #define MULTI_TAP_DATA          16
  47.  
  48. #define MOUSE                   1           // SCPH-1030
  49. #define NEGCON                  2           // SLPH-00001 (Namco Ltd)
  50. #define GUN_PAD                 3           // SLPH-00014 (Konami Ltd)
  51. #define STD_PAD                 4           // SCPH-1080, 1150, 1200 (Standard Pad)
  52. #define ANALOG_JOY              5           // SCPH-1110 (Analog Joystick)
  53. #define GUNCON                  6           // SLPH-00034 (Namco Ltd)
  54. #define ANALOG_PAD              7           // SCPH-1150, 1200 (Dual Shock)
  55. #define MULTI_TAP               8           // SCPH-1070
  56.  
  57. /*+--------+----------+----------+----------+----------+----------+---------+*/
  58. /* Pad controller data structure. */
  59.  
  60. /* The data returned by a pad is just a short bit mask for each key.         */
  61.  
  62. typedef unsigned short PadData;
  63.  
  64. /* Pad Controller Macros and masks. */
  65.  
  66. /* #defines for the keys on the pad. The best way to use these is to do      */
  67. /* for example,  if (!(buffer1.data.pad & PAD_SEL)) { <handle select key> }  */
  68. /* Or use the PadKeyIsPressed(&buffer,PAD_SEL).                              */
  69.  
  70. /* Front or shoulder buttons - F for front, L/R for left/right, T/B for      */
  71. /* top or bottom, U/D for up/down.                                           */
  72.  
  73. #define PAD_FRB                  0x0200
  74. #define PAD_FLB                  0x0100
  75. #define PAD_FRT                  0x0800
  76. #define PAD_FLT                  0x0400
  77.  
  78. /* Right directional;  RU = right up, RD = right down, and so on.            */
  79.      
  80. #define PAD_RU                   0x1000
  81. #define PAD_RD                   0x4000
  82. #define PAD_RL                   0x8000
  83. #define PAD_RR                   0x2000
  84.  
  85. /* Left directional;  LU = left up, LD = left down, and so on.               */
  86.  
  87. #define PAD_LU                   0x0010
  88. #define PAD_LD                   0x0040
  89. #define PAD_LL                   0x0080
  90. #define PAD_LR                   0x0020
  91.  
  92. /* The other two keys.                                                       */
  93.  
  94. #define PAD_SEL                  0x0001
  95. #define PAD_START                0x0008
  96.  
  97. /* Controller packet processing (pass in address of packet) for pads.        */
  98.  
  99. #define PadKeyIsPressed(x,y)      (!((x)->data.pad & (y)))
  100.  
  101. #define PadKeyPressed(x)          ((x)->data.pad != NOKEY)
  102. #define NoPadKeyPressed(x)        ((x)->data.pad == NOKEY)
  103.  
  104. #define PAD_LOCK    10
  105.  
  106. /*+--------+----------+----------+----------+----------+----------+---------+*/
  107. /* Mouse data packet returns. You can use the routines from mouse.obj to     */
  108. /* work with the mouse packets if you like, but its not that tough to deal   */
  109. /* with the raw data yourself by working with the x and y offsets.           */
  110.  
  111. typedef struct MouseData
  112.   {
  113.      unsigned short buttons;
  114.      signed char xOffset;
  115.      signed char yOffset;
  116.   }
  117. MouseData;
  118.  
  119. /* Mouse Controller macros and masks. */
  120.  
  121. #define MOUSE_LEFT               0x0800               /* Left Mouse button.  */
  122. #define MOUSE_RIGHT              0x0400               /* Right Mouse button. */
  123.  
  124. #define MOUSE_NOKEY              0xfcff               /* No buttons pressed. */
  125.  
  126. /* Mouse packet handling macros (pass address of packet).                    */
  127.  
  128. #define MouseXOffset(x)          ((x)->data.mouse.xOffset)
  129. #define MouseYOffset(x)          ((x)->data.mouse.yOffset)
  130.  
  131. #define MouseMoving(x)           ((x)->data.mouse.xOffset || \
  132.                                   (x)->data.mouse.yOffset)
  133.  
  134. #define MouseKeyIsPressed(x,y)   (!((x)->data.mouse.buttons & (y)))
  135.  
  136. #define MouseKeyPressed(x)       ((x)->data.mouse.buttons != MOUSE_NOKEY)
  137. #define NoMouseKeyPressed(x)     ((x)->data.mouse.buttons == MOUSE_NOKEY)
  138.  
  139. /*+--------+----------+----------+----------+----------+----------+---------+*/
  140. /* Negcon controller packet structure. The Negcon has several different      */
  141. /* buttons / analogue inputs; there is the 4 way directional pad on the left */
  142. /* of the controller, the start button on the left, the B and A buttons on   */
  143. /* the right, two analogue buttons (I and II), the central twisting analogue */
  144. /* input, and two top buttons - the top left is analogue, the top right is   */
  145. /* digital (strangely enough). Bit masks and locations are given for these.  */
  146.  
  147. typedef struct NegconData
  148. {
  149.     unsigned short digitalButtons;               /* Bit mask of plain keys. */
  150.     char centralTwist;                           /* Analogue twisting thing.*/
  151.     char buttonI;                                /* The I analogue button.  */
  152.     char buttonII;                               /* The II analogue button. */
  153.     char topLeft;                                /* The analogue tl button. */
  154. }
  155. NegconData;
  156.  
  157. /* Negcon handling macros and masks. */
  158.                                    
  159. #define NEGCON_UP                0x0010
  160. #define NEGCON_RIGHT             0x0020
  161. #define NEGCON_DOWN              0x0040
  162. #define NEGCON_LEFT              0x0080
  163.  
  164. #define NEGCON_START             0x0008
  165. #define NEGCON_A                 0x2000                                    
  166. #define NEGCON_B                 0x1000                                    
  167. #define NEGCON_TR                0x0800
  168.  
  169. #define TZP_UPPER                128
  170. #define TZP_LOWER                125
  171.                                    
  172. #define NegconKeyIsPressed(x,y)   (!((x)->data.negcon.digitalButtons & (y)))
  173.  
  174. #define NegconKeyPressed(x)       ((x)->data.negcon.digitalButtons != NOKEY)
  175. #define NoNegconKeyPressed(x)     ((x)->data.negcon.digitalButtons == NOKEY)
  176.  
  177. #define NegconTopLeft(x)          ((x)->data.negcon.topLeft)
  178. #define NegconI(x)                ((x)->data.negcon.buttonI)
  179. #define NegconII(x)               ((x)->data.negcon.buttonII)
  180.  
  181. #define NegconTwisting(x)         ((x)->data.negcon.centralTwist < TZP_LOWER || \
  182.                                    (x)->data.negcon.centralTwist > TZP_UPPER)
  183.  
  184. #define NegconTwist(x)            ((x)->data.negcon.centralTwist)
  185.  
  186.  
  187. /*
  188. ** Analog Joystick
  189. */
  190. typedef struct AnalogjoyData
  191. {
  192.      unsigned short digitalButtons;               /* Bit mask of plain keys. */
  193.      unsigned char  right_x;
  194.      unsigned char  right_y;
  195.      unsigned char  left_x;
  196.      unsigned char  left_y;
  197. } AnalogjoyData;
  198.  
  199.  
  200. #define LEFT_MAIN_FIRE      0x0100
  201. #define RIGHT_MAIN_FIRE     0x8000
  202.  
  203.  
  204.  
  205. #define JoystickRightX(x)           ( (x)->data.joystick.right_x)
  206. #define JoystickRightY(x)           ( (x)->data.joystick.right_y)
  207.  
  208. #define JoystickLeftX(x)            ( (x)->data.joystick.left_x)
  209. #define JoystickLeftY(x)            ( (x)->data.joystick.left_y)
  210.  
  211.  
  212. #define JoystickKeyIsPressed(x,y)   (!((x)->data.joystick.digitalButtons & (y)))
  213. #define JoystickKeyPressed(x)       ((x)->data.joystick.digitalButtons != NOKEY)
  214. #define NojoystickKeyPressed(x)     ((x)->data.joystick.digitalButtons == NOKEY)
  215.  
  216.  
  217.  /*+--------+----------+----------+----------+----------+----------+---------+*/
  218. /* The data returned by the multi-tap is a set of controller returns.        */
  219. /* Each of the controllers connected to the multi-tap can return up to 6     */
  220. /* bytes of information; each of the controllers returns its own packet.     */
  221. /* This means you can have 4 pads or NegCons connected, but not 4 mice, and  */
  222. /* not 4 multi-taps (surprisingly). The packet for each of the multi-tap     */
  223. /* controllers is just the same as the packet for a plain controller apart   */
  224. /* from this, so you can handle the controller packet from the multi-tap     */
  225. /* with the same macros as for the normal controller packets.                */
  226.  
  227. typedef struct TapCtrllerData
  228.   {
  229.      unsigned char transStatus;  /* 0xff = no pad, bad pad, bad transmission */
  230.      unsigned char dataFormat;            /* Top 4 bits = type of controller */
  231.  
  232.      union                                         /* Controller data union. */                   /* Controller data union. */
  233.       {
  234.          PadData    pad;                                 /* Plain pad.       */
  235.          NegconData negcon;                              /* Namco controller.*/
  236.       }
  237.      data;
  238.   }
  239. TapCtrllerData;
  240.  
  241. /* Now the multi-tap return structure, which is an array of the above.       */
  242.  
  243. typedef struct MultiTapData
  244.   {
  245.      TapCtrllerData ctrllers[4];               /* Just 4 controller packets. */
  246.   }
  247. MultiTapData;
  248.  
  249.  
  250. #define GetTapData(x,y)           (&((x)->data.tap.ctrllers[(y)]))
  251.  
  252. /*+--------+----------+----------+----------+----------+----------+---------+*/
  253. /* Controller packet structure. */
  254.  
  255. typedef struct ControllerPacket
  256. {
  257.     unsigned char transStatus;  /* 0xff = no pad, bad pad, bad transmission */
  258.     unsigned char dataFormat;            /* Top 4 bits = type of controller */
  259.                                        /* Bottom 4 == shorts of data written */
  260.     union                                         /* Controller data union. */
  261.     {
  262.          PadData       pad;                     /* Plain pad.       */
  263.          MouseData     mouse;                   /* Mouse.           */
  264.          NegconData    negcon;                  /* Namco controller.*/
  265.          AnalogjoyData joystick;                /* Anlog Joystick   */
  266.          MultiTapData  tap;                     /* 4-way multi-tap. */
  267.     }
  268.     data;
  269. } ControllerPacket;
  270.  
  271. /* Packet macros. */
  272.  
  273. /* Macros for handling the controller packets; pass in the packet address.   */
  274.  
  275.  
  276. #define GoodData(x) ((x)->transStatus != 0xff)
  277.  
  278. #define GetType(x) (((x)->dataFormat & 0xf0) >> 4)
  279.  
  280. #define DataShortsReturned(x) ((x)->dataFormat & 0xf)
  281.  
  282. #define DataBytesReturned(x)  (((x)->dataFormat & 0xf) << 1 )
  283.  
  284. #define ControllerDataAddress(x) (&((x)->dataFormat)+1)
  285.  
  286. /*+--------+----------+----------+----------+----------+----------+---------+*/
  287.  
  288. #endif  
  289.  
  290. /*+--------+----------+----------+----------+----------+----------+---------+*/
  291. /* End ctrller.h                                                             */
  292. /*+--------+----------+----------+----------+----------+----------+---------+*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement