Skip to content

Commit

Permalink
Load MBK settings from booted .nds file
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Sep 17, 2024
1 parent cbd035e commit f994a18
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
13 changes: 13 additions & 0 deletions bootloader/source/arm9clear.arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ Modified by Chishm:
--------------------------------------------------------------------------*/
void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 (void)
{
if ((*(u8*)0x2FFE012 == *(u8*)0x2FFFE12) && (*(u8*)0x2FFE012 > 0)) {
*(vu32*)REG_MBK1 = *(u32*)0x02FFE180;
*(vu32*)REG_MBK2 = *(u32*)0x02FFE184;
*(vu32*)REG_MBK3 = *(u32*)0x02FFE188;
*(vu32*)REG_MBK4 = *(u32*)0x02FFE18C;
*(vu32*)REG_MBK5 = *(u32*)0x02FFE190;
REG_MBK6 = *(u32*)0x02FFE194;
REG_MBK7 = *(u32*)0x02FFE198;
REG_MBK8 = *(u32*)0x02FFE19C;
REG_MBK9 = *(u32*)0x02FFE1AC;
WRAM_CR = *(u8*)0x02FFE1AF;
}

REG_IME=0;
REG_EXMEMCNT = 0xE880;
// set ARM9 load address to 0 and wait for it to change again
Expand Down
19 changes: 18 additions & 1 deletion bootloader/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ void passArgs_ARM7 (void) {



static void initMBK_dsiMode(void) {
// This function has no effect with ARM7 SCFG locked
*(vu32*)REG_MBK1 = *(u32*)0x02FFE180;
*(vu32*)REG_MBK2 = *(u32*)0x02FFE184;
*(vu32*)REG_MBK3 = *(u32*)0x02FFE188;
*(vu32*)REG_MBK4 = *(u32*)0x02FFE18C;
*(vu32*)REG_MBK5 = *(u32*)0x02FFE190;
REG_MBK6 = *(u32*)0x02FFE1A0;
REG_MBK7 = *(u32*)0x02FFE1A4;
REG_MBK8 = *(u32*)0x02FFE1A8;
REG_MBK9 = *(u32*)0x02FFE1AC;
}

void memset_addrs_arm7(u32 start, u32 end)
{
if (!dsiMode && !(REG_SCFG_EXT & BIT(16))) {
Expand Down Expand Up @@ -286,6 +299,8 @@ void loadBinary_ARM7 (u32 fileCluster)
fileRead(ARM9i_DST, fileCluster, ARM9i_SRC, ARM9i_LEN);
if (ARM7i_LEN)
fileRead(ARM7i_DST, fileCluster, ARM7i_SRC, ARM7i_LEN);

initMBK_dsiMode();
}
}

Expand Down Expand Up @@ -362,7 +377,9 @@ int main (void) {
sdRead = false;

// Fix for Pictochat and DLP
if (ROM_TID == 0x41444E48 || ROM_TID == 0x41454E48) {
if (ROM_TID == 0x41444E48 || ROM_TID == 0x41454E48
|| ROM_TID == 0x43444E48 || ROM_TID == 0x43454E48
|| ROM_TID == 0x4B444E48 || ROM_TID == 0x4B454E48) {
(*(vu16*)0x02FFFCFA) = 0x1041; // NoCash: channel ch1+7+13
}

Expand Down
2 changes: 1 addition & 1 deletion bootloader/source/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define resetMemory2_ARM9_size 0x400
void __attribute__ ((long_call)) __attribute__((naked)) __attribute__((noreturn)) resetMemory2_ARM9();
#define startBinary_ARM9_size 0x100
#define startBinary_ARM9_size 0x200
void __attribute__ ((long_call)) __attribute__((noreturn)) __attribute__((naked)) startBinary_ARM9 ();
#define ARM9_START_FLAG (*(vu8*)0x02FFFDFB)

Expand Down

0 comments on commit f994a18

Please sign in to comment.