Adaptateur de manette pour ; - Master system - Megadrive - Saturn - Dreamcast - Nes - Snes - N64 - PS1 - PS2

Dependencies:   mbed mbed-MapleMini USBDevice_STM32F103 USBJoystick

Committer:
fabdu117
Date:
Sun May 26 20:50:21 2019 +0000
Revision:
0:0ce3bda826e8
Test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabdu117 0:0ce3bda826e8 1 #include "MapleMini.h"
fabdu117 0:0ce3bda826e8 2 #include "mbed.h"
fabdu117 0:0ce3bda826e8 3 #include "nintendo.h"
fabdu117 0:0ce3bda826e8 4
fabdu117 0:0ce3bda826e8 5 int *SegaMasterGenesisSaturn()
fabdu117 0:0ce3bda826e8 6 { // AUTRE SATURN SATURN 3D
fabdu117 0:0ce3bda826e8 7 USB2.input(); // UP DATA 1 0v DATA 1 0v
fabdu117 0:0ce3bda826e8 8 USB3.input(); // DOWN DATA 0 0v DATA 0 5v
fabdu117 0:0ce3bda826e8 9 USB4.input(); // LEFT SELECT0 SELECT
fabdu117 0:0ce3bda826e8 10 USB5.input(); // RIGHT DATA 3 5v DATA 3 0v
fabdu117 0:0ce3bda826e8 11 USB6.input(); // B DATA 2 5v DATA 2 0v
fabdu117 0:0ce3bda826e8 12 USB7.output(); // SELECT SELECT1 REQ
fabdu117 0:0ce3bda826e8 13 USB8.input(); // C -- ACK
fabdu117 0:0ce3bda826e8 14
fabdu117 0:0ce3bda826e8 15 USB2.mode(PullUp);
fabdu117 0:0ce3bda826e8 16 USB3.mode(PullUp);
fabdu117 0:0ce3bda826e8 17 USB4.mode(PullUp);
fabdu117 0:0ce3bda826e8 18 USB5.mode(PullUp);
fabdu117 0:0ce3bda826e8 19 USB6.mode(PullUp);
fabdu117 0:0ce3bda826e8 20 USB8.mode(PullUp);
fabdu117 0:0ce3bda826e8 21
fabdu117 0:0ce3bda826e8 22 // Flag des boutton
fabdu117 0:0ce3bda826e8 23 const int UP = 1;
fabdu117 0:0ce3bda826e8 24 const int DOWN = 2;
fabdu117 0:0ce3bda826e8 25 const int LEFT = 4;
fabdu117 0:0ce3bda826e8 26 const int RIGHT = 8;
fabdu117 0:0ce3bda826e8 27 const int X = 16;
fabdu117 0:0ce3bda826e8 28 const int Z = 32;
fabdu117 0:0ce3bda826e8 29 const int C = 64;
fabdu117 0:0ce3bda826e8 30 const int B = 128;
fabdu117 0:0ce3bda826e8 31 const int Y = 256;
fabdu117 0:0ce3bda826e8 32 const int A = 512;
fabdu117 0:0ce3bda826e8 33 const int START = 2048;
fabdu117 0:0ce3bda826e8 34 const int GND = 0;
fabdu117 0:0ce3bda826e8 35 const int MODE = 8192;
fabdu117 0:0ce3bda826e8 36
fabdu117 0:0ce3bda826e8 37 // Tableau avec les pin et leur valeur
fabdu117 0:0ce3bda826e8 38 // pin, Master System, 3 btn select 0V, 3 btn select 5V, 6 btn........
fabdu117 0:0ce3bda826e8 39 /* int buttonMap[6][11] = {
fabdu117 0:0ce3bda826e8 40 //SMS SMD - SMD6 - - - - - - -
fabdu117 0:0ce3bda826e8 41 //0V 0V 5V 0 1 2 3 4 5 6 7
fabdu117 0:0ce3bda826e8 42 {UP, UP, UP, UP, UP, UP, UP, GND, Z, 0, 0}, //USB2
fabdu117 0:0ce3bda826e8 43 {DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, GND, Y, 0, 0}, //USB3
fabdu117 0:0ce3bda826e8 44 {LEFT, GND, LEFT, GND, LEFT, GND, LEFT, 0, X, 0, 0}, //USB4
fabdu117 0:0ce3bda826e8 45 {RIGHT, GND, RIGHT, GND, RIGHT, GND, RIGHT, 0, MODE, 0, 0}, //USB5
fabdu117 0:0ce3bda826e8 46 {B, A, B, A, B, A, B, 0, 0, 0, 0}, //USB6
fabdu117 0:0ce3bda826e8 47 {C, START, C, START, C, START, C, 0, 0, 0, 0} //USB8
fabdu117 0:0ce3bda826e8 48 };
fabdu117 0:0ce3bda826e8 49
fabdu117 0:0ce3bda826e8 50 USB2 DATA 1
fabdu117 0:0ce3bda826e8 51 USB3 DATA 0
fabdu117 0:0ce3bda826e8 52 USB4 SELECT0 SELECT
fabdu117 0:0ce3bda826e8 53 USB5 DATA 3
fabdu117 0:0ce3bda826e8 54 USB6 DATA 2
fabdu117 0:0ce3bda826e8 55 USB7 SELECT1 REQ
fabdu117 0:0ce3bda826e8 56 USB8 ACK
fabdu117 0:0ce3bda826e8 57
fabdu117 0:0ce3bda826e8 58 */
fabdu117 0:0ce3bda826e8 59
fabdu117 0:0ce3bda826e8 60 int buttons = 0;
fabdu117 0:0ce3bda826e8 61 int analog_x = 0;
fabdu117 0:0ce3bda826e8 62 int analog_y = 0;
fabdu117 0:0ce3bda826e8 63 int analog_l = -128;
fabdu117 0:0ce3bda826e8 64 int analog_r = -128;
fabdu117 0:0ce3bda826e8 65
fabdu117 0:0ce3bda826e8 66 int controller = 0; // 0 master system, 3 btn megadrive, 6 btn megadrive
fabdu117 0:0ce3bda826e8 67 // 4 saturn, 5 saturn 3d
fabdu117 0:0ce3bda826e8 68 int controllerOld = 0;
fabdu117 0:0ce3bda826e8 69
fabdu117 0:0ce3bda826e8 70
fabdu117 0:0ce3bda826e8 71 USB7 = 0;
fabdu117 0:0ce3bda826e8 72 wait_us(1700);
fabdu117 0:0ce3bda826e8 73 for (int i = 0; i < 8; i++)
fabdu117 0:0ce3bda826e8 74 {
fabdu117 0:0ce3bda826e8 75 if (i % 2 == 0) //nombre pair
fabdu117 0:0ce3bda826e8 76 {
fabdu117 0:0ce3bda826e8 77 USB7 = 0;
fabdu117 0:0ce3bda826e8 78 wait_us(20);
fabdu117 0:0ce3bda826e8 79 if (i == 2 && !USB4 && !USB5)
fabdu117 0:0ce3bda826e8 80 {
fabdu117 0:0ce3bda826e8 81 controller = 3; // Magadrive
fabdu117 0:0ce3bda826e8 82 }
fabdu117 0:0ce3bda826e8 83 if (i == 4 && !USB2 && !USB3)
fabdu117 0:0ce3bda826e8 84 {
fabdu117 0:0ce3bda826e8 85 controller = 6; // Megadrive 6 btn
fabdu117 0:0ce3bda826e8 86 }
fabdu117 0:0ce3bda826e8 87 }
fabdu117 0:0ce3bda826e8 88 else //nombre impair
fabdu117 0:0ce3bda826e8 89 {
fabdu117 0:0ce3bda826e8 90 USB7 = 1;
fabdu117 0:0ce3bda826e8 91 wait_us(20);
fabdu117 0:0ce3bda826e8 92 if (i == 7 && !USB2 && !USB3 && USB6) // && USB5 && USB6)
fabdu117 0:0ce3bda826e8 93 {
fabdu117 0:0ce3bda826e8 94 controller = 4; // Saturn
fabdu117 0:0ce3bda826e8 95 break;
fabdu117 0:0ce3bda826e8 96 }
fabdu117 0:0ce3bda826e8 97 if (i == 7 && !USB2 && USB3 && !USB6) // && !USB5 && !USB6)
fabdu117 0:0ce3bda826e8 98 {
fabdu117 0:0ce3bda826e8 99 controller = 5; // Saturn 3D
fabdu117 0:0ce3bda826e8 100 break;
fabdu117 0:0ce3bda826e8 101 }
fabdu117 0:0ce3bda826e8 102 if (i == 5 && controller == 6 && controllerOld == 0 && !USB5) // Utile ou pas utile ????
fabdu117 0:0ce3bda826e8 103 {
fabdu117 0:0ce3bda826e8 104 controller = 3; // Magadrive
fabdu117 0:0ce3bda826e8 105 }
fabdu117 0:0ce3bda826e8 106 }
fabdu117 0:0ce3bda826e8 107 }
fabdu117 0:0ce3bda826e8 108
fabdu117 0:0ce3bda826e8 109 switch (controller) {
fabdu117 0:0ce3bda826e8 110 case 0: // Master system
fabdu117 0:0ce3bda826e8 111 // Lecture des boutons
fabdu117 0:0ce3bda826e8 112 if(!USB2) buttons |= UP;
fabdu117 0:0ce3bda826e8 113 if(!USB3) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 114 if(!USB4) buttons |= LEFT;
fabdu117 0:0ce3bda826e8 115 if(!USB5) buttons |= RIGHT;
fabdu117 0:0ce3bda826e8 116 if(!USB6) buttons |= B;
fabdu117 0:0ce3bda826e8 117 if(!USB8) buttons |= C;
fabdu117 0:0ce3bda826e8 118
fabdu117 0:0ce3bda826e8 119 //buttons |= 16384;
fabdu117 0:0ce3bda826e8 120 break;
fabdu117 0:0ce3bda826e8 121 case 3: // Megadrive 3 btns
fabdu117 0:0ce3bda826e8 122 USB7 = 0;
fabdu117 0:0ce3bda826e8 123 wait_us(1700);
fabdu117 0:0ce3bda826e8 124 if(!USB2) buttons |= UP;
fabdu117 0:0ce3bda826e8 125 if(!USB3) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 126 // if(!USB4) buttons |= GND;
fabdu117 0:0ce3bda826e8 127 // if(!USB5) buttons |= GND;
fabdu117 0:0ce3bda826e8 128 if(!USB6) buttons |= A;
fabdu117 0:0ce3bda826e8 129 if(!USB8) buttons |= START;
fabdu117 0:0ce3bda826e8 130 USB7 = 1;
fabdu117 0:0ce3bda826e8 131 wait_us(20);
fabdu117 0:0ce3bda826e8 132 if(!USB2) buttons |= UP;
fabdu117 0:0ce3bda826e8 133 if(!USB3) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 134 if(!USB4) buttons |= LEFT;
fabdu117 0:0ce3bda826e8 135 if(!USB5) buttons |= RIGHT;
fabdu117 0:0ce3bda826e8 136 if(!USB6) buttons |= B;
fabdu117 0:0ce3bda826e8 137 if(!USB8) buttons |= C;
fabdu117 0:0ce3bda826e8 138
fabdu117 0:0ce3bda826e8 139 //buttons |= 32768;
fabdu117 0:0ce3bda826e8 140 //getMegadrive3Buttons();
fabdu117 0:0ce3bda826e8 141 //return controller;
fabdu117 0:0ce3bda826e8 142 break;
fabdu117 0:0ce3bda826e8 143 case 4: // Saturn
fabdu117 0:0ce3bda826e8 144 //buttons = 2;
fabdu117 0:0ce3bda826e8 145 // Lecture des boutons
fabdu117 0:0ce3bda826e8 146 USB4.output();
fabdu117 0:0ce3bda826e8 147
fabdu117 0:0ce3bda826e8 148 USB4 = 1;
fabdu117 0:0ce3bda826e8 149 USB7 = 1;
fabdu117 0:0ce3bda826e8 150 wait_us(100);
fabdu117 0:0ce3bda826e8 151
fabdu117 0:0ce3bda826e8 152 USB4 = 0;
fabdu117 0:0ce3bda826e8 153 USB7 = 1;
fabdu117 0:0ce3bda826e8 154 wait_us(30);
fabdu117 0:0ce3bda826e8 155
fabdu117 0:0ce3bda826e8 156 if(!USB5) buttons |= RIGHT;
fabdu117 0:0ce3bda826e8 157 if(!USB6) buttons |= LEFT;
fabdu117 0:0ce3bda826e8 158 if(!USB2) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 159 if(!USB3) buttons |= UP;
fabdu117 0:0ce3bda826e8 160
fabdu117 0:0ce3bda826e8 161 USB4 = 1;
fabdu117 0:0ce3bda826e8 162 USB7 = 0;
fabdu117 0:0ce3bda826e8 163 wait_us(30);
fabdu117 0:0ce3bda826e8 164
fabdu117 0:0ce3bda826e8 165 if(!USB5) buttons |= START;
fabdu117 0:0ce3bda826e8 166 if(!USB6) buttons |= A;
fabdu117 0:0ce3bda826e8 167 if(!USB2) buttons |= C;
fabdu117 0:0ce3bda826e8 168 if(!USB3) buttons |= B;
fabdu117 0:0ce3bda826e8 169
fabdu117 0:0ce3bda826e8 170 USB4 = 0;
fabdu117 0:0ce3bda826e8 171 USB7 = 0;
fabdu117 0:0ce3bda826e8 172 wait_us(30);
fabdu117 0:0ce3bda826e8 173
fabdu117 0:0ce3bda826e8 174 if(!USB5) analog_r = 127; // 8192
fabdu117 0:0ce3bda826e8 175 if(!USB6) buttons |= X;
fabdu117 0:0ce3bda826e8 176 if(!USB2) buttons |= Y;
fabdu117 0:0ce3bda826e8 177 if(!USB3) buttons |= Z;
fabdu117 0:0ce3bda826e8 178
fabdu117 0:0ce3bda826e8 179 USB4 = 1;
fabdu117 0:0ce3bda826e8 180 USB7 = 1;
fabdu117 0:0ce3bda826e8 181 wait_us(30);
fabdu117 0:0ce3bda826e8 182
fabdu117 0:0ce3bda826e8 183 if(!USB5) analog_l = 127; // 4096
fabdu117 0:0ce3bda826e8 184
fabdu117 0:0ce3bda826e8 185 //buttons |= 131072;
fabdu117 0:0ce3bda826e8 186
fabdu117 0:0ce3bda826e8 187 break;
fabdu117 0:0ce3bda826e8 188 case 5: // Saturn 3D
fabdu117 0:0ce3bda826e8 189 //buttons = 4;
fabdu117 0:0ce3bda826e8 190 int bite = 0;
fabdu117 0:0ce3bda826e8 191 bool analog = false;
fabdu117 0:0ce3bda826e8 192
fabdu117 0:0ce3bda826e8 193 USB4.output();
fabdu117 0:0ce3bda826e8 194
fabdu117 0:0ce3bda826e8 195 USB4 = 0;
fabdu117 0:0ce3bda826e8 196 wait_us(50);
fabdu117 0:0ce3bda826e8 197 USB7 = 0;
fabdu117 0:0ce3bda826e8 198
fabdu117 0:0ce3bda826e8 199 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 200 if(!USB8) break;
fabdu117 0:0ce3bda826e8 201 wait_us(5);
fabdu117 0:0ce3bda826e8 202 }
fabdu117 0:0ce3bda826e8 203
fabdu117 0:0ce3bda826e8 204 if(USB3) analog = true;
fabdu117 0:0ce3bda826e8 205
fabdu117 0:0ce3bda826e8 206 USB7 = 1;
fabdu117 0:0ce3bda826e8 207
fabdu117 0:0ce3bda826e8 208 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 209 if(USB8) break;
fabdu117 0:0ce3bda826e8 210 wait_us(5);
fabdu117 0:0ce3bda826e8 211 }
fabdu117 0:0ce3bda826e8 212
fabdu117 0:0ce3bda826e8 213 if(USB3) bite |= 1;
fabdu117 0:0ce3bda826e8 214 if(USB2) bite |= 2;
fabdu117 0:0ce3bda826e8 215 if(USB6) bite |= 4;
fabdu117 0:0ce3bda826e8 216 if(USB5) bite |= 8;
fabdu117 0:0ce3bda826e8 217
fabdu117 0:0ce3bda826e8 218 USB7 = 0;
fabdu117 0:0ce3bda826e8 219
fabdu117 0:0ce3bda826e8 220 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 221 if(!USB8) break;
fabdu117 0:0ce3bda826e8 222 wait_us(5);
fabdu117 0:0ce3bda826e8 223 }
fabdu117 0:0ce3bda826e8 224
fabdu117 0:0ce3bda826e8 225 if(!USB3) buttons |= UP;
fabdu117 0:0ce3bda826e8 226 if(!USB2) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 227 if(!USB6) buttons |= LEFT;
fabdu117 0:0ce3bda826e8 228 if(!USB5) buttons |= RIGHT;
fabdu117 0:0ce3bda826e8 229
fabdu117 0:0ce3bda826e8 230 USB7 = 1;
fabdu117 0:0ce3bda826e8 231
fabdu117 0:0ce3bda826e8 232 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 233 if(USB8) break;
fabdu117 0:0ce3bda826e8 234 wait_us(5);
fabdu117 0:0ce3bda826e8 235 }
fabdu117 0:0ce3bda826e8 236
fabdu117 0:0ce3bda826e8 237 if(!USB3) buttons |= B;
fabdu117 0:0ce3bda826e8 238 if(!USB2) buttons |= C;
fabdu117 0:0ce3bda826e8 239 if(!USB6) buttons |= A;
fabdu117 0:0ce3bda826e8 240 if(!USB5) buttons |= START;
fabdu117 0:0ce3bda826e8 241
fabdu117 0:0ce3bda826e8 242 USB7 = 0;
fabdu117 0:0ce3bda826e8 243
fabdu117 0:0ce3bda826e8 244 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 245 if(!USB8) break;
fabdu117 0:0ce3bda826e8 246 wait_us(5);
fabdu117 0:0ce3bda826e8 247 }
fabdu117 0:0ce3bda826e8 248
fabdu117 0:0ce3bda826e8 249 if(!USB3) buttons |= Z;
fabdu117 0:0ce3bda826e8 250 if(!USB2) buttons |= Y;
fabdu117 0:0ce3bda826e8 251 if(!USB6) buttons |= X;
fabdu117 0:0ce3bda826e8 252 if(!USB5) analog_r = 127;
fabdu117 0:0ce3bda826e8 253
fabdu117 0:0ce3bda826e8 254 USB7 = 1;
fabdu117 0:0ce3bda826e8 255
fabdu117 0:0ce3bda826e8 256 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 257 if(USB8) break;
fabdu117 0:0ce3bda826e8 258 wait_us(5);
fabdu117 0:0ce3bda826e8 259 }
fabdu117 0:0ce3bda826e8 260
fabdu117 0:0ce3bda826e8 261 /*if(!USB3) buttons |= 4096;
fabdu117 0:0ce3bda826e8 262 if(!USB2) buttons |= 8192;
fabdu117 0:0ce3bda826e8 263 if(!USB6) buttons |= 16384;*/
fabdu117 0:0ce3bda826e8 264 if(!USB5) analog_l = 127;
fabdu117 0:0ce3bda826e8 265
fabdu117 0:0ce3bda826e8 266 if(bite == 6 && analog){
fabdu117 0:0ce3bda826e8 267
fabdu117 0:0ce3bda826e8 268 analog_l = 0;
fabdu117 0:0ce3bda826e8 269 analog_r = 0;
fabdu117 0:0ce3bda826e8 270
fabdu117 0:0ce3bda826e8 271 USB7 = 0;
fabdu117 0:0ce3bda826e8 272
fabdu117 0:0ce3bda826e8 273 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 274 if(!USB8) break;
fabdu117 0:0ce3bda826e8 275 wait_us(5);
fabdu117 0:0ce3bda826e8 276 }
fabdu117 0:0ce3bda826e8 277
fabdu117 0:0ce3bda826e8 278 if(USB3) analog_x |= 16;
fabdu117 0:0ce3bda826e8 279 if(USB2) analog_x |= 32;
fabdu117 0:0ce3bda826e8 280 if(USB6) analog_x |= 64;
fabdu117 0:0ce3bda826e8 281 if(USB5) analog_x |= 128;
fabdu117 0:0ce3bda826e8 282
fabdu117 0:0ce3bda826e8 283 USB7 = 1;
fabdu117 0:0ce3bda826e8 284
fabdu117 0:0ce3bda826e8 285 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 286 if(USB8) break;
fabdu117 0:0ce3bda826e8 287 wait_us(5);
fabdu117 0:0ce3bda826e8 288 }
fabdu117 0:0ce3bda826e8 289
fabdu117 0:0ce3bda826e8 290 if(USB3) analog_x |= 1;
fabdu117 0:0ce3bda826e8 291 if(USB2) analog_x |= 2;
fabdu117 0:0ce3bda826e8 292 if(USB6) analog_x |= 4;
fabdu117 0:0ce3bda826e8 293 if(USB5) analog_x |= 8;
fabdu117 0:0ce3bda826e8 294
fabdu117 0:0ce3bda826e8 295 USB7 = 0;
fabdu117 0:0ce3bda826e8 296
fabdu117 0:0ce3bda826e8 297 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 298 if(!USB8) break;
fabdu117 0:0ce3bda826e8 299 wait_us(5);
fabdu117 0:0ce3bda826e8 300 }
fabdu117 0:0ce3bda826e8 301
fabdu117 0:0ce3bda826e8 302 if(USB3) analog_y |= 16;
fabdu117 0:0ce3bda826e8 303 if(USB2) analog_y |= 32;
fabdu117 0:0ce3bda826e8 304 if(USB6) analog_y |= 64;
fabdu117 0:0ce3bda826e8 305 if(USB5) analog_y |= 128;
fabdu117 0:0ce3bda826e8 306
fabdu117 0:0ce3bda826e8 307 USB7 = 1;
fabdu117 0:0ce3bda826e8 308
fabdu117 0:0ce3bda826e8 309 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 310 if(USB8) break;
fabdu117 0:0ce3bda826e8 311 wait_us(5);
fabdu117 0:0ce3bda826e8 312 }
fabdu117 0:0ce3bda826e8 313
fabdu117 0:0ce3bda826e8 314 if(USB3) analog_y |= 1;
fabdu117 0:0ce3bda826e8 315 if(USB2) analog_y |= 2;
fabdu117 0:0ce3bda826e8 316 if(USB6) analog_y |= 4;
fabdu117 0:0ce3bda826e8 317 if(USB5) analog_y |= 8;
fabdu117 0:0ce3bda826e8 318
fabdu117 0:0ce3bda826e8 319 USB7 = 0;
fabdu117 0:0ce3bda826e8 320
fabdu117 0:0ce3bda826e8 321 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 322 if(!USB8) break;
fabdu117 0:0ce3bda826e8 323 wait_us(5);
fabdu117 0:0ce3bda826e8 324 }
fabdu117 0:0ce3bda826e8 325
fabdu117 0:0ce3bda826e8 326 if(USB3) analog_r |= 16;
fabdu117 0:0ce3bda826e8 327 if(USB2) analog_r |= 32;
fabdu117 0:0ce3bda826e8 328 if(USB6) analog_r |= 64;
fabdu117 0:0ce3bda826e8 329 if(USB5) analog_r |= 128;
fabdu117 0:0ce3bda826e8 330
fabdu117 0:0ce3bda826e8 331 USB7 = 1;
fabdu117 0:0ce3bda826e8 332
fabdu117 0:0ce3bda826e8 333 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 334 if(USB8) break;
fabdu117 0:0ce3bda826e8 335 wait_us(5);
fabdu117 0:0ce3bda826e8 336 }
fabdu117 0:0ce3bda826e8 337
fabdu117 0:0ce3bda826e8 338 if(USB3) analog_r |= 1;
fabdu117 0:0ce3bda826e8 339 if(USB2) analog_r |= 2;
fabdu117 0:0ce3bda826e8 340 if(USB6) analog_r |= 4;
fabdu117 0:0ce3bda826e8 341 if(USB5) analog_r |= 8;
fabdu117 0:0ce3bda826e8 342
fabdu117 0:0ce3bda826e8 343 USB7 = 0;
fabdu117 0:0ce3bda826e8 344
fabdu117 0:0ce3bda826e8 345 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 346 if(!USB8) break;
fabdu117 0:0ce3bda826e8 347 wait_us(5);
fabdu117 0:0ce3bda826e8 348 }
fabdu117 0:0ce3bda826e8 349
fabdu117 0:0ce3bda826e8 350 if(USB3) analog_l |= 16;
fabdu117 0:0ce3bda826e8 351 if(USB2) analog_l |= 32;
fabdu117 0:0ce3bda826e8 352 if(USB6) analog_l |= 64;
fabdu117 0:0ce3bda826e8 353 if(USB5) analog_l |= 128;
fabdu117 0:0ce3bda826e8 354
fabdu117 0:0ce3bda826e8 355 USB7 = 1;
fabdu117 0:0ce3bda826e8 356
fabdu117 0:0ce3bda826e8 357 for (int i = 0; i <= 100; i++) {
fabdu117 0:0ce3bda826e8 358 if(USB8) break;
fabdu117 0:0ce3bda826e8 359 wait_us(5);
fabdu117 0:0ce3bda826e8 360 }
fabdu117 0:0ce3bda826e8 361
fabdu117 0:0ce3bda826e8 362 if(USB3) analog_l |= 1;
fabdu117 0:0ce3bda826e8 363 if(USB2) analog_l |= 2;
fabdu117 0:0ce3bda826e8 364 if(USB6) analog_l |= 4;
fabdu117 0:0ce3bda826e8 365 if(USB5) analog_l |= 8;
fabdu117 0:0ce3bda826e8 366
fabdu117 0:0ce3bda826e8 367 analog_x = analog_x - 128;
fabdu117 0:0ce3bda826e8 368 analog_y = analog_y - 128;
fabdu117 0:0ce3bda826e8 369 analog_l = analog_l - 128;
fabdu117 0:0ce3bda826e8 370 analog_r = analog_r - 128;
fabdu117 0:0ce3bda826e8 371
fabdu117 0:0ce3bda826e8 372 }
fabdu117 0:0ce3bda826e8 373
fabdu117 0:0ce3bda826e8 374 //buttons |= 262144;
fabdu117 0:0ce3bda826e8 375
fabdu117 0:0ce3bda826e8 376 break;
fabdu117 0:0ce3bda826e8 377 case 6: // Megadrive 6 btns
fabdu117 0:0ce3bda826e8 378 USB7 = 0;
fabdu117 0:0ce3bda826e8 379 wait_us(1700);
fabdu117 0:0ce3bda826e8 380
fabdu117 0:0ce3bda826e8 381 USB7 = 1;
fabdu117 0:0ce3bda826e8 382 wait_us(20);
fabdu117 0:0ce3bda826e8 383
fabdu117 0:0ce3bda826e8 384 USB7 = 0;
fabdu117 0:0ce3bda826e8 385 wait_us(20);
fabdu117 0:0ce3bda826e8 386 if(!USB2) buttons |= UP;
fabdu117 0:0ce3bda826e8 387 if(!USB3) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 388 // if(!USB4) buttons |= GND;
fabdu117 0:0ce3bda826e8 389 // if(!USB5) buttons |= GND;
fabdu117 0:0ce3bda826e8 390 if(!USB6) buttons |= A;
fabdu117 0:0ce3bda826e8 391 if(!USB8) buttons |= START;
fabdu117 0:0ce3bda826e8 392 USB7 = 1;
fabdu117 0:0ce3bda826e8 393 wait_us(20);
fabdu117 0:0ce3bda826e8 394 if(!USB2) buttons |= UP;
fabdu117 0:0ce3bda826e8 395 if(!USB3) buttons |= DOWN;
fabdu117 0:0ce3bda826e8 396 if(!USB4) buttons |= LEFT;
fabdu117 0:0ce3bda826e8 397 if(!USB5) buttons |= RIGHT;
fabdu117 0:0ce3bda826e8 398 if(!USB6) buttons |= B;
fabdu117 0:0ce3bda826e8 399 if(!USB8) buttons |= C;
fabdu117 0:0ce3bda826e8 400 USB7 = 0;
fabdu117 0:0ce3bda826e8 401 wait_us(20);
fabdu117 0:0ce3bda826e8 402 // if(!USB2) buttons |= GND;
fabdu117 0:0ce3bda826e8 403 // if(!USB3) buttons |= GND;
fabdu117 0:0ce3bda826e8 404 USB7 = 1;
fabdu117 0:0ce3bda826e8 405 wait_us(20);
fabdu117 0:0ce3bda826e8 406 if(!USB2) buttons |= Z;
fabdu117 0:0ce3bda826e8 407 if(!USB3) buttons |= Y;
fabdu117 0:0ce3bda826e8 408 if(!USB4) buttons |= X;
fabdu117 0:0ce3bda826e8 409 if(!USB5) buttons |= MODE;
fabdu117 0:0ce3bda826e8 410
fabdu117 0:0ce3bda826e8 411 //buttons |= 65536; // 15
fabdu117 0:0ce3bda826e8 412 //getMegadrive6Buttons();
fabdu117 0:0ce3bda826e8 413 //return controller;
fabdu117 0:0ce3bda826e8 414 break;
fabdu117 0:0ce3bda826e8 415 }
fabdu117 0:0ce3bda826e8 416
fabdu117 0:0ce3bda826e8 417 controllerOld = controller;
fabdu117 0:0ce3bda826e8 418 int array[] = {analog_r, analog_l, analog_x, analog_y, buttons, 0};
fabdu117 0:0ce3bda826e8 419 return array;
fabdu117 0:0ce3bda826e8 420 }
fabdu117 0:0ce3bda826e8 421
fabdu117 0:0ce3bda826e8 422 int *SegaDreamcast()
fabdu117 0:0ce3bda826e8 423 {
fabdu117 0:0ce3bda826e8 424 int array[] = {0, 0, 0, 0, 0, 0};
fabdu117 0:0ce3bda826e8 425 return array;
fabdu117 0:0ce3bda826e8 426 }