1 /* Copyright 2005 Guillaume Duhamel 2 Copyright 2005-2006, 2013 Theo Berkau 3 4 This file is part of Yabause. 5 6 Yabause is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 Yabause is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Yabause; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #ifndef PERIPHERAL_H 22 #define PERIPHERAL_H 23 24 #include "core.h" 25 #include "smpc.h" 26 #include "yabause.h" 27 28 /** @defgroup peripheral Peripheral 29 * 30 * @brief This module provides two kind of functions 31 * - peripheral core management functions 32 * - controller ports management functions 33 * 34 * @{ 35 */ 36 37 #define PERPAD 0x02 38 //virtual on twin sticks is a standard controller from 39 //the saturn's point of view 40 //we just insert a standard pad and map it differently 41 //this id is just for keeping track of it in the GUI 42 #define PERVIRTUALON 0x102 43 #define PERWHEEL 0x13 44 #define PERMISSIONSTICK 0x15 45 #define PER3DPAD 0x16 46 #define PERTWINSTICKS 0x19//double mission sticks 47 #define PERGUN 0x25 48 #define PERKEYBOARD 0x34 49 #define PERMOUSE 0xE3 50 51 #define PERCORE_DEFAULT -1 52 #define PERCORE_DUMMY 0 53 54 extern PortData_struct PORTDATA1; 55 extern PortData_struct PORTDATA2; 56 57 #define PERSF_ALL (0xFFFFFFFF) 58 #define PERSF_KEY (1 << 0) 59 #define PERSF_BUTTON (1 << 1) 60 #define PERSF_HAT (1 << 2) 61 #define PERSF_AXIS (1 << 3) 62 #define PERSF_MOUSEMOVE (1 << 4) 63 64 typedef struct 65 { 66 int id; 67 const char * Name; 68 int (*Init)(void); 69 void (*DeInit)(void); 70 int (*HandleEvents)(void); 71 u32 (*Scan)(u32 flags); 72 int canScan; 73 void (*Flush)(void); 74 void (*KeyName)(u32 key, char * name, int size); 75 } PerInterface_struct; 76 77 /** @brief Pointer to the current peripheral core. 78 * 79 * You should not set this manually but use 80 * PerInit() and PerDeInit() instead. */ 81 extern PerInterface_struct * PERCore; 82 83 extern PerInterface_struct PERDummy; 84 85 /** 86 * @brief Init a peripheral core 87 * 88 * Searches through the PERCoreList array for the given coreid. 89 * If found, PERCore is set to the address of that core and 90 * the core's Init function is called. 91 * 92 * @param coreid the peripheral core to be used 93 * @return 0 if core has been inited, -1 otherwise 94 */ 95 int PerInit(int coreid); 96 /** 97 * @brief De-init a peripheral core 98 * 99 * Calls the core's DeInit callback and set PERCore to NULL. 100 */ 101 void PerDeInit(void); 102 103 /** @brief Adds a peripheral 104 * 105 * You shouldn't directly use this function but 106 * PerPadAdd() or PerMouseAdd() instead. 107 */ 108 void * PerAddPeripheral(PortData_struct *port, int perid); 109 int PerGetId(void * peripheral); 110 void PerPortReset(void); 111 /** 112 * Iterate the list of peripherals connected to a port 113 * and flush them if necesseray. This is needed for mouses. 114 */ 115 void PerFlush(PortData_struct * port); 116 117 void PerKeyDown(u32 key); 118 void PerKeyUp(u32 key); 119 void PerSetKey(u32 key, u8 name, void * controller); 120 void PerAxisValue(u32 key, u8 val); 121 void PerAxisMove(u32 key, s32 dispx, s32 dispy); 122 123 /** @defgroup pad Pad 124 * 125 * @{ 126 */ 127 #define PERPAD_UP 0 128 #define PERPAD_RIGHT 1 129 #define PERPAD_DOWN 2 130 #define PERPAD_LEFT 3 131 #define PERPAD_RIGHT_TRIGGER 4 132 #define PERPAD_LEFT_TRIGGER 5 133 #define PERPAD_START 6 134 #define PERPAD_A 7 135 #define PERPAD_B 8 136 #define PERPAD_C 9 137 #define PERPAD_X 10 138 #define PERPAD_Y 11 139 #define PERPAD_Z 12 140 141 extern const char * PerPadNames[14]; 142 143 typedef struct 144 { 145 u8 perid; 146 u8 padbits[2]; 147 } PerPad_struct; 148 149 /** @brief Adds a pad to one of the controller ports. 150 * 151 * @param port can be either &PORTDATA1 or &PORTDATA2 152 * @return pointer to a PerPad_struct or NULL if it fails 153 * */ 154 PerPad_struct * PerPadAdd(PortData_struct * port); 155 156 void PerPadUpPressed(PerPad_struct * pad); 157 void PerPadUpReleased(PerPad_struct * pad); 158 159 void PerPadDownPressed(PerPad_struct * pad); 160 void PerPadDownReleased(PerPad_struct * pad); 161 162 void PerPadRightPressed(PerPad_struct * pad); 163 void PerPadRightReleased(PerPad_struct * pad); 164 165 void PerPadLeftPressed(PerPad_struct * pad); 166 void PerPadLeftReleased(PerPad_struct * pad); 167 168 void PerPadStartPressed(PerPad_struct * pad); 169 void PerPadStartReleased(PerPad_struct * pad); 170 171 void PerPadAPressed(PerPad_struct * pad); 172 void PerPadAReleased(PerPad_struct * pad); 173 174 void PerPadBPressed(PerPad_struct * pad); 175 void PerPadBReleased(PerPad_struct * pad); 176 177 void PerPadCPressed(PerPad_struct * pad); 178 void PerPadCReleased(PerPad_struct * pad); 179 180 void PerPadXPressed(PerPad_struct * pad); 181 void PerPadXReleased(PerPad_struct * pad); 182 183 void PerPadYPressed(PerPad_struct * pad); 184 void PerPadYReleased(PerPad_struct * pad); 185 186 void PerPadZPressed(PerPad_struct * pad); 187 void PerPadZReleased(PerPad_struct * pad); 188 189 void PerPadRTriggerPressed(PerPad_struct * pad); 190 void PerPadRTriggerReleased(PerPad_struct * pad); 191 192 void PerPadLTriggerPressed(PerPad_struct * pad); 193 void PerPadLTriggerReleased(PerPad_struct * pad); 194 /** @} */ 195 196 /** @defgroup mouse Mouse 197 * 198 * @{ 199 * */ 200 #define PERMOUSE_LEFT 13 201 #define PERMOUSE_MIDDLE 14 202 #define PERMOUSE_RIGHT 15 203 #define PERMOUSE_START 16 204 #define PERMOUSE_AXIS 17 205 206 extern const char * PerMouseNames[5]; 207 208 typedef struct 209 { 210 u8 perid; 211 u8 mousebits[3]; 212 } PerMouse_struct; 213 214 /** @brief Adds a mouse to one of the controller ports. 215 * 216 * @param port can be either &PORTDATA1 or &PORTDATA2 217 * @return pointer to a PerMouse_struct or NULL if it fails 218 * */ 219 PerMouse_struct * PerMouseAdd(PortData_struct * port); 220 221 void PerMouseLeftPressed(PerMouse_struct * mouse); 222 void PerMouseLeftReleased(PerMouse_struct * mouse); 223 224 void PerMouseMiddlePressed(PerMouse_struct * mouse); 225 void PerMouseMiddleReleased(PerMouse_struct * mouse); 226 227 void PerMouseRightPressed(PerMouse_struct * mouse); 228 void PerMouseRightReleased(PerMouse_struct * mouse); 229 230 void PerMouseStartPressed(PerMouse_struct * mouse); 231 void PerMouseStartReleased(PerMouse_struct * mouse); 232 233 void PerMouseMove(PerMouse_struct * mouse, s32 dispx, s32 dispy); 234 /** @} */ 235 236 /** @defgroup 3danalog 3DAnalog 237 * 238 * @{ 239 * */ 240 241 #define PERANALOG_AXIS1 18 242 #define PERANALOG_AXIS2 19 243 #define PERANALOG_AXIS3 20 244 #define PERANALOG_AXIS4 21 245 #define PERANALOG_AXIS5 22 246 #define PERANALOG_AXIS6 23 247 #define PERANALOG_AXIS7 24 248 249 typedef struct 250 { 251 u8 perid; 252 u8 analogbits[9]; 253 } PerAnalog_struct; 254 255 /** @brief Adds a Analog control pad to one of the controller ports. 256 * 257 * @param port can be either &PORTDATA1 or &PORTDATA2 258 * @return pointer to a Per3DAnalog_struct or NULL if it fails 259 * */ 260 261 PerAnalog_struct * PerWheelAdd(PortData_struct * port); 262 PerAnalog_struct * PerMissionStickAdd(PortData_struct * port); 263 PerAnalog_struct * Per3DPadAdd(PortData_struct * port); 264 PerAnalog_struct * PerTwinSticksAdd(PortData_struct * port); 265 266 void PerAxis1Value(PerAnalog_struct * analog, u32 val); 267 void PerAxis2Value(PerAnalog_struct * analog, u32 val); 268 void PerAxis3Value(PerAnalog_struct * analog, u32 val); 269 void PerAxis4Value(PerAnalog_struct * analog, u32 val); 270 void PerAxis5Value(PerAnalog_struct * analog, u32 val); 271 void PerAxis6Value(PerAnalog_struct * analog, u32 val); 272 void PerAxis7Value(PerAnalog_struct * analog, u32 val); 273 274 /** @} */ 275 276 /** @defgroup gun Gun 277 * 278 * @{ 279 * */ 280 281 #define PERGUN_TRIGGER 25 282 #define PERGUN_START 27 283 #define PERGUN_AXIS 28 284 285 typedef struct 286 { 287 u8 perid; 288 u8 gunbits[5]; 289 } PerGun_struct; 290 291 /** @brief Adds a Gun to one of the controller ports up to a maximum of one per port. 292 * 293 * @param port can be either &PORTDATA1 or &PORTDATA2 294 * @return pointer to a PerGun_struct or NULL if it fails 295 * */ 296 297 PerGun_struct * PerGunAdd(PortData_struct * port); 298 299 void PerGunTriggerPressed(PerGun_struct * gun); 300 void PerGunTriggerReleased(PerGun_struct * gun); 301 302 void PerGunStartPressed(PerGun_struct * gun); 303 void PerGunStartReleased(PerGun_struct * gun); 304 305 void PerGunMove(PerGun_struct * gun, s32 dispx, s32 dispy); 306 307 /** @} */ 308 309 /** @} */ 310 311 #endif 312