diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index b0d8941ee..89f3f5413 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -981,6 +981,14 @@ void MMU_Reset() MMU_timing.arm9dataCache.Reset(); } +void SetupMMU(bool debugConsole, bool dsi) { + if(debugConsole) _MMU_MAIN_MEM_MASK = 0x7FFFFF; + else _MMU_MAIN_MEM_MASK = 0x3FFFFF; + if(dsi) _MMU_MAIN_MEM_MASK = 0xFFFFFF; + _MMU_MAIN_MEM_MASK16 = _MMU_MAIN_MEM_MASK & ~1; + _MMU_MAIN_MEM_MASK32 = _MMU_MAIN_MEM_MASK & ~3; +} + void MMU_setRom(u8 * rom, u32 mask) { MMU.CART_ROM = rom; @@ -3536,10 +3544,10 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) switch(adr) { case REG_DSIMODE: - if(!CommonSettings.Is_DSI()) break; + if(!nds.Is_DSI()) break; return 1; case 0x04004008: - if(!CommonSettings.Is_DSI()) break; + if(!nds.Is_DSI()) break; return 0x8000; case REG_DISPA_DISPSTAT: @@ -3947,7 +3955,7 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) case 2: { - if(CommonSettings.Is_DSI()) + if(nds.Is_DSI()) { //pass data to TSC val = MMU_new.dsi_tsc.write16(val); diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 57fa04264..ea7262f2a 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -317,11 +317,14 @@ struct MMU_struct { //ARM9 mem u8 ARM9_ITCM[0x8000]; - u8 ARM9_DTCM[0x4000]; - u8 MAIN_MEM[0x800000]; //this has been expanded to 8MB to support debug consoles - u8 ARM9_REG[0x1000000]; - u8 ARM9_BIOS[0x8000]; - u8 ARM9_VMEM[0x800]; + u8 ARM9_DTCM[0x4000]; + + //u8 MAIN_MEM[4*1024*1024]; //expanded from 4MB to 8MB to support debug consoles + //u8 MAIN_MEM[8*1024*1024]; //expanded from 8MB to 16MB to support dsi + u8 MAIN_MEM[16*1024*1024]; //expanded from 8MB to 16MB to support dsi + u8 ARM9_REG[0x1000000]; //this variable is evil and should be removed by correctly emulating all registers. + u8 ARM9_BIOS[0x8000]; + u8 ARM9_VMEM[0x800]; #include "PACKED.h" struct { @@ -611,13 +614,7 @@ extern u32 partie; extern u32 _MMU_MAIN_MEM_MASK; extern u32 _MMU_MAIN_MEM_MASK16; extern u32 _MMU_MAIN_MEM_MASK32; -inline void SetupMMU(BOOL debugConsole) { - if(debugConsole) _MMU_MAIN_MEM_MASK = 0x7FFFFF; - else _MMU_MAIN_MEM_MASK = 0x3FFFFF; - _MMU_MAIN_MEM_MASK16 = _MMU_MAIN_MEM_MASK & ~1; - _MMU_MAIN_MEM_MASK32 = _MMU_MAIN_MEM_MASK & ~3; -} - +void SetupMMU(bool debugConsole, bool dsi); FORCEINLINE void CheckMemoryDebugEvent(EDEBUG_EVENT event, const MMU_ACCESS_TYPE type, const u32 procnum, const u32 addr, const u32 size, const u32 val) { diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index b73052b67..436978c6b 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -2385,11 +2385,12 @@ void NDS_Reset() nds.scr_touchX = nds.scr_touchY = nds.adc_touchX = nds.adc_touchY = 0; nds.isTouch = 0; nds.paddle = 0; - nds.debugConsole = CommonSettings.DebugConsole; + nds.ConsoleType = CommonSettings.ConsoleType; + nds._DebugConsole = CommonSettings.DebugConsole; nds.ensataEmulation = CommonSettings.EnsataEmulation; nds.ensataHandshake = ENSATA_HANDSHAKE_none; nds.ensataIpcSyncCounter = 0; - SetupMMU(nds.debugConsole); + SetupMMU(nds.Is_DebugConsole(),nds.Is_DSI()); _MMU_write16(REG_KEYINPUT, 0x3FF); _MMU_write16(REG_KEYINPUT, 0x3FF); @@ -2412,12 +2413,20 @@ void NDS_Reset() } } - // Copy the whole header to Main RAM 0x27FFE00 on startup. - // Reference: http://nocash.emubase.de/gbatek.htm#dscartridgeheader - //zero 27-jun-09 : why did this copy 0x90 more? gbatek says its not stored in ram. - //for (i = 0; i < ((0x170+0x90)/4); i++) { - for (int i = 0; i < ((0x170)/4); i++) - _MMU_write32(0x027FFE00+i*4, LE_TO_LOCAL_32(((u32*)MMU.CART_ROM)[i])); + // Copy the whole header to Main RAM 0x27FFE00 on startup. (http://nocash.emubase.de/gbatek.htm#dscartridgeheader) + //once upon a time this copied 0x90 more. this was thought to be wrong, and changed. + if(nds.Is_DSI()) + { + //dsi needs this copied later in memory. there are probably a number of things that get copied to a later location in memory.. thats where the NDS consoles tend to stash stuff. + for (int i = 0; i < ((0x170)/4); i++) + _MMU_write32(0x02FFFE00+i*4, LE_TO_LOCAL_32(((u32*)MMU.CART_ROM)[i])); + } + else + { + for (int i = 0; i < ((0x170)/4); i++) + _MMU_write32(0x027FFE00+i*4, LE_TO_LOCAL_32(((u32*)MMU.CART_ROM)[i])); + } + // Write the header checksum to memory (the firmware needs it to see the cart) _MMU_write16(0x027FF808, T1ReadWord(MMU.CART_ROM, 0x15E)); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index fed73bae2..89b22f6c2 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -157,6 +157,14 @@ enum ENSATA_HANDSHAKE ENSATA_HANDSHAKE_complete = 4, }; +enum NDS_CONSOLE_TYPE : u8 +{ + NDS_CONSOLE_TYPE_FAT, + NDS_CONSOLE_TYPE_LITE, + NDS_CONSOLE_TYPE_IQUE, + NDS_CONSOLE_TYPE_DSI +}; + struct NDSSystem { s32 wifiCycle; @@ -199,9 +207,12 @@ struct NDSSystem s32 idleFrameCounter; s32 cpuloopIterationCount; //counts the number of times during a frame that a reschedule happened - //if the game was booted on a debug console, this is set - BOOL debugConsole; - + //console type must be copied in when the system boots. it can't be changed on the fly. + NDS_CONSOLE_TYPE ConsoleType; + bool Is_DSI() { return ConsoleType == NDS_CONSOLE_TYPE_DSI; } + bool Is_DebugConsole() { return _DebugConsole!=0; } + BOOL _DebugConsole; + //set if the user requests ensata emulation BOOL ensataEmulation; @@ -233,14 +244,6 @@ struct NDS_fw_touchscreen_cal { u8 screen_y; }; -enum NDS_CONSOLE_TYPE -{ - NDS_CONSOLE_TYPE_FAT, - NDS_CONSOLE_TYPE_LITE, - NDS_CONSOLE_TYPE_IQUE, - NDS_CONSOLE_TYPE_DSI -}; - #define MAX_FW_NICKNAME_LENGTH 10 #define MAX_FW_MESSAGE_LENGTH 26 @@ -539,7 +542,6 @@ extern struct TCommonSettings { struct NDS_fw_config_data InternalFirmConf; NDS_CONSOLE_TYPE ConsoleType; - bool Is_DSI() { return ConsoleType == NDS_CONSOLE_TYPE_DSI; } bool DebugConsole; bool EnsataEmulation; diff --git a/desmume/src/bios.cpp b/desmume/src/bios.cpp index 09ee7bd4d..d0c2c933e 100644 --- a/desmume/src/bios.cpp +++ b/desmume/src/bios.cpp @@ -1079,7 +1079,7 @@ TEMPLATE static u32 getCRC16() TEMPLATE static u32 isDebugger() { //gbatek has additional specifications which are not emulated here - if(CommonSettings.DebugConsole) + if(nds.Is_DebugConsole()) cpu->R[0] = 1; else cpu->R[0] = 0; diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 472feb302..d2f6d20ac 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -168,8 +168,9 @@ SFORMAT SF_NDS[]={ { "_STX", 2, 1, &nds.scr_touchX}, { "_STY", 2, 1, &nds.scr_touchY}, { "_TPB", 4, 1, &nds.isTouch}, - { "_DBG", 4, 1, &nds.debugConsole}, + { "_DBG", 4, 1, &nds._DebugConsole}, { "_ENS", 4, 1, &nds.ensataEmulation}, + { "_TYP", 1, 1, &nds.ConsoleType}, { "_ENH", 4, 1, &nds.ensataHandshake}, { "_ENI", 4, 1, &nds.ensataIpcSyncCounter}, { "_SLP", 4, 1, &nds.sleeping}, @@ -1067,7 +1068,7 @@ static void loadstate() _MMU_write16(REG_BASE_DISPB+subRegenAddr[i], _MMU_read16(REG_BASE_DISPB+subRegenAddr[i])); // no need to restore 0x60 since control and MMU.ARM9_REG are both in the savestates, and restoring it could mess up the ack bits anyway - SetupMMU(nds.debugConsole); + SetupMMU(nds.Is_DebugConsole(),nds.Is_DSI()); execute = !driver->EMU_IsEmulationPaused(); } @@ -1122,7 +1123,7 @@ bool savestate_load(EMUFILE* is) _HACK_DONT_STOPMOVIE = false; //reset some options to their old defaults which werent saved - nds.debugConsole = FALSE; + nds._DebugConsole = FALSE; //GPU_Reset(MainScreen.gpu, 0); //GPU_Reset(SubScreen.gpu, 1); @@ -1145,10 +1146,15 @@ bool savestate_load(EMUFILE* is) loadstate(); - if((nds.debugConsole!=0) != CommonSettings.DebugConsole) { - printf("WARNING: forcing console debug mode to: debugmode=%s\n",nds.debugConsole?"TRUE":"FALSE"); + if(nds.ConsoleType != CommonSettings.ConsoleType) { + printf("WARNING: forcing console type to: ConsoleType=%d\n",nds.ConsoleType); } + if((nds._DebugConsole!=0) != CommonSettings.DebugConsole) { + printf("WARNING: forcing console debug mode to: debugmode=%s\n",nds._DebugConsole?"TRUE":"FALSE"); + } + + return true; } @@ -1195,14 +1201,11 @@ void rewindsave () { void dorewind() { - if(currFrameCounter % rewindinterval) return; //printf("rewind\n"); - nds.debugConsole = FALSE; - int size = rewindbuffer.size(); if(size < 1) {