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

Dependencies:   mbed mbed-MapleMini USBDevice_STM32F103 USBJoystick

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nintendo.cpp Source File

nintendo.cpp

00001 #include "MapleMini.h"
00002 #include "mbed.h"
00003 #include "nintendo.h"
00004  
00005 int *NintendoNes()    
00006 {
00007     USB2.output(); // CLOCK
00008     USB3.output(); // LATCH
00009     USB4.input();  // DATA
00010     USB4.mode(PullUp);
00011 
00012     USB3 = 0;
00013     USB2 = 0;
00014 
00015     // Flag des boutton
00016     const int UP     = 1;
00017     const int DOWN   = 2;
00018     const int LEFT   = 4;
00019     const int RIGHT  = 8;
00020     const int A      = 64;
00021     const int B      = 128;
00022     const int SELECT = 1024;
00023     const int START  = 2048;
00024 
00025     int buttonMap[] = {
00026         A,
00027         B,
00028         SELECT,
00029         START,
00030         UP,
00031         DOWN,
00032         LEFT,
00033         RIGHT
00034     };
00035 
00036     int buttons = 0;
00037 
00038     // Envoi impulsion LATCH
00039     USB3 = 1;
00040     wait_us(12);
00041     USB3 = 0;
00042     wait_us(6);
00043 
00044     // Lecture des boutons
00045     for (int i = 0; i < 8; i++) {
00046         if(!USB4) { // Lecture du boutton
00047             buttons |= buttonMap[i];
00048         }
00049         // Envoi impulsion CLOCK
00050         USB2 = 1;
00051         wait_us(6);
00052         USB2 = 0;
00053         wait_us(6);
00054     }
00055     int array[] = {0, 0, 0, 0, buttons, 0};
00056     return array;
00057     //joystick.update(0, 0, 0, 0, buttons, 0); // Envoi des position des noutton au pc
00058 }
00059 
00060 int *NintendoSnes()    
00061 {
00062     USB2.output(); // CLOCK
00063     USB3.output(); // LATCH
00064     USB4.input();  // DATA
00065     USB4.mode(PullUp);
00066 
00067     USB3 = 0;
00068     USB2 = 0;
00069     
00070     
00071 
00072     // Flag des boutton
00073     const int UP     = 1;
00074     const int DOWN   = 2;
00075     const int LEFT   = 4;
00076     const int RIGHT  = 8;
00077     const int L      = 16;
00078     const int R      = 32;
00079     const int A      = 64;
00080     const int B      = 128;
00081     const int X      = 256;
00082     const int Y      = 512;
00083     const int SELECT = 1024;
00084     const int START  = 2048;
00085     
00086     int buttonMap[] = {
00087         B,
00088         Y,
00089         SELECT,
00090         START,
00091         UP,
00092         DOWN,
00093         LEFT,
00094         RIGHT,
00095         A,
00096         X,
00097         L,
00098         R
00099     };
00100 
00101     int buttons = 0;
00102     int analog_l = -128;
00103     int analog_r = -128;
00104 
00105     // Envoi impulsion LATCH
00106     USB3 = 1;
00107     wait_us(12);
00108     USB3 = 0;
00109     wait_us(6);
00110 
00111     // Lecture des boutons
00112     for (int i = 0; i < 12; i++) {
00113         if(!USB4) { // Lecture du boutton
00114             buttons |= buttonMap[i];
00115         }
00116         // Envoi impulsion CLOCK
00117         USB2 = 1;
00118         wait_us(6);
00119         USB2 = 0;
00120         wait_us(6);
00121     }
00122     int array[] = {analog_r, analog_l, 0, 0, buttons, 0};
00123     return array;
00124     //joystick.update(0, 0, 0, 0, buttons, 0); // Envoi des position des noutton au pc
00125 }