From 282dcdece36f2f0e3c400df929db5dc0444a6d5e Mon Sep 17 00:00:00 2001 From: StapleButter Date: Wed, 1 Feb 2017 21:35:00 +0100 Subject: [PATCH] * make direct boot less shitty. * add main RAM mirror at 0x02800000 for ARM7. --- NDS.cpp | 37 +++++++++++++------------------------ NDS.h | 2 ++ NDSCart.cpp | 2 ++ NDSCart.h | 3 +++ main.cpp | 7 +++++++ melonDS.depend | 14 +++++++------- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/NDS.cpp b/NDS.cpp index 4d59b50b..2b20471f 100644 --- a/NDS.cpp +++ b/NDS.cpp @@ -134,19 +134,11 @@ void Init() Reset(); } -// temp -void LoadROM() + +void SetupDirectBoot() { - FILE* f; - - //f = fopen("rom/armwrestler.nds", "rb"); - //f = fopen("rom/zorp.nds", "rb"); - //f = fopen("rom/hello_world.nds", "rb"); - f = fopen("rom/mkds.nds", "rb"); - u32 bootparams[8]; - fseek(f, 0x20, SEEK_SET); - fread(bootparams, 8, 4, f); + memcpy(bootparams, &NDSCart::CartROM[0x20], 8*4); printf("ARM9: offset=%08X entry=%08X RAM=%08X size=%08X\n", bootparams[0], bootparams[1], bootparams[2], bootparams[3]); @@ -155,32 +147,24 @@ void LoadROM() MapSharedWRAM(3); - fseek(f, bootparams[0], SEEK_SET); for (u32 i = 0; i < bootparams[3]; i+=4) { - u32 tmp; - fread(&tmp, 4, 1, f); + u32 tmp = *(u32*)&NDSCart::CartROM[bootparams[0]+i]; ARM9Write32(bootparams[2]+i, tmp); } - fseek(f, bootparams[4], SEEK_SET); for (u32 i = 0; i < bootparams[7]; i+=4) { - u32 tmp; - fread(&tmp, 4, 1, f); + u32 tmp = *(u32*)&NDSCart::CartROM[bootparams[4]+i]; ARM7Write32(bootparams[6]+i, tmp); } - fseek(f, 0, SEEK_SET); for (u32 i = 0; i < 0x170; i+=4) { - u32 tmp; - fread(&tmp, 4, 1, f); + u32 tmp = *(u32*)&NDSCart::CartROM[i]; ARM9Write32(0x027FFE00+i, tmp); } - fclose(f); - ARM9Write32(0x027FF800, 0x00001FC2); ARM9Write32(0x027FF804, 0x00001FC2); ARM9Write32(0x027FFC00, 0x00001FC2); @@ -287,8 +271,7 @@ void Reset() // test //LoadROM(); //LoadFirmware(); - NDSCart::LoadROM("rom/nsmb.nds"); - LoadROM(); + NDSCart::LoadROM("rom/mkds.nds"); Running = true; // hax } @@ -1004,6 +987,7 @@ u8 ARM7Read8(u32 addr) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: return *(u8*)&MainRAM[addr & 0x3FFFFF]; case 0x03000000: @@ -1042,6 +1026,7 @@ u16 ARM7Read16(u32 addr) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: return *(u16*)&MainRAM[addr & 0x3FFFFF]; case 0x03000000: @@ -1088,6 +1073,7 @@ u32 ARM7Read32(u32 addr) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: return *(u32*)&MainRAM[addr & 0x3FFFFF]; case 0x03000000: @@ -1120,6 +1106,7 @@ void ARM7Write8(u32 addr, u8 val) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: *(u8*)&MainRAM[addr & 0x3FFFFF] = val; return; @@ -1155,6 +1142,7 @@ void ARM7Write16(u32 addr, u16 val) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: *(u16*)&MainRAM[addr & 0x3FFFFF] = val; return; @@ -1194,6 +1182,7 @@ void ARM7Write32(u32 addr, u32 val) switch (addr & 0xFF800000) { case 0x02000000: + case 0x02800000: *(u32*)&MainRAM[addr & 0x3FFFFF] = val; return; diff --git a/NDS.h b/NDS.h index ecf27ccc..8ca022be 100644 --- a/NDS.h +++ b/NDS.h @@ -115,6 +115,8 @@ extern u8 ARM7BIOS[0x4000]; void Init(); void Reset(); +void SetupDirectBoot(); + void RunFrame(); void PressKey(u32 key); diff --git a/NDSCart.cpp b/NDSCart.cpp index d4f657df..145f627e 100644 --- a/NDSCart.cpp +++ b/NDSCart.cpp @@ -347,6 +347,8 @@ void LoadROM(char* path) fclose(f); //CartROM = f; + NDS::SetupDirectBoot(); + CartInserted = true; // generate a ROM ID diff --git a/NDSCart.h b/NDSCart.h index 71702192..54ccfc63 100644 --- a/NDSCart.h +++ b/NDSCart.h @@ -33,6 +33,9 @@ extern u32 ROMDataOut; extern u8 EncSeed0[5]; extern u8 EncSeed1[5]; +extern u8* CartROM; +extern u32 CartROMSize; + void Init(); void Reset(); diff --git a/main.cpp b/main.cpp index 8ae99690..3e0a6a8f 100644 --- a/main.cpp +++ b/main.cpp @@ -48,6 +48,13 @@ LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) fwrite(&blarg, 4, 1, f); } fclose(f); + f = fopen("mainram.bin", "wb"); + for (u32 i = 0x2000000; i < 0x2400000; i+=4) + { + u32 blarg = NDS::ARM9Read32(i); + fwrite(&blarg, 4, 1, f); + } + fclose(f); } PostQuitMessage(0); return 0; diff --git a/melonDS.depend b/melonDS.depend index afea7fe4..f83cd3e4 100644 --- a/melonDS.depend +++ b/melonDS.depend @@ -1,16 +1,16 @@ # depslib dependency file v1.0 -1485901373 source:c:\documents\sources\melonds\main.cpp +1485974193 source:c:\documents\sources\melonds\main.cpp "NDS.h" "GPU.h" -1485901230 c:\documents\sources\melonds\nds.h +1485981187 c:\documents\sources\melonds\nds.h "types.h" 1481161027 c:\documents\sources\melonds\types.h -1485973806 source:c:\documents\sources\melonds\nds.cpp +1485981206 source:c:\documents\sources\melonds\nds.cpp "NDS.h" @@ -24,7 +24,7 @@ "RTC.h" "Wifi.h" -1485973712 source:c:\documents\sources\melonds\arm.cpp +1485979545 source:c:\documents\sources\melonds\arm.cpp "NDS.h" "ARM.h" @@ -65,7 +65,7 @@ 1485795628 c:\documents\sources\melonds\arminterpreter_loadstore.h -1485830927 source:c:\documents\sources\melonds\arminterpreter_loadstore.cpp +1485977845 source:c:\documents\sources\melonds\arminterpreter_loadstore.cpp "ARM.h" @@ -134,10 +134,10 @@ "RTC.h" -1485878561 c:\documents\sources\melonds\ndscart.h +1485980863 c:\documents\sources\melonds\ndscart.h "types.h" -1485880110 source:c:\documents\sources\melonds\ndscart.cpp +1485981191 source:c:\documents\sources\melonds\ndscart.cpp "NDS.h"