@@ -71,6 +71,7 @@ int perGameSettings_useBootstrap = -1;
7171int perGameSettings_fcGameLoader = -1 ;
7272int perGameSettings_fcGameLoaderCheat = -1 ;
7373int perGameSettings_saveRelocation = -1 ;
74+ int perGameSettings_remappedKeys[12 ] = {0 };
7475
7576static char SET_AS_DONOR_ROM[32 ];
7677
@@ -89,7 +90,7 @@ char gameTIDText[16];
8990
9091static int firstPerGameOpShown = 0 ;
9192static int perGameOps = -1 ;
92- static int perGameOp[18 ] = {-1 };
93+ static int perGameOp[19 ] = {-1 };
9394
9495bool blacklisted_colorLut = false ;
9596bool blacklisted_boostCpu = false ;
@@ -122,6 +123,19 @@ void loadPerGameSettings (std::string filename) {
122123 perGameSettings_fcGameLoader = pergameini.GetInt (" GAMESETTINGS" , " FC_GAME_LOADER" , -1 );
123124 perGameSettings_fcGameLoaderCheat = perGameSettings_fcGameLoader;
124125 perGameSettings_saveRelocation = pergameini.GetInt (" GAMESETTINGS" , " SAVE_RELOCATION" , -1 );
126+
127+ perGameSettings_remappedKeys[0 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_A" , 0 );
128+ perGameSettings_remappedKeys[1 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_B" , 1 );
129+ perGameSettings_remappedKeys[2 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_SELECT" , 2 );
130+ perGameSettings_remappedKeys[3 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_START" , 3 );
131+ perGameSettings_remappedKeys[4 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_RIGHT" , 4 );
132+ perGameSettings_remappedKeys[5 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_LEFT" , 5 );
133+ perGameSettings_remappedKeys[6 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_UP" , 6 );
134+ perGameSettings_remappedKeys[7 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_DOWN" , 7 );
135+ perGameSettings_remappedKeys[8 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_R" , 8 );
136+ perGameSettings_remappedKeys[9 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_L" , 9 );
137+ perGameSettings_remappedKeys[10 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_X" , 10 );
138+ perGameSettings_remappedKeys[11 ] = pergameini.GetInt (" GAMESETTINGS" , " REMAPPED_KEY_Y" , 11 );
125139}
126140
127141void savePerGameSettings (std::string filename) {
@@ -181,6 +195,19 @@ void savePerGameSettings (std::string filename) {
181195 pergameini.SetInt (" GAMESETTINGS" , " DSIWARE_BOOTER" , perGameSettings_dsiwareBooter);
182196 }
183197 pergameini.SetInt (" GAMESETTINGS" , " SAVE_RELOCATION" , perGameSettings_saveRelocation);
198+
199+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_A" , perGameSettings_remappedKeys[0 ]);
200+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_B" , perGameSettings_remappedKeys[1 ]);
201+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_SELECT" , perGameSettings_remappedKeys[2 ]);
202+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_START" , perGameSettings_remappedKeys[3 ]);
203+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_RIGHT" , perGameSettings_remappedKeys[4 ]);
204+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_LEFT" , perGameSettings_remappedKeys[5 ]);
205+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_UP" , perGameSettings_remappedKeys[6 ]);
206+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_DOWN" , perGameSettings_remappedKeys[7 ]);
207+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_R" , perGameSettings_remappedKeys[8 ]);
208+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_L" , perGameSettings_remappedKeys[9 ]);
209+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_X" , perGameSettings_remappedKeys[10 ]);
210+ pergameini.SetInt (" GAMESETTINGS" , " REMAPPED_KEY_Y" , perGameSettings_remappedKeys[11 ]);
184211 }
185212 pergameini.SaveIniFile ( pergamefilepath );
186213}
@@ -354,6 +381,75 @@ const char* getRegionString(char region) {
354381 return " N/A" ;
355382}
356383
384+ std::string keyText[12 ] = {" " , " " , " SELECT" , " START" , " Right" , " Left" , " Up" , " Down" , " " , " " , " " , " " };
385+
386+ void remapButtons (void ) {
387+ int pressed = 0 , held = 0 ;
388+ int firstShown = 0 ;
389+ int remapButtons_cursorPosition = 0 ;
390+ int perGameOpXpos = 24 ;
391+
392+ int oldDialogboxHeight = dialogboxHeight;
393+ dialogboxHeight = 5 ;
394+
395+ while (1 ) {
396+ int perGameOpYpos = 90 ;
397+
398+ clearText (false );
399+ printSmall (false , 0 , 74 , " Remap Buttons" , Alignment::center, FontPalette::formTitleText);
400+ printSmall (false , 0 , 166 , " Back" , Alignment::center, FontPalette::formText);
401+
402+ for (int i = firstShown; i < firstShown+6 ; i++) {
403+ const FontPalette highlighted = (i == remapButtons_cursorPosition) ? FontPalette::user : FontPalette::formText;
404+ printSmall (false , perGameOpXpos, perGameOpYpos, keyText[i], Alignment::left, highlighted);
405+ printSmall (false , 0 , perGameOpYpos, " ->" , Alignment::center, highlighted);
406+ printSmall (false , 256 -perGameOpXpos, perGameOpYpos, keyText[perGameSettings_remappedKeys[i]], Alignment::right, highlighted);
407+ perGameOpYpos += 12 ;
408+ }
409+
410+ updateText (false );
411+
412+ do {
413+ scanKeys ();
414+ pressed = keysDown ();
415+ held = keysDownRepeat ();
416+ bgOperations (true );
417+ } while (!held);
418+
419+ if (held & KEY_UP) {
420+ remapButtons_cursorPosition--;
421+ if (remapButtons_cursorPosition < 0 ) {
422+ remapButtons_cursorPosition = 11 ;
423+ firstShown = 11 -5 ;
424+ } else if (remapButtons_cursorPosition < firstShown) {
425+ firstShown--;
426+ }
427+ }
428+ if (held & KEY_DOWN) {
429+ remapButtons_cursorPosition++;
430+ if (remapButtons_cursorPosition > 11 ) {
431+ remapButtons_cursorPosition = 0 ;
432+ firstShown = 0 ;
433+ } else if (remapButtons_cursorPosition > firstShown+5 ) {
434+ firstShown++;
435+ }
436+ }
437+
438+ if (held & KEY_LEFT) {
439+ perGameSettings_remappedKeys[remapButtons_cursorPosition]--;
440+ if (perGameSettings_remappedKeys[remapButtons_cursorPosition] < 0 ) perGameSettings_remappedKeys[remapButtons_cursorPosition] = 11 ;
441+ } else if ((pressed & KEY_A) || (held & KEY_RIGHT)) {
442+ perGameSettings_remappedKeys[remapButtons_cursorPosition]++;
443+ if (perGameSettings_remappedKeys[remapButtons_cursorPosition] > 11 ) perGameSettings_remappedKeys[remapButtons_cursorPosition] = 0 ;
444+ }
445+ if (pressed & KEY_B) {
446+ break ;
447+ }
448+ }
449+
450+ dialogboxHeight = oldDialogboxHeight;
451+ }
452+
357453void perGameSettings (std::string filename) {
358454 if (ms ().macroMode ) {
359455 lcdMainOnBottom ();
@@ -526,7 +622,7 @@ void perGameSettings (std::string filename) {
526622
527623 firstPerGameOpShown = 0 ;
528624 perGameOps = -1 ;
529- for (int i = 0 ; i < 17 ; i++) {
625+ for (int i = 0 ; i < 19 ; i++) {
530626 perGameOp[i] = -1 ;
531627 }
532628 if (isHomebrew[cursorPosOnScreen]) { // Per-game settings for homebrew
@@ -598,6 +694,8 @@ void perGameSettings (std::string filename) {
598694 }
599695 perGameOps++;
600696 perGameOp[perGameOps] = 7 ; // Bootstrap
697+ perGameOps++;
698+ perGameOp[perGameOps] = 18 ; // Remap Buttons
601699 if (((dsiFeatures () && sdFound ()) || !ms ().secondaryDevice ) && ms ().consoleModel >= 2 && (!isDSiMode () || !sys ().arm7SCFGLocked ()) && widescreenFound) {
602700 perGameOps++;
603701 perGameOp[perGameOps] = 8 ; // Screen Aspect Ratio
@@ -661,6 +759,8 @@ void perGameSettings (std::string filename) {
661759 }
662760 perGameOps++;
663761 perGameOp[perGameOps] = 7 ; // Bootstrap
762+ perGameOps++;
763+ perGameOp[perGameOps] = 18 ; // Remap Buttons
664764 if (((dsiFeatures () && sdFound ()) || !ms ().secondaryDevice ) && widescreenFound) {
665765 perGameOps++;
666766 perGameOp[perGameOps] = 8 ; // Screen Aspect Ratio
@@ -958,6 +1058,9 @@ void perGameSettings (std::string filename) {
9581058 printSmall (false , 256 -perGameOpXpos, perGameOpYpos, " Game Card" , Alignment::right, highlighted);
9591059 }
9601060 break ;
1061+ case 18 :
1062+ printSmall (false , 0 , perGameOpYpos, " Remap Buttons" , Alignment::center, highlighted);
1063+ break ;
9611064 }
9621065 perGameOpYpos += 12 ;
9631066 }
@@ -1221,6 +1324,9 @@ void perGameSettings (std::string filename) {
12211324 perGameSettings_saveRelocation--;
12221325 if (perGameSettings_saveRelocation < -1 ) perGameSettings_saveRelocation = 1 ;
12231326 break ;
1327+ case 18 :
1328+ if (pressed & KEY_A) remapButtons ();
1329+ break ;
12241330 }
12251331 perGameSettingsChanged = true ;
12261332 }
0 commit comments