Skip to content

Commit 5cff876

Browse files
committed
slot1launch: Fix issue with setting MBK registers
Ported from Lorenzooone/Simple-DS-Slot-1-Launcher@03a494d
1 parent 19d926f commit 5cff876

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

slot1launch/bootloader/source/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
#define ARM9_BOOTBIN 4
5757
#define ARM9_DISPERR 5
5858
#define ARM9_SETSCFG 6
59+
#define ARM9_SETMBK 7
60+
#define ARM9_SETMBK_START 8
5961
//};
6062

6163
extern tNDSHeader* ndsHeader;

slot1launch/bootloader/source/main.arm7.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,19 +307,8 @@ static void my_readUserSettings(tNDSHeader* ndsHeader) {
307307
}
308308

309309
void initMBK() {
310-
// arm7 is master of WRAM-A, arm9 of WRAM-B & C
311-
REG_MBK9=0x3000000F;
312-
313-
// WRAM-A fully mapped to arm7
314-
*((vu32*)REG_MBK1)=0x8D898581; // same as dsiware
315-
316-
// WRAM-B fully mapped to arm9 // inverted order
317-
*((vu32*)REG_MBK2)=0x8C888480;
318-
*((vu32*)REG_MBK3)=0x9C989490;
319-
320-
// WRAM-C fully mapped to arm9 // inverted order
321-
*((vu32*)REG_MBK4)=0x8C888480;
322-
*((vu32*)REG_MBK5)=0x9C989490;
310+
// Allow setting data from ARM9
311+
REG_MBK9 = 0;
323312

324313
// WRAM mapped to the 0x3700000 - 0x37FFFFF area
325314
// WRAM-A mapped to the 0x3000000 - 0x303FFFF area : 256k
@@ -331,16 +320,12 @@ void initMBK() {
331320
}
332321

333322
static void initMBK_dsiMode(void) {
334-
// This function has no effect with ARM7 SCFG locked
335-
*(vu32*)REG_MBK1 = *(u32*)0x02FFE180;
336-
*(vu32*)REG_MBK2 = *(u32*)0x02FFE184;
337-
*(vu32*)REG_MBK3 = *(u32*)0x02FFE188;
338-
*(vu32*)REG_MBK4 = *(u32*)0x02FFE18C;
339-
*(vu32*)REG_MBK5 = *(u32*)0x02FFE190;
340323
REG_MBK6 = *(u32*)0x02FFE1A0;
341324
REG_MBK7 = *(u32*)0x02FFE1A4;
342325
REG_MBK8 = *(u32*)0x02FFE1A8;
343-
REG_MBK9 = *(u32*)0x02FFE1AC;
326+
327+
// Unlock for writing data in ARM9
328+
REG_MBK9 = 0;
344329
}
345330

346331
void memset_addrs_arm7(u32 start, u32 end)
@@ -950,6 +935,11 @@ void arm7_main (void) {
950935
// Wait for ARM9 to at least start
951936
while (arm9_stateFlag < ARM9_START);
952937

938+
arm9_stateFlag = ARM9_SETMBK_START;
939+
while (arm9_stateFlag != ARM9_START);
940+
// arm7 is master of WRAM-A, arm9 of WRAM-B & C
941+
REG_MBK9=0x3000000F;
942+
953943
//debugOutput (ERR_STS_CLR_MEM);
954944

955945
scfgRomBak = REG_SCFG_ROM;
@@ -1151,6 +1141,12 @@ void arm7_main (void) {
11511141
initMBK_dsiMode();
11521142
REG_SCFG_EXT = 0x93FFFB06;
11531143
REG_SCFG_CLK = 0x187;
1144+
1145+
while (arm9_stateFlag != ARM9_READY);
1146+
arm9_stateFlag = ARM9_SETMBK;
1147+
while (arm9_stateFlag != ARM9_READY);
1148+
1149+
REG_MBK9 = (*(u32*)0x02FFE1AC) & 0x00FFFFFF;
11541150
}
11551151

11561152
if (!scfgUnlock && !dsiModeConfirmed) {

slot1launch/bootloader/source/main.arm9.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ extern __attribute__((noreturn)) void arm9_actual_jump(void* fn);
6767

6868
void initMBKARM9() {
6969
// default dsiware settings
70+
// arm7 is master of WRAM-A, arm9 of WRAM-B & C
71+
72+
// WRAM-A fully mapped to arm7
73+
*((vu32*)REG_MBK1)=0x8D898581; // same as dsiware
7074

7175
// WRAM-B fully mapped to arm9 // inverted order
7276
*((vu32*)REG_MBK2)=0x8C888480;
@@ -93,7 +97,6 @@ void initMBKARM9_dsiMode(void) {
9397
REG_MBK6 = *(u32*)0x02FFE194;
9498
REG_MBK7 = *(u32*)0x02FFE198;
9599
REG_MBK8 = *(u32*)0x02FFE19C;
96-
REG_MBK9 = *(u32*)0x02FFE1AC;
97100
}
98101

99102
void SetBrightness(u8 screen, s8 bright) {
@@ -210,8 +213,10 @@ void __attribute__((target("arm"))) arm9_main (void) {
210213
WRAM_CR = 0x03;
211214
REG_EXMEMCNT = 0xE880;
212215

213-
initMBKARM9();
216+
arm9_stateFlag = ARM9_START;
214217

218+
while(arm9_stateFlag != ARM9_SETMBK_START);
219+
initMBKARM9();
215220
arm9_stateFlag = ARM9_START;
216221

217222
REG_IME = 0;
@@ -306,11 +311,13 @@ void __attribute__((target("arm"))) arm9_main (void) {
306311
arm9_stateFlag = ARM9_READY;
307312
}
308313
}
314+
if (arm9_stateFlag == ARM9_SETMBK) {
315+
if (dsiModeConfirmed && arm9_isSdk5 && ndsHeader->unitCode > 0)
316+
initMBKARM9_dsiMode();
317+
arm9_stateFlag = ARM9_READY;
318+
}
309319
if (arm9_stateFlag == ARM9_SETSCFG) {
310320
if (dsiModeConfirmed) {
311-
if (arm9_isSdk5 && ndsHeader->unitCode > 0) {
312-
initMBKARM9_dsiMode();
313-
}
314321
REG_SCFG_EXT = 0x8307F100;
315322
// bit 7 is read only in reality...
316323
if(arm9_twlClock)
@@ -340,6 +347,9 @@ void __attribute__((target("arm"))) arm9_main (void) {
340347
}
341348
}
342349

350+
if (dsiModeConfirmed && arm9_isSdk5 && ndsHeader->unitCode > 0)
351+
WRAM_CR = *(u8*)0x02FFE1AF;
352+
343353
// wait for vblank then boot
344354
while (REG_VCOUNT!=191);
345355
while (REG_VCOUNT==191);

0 commit comments

Comments
 (0)