Skip to content

Commit f994a18

Browse files
committed
Load MBK settings from booted .nds file
1 parent cbd035e commit f994a18

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

bootloader/source/arm9clear.arm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ Modified by Chishm:
8888
--------------------------------------------------------------------------*/
8989
void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 (void)
9090
{
91+
if ((*(u8*)0x2FFE012 == *(u8*)0x2FFFE12) && (*(u8*)0x2FFE012 > 0)) {
92+
*(vu32*)REG_MBK1 = *(u32*)0x02FFE180;
93+
*(vu32*)REG_MBK2 = *(u32*)0x02FFE184;
94+
*(vu32*)REG_MBK3 = *(u32*)0x02FFE188;
95+
*(vu32*)REG_MBK4 = *(u32*)0x02FFE18C;
96+
*(vu32*)REG_MBK5 = *(u32*)0x02FFE190;
97+
REG_MBK6 = *(u32*)0x02FFE194;
98+
REG_MBK7 = *(u32*)0x02FFE198;
99+
REG_MBK8 = *(u32*)0x02FFE19C;
100+
REG_MBK9 = *(u32*)0x02FFE1AC;
101+
WRAM_CR = *(u8*)0x02FFE1AF;
102+
}
103+
91104
REG_IME=0;
92105
REG_EXMEMCNT = 0xE880;
93106
// set ARM9 load address to 0 and wait for it to change again

bootloader/source/boot.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ void passArgs_ARM7 (void) {
159159

160160

161161

162+
static void initMBK_dsiMode(void) {
163+
// This function has no effect with ARM7 SCFG locked
164+
*(vu32*)REG_MBK1 = *(u32*)0x02FFE180;
165+
*(vu32*)REG_MBK2 = *(u32*)0x02FFE184;
166+
*(vu32*)REG_MBK3 = *(u32*)0x02FFE188;
167+
*(vu32*)REG_MBK4 = *(u32*)0x02FFE18C;
168+
*(vu32*)REG_MBK5 = *(u32*)0x02FFE190;
169+
REG_MBK6 = *(u32*)0x02FFE1A0;
170+
REG_MBK7 = *(u32*)0x02FFE1A4;
171+
REG_MBK8 = *(u32*)0x02FFE1A8;
172+
REG_MBK9 = *(u32*)0x02FFE1AC;
173+
}
174+
162175
void memset_addrs_arm7(u32 start, u32 end)
163176
{
164177
if (!dsiMode && !(REG_SCFG_EXT & BIT(16))) {
@@ -286,6 +299,8 @@ void loadBinary_ARM7 (u32 fileCluster)
286299
fileRead(ARM9i_DST, fileCluster, ARM9i_SRC, ARM9i_LEN);
287300
if (ARM7i_LEN)
288301
fileRead(ARM7i_DST, fileCluster, ARM7i_SRC, ARM7i_LEN);
302+
303+
initMBK_dsiMode();
289304
}
290305
}
291306

@@ -362,7 +377,9 @@ int main (void) {
362377
sdRead = false;
363378

364379
// Fix for Pictochat and DLP
365-
if (ROM_TID == 0x41444E48 || ROM_TID == 0x41454E48) {
380+
if (ROM_TID == 0x41444E48 || ROM_TID == 0x41454E48
381+
|| ROM_TID == 0x43444E48 || ROM_TID == 0x43454E48
382+
|| ROM_TID == 0x4B444E48 || ROM_TID == 0x4B454E48) {
366383
(*(vu16*)0x02FFFCFA) = 0x1041; // NoCash: channel ch1+7+13
367384
}
368385

bootloader/source/boot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define resetMemory2_ARM9_size 0x400
55
void __attribute__ ((long_call)) __attribute__((naked)) __attribute__((noreturn)) resetMemory2_ARM9();
6-
#define startBinary_ARM9_size 0x100
6+
#define startBinary_ARM9_size 0x200
77
void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 ();
88
#define ARM9_START_FLAG (*(vu8*)0x02FFFDFB)
99

0 commit comments

Comments
 (0)