Skip to content

Commit 0bb9adf

Browse files
committed
Add MPU settings for some games
1 parent d5899d6 commit 0bb9adf

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

7zfile/_nds/nds-bootstrap.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ ARM7_DONOR_PATH =
55
BOOTSTRAP_PATH = sd:/_nds/bootstrap.nds
66
NTR_MODE_SWITCH = 0
77
BOOST_CPU = 0
8+
BOOST_VRAM = 0
89
BOOTSPLASH = 0
910
DEBUG = 0
1011
RESETSLOT1 = 0
1112
LOCK_ARM9_SCFG_EXT = 0
13+
PATCH_MPU_REGION = 0
14+
PATCH_MPU_SIZE = 0

romsel_dsimenutheme/arm9/source/main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ std::string gbromfolder;
6868

6969
std::string arm7DonorPath;
7070

71+
int mpuregion = 0;
72+
int mpusize = 0;
73+
7174
int romtype = 0;
7275

7376
bool applaunch = false;
@@ -236,6 +239,77 @@ typedef struct {
236239
char gameCode[4]; //!< 4 characters for the game code.
237240
} sNDSHeadertitlecodeonly;
238241

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+
239313
//---------------------------------------------------------------------------------
240314
void stop (void) {
241315
//---------------------------------------------------------------------------------
@@ -490,11 +564,15 @@ int main(int argc, char **argv) {
490564

491565
}
492566

567+
SetMPUSettings(argarray[0]);
568+
493569
std::string path = argarray[0];
494570
std::string savepath = savename;
495571
CIniFile bootstrapini( "sd:/_nds/nds-bootstrap.ini" );
496572
bootstrapini.SetString("NDS-BOOTSTRAP", "NDS_PATH", path);
497573
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);
498576
bootstrapini.SaveIniFile( "sd:/_nds/nds-bootstrap.ini" );
499577
bootstrapfilename = bootstrapini.GetString("NDS-BOOTSTRAP", "BOOTSTRAP_PATH","");
500578
int err = runNdsFile (bootstrapfilename.c_str(), 0, 0);

romsel_dsmenutheme/arm9/source/main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ std::string gbromfolder;
6565

6666
std::string arm7DonorPath;
6767

68+
int mpuregion = 0;
69+
int mpusize = 0;
70+
6871
int romtype = 0;
6972

7073
bool applaunch = false;
@@ -124,6 +127,77 @@ typedef struct {
124127
char gameCode[4]; //!< 4 characters for the game code.
125128
} sNDSHeadertitlecodeonly;
126129

130+
/**
131+
* Set MPU settings for a specific game.
132+
*/
133+
void SetMPUSettings(const char* filename) {
134+
FILE *f_nds_file = fopen(filename, "rb");
135+
136+
char game_TID[5];
137+
fseek(f_nds_file, offsetof(sNDSHeadertitlecodeonly, gameCode), SEEK_SET);
138+
fread(game_TID, 1, 4, f_nds_file);
139+
game_TID[4] = 0;
140+
game_TID[3] = 0;
141+
fclose(f_nds_file);
142+
143+
scanKeys();
144+
int pressed = keysDownRepeat();
145+
146+
if(pressed & KEY_B){
147+
mpuregion = 1;
148+
} else if(pressed & KEY_X){
149+
mpuregion = 2;
150+
} else if(pressed & KEY_Y){
151+
mpuregion = 3;
152+
} else {
153+
mpuregion = 0;
154+
}
155+
if(pressed & KEY_RIGHT){
156+
mpusize = 3145728;
157+
} else if(pressed & KEY_LEFT){
158+
mpusize = 1;
159+
} else {
160+
mpusize = 0;
161+
}
162+
163+
// Check for games that need an MPU size of 3 MB.
164+
static const char mpu_3MB_list[][4] = {
165+
"A7A", // DS Download Station - Vol 1
166+
"A7B", // DS Download Station - Vol 2
167+
"A7C", // DS Download Station - Vol 3
168+
"A7D", // DS Download Station - Vol 4
169+
"A7E", // DS Download Station - Vol 5
170+
"A7F", // DS Download Station - Vol 6 (EUR)
171+
"A7G", // DS Download Station - Vol 6 (USA)
172+
"A7H", // DS Download Station - Vol 7
173+
"A7I", // DS Download Station - Vol 8
174+
"A7J", // DS Download Station - Vol 9
175+
"A7K", // DS Download Station - Vol 10
176+
"A7L", // DS Download Station - Vol 11
177+
"A7M", // DS Download Station - Vol 12
178+
"A7N", // DS Download Station - Vol 13
179+
"A7O", // DS Download Station - Vol 14
180+
"A7P", // DS Download Station - Vol 15
181+
"A7Q", // DS Download Station - Vol 16
182+
"A7R", // DS Download Station - Vol 17
183+
"A7S", // DS Download Station - Vol 18
184+
"A7T", // DS Download Station - Vol 19
185+
"ARZ", // Rockman ZX/MegaMan ZX
186+
"YZX", // Rockman ZX Advent/MegaMan ZX Advent
187+
"B6Z", // Rockman Zero Collection/MegaMan Zero Collection
188+
};
189+
190+
// TODO: If the list gets large enough, switch to bsearch().
191+
for (unsigned int i = 0; i < sizeof(mpu_3MB_list)/sizeof(mpu_3MB_list[0]); i++) {
192+
if (!memcmp(game_TID, mpu_3MB_list[i], 3)) {
193+
// Found a match.
194+
mpuregion = 1;
195+
mpusize = 3145728;
196+
break;
197+
}
198+
}
199+
}
200+
127201
//---------------------------------------------------------------------------------
128202
void stop (void) {
129203
//---------------------------------------------------------------------------------
@@ -328,11 +402,15 @@ int main(int argc, char **argv) {
328402

329403
}
330404

405+
SetMPUSettings(argarray[0]);
406+
331407
std::string path = argarray[0];
332408
std::string savepath = savename;
333409
CIniFile bootstrapini( "sd:/_nds/nds-bootstrap.ini" );
334410
bootstrapini.SetString("NDS-BOOTSTRAP", "NDS_PATH", path);
335411
bootstrapini.SetString("NDS-BOOTSTRAP", "SAV_PATH", savepath);
412+
bootstrapini.SetInt( "NDS-BOOTSTRAP", "PATCH_MPU_REGION", mpuregion);
413+
bootstrapini.SetInt( "NDS-BOOTSTRAP", "PATCH_MPU_SIZE", mpusize);
336414
bootstrapini.SaveIniFile( "sd:/_nds/nds-bootstrap.ini" );
337415
bootstrapfilename = bootstrapini.GetString("NDS-BOOTSTRAP", "BOOTSTRAP_PATH","");
338416
int err = runNdsFile (bootstrapfilename.c_str(), 0, 0);

0 commit comments

Comments
 (0)