@@ -68,6 +68,9 @@ std::string gbromfolder;
68
68
69
69
std::string arm7DonorPath;
70
70
71
+ int mpuregion = 0 ;
72
+ int mpusize = 0 ;
73
+
71
74
int romtype = 0 ;
72
75
73
76
bool applaunch = false ;
@@ -236,6 +239,77 @@ typedef struct {
236
239
char gameCode[4 ]; // !< 4 characters for the game code.
237
240
} sNDSHeadertitlecodeonly ;
238
241
242
+ /* *
243
+ * Set MPU settings for a specific game.
244
+ */
245
+ void SetMPUSettings (const char * filename) {
246
+ FILE *f_nds_file = fopen (filename, " rb" );
247
+
248
+ char game_TID[5 ];
249
+ fseek (f_nds_file, offsetof (sNDSHeadertitlecodeonly , gameCode), SEEK_SET);
250
+ fread (game_TID, 1 , 4 , f_nds_file);
251
+ game_TID[4 ] = 0 ;
252
+ game_TID[3 ] = 0 ;
253
+ fclose (f_nds_file);
254
+
255
+ scanKeys ();
256
+ int pressed = keysDownRepeat ();
257
+
258
+ if (pressed & KEY_B){
259
+ mpuregion = 1 ;
260
+ } else if (pressed & KEY_X){
261
+ mpuregion = 2 ;
262
+ } else if (pressed & KEY_Y){
263
+ mpuregion = 3 ;
264
+ } else {
265
+ mpuregion = 0 ;
266
+ }
267
+ if (pressed & KEY_RIGHT){
268
+ mpusize = 3145728 ;
269
+ } else if (pressed & KEY_LEFT){
270
+ mpusize = 1 ;
271
+ } else {
272
+ mpusize = 0 ;
273
+ }
274
+
275
+ // Check for games that need an MPU size of 3 MB.
276
+ static const char mpu_3MB_list[][4 ] = {
277
+ " A7A" , // DS Download Station - Vol 1
278
+ " A7B" , // DS Download Station - Vol 2
279
+ " A7C" , // DS Download Station - Vol 3
280
+ " A7D" , // DS Download Station - Vol 4
281
+ " A7E" , // DS Download Station - Vol 5
282
+ " A7F" , // DS Download Station - Vol 6 (EUR)
283
+ " A7G" , // DS Download Station - Vol 6 (USA)
284
+ " A7H" , // DS Download Station - Vol 7
285
+ " A7I" , // DS Download Station - Vol 8
286
+ " A7J" , // DS Download Station - Vol 9
287
+ " A7K" , // DS Download Station - Vol 10
288
+ " A7L" , // DS Download Station - Vol 11
289
+ " A7M" , // DS Download Station - Vol 12
290
+ " A7N" , // DS Download Station - Vol 13
291
+ " A7O" , // DS Download Station - Vol 14
292
+ " A7P" , // DS Download Station - Vol 15
293
+ " A7Q" , // DS Download Station - Vol 16
294
+ " A7R" , // DS Download Station - Vol 17
295
+ " A7S" , // DS Download Station - Vol 18
296
+ " A7T" , // DS Download Station - Vol 19
297
+ " ARZ" , // Rockman ZX/MegaMan ZX
298
+ " YZX" , // Rockman ZX Advent/MegaMan ZX Advent
299
+ " B6Z" , // Rockman Zero Collection/MegaMan Zero Collection
300
+ };
301
+
302
+ // TODO: If the list gets large enough, switch to bsearch().
303
+ for (unsigned int i = 0 ; i < sizeof (mpu_3MB_list)/sizeof (mpu_3MB_list[0 ]); i++) {
304
+ if (!memcmp (game_TID, mpu_3MB_list[i], 3 )) {
305
+ // Found a match.
306
+ mpuregion = 1 ;
307
+ mpusize = 3145728 ;
308
+ break ;
309
+ }
310
+ }
311
+ }
312
+
239
313
// ---------------------------------------------------------------------------------
240
314
void stop (void ) {
241
315
// ---------------------------------------------------------------------------------
@@ -490,11 +564,15 @@ int main(int argc, char **argv) {
490
564
491
565
}
492
566
567
+ SetMPUSettings (argarray[0 ]);
568
+
493
569
std::string path = argarray[0 ];
494
570
std::string savepath = savename;
495
571
CIniFile bootstrapini ( " sd:/_nds/nds-bootstrap.ini" );
496
572
bootstrapini.SetString (" NDS-BOOTSTRAP" , " NDS_PATH" , path);
497
573
bootstrapini.SetString (" NDS-BOOTSTRAP" , " SAV_PATH" , savepath);
574
+ bootstrapini.SetInt ( " NDS-BOOTSTRAP" , " PATCH_MPU_REGION" , mpuregion);
575
+ bootstrapini.SetInt ( " NDS-BOOTSTRAP" , " PATCH_MPU_SIZE" , mpusize);
498
576
bootstrapini.SaveIniFile ( " sd:/_nds/nds-bootstrap.ini" );
499
577
bootstrapfilename = bootstrapini.GetString (" NDS-BOOTSTRAP" , " BOOTSTRAP_PATH" ," " );
500
578
int err = runNdsFile (bootstrapfilename.c_str (), 0 , 0 );
0 commit comments