From 35ce5d847322c7066cb6ac83cdf6d3bf8da49546 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 4 May 2009 05:43:47 +0000 Subject: [PATCH] fix movie rtc so the timekeeping actually works now! --- src/MMU.cpp | 193 +++++++++++------------- src/MMU.h | 46 +++--- src/NDSSystem.cpp | 251 +++++++++++++++++--------------- src/armcpu.cpp | 61 ++++---- src/armcpu.h | 9 +- src/rtc.cpp | 9 +- src/saves.cpp | 24 +-- src/thumb_instructions.cpp | 3 + src/windows/DeSmuME_2005.vcproj | 1 + src/windows/DeSmuME_2008.vcproj | 3 +- src/windows/ginfo.cpp | 56 +++---- src/windows/ram_search.cpp | 1 + src/windows/ramwatch.cpp | 1 + 13 files changed, 337 insertions(+), 321 deletions(-) diff --git a/src/MMU.cpp b/src/MMU.cpp index df08ab890..602e4e6ba 100644 --- a/src/MMU.cpp +++ b/src/MMU.cpp @@ -97,7 +97,19 @@ static const int save_types[7][2] = { {MC_TYPE_FLASH,MC_SIZE_4MBITS} }; -u16 partie = 1; +//Card rom & ram + +u16 SPI_CNT; +u16 SPI_CMD; +u16 AUX_SPI_CNT; +u16 AUX_SPI_CMD; + +u32 rom_mask = 0; + +u32 DMASrc[2][4]; +u32 DMADst[2][4]; + +u16 partie; u32 _MMU_MAIN_MEM_MASK = 0x3FFFFF; #define ROM_MASK 3 @@ -178,6 +190,7 @@ void mmu_log_debug_ARM7(u32 adr, const char *fmt, ...) #define DUP16(x) x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x MMU_struct MMU; +MMU_static_struct MMU_static; u8 * MMU_struct::MMU_MEM[2][256] = { //arm9 @@ -358,6 +371,15 @@ static FORCEINLINE u32 MMU_LCDmap(u32 addr, bool& unmapped) { unmapped = false; + if(addr==0x6201dc0) + { + int zzz=9; + } + if((addr&0x0F000000)==0x06000000 && PROCNUM==1) + { + printf("%08x\n",addr); + } + //in case the address is entirely outside of the interesting ranges if(addr < 0x06000000) return addr; if(addr >= 0x07000000) return addr; @@ -527,7 +549,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) u8 en = VRAMBankCnt & 0x80; if(!en) return; - int mst,ofs; + int mst,ofs=0; switch(bank) { case VRAM_BANK_A: case VRAM_BANK_B: @@ -541,7 +563,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+ofs*8); break; case 2: //AOBJ @@ -549,7 +571,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) switch(ofs) { case 0: case 1: - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+ofs*8); break; default: @@ -575,7 +597,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+ofs*8); break; case 2: //arm7 @@ -597,7 +619,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) ARM9Mem.texInfo.textureSlotAddr[ofs] = MMU_vram_physical(vram_bank_info[bank].page_addr); break; case 4: //BGB or BOBJ - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); if(bank == VRAM_BANK_C) { vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; MMU_vram_arm9(bank,VRAM_PAGE_BBG); //BBG @@ -619,11 +641,11 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG); break; case 2: //AOBJ - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); vramConfiguration.banks[bank].purpose = VramConfiguration::AOBJ; MMU_vram_arm9(bank,VRAM_PAGE_AOBJ); break; @@ -659,13 +681,13 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+pageofs); MMU_vram_arm9(bank,VRAM_PAGE_ABG+pageofs+2); //unexpected mirroring (required by spyro eternal night) break; case 2: //AOBJ vramConfiguration.banks[bank].purpose = VramConfiguration::AOBJ; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+pageofs); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+pageofs+2); //unexpected mirroring - I have no proof, but it is inferred from the ABG above break; @@ -707,7 +729,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //BBG vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BBG); MMU_vram_arm9(bank,VRAM_PAGE_BBG + 4); //unexpected mirroring break; @@ -732,13 +754,13 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //BBG vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BBG+2); MMU_vram_arm9(bank,VRAM_PAGE_BBG+3); //unexpected mirroring break; case 2: //BOBJ vramConfiguration.banks[bank].purpose = VramConfiguration::BOBJ; - MMU_vram_lcdc(bank); + //MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BOBJ); break; case 3: //B OBJ extended palette @@ -892,33 +914,20 @@ void MMU_Init(void) { LOG("MMU init\n"); - memset(&MMU, 0, sizeof(MMU_struct)); + MMU_clearMem(); - MMU.CART_ROM = MMU.UNUSED_RAM; + MMU_static.CART_ROM = MMU.UNUSED_RAM; for(i = 0x80; i<0xA0; ++i) { - MMU_struct::MMU_MEM[0][i] = MMU.CART_ROM; - MMU_struct::MMU_MEM[1][i] = MMU.CART_ROM; + MMU_struct::MMU_MEM[0][i] = MMU_static.CART_ROM; + MMU_struct::MMU_MEM[1][i] = MMU_static.CART_ROM; } - MMU.DTCMRegion = 0x027C0000; - MMU.ITCMRegion = 0x00000000; + mc_init(&MMU_static.fw, MC_TYPE_FLASH); /* init fw device */ + mc_alloc(&MMU_static.fw, NDS_FW_SIZE_V1); + MMU_static.fw.fp = NULL; - IPC_FIFOinit(ARMCPU_ARM9); - IPC_FIFOinit(ARMCPU_ARM7); - GFX_FIFOclear(); - DISP_FIFOinit(); - - mc_init(&MMU.fw, MC_TYPE_FLASH); /* init fw device */ - mc_alloc(&MMU.fw, NDS_FW_SIZE_V1); - MMU.fw.fp = NULL; - - // Init Backup Memory device, this should really be done when the rom is loaded - mc_init(&MMU.bupmem, MC_TYPE_AUTODETECT); - mc_alloc(&MMU.bupmem, 1); - MMU.bupmem.fp = NULL; - rtcInit(); addonsInit(); if(Mic_Init() == FALSE) INFO("Microphone init failed.\n"); @@ -928,77 +937,51 @@ void MMU_Init(void) { void MMU_DeInit(void) { LOG("MMU deinit\n"); - if (MMU.fw.fp) - fclose(MMU.fw.fp); - mc_free(&MMU.fw); - if (MMU.bupmem.fp) - fclose(MMU.bupmem.fp); - mc_free(&MMU.bupmem); + if (MMU_static.fw.fp) + fclose(MMU_static.fw.fp); + mc_free(&MMU_static.fw); + if (MMU_static.bupmem.fp) + fclose(MMU_static.bupmem.fp); + mc_free(&MMU_static.bupmem); addonsClose(); Mic_DeInit(); } -//Card rom & ram - -u16 SPI_CNT = 0; -u16 SPI_CMD = 0; -u16 AUX_SPI_CNT = 0; -u16 AUX_SPI_CMD = 0; - -u32 rom_mask = 0; - -u32 DMASrc[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; -u32 DMADst[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; - void MMU_clearMem() { - memset(ARM9Mem.ARM9_DTCM, 0, sizeof(ARM9Mem.ARM9_DTCM)); - memset(ARM9Mem.ARM9_ITCM, 0, sizeof(ARM9Mem.ARM9_ITCM)); - memset(ARM9Mem.ARM9_LCD, 0, sizeof(ARM9Mem.ARM9_LCD)); - memset(ARM9Mem.ARM9_OAM, 0, sizeof(ARM9Mem.ARM9_OAM)); - memset(ARM9Mem.ARM9_REG, 0, sizeof(ARM9Mem.ARM9_REG)); - memset(ARM9Mem.ARM9_VMEM, 0, sizeof(ARM9Mem.ARM9_VMEM)); - memset(ARM9Mem.MAIN_MEM, 0, sizeof(ARM9Mem.MAIN_MEM)); + printf("-------------------------clear---\n"); - memset(ARM9Mem.blank_memory, 0, sizeof(ARM9Mem.blank_memory)); + partie = 1; + + memset(&ARM9Mem,0,sizeof(ARM9Mem)); + memset(&MMU,0,sizeof(MMU)); + + //things which used to be only static initialized, now cleared here + memset(DMASrc,0,sizeof(DMASrc)); + memset(DMADst,0,sizeof(DMADst)); + SPI_CNT = 0; + SPI_CMD = 0; + AUX_SPI_CNT = 0; + AUX_SPI_CMD = 0; + + MMU_VRAM_unmap_all(); + + //reset gpu system + MainScreen.offset = 0; + SubScreen.offset = 192; + if(osdA != NULL) osdA->setOffset(MainScreen.offset); + if(osdB != NULL) osdB->setOffset(SubScreen.offset); - memset(MMU.ARM7_ERAM, 0, sizeof(MMU.ARM7_ERAM)); - memset(MMU.ARM7_REG, 0, sizeof(MMU.ARM7_REG)); - IPC_FIFOinit(ARMCPU_ARM9); IPC_FIFOinit(ARMCPU_ARM7); GFX_FIFOclear(); DISP_FIFOinit(); - - MMU.DTCMRegion = 0x027C0000; - MMU.ITCMRegion = 0x00000000; - - memset(MMU.timer, 0, sizeof(u16) * 2 * 4); - memset(MMU.timerMODE, 0, sizeof(s32) * 2 * 4); - memset(MMU.timerON, 0, sizeof(u32) * 2 * 4); - memset(MMU.timerRUN, 0, sizeof(u32) * 2 * 4); - memset(MMU.timerReload, 0, sizeof(u16) * 2 * 4); - - memset(MMU.reg_IME, 0, sizeof(u32) * 2); - memset(MMU.reg_IE, 0, sizeof(u32) * 2); - memset(MMU.reg_IF, 0, sizeof(u32) * 2); - - memset(MMU.DMAStartTime, 0, sizeof(u32) * 2 * 4); - memset(MMU.DMACycle, 0, sizeof(s32) * 2 * 4); - memset(MMU.DMACrt, 0, sizeof(u32) * 2 * 4); - memset(MMU.DMAing, 0, sizeof(BOOL) * 2 * 4); - - memset(MMU.dscard, 0, sizeof(nds_dscard) * 2); + //------- + //setup non-zero registers + MMU.DTCMRegion = 0x027C0000; // Enable the sound speakers T1WriteWord(MMU.ARM7_REG, 0x304, 0x0001); - - MainScreen.offset = 0; - SubScreen.offset = 192; - osdA->setOffset(MainScreen.offset); - osdB->setOffset(SubScreen.offset); - - MMU_VRAM_unmap_all(); MMU.powerMan_CntReg = 0x00; MMU.powerMan_CntRegWritten = FALSE; @@ -1007,17 +990,15 @@ void MMU_clearMem() MMU.powerMan_Reg[2] = 0x01; MMU.powerMan_Reg[3] = 0x00; - rtcInit(); - partie = 1; - addonsReset(); - Mic_Reset(); + MMU.DTCMRegion = 0x027C0000; + MMU.ITCMRegion = 0x00000000; } void MMU_setRom(u8 * rom, u32 mask) { unsigned int i; - MMU.CART_ROM = rom; - MMU.CART_ROM_MASK = mask; + MMU_static.CART_ROM = rom; + MMU_static.CART_ROM_MASK = mask; for(i = 0x80; i<0xA0; ++i) { @@ -1032,7 +1013,7 @@ void MMU_setRom(u8 * rom, u32 mask) void MMU_unsetRom() { unsigned int i; - MMU.CART_ROM=MMU.UNUSED_RAM; + MMU_static.CART_ROM=MMU.UNUSED_RAM; for(i = 0x80; i<0xA0; ++i) { @@ -2220,14 +2201,14 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) AUX_SPI_CNT = val; if (val == 0) - mc_reset_com(&MMU.bupmem); /* reset backup memory device communication */ + mc_reset_com(&MMU_static.bupmem); /* reset backup memory device communication */ return; case REG_AUXSPIDATA: if(val!=0) AUX_SPI_CMD = val & 0xFF; - T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][(REG_AUXSPIDATA >> 20) & 0xff], REG_AUXSPIDATA & 0xfff, bm_transfer(&MMU.bupmem, val)); + T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][(REG_AUXSPIDATA >> 20) & 0xff], REG_AUXSPIDATA & 0xfff, bm_transfer(&MMU_static.bupmem, val)); return; case REG_DISPA_BG0CNT : //GPULOG("MAIN BG0 SETPROP 16B %08X\r\n", val); @@ -3398,7 +3379,7 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) { MMU.dscard[ARMCPU_ARM9].address = (0x8000 + (MMU.dscard[ARMCPU_ARM9].address&0x1FF)); } - val = T1ReadLong(MMU.CART_ROM, MMU.dscard[ARMCPU_ARM9].address & MMU.CART_ROM_MASK); + val = T1ReadLong(MMU_static.CART_ROM, MMU.dscard[ARMCPU_ARM9].address & MMU_static.CART_ROM_MASK); } break; @@ -3563,14 +3544,14 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) AUX_SPI_CNT = val; if (val == 0) - mc_reset_com(&MMU.bupmem); // reset backup memory device communication + mc_reset_com(&MMU_static.bupmem); // reset backup memory device communication return; case REG_AUXSPIDATA: if(val!=0) AUX_SPI_CMD = val & 0xFF; - T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][(REG_AUXSPIDATA >> 20) & 0xff], REG_AUXSPIDATA & 0xfff, bm_transfer(&MMU.bupmem, val)); + T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][(REG_AUXSPIDATA >> 20) & 0xff], REG_AUXSPIDATA & 0xfff, bm_transfer(&MMU_static.bupmem, val)); return; case REG_SPICNT : @@ -3589,11 +3570,11 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) } } - //MMU.fw.com == 0; // reset fw device communication + //MMU_static.fw.com == 0; // reset fw device communication if ( reset_firmware) { // reset fw device communication - mc_reset_com(&MMU.fw); + mc_reset_com(&MMU_static.fw); } SPI_CNT = val; @@ -3641,7 +3622,7 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][(REG_SPIDATA >> 20) & 0xff], REG_SPIDATA & 0xfff, 0); break; } - T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][(REG_SPIDATA >> 20) & 0xff], REG_SPIDATA & 0xfff, fw_transfer(&MMU.fw, val)); + T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][(REG_SPIDATA >> 20) & 0xff], REG_SPIDATA & 0xfff, fw_transfer(&MMU_static.fw, val)); return; case 2 : @@ -4397,7 +4378,7 @@ u32 FASTCALL _MMU_ARM7_read32(u32 adr) case 0xB7: { /* TODO: prevent read if the address is out of range */ - val = T1ReadLong(MMU.CART_ROM, MMU.dscard[ARMCPU_ARM7].address); + val = T1ReadLong(MMU_static.CART_ROM, MMU.dscard[ARMCPU_ARM7].address); } break; @@ -4516,5 +4497,5 @@ void mmu_select_savetype(int type, int *bmemtype, u32 *bmemsize) { if (type<0 || type > 6) return; *bmemtype=save_types[type][0]; *bmemsize=save_types[type][1]; - mc_realloc(&MMU.bupmem, *bmemtype, *bmemsize); + mc_realloc(&MMU_static.bupmem, *bmemtype, *bmemsize); } diff --git a/src/MMU.h b/src/MMU.h index cb81e178b..d445f1e4b 100644 --- a/src/MMU.h +++ b/src/MMU.h @@ -47,34 +47,39 @@ typedef const u32 TWaitState; +struct MMU_static_struct { + + //Card rom + u8 * CART_ROM; + u32 CART_ROM_MASK; + + memory_chip_t fw; + memory_chip_t bupmem; + +}; + struct MMU_struct { //ARM7 mem u8 ARM7_BIOS[0x4000]; u8 ARM7_ERAM[0x10000]; u8 ARM7_REG[0x10000]; u8 ARM7_WIRAM[0x10000]; + u8 CART_RAM[0x10000]; + //this is here so that we can trap glitchy emulator code + //which is accessing offsets 5,6,7 of unused ram due to unaligned accesses + //(also since the emulator doesn't prevent unaligned accesses) + u8 MORE_UNUSED_RAM[4]; + //Shared ram + u8 SWIRAM[0x8000]; + //Unused ram + u8 UNUSED_RAM[4]; // VRAM mapping u8 VRAM_MAP[4][32]; u32 LCD_VRAM_ADDR[10]; u8 LCDCenable[10]; - //Shared ram - u8 SWIRAM[0x8000]; - - //Card rom & ram - u8 * CART_ROM; - u32 CART_ROM_MASK; - u8 CART_RAM[0x10000]; - - //Unused ram - u8 UNUSED_RAM[4]; - - //this is here so that we can trap glitchy emulator code - //which is accessing offsets 5,6,7 of unused ram due to unaligned accesses - //(also since the emulator doesn't prevent unaligned accesses) - u8 MORE_UNUSED_RAM[4]; - + static u8 * MMU_MEM[2][256]; static u32 MMU_MASK[2][256]; @@ -115,17 +120,14 @@ struct MMU_struct { u8 powerMan_CntReg; BOOL powerMan_CntRegWritten; u8 powerMan_Reg[4]; - - memory_chip_t fw; - memory_chip_t bupmem; - + nds_dscard dscard[2]; u32 CheckTimers; - u32 CheckDMAs; - + u32 CheckDMAs; }; extern MMU_struct MMU; +extern MMU_static_struct MMU_static; struct armcpu_memory_iface { diff --git a/src/NDSSystem.cpp b/src/NDSSystem.cpp index 0e43eee93..98aff87fc 100644 --- a/src/NDSSystem.cpp +++ b/src/NDSSystem.cpp @@ -41,6 +41,9 @@ #include "debug.h" #include "cheatSystem.h" #include "movie.h" +#include "rtc.h" +#include "mic.h" +#include "addons.h" #ifdef _WIN32 #include "./windows/disView.h" @@ -53,7 +56,7 @@ static Driver _stub_driver; Driver* driver = &_stub_driver; std::string InputDisplayString; -static BOOL LidClosed = FALSE; +static BOOL LidClosed; static u8 countLid = 0; char pathToROM[MAX_PATH]; char pathFilenameToROMwithoutExt[MAX_PATH]; @@ -489,21 +492,17 @@ struct armcpu_ctrl_iface **arm7_ctrl_iface) { #else int NDS_Init( void) { #endif - nds.ARM9Cycle = 0; - nds.ARM7Cycle = 0; - nds.cycles = 0; - nds.idleFrameCounter = 0; - memset(nds.runCycleCollector,0,sizeof(nds.runCycleCollector)); MMU_Init(); - nds.nextHBlank = 3168; - nds.VCount = 0; - nds.lignerendu = FALSE; - - nds.sleeping = FALSE; if (Screen_Init(GFXCORE_DUMMY) != 0) return -1; + //reset gpu system + MainScreen.offset = 0; + SubScreen.offset = 192; + osdA->setOffset(MainScreen.offset); + osdB->setOffset(SubScreen.offset); + gfx3d_init(); #ifdef GDB_STUB @@ -530,7 +529,7 @@ int NDS_Init( void) { } void NDS_DeInit(void) { - if(MMU.CART_ROM != MMU.UNUSED_RAM) + if(MMU_static.CART_ROM != MMU.UNUSED_RAM) NDS_FreeROM(); nds.nextHBlank = 3168; @@ -556,45 +555,45 @@ NDS_header * NDS_getROMHeader(void) { NDS_header * header = new NDS_header; - memcpy(header->gameTile, MMU.CART_ROM, 12); - memcpy(header->gameCode, MMU.CART_ROM + 12, 4); - header->makerCode = T1ReadWord(MMU.CART_ROM, 16); - header->unitCode = MMU.CART_ROM[18]; - header->deviceCode = MMU.CART_ROM[19]; - header->cardSize = MMU.CART_ROM[20]; - memcpy(header->cardInfo, MMU.CART_ROM + 21, 8); - header->flags = MMU.CART_ROM[29]; - header->ARM9src = T1ReadLong(MMU.CART_ROM, 32); - header->ARM9exe = T1ReadLong(MMU.CART_ROM, 36); - header->ARM9cpy = T1ReadLong(MMU.CART_ROM, 40); - header->ARM9binSize = T1ReadLong(MMU.CART_ROM, 44); - header->ARM7src = T1ReadLong(MMU.CART_ROM, 48); - header->ARM7exe = T1ReadLong(MMU.CART_ROM, 52); - header->ARM7cpy = T1ReadLong(MMU.CART_ROM, 56); - header->ARM7binSize = T1ReadLong(MMU.CART_ROM, 60); - header->FNameTblOff = T1ReadLong(MMU.CART_ROM, 64); - header->FNameTblSize = T1ReadLong(MMU.CART_ROM, 68); - header->FATOff = T1ReadLong(MMU.CART_ROM, 72); - header->FATSize = T1ReadLong(MMU.CART_ROM, 76); - header->ARM9OverlayOff = T1ReadLong(MMU.CART_ROM, 80); - header->ARM9OverlaySize = T1ReadLong(MMU.CART_ROM, 84); - header->ARM7OverlayOff = T1ReadLong(MMU.CART_ROM, 88); - header->ARM7OverlaySize = T1ReadLong(MMU.CART_ROM, 92); - header->unknown2a = T1ReadLong(MMU.CART_ROM, 96); - header->unknown2b = T1ReadLong(MMU.CART_ROM, 100); - header->IconOff = T1ReadLong(MMU.CART_ROM, 104); - header->CRC16 = T1ReadWord(MMU.CART_ROM, 108); - header->ROMtimeout = T1ReadWord(MMU.CART_ROM, 110); - header->ARM9unk = T1ReadLong(MMU.CART_ROM, 112); - header->ARM7unk = T1ReadLong(MMU.CART_ROM, 116); - memcpy(header->unknown3c, MMU.CART_ROM + 120, 8); - header->ROMSize = T1ReadLong(MMU.CART_ROM, 128); - header->HeaderSize = T1ReadLong(MMU.CART_ROM, 132); - memcpy(header->unknown5, MMU.CART_ROM + 136, 56); - memcpy(header->logo, MMU.CART_ROM + 192, 156); - header->logoCRC16 = T1ReadWord(MMU.CART_ROM, 348); - header->headerCRC16 = T1ReadWord(MMU.CART_ROM, 350); - memcpy(header->reserved, MMU.CART_ROM + 352, 160); + memcpy(header->gameTile, MMU_static.CART_ROM, 12); + memcpy(header->gameCode, MMU_static.CART_ROM + 12, 4); + header->makerCode = T1ReadWord(MMU_static.CART_ROM, 16); + header->unitCode = MMU_static.CART_ROM[18]; + header->deviceCode = MMU_static.CART_ROM[19]; + header->cardSize = MMU_static.CART_ROM[20]; + memcpy(header->cardInfo, MMU_static.CART_ROM + 21, 8); + header->flags = MMU_static.CART_ROM[29]; + header->ARM9src = T1ReadLong(MMU_static.CART_ROM, 32); + header->ARM9exe = T1ReadLong(MMU_static.CART_ROM, 36); + header->ARM9cpy = T1ReadLong(MMU_static.CART_ROM, 40); + header->ARM9binSize = T1ReadLong(MMU_static.CART_ROM, 44); + header->ARM7src = T1ReadLong(MMU_static.CART_ROM, 48); + header->ARM7exe = T1ReadLong(MMU_static.CART_ROM, 52); + header->ARM7cpy = T1ReadLong(MMU_static.CART_ROM, 56); + header->ARM7binSize = T1ReadLong(MMU_static.CART_ROM, 60); + header->FNameTblOff = T1ReadLong(MMU_static.CART_ROM, 64); + header->FNameTblSize = T1ReadLong(MMU_static.CART_ROM, 68); + header->FATOff = T1ReadLong(MMU_static.CART_ROM, 72); + header->FATSize = T1ReadLong(MMU_static.CART_ROM, 76); + header->ARM9OverlayOff = T1ReadLong(MMU_static.CART_ROM, 80); + header->ARM9OverlaySize = T1ReadLong(MMU_static.CART_ROM, 84); + header->ARM7OverlayOff = T1ReadLong(MMU_static.CART_ROM, 88); + header->ARM7OverlaySize = T1ReadLong(MMU_static.CART_ROM, 92); + header->unknown2a = T1ReadLong(MMU_static.CART_ROM, 96); + header->unknown2b = T1ReadLong(MMU_static.CART_ROM, 100); + header->IconOff = T1ReadLong(MMU_static.CART_ROM, 104); + header->CRC16 = T1ReadWord(MMU_static.CART_ROM, 108); + header->ROMtimeout = T1ReadWord(MMU_static.CART_ROM, 110); + header->ARM9unk = T1ReadLong(MMU_static.CART_ROM, 112); + header->ARM7unk = T1ReadLong(MMU_static.CART_ROM, 116); + memcpy(header->unknown3c, MMU_static.CART_ROM + 120, 8); + header->ROMSize = T1ReadLong(MMU_static.CART_ROM, 128); + header->HeaderSize = T1ReadLong(MMU_static.CART_ROM, 132); + memcpy(header->unknown5, MMU_static.CART_ROM + 136, 56); + memcpy(header->logo, MMU_static.CART_ROM + 192, 156); + header->logoCRC16 = T1ReadWord(MMU_static.CART_ROM, 348); + header->headerCRC16 = T1ReadWord(MMU_static.CART_ROM, 350); + memcpy(header->reserved, MMU_static.CART_ROM + 352, 160); return header; } @@ -798,7 +797,7 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, // Make sure old ROM is freed first(at least this way we won't be eating // up a ton of ram before the old ROM is freed) - if(MMU.CART_ROM != MMU.UNUSED_RAM) + if(MMU_static.CART_ROM != MMU.UNUSED_RAM) NDS_FreeROM(); data = new u8[mask + 1]; @@ -832,8 +831,8 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, strcpy(buf, pathFilenameToROMwithoutExt); strcat(buf, ".sav"); // DeSmuME memory card :) - mc_realloc(&MMU.bupmem, bmtype, bmsize); - mc_load_file(&MMU.bupmem, buf); + mc_realloc(&MMU_static.bupmem, bmtype, bmsize); + mc_load_file(&MMU_static.bupmem, buf); memset(buf, 0, MAX_PATH); strcpy(buf, pathFilenameToROMwithoutExt); @@ -847,8 +846,8 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, void MovieSRAM() { - int bmtype = MMU.bupmem.type; - u32 bmsize = MMU.bupmem.size; + int bmtype = MMU_static.bupmem.type; + u32 bmsize = MMU_static.bupmem.size; char buf[MAX_PATH]; @@ -860,18 +859,19 @@ void MovieSRAM() strcat(buf, "movie"); } - mc_realloc(&MMU.bupmem, bmtype, bmsize); - mc_load_file(&MMU.bupmem, buf); + mc_realloc(&MMU_static.bupmem,MC_TYPE_AUTODETECT,0); + //mc_realloc(&MMU_static.bupmem, bmtype, bmsize); + mc_load_file(&MMU_static.bupmem, buf); } void NDS_FreeROM(void) { - if (MMU.CART_ROM != MMU.UNUSED_RAM) - delete [] MMU.CART_ROM; + if (MMU_static.CART_ROM != MMU.UNUSED_RAM) + delete [] MMU_static.CART_ROM; MMU_unsetRom(); - if (MMU.bupmem.fp) - fclose(MMU.bupmem.fp); - MMU.bupmem.fp = NULL; + if (MMU_static.bupmem.fp) + fclose(MMU_static.bupmem.fp); + MMU_static.bupmem.fp = NULL; } void NDS_Reset( void) @@ -886,12 +886,12 @@ void NDS_Reset( void) if (!header) return ; - if (MMU.bupmem.fp) + if (MMU_static.bupmem.fp) { - fclose(MMU.bupmem.fp); - MMU.bupmem.fp = NULL; + fclose(MMU_static.bupmem.fp); + MMU_static.bupmem.fp = NULL; } - + lagframecounter=0; LagFrameFlag=0; lastLag=0; @@ -900,6 +900,11 @@ void NDS_Reset( void) currFrameCounter=0; MMU_clearMem(); + //things formerly from MMU_clearMem before we changed it to do less: + rtcInit(); + addonsReset(); + Mic_Reset(); + //------------ //ARM7 BIOS IRQ HANDLER if(CommonSettings.UseExtBIOS == true) @@ -988,7 +993,7 @@ void NDS_Reset( void) for(i = 0; i < (header->ARM9binSize>>2); ++i) { - _MMU_write32(dst, T1ReadLong(MMU.CART_ROM, src)); + _MMU_write32(dst, T1ReadLong(MMU_static.CART_ROM, src)); dst += 4; src += 4; } @@ -998,7 +1003,7 @@ void NDS_Reset( void) for(i = 0; i < (header->ARM7binSize>>2); ++i) { - _MMU_write32(dst, T1ReadLong(MMU.CART_ROM, src)); + _MMU_write32(dst, T1ReadLong(MMU_static.CART_ROM, src)); dst += 4; src += 4; } @@ -1010,6 +1015,8 @@ void NDS_Reset( void) nds.ARM9Cycle = 0; nds.ARM7Cycle = 0; nds.cycles = 0; + nds.idleFrameCounter = 0; + memset(nds.runCycleCollector,0,sizeof(nds.runCycleCollector)); memset(nds.timerCycle, 0, sizeof(s32) * 2 * 4); memset(nds.timerOver, 0, sizeof(BOOL) * 2 * 4); nds.nextHBlank = 3168; @@ -1017,6 +1024,7 @@ void NDS_Reset( void) nds.old = 0; nds.diff = 0; nds.lignerendu = FALSE; + nds.sleeping = FALSE; nds.touchX = nds.touchY = 0; nds.isTouch = 0; nds.debugConsole = CommonSettings.DebugConsole; @@ -1037,7 +1045,7 @@ void NDS_Reset( void) u8 temp_buffer[NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT]; int fw_index; - if ( copy_firmware_user_data( temp_buffer, MMU.fw.data)) { + if ( copy_firmware_user_data( temp_buffer, MMU_static.fw.data)) { for ( fw_index = 0; fw_index < NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT; fw_index++) _MMU_write08(0x027FFC80 + fw_index, temp_buffer[fw_index]); } @@ -1046,11 +1054,11 @@ void NDS_Reset( void) // Copy the whole header to Main RAM 0x27FFE00 on startup. // Reference: http://nocash.emubase.de/gbatek.htm#dscartridgeheader for (i = 0; i < ((0x170+0x90)/4); i++) { - _MMU_write32(0x027FFE00+i*4, LE_TO_LOCAL_32(((u32*)MMU.CART_ROM)[i])); + _MMU_write32(0x027FFE00+i*4, LE_TO_LOCAL_32(((u32*)MMU_static.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)); + _MMU_write16(0x027FF808, T1ReadWord(MMU_static.CART_ROM, 0x15E)); MainScreen.offset = 0; SubScreen.offset = 192; @@ -1075,7 +1083,7 @@ void NDS_Reset( void) } #endif - memcpy(FW_Mac, (MMU.fw.data + 0x36), 6); + memcpy(FW_Mac, (MMU_static.fw.data + 0x36), 6); } int NDS_ImportSave(const char *filename) @@ -1084,7 +1092,7 @@ int NDS_ImportSave(const char *filename) return 0; if (memcmp(filename+strlen(filename)-4, ".duc", 4) == 0) - return mc_load_duc(&MMU.bupmem, filename); + return mc_load_duc(&MMU_static.bupmem, filename); return 0; } @@ -1415,85 +1423,85 @@ int NDS_CreateDummyFirmware( struct NDS_fw_config_data *user_settings) /* * Create the firmware header */ - memset( MMU.fw.data, 0, 0x40000); + memset( MMU_static.fw.data, 0, 0x40000); /* firmware identifier */ - MMU.fw.data[0x8] = 'M'; - MMU.fw.data[0x8 + 1] = 'A'; - MMU.fw.data[0x8 + 2] = 'C'; - MMU.fw.data[0x8 + 3] = 'P'; + MMU_static.fw.data[0x8] = 'M'; + MMU_static.fw.data[0x8 + 1] = 'A'; + MMU_static.fw.data[0x8 + 2] = 'C'; + MMU_static.fw.data[0x8 + 3] = 'P'; /* DS type */ if ( user_settings->ds_type == NDS_FW_DS_TYPE_LITE) - MMU.fw.data[0x1d] = 0x20; + MMU_static.fw.data[0x1d] = 0x20; else - MMU.fw.data[0x1d] = 0xff; + MMU_static.fw.data[0x1d] = 0xff; /* User Settings offset 0x3fe00 / 8 */ - MMU.fw.data[0x20] = 0xc0; - MMU.fw.data[0x21] = 0x7f; + MMU_static.fw.data[0x20] = 0xc0; + MMU_static.fw.data[0x21] = 0x7f; /* * User settings (at 0x3FE00 and 0x3FF00) */ - fill_user_data_area( user_settings, &MMU.fw.data[ 0x3FE00], 0); - fill_user_data_area( user_settings, &MMU.fw.data[ 0x3FF00], 1); + fill_user_data_area( user_settings, &MMU_static.fw.data[ 0x3FE00], 0); + fill_user_data_area( user_settings, &MMU_static.fw.data[ 0x3FF00], 1); /* Wifi config length */ - MMU.fw.data[0x2C] = 0x38; - MMU.fw.data[0x2D] = 0x01; + MMU_static.fw.data[0x2C] = 0x38; + MMU_static.fw.data[0x2D] = 0x01; - MMU.fw.data[0x2E] = 0x00; + MMU_static.fw.data[0x2E] = 0x00; /* Wifi version */ - MMU.fw.data[0x2F] = 0x00; + MMU_static.fw.data[0x2F] = 0x00; /* MAC address */ - memcpy((MMU.fw.data + 0x36), FW_Mac, sizeof(FW_Mac)); + memcpy((MMU_static.fw.data + 0x36), FW_Mac, sizeof(FW_Mac)); /* Enabled channels */ - MMU.fw.data[0x3C] = 0xFE; - MMU.fw.data[0x3D] = 0x3F; + MMU_static.fw.data[0x3C] = 0xFE; + MMU_static.fw.data[0x3D] = 0x3F; - MMU.fw.data[0x3E] = 0xFF; - MMU.fw.data[0x3F] = 0xFF; + MMU_static.fw.data[0x3E] = 0xFF; + MMU_static.fw.data[0x3F] = 0xFF; /* RF related */ - MMU.fw.data[0x40] = 0x02; - MMU.fw.data[0x41] = 0x18; - MMU.fw.data[0x42] = 0x0C; + MMU_static.fw.data[0x40] = 0x02; + MMU_static.fw.data[0x41] = 0x18; + MMU_static.fw.data[0x42] = 0x0C; - MMU.fw.data[0x43] = 0x01; + MMU_static.fw.data[0x43] = 0x01; /* Wifi I/O init values */ - memcpy((MMU.fw.data + 0x44), FW_WIFIInit, sizeof(FW_WIFIInit)); + memcpy((MMU_static.fw.data + 0x44), FW_WIFIInit, sizeof(FW_WIFIInit)); /* Wifi BB init values */ - memcpy((MMU.fw.data + 0x64), FW_BBInit, sizeof(FW_BBInit)); + memcpy((MMU_static.fw.data + 0x64), FW_BBInit, sizeof(FW_BBInit)); /* Wifi RF init values */ - memcpy((MMU.fw.data + 0xCE), FW_RFInit, sizeof(FW_RFInit)); + memcpy((MMU_static.fw.data + 0xCE), FW_RFInit, sizeof(FW_RFInit)); /* Wifi channel-related init values */ - memcpy((MMU.fw.data + 0xF2), FW_RFChannel, sizeof(FW_RFChannel)); - memcpy((MMU.fw.data + 0x146), FW_BBChannel, sizeof(FW_BBChannel)); - memset((MMU.fw.data + 0x154), 0x10, 0xE); + memcpy((MMU_static.fw.data + 0xF2), FW_RFChannel, sizeof(FW_RFChannel)); + memcpy((MMU_static.fw.data + 0x146), FW_BBChannel, sizeof(FW_BBChannel)); + memset((MMU_static.fw.data + 0x154), 0x10, 0xE); /* WFC profiles */ - memcpy((MMU.fw.data + 0x3FA40), &FW_WFCProfile1, sizeof(FW_WFCProfile)); - memcpy((MMU.fw.data + 0x3FB40), &FW_WFCProfile2, sizeof(FW_WFCProfile)); - memcpy((MMU.fw.data + 0x3FC40), &FW_WFCProfile3, sizeof(FW_WFCProfile)); - (*(u16*)(MMU.fw.data + 0x3FAFE)) = (u16)calc_CRC16(0, (MMU.fw.data + 0x3FA00), 0xFE); - (*(u16*)(MMU.fw.data + 0x3FBFE)) = (u16)calc_CRC16(0, (MMU.fw.data + 0x3FB00), 0xFE); - (*(u16*)(MMU.fw.data + 0x3FCFE)) = (u16)calc_CRC16(0, (MMU.fw.data + 0x3FC00), 0xFE); + memcpy((MMU_static.fw.data + 0x3FA40), &FW_WFCProfile1, sizeof(FW_WFCProfile)); + memcpy((MMU_static.fw.data + 0x3FB40), &FW_WFCProfile2, sizeof(FW_WFCProfile)); + memcpy((MMU_static.fw.data + 0x3FC40), &FW_WFCProfile3, sizeof(FW_WFCProfile)); + (*(u16*)(MMU_static.fw.data + 0x3FAFE)) = (u16)calc_CRC16(0, (MMU_static.fw.data + 0x3FA00), 0xFE); + (*(u16*)(MMU_static.fw.data + 0x3FBFE)) = (u16)calc_CRC16(0, (MMU_static.fw.data + 0x3FB00), 0xFE); + (*(u16*)(MMU_static.fw.data + 0x3FCFE)) = (u16)calc_CRC16(0, (MMU_static.fw.data + 0x3FC00), 0xFE); - MMU.fw.data[0x162] = 0x19; - memset((MMU.fw.data + 0x163), 0xFF, 0x9D); + MMU_static.fw.data[0x162] = 0x19; + memset((MMU_static.fw.data + 0x163), 0xFF, 0x9D); /* Wifi settings CRC16 */ - (*(u16*)(MMU.fw.data + 0x2A)) = calc_CRC16(0, (MMU.fw.data + 0x2C), 0x138); + (*(u16*)(MMU_static.fw.data + 0x2A)) = calc_CRC16(0, (MMU_static.fw.data + 0x2C), 0x138); return TRUE ; } @@ -1546,26 +1554,26 @@ int NDS_LoadFirmware(const char *filename) unsigned long size; //FILE *file; - if ((MMU.fw.fp = fopen(filename, "rb+")) == NULL) + if ((MMU_static.fw.fp = fopen(filename, "rb+")) == NULL) return -1; - fseek(MMU.fw.fp, 0, SEEK_END); - size = ftell(MMU.fw.fp); - fseek(MMU.fw.fp, 0, SEEK_SET); + fseek(MMU_static.fw.fp, 0, SEEK_END); + size = ftell(MMU_static.fw.fp); + fseek(MMU_static.fw.fp, 0, SEEK_SET); - if(size > MMU.fw.size) + if(size > MMU_static.fw.size) { - fclose(MMU.fw.fp); + fclose(MMU_static.fw.fp); fw_success = FALSE; return -1; } - i = fread(MMU.fw.data, size, 1, MMU.fw.fp); + i = fread(MMU_static.fw.data, size, 1, MMU_static.fw.fp); //fclose(file); INFO("Firmware: decrypting NDS firmware %s...\n", filename); - if(decryptFirmware(MMU.fw.data) == FALSE) + if(decryptFirmware(MMU_static.fw.data) == FALSE) { INFO("Firmware: decryption failed.\n"); fw_success = FALSE; @@ -1720,6 +1728,7 @@ u32 NDS_exec(s32 nb) { if(!nds.lignerendu) { + printf("%04d %03d: %08X\n",currFrameCounter,nds.VCount,NDS_ARM9.instruct_adr); T1WriteWord(ARM9Mem.ARM9_REG, 4, T1ReadWord(ARM9Mem.ARM9_REG, 4) | 2); T1WriteWord(MMU.ARM7_REG, 4, T1ReadWord(MMU.ARM7_REG, 4) | 2); NDS_ARM9HBlankInt(); diff --git a/src/armcpu.cpp b/src/armcpu.cpp index 31db6a191..d3ca0e817 100644 --- a/src/armcpu.cpp +++ b/src/armcpu.cpp @@ -28,7 +28,7 @@ #include "bios.h" #include "debug.h" #include "Disassembler.h" - +#include "ndssystem.h" template static u32 armcpu_prefetch(); @@ -179,6 +179,12 @@ int armcpu_new( armcpu_t *armcpu, u32 id, int armcpu_new( armcpu_t *armcpu, u32 id) #endif { + if(armcpu->initialized) return 0; + armcpu->initialized = true; + + for(int i = 0; i < 16; ++i) + armcpu->coproc[i] = NULL; + armcpu->proc_ID = id; #ifdef GDB_STUB @@ -208,6 +214,15 @@ void armcpu_init(armcpu_t *armcpu, u32 adr) { u32 i; + //TODO - breaks gdb stub + if(armcpu->coproc[15]) free(armcpu->coproc[15]); + u32 proc_ID = armcpu->proc_ID; + //memset(armcpu,0,sizeof(armcpu_t)); + armcpu->initialized = true; + armcpu->proc_ID = proc_ID; + + armcpu->coproc[15] = (armcp_t*)armcp15_new(armcpu); + armcpu->LDTBit = (armcpu->proc_ID==0); //Si ARM9 utiliser le syte v5 pour le load armcpu->intVector = 0xFFFF0000 * (armcpu->proc_ID==0); armcpu->waitIRQ = FALSE; @@ -215,18 +230,10 @@ void armcpu_init(armcpu_t *armcpu, u32 adr) armcpu->newIrqFlags = 0; -#ifdef GDB_STUB - armcpu->irq_flag = 0; -#endif + #ifdef GDB_STUB + armcpu->irq_flag = 0; + #endif - if(armcpu->coproc[15]) free(armcpu->coproc[15]); - - for(i = 0; i < 15; ++i) - { - armcpu->R[i] = 0; - armcpu->coproc[i] = NULL; - } - armcpu->CPSR.val = armcpu->SPSR.val = SYS; armcpu->R13_usr = armcpu->R14_usr = 0; @@ -238,20 +245,18 @@ void armcpu_init(armcpu_t *armcpu, u32 adr) armcpu->SPSR_svc.val = armcpu->SPSR_abt.val = armcpu->SPSR_und.val = armcpu->SPSR_irq.val = armcpu->SPSR_fiq.val = 0; -#ifdef GDB_STUB - armcpu->instruct_adr = adr; - armcpu->R[15] = adr + 8; -#else - armcpu->R[15] = adr; -#endif + #ifdef GDB_STUB + armcpu->instruct_adr = adr; + armcpu->R[15] = adr + 8; + #else + armcpu->R[15] = adr; + #endif armcpu->next_instruction = adr; - armcpu->coproc[15] = (armcp_t*)armcp15_new(armcpu); - -#ifndef GDB_STUB - armcpu_prefetch(armcpu); -#endif + #ifndef GDB_STUB + armcpu_prefetch(armcpu); + #endif } u32 armcpu_switchMode(armcpu_t *armcpu, u8 mode) @@ -480,6 +485,8 @@ BOOL armcpu_irqException(armcpu_t *armcpu) return TRUE; } +#define WANTASMLISTING + BOOL armcpu_flagIrq( armcpu_t *armcpu) { if(armcpu->CPSR.bits.I) return FALSE; @@ -524,9 +531,13 @@ u32 armcpu_exec() { if(PROCNUM==0) { #ifdef WANTASMLISTING + extern int currFrameCounter; char txt[128]; - des_arm_instructions_set[INSTRUCTION_INDEX(ARMPROC.instruction)](ARMPROC.instruct_adr,ARMPROC.instruction,txt); - printf("%X: %X - %s\n", ARMPROC.instruct_adr,ARMPROC.instruction, txt); + if(currFrameCounter>26) + { + // des_arm_instructions_set[INSTRUCTION_INDEX(ARMPROC.instruction)](ARMPROC.instruct_adr,ARMPROC.instruction,txt); + // printf("%04d %03d %08d: %X: %X - %s\n", currFrameCounter,nds.VCount,nds.cycles, ARMPROC.instruct_adr,ARMPROC.instruction, txt); + } #endif c += arm_instructions_set_0[INSTRUCTION_INDEX(ARMPROC.instruction)](); } diff --git a/src/armcpu.h b/src/armcpu.h index ff45635ca..b8a038572 100644 --- a/src/armcpu.h +++ b/src/armcpu.h @@ -156,8 +156,13 @@ struct armcpu_ctrl_iface { typedef void* armcp_t; -typedef struct armcpu_t +struct armcpu_t { + armcpu_t() + : initialized(false) + {} + + bool initialized; u32 proc_ID; u32 instruction; //4 u32 instruct_adr; //8 @@ -207,7 +212,7 @@ typedef struct armcpu_t /** the ctrl interface */ struct armcpu_ctrl_iface ctrl_iface; #endif -} armcpu_t; +}; #ifdef GDB_STUB int armcpu_new( armcpu_t *armcpu, u32 id, struct armcpu_memory_iface *mem_if, diff --git a/src/rtc.cpp b/src/rtc.cpp index c82e31ad0..79b9bfce0 100644 --- a/src/rtc.cpp +++ b/src/rtc.cpp @@ -96,12 +96,13 @@ static void MovieTime(void) { //when we could just assume that there are 60fps and base the seconds on frameCounter/60 //but, we were imagining that one day we might need more precision - const u32 arm9rate = 560190<<1; - const u64 noon = (u64)arm9rate * 60 * 60 * 12; + const u32 arm9rate_unitsperframe = 560190<<1; + const u32 arm9rate_unitspersecond = (u32)(arm9rate_unitspersecond * 59.8261); + const u64 noon = (u64)arm9rate_unitspersecond * 60 * 60 * 12; - u64 frameCycles = (u64)arm9rate * currFrameCounter; + u64 frameCycles = (u64)arm9rate_unitsperframe * currFrameCounter; u64 totalcycles = frameCycles + noon; - u32 totalseconds=totalcycles/arm9rate; + u32 totalseconds=totalcycles/arm9rate_unitspersecond; movie.sec=totalseconds % 60; movie.minute=totalseconds/60; diff --git a/src/saves.cpp b/src/saves.cpp index 084993354..e1a492105 100644 --- a/src/saves.cpp +++ b/src/saves.cpp @@ -218,11 +218,11 @@ SFORMAT SF_MMU[]={ //we are skipping the firmware, because we really don't want to save the firmware to the savestate //but, we will need to think about the philosophy of this. //should we perhaps hash the current firmware and save it, so that we can match it against the loader's firmware? - { "BUCO", 1, 1, &MMU.bupmem.com}, - { "BUAD", 4, 1, &MMU.bupmem.addr}, - { "BUAS", 1, 1, &MMU.bupmem.addr_shift}, - { "BUAZ", 1, 1, &MMU.bupmem.addr_size}, - { "BUWE", 4, 1, &MMU.bupmem.write_enable}, + { "BUCO", 1, 1, &MMU_static.bupmem.com}, + { "BUAD", 4, 1, &MMU_static.bupmem.addr}, + { "BUAS", 1, 1, &MMU_static.bupmem.addr_shift}, + { "BUAZ", 1, 1, &MMU_static.bupmem.addr_size}, + { "BUWE", 4, 1, &MMU_static.bupmem.write_enable}, //writeable_buffer ??? //end memory chips @@ -257,9 +257,9 @@ static void mmu_savestate(std::ostream* os) //version write32le(1,os); - write32le(MMU.bupmem.type,os); - write32le(MMU.bupmem.size,os); - os->write((char*)MMU.bupmem.data,MMU.bupmem.size); + write32le(MMU_static.bupmem.type,os); + write32le(MMU_static.bupmem.size,os); + os->write((char*)MMU_static.bupmem.data,MMU_static.bupmem.size); } static bool mmu_loadstate(std::istream* is, int size) @@ -277,8 +277,8 @@ static bool mmu_loadstate(std::istream* is, int size) //it would silently fail if there was a size mismatch SAV_silent_fail_flag = true; if(read32le(&bupmem_size,is) != 1) return false; - //if(bupmem_size != MMU.bupmem.size) return false; //mismatch between current initialized and saved size - mc_realloc(&MMU.bupmem,MC_TYPE_AUTODETECT,bupmem_size); + //if(bupmem_size != MMU_static.bupmem.size) return false; //mismatch between current initialized and saved size + mc_realloc(&MMU_static.bupmem,MC_TYPE_AUTODETECT,bupmem_size); } else { @@ -286,10 +286,10 @@ static bool mmu_loadstate(std::istream* is, int size) int bupmem_type; if(read32le(&bupmem_type,is) != 1) return false; if(read32le(&bupmem_size,is) != 1) return false; - mc_realloc(&MMU.bupmem,bupmem_type,bupmem_size); + mc_realloc(&MMU_static.bupmem,bupmem_type,bupmem_size); } - is->read((char*)MMU.bupmem.data,bupmem_size); + is->read((char*)MMU_static.bupmem.data,bupmem_size); if(is->fail()) return false; return true; diff --git a/src/thumb_instructions.cpp b/src/thumb_instructions.cpp index dfea7e859..da7048c1e 100644 --- a/src/thumb_instructions.cpp +++ b/src/thumb_instructions.cpp @@ -893,6 +893,9 @@ TEMPLATE static u32 FASTCALL OP_B_COND() TEMPLATE static u32 FASTCALL OP_SWI_THUMB() { + if(cpu->proc_ID==0) { + int zzz=9; + } if(cpu->swi_tab) { //zero 25-dec-2008 - in arm, we were masking to 0x1F. //this is probably safer since an invalid opcode could crash the emu diff --git a/src/windows/DeSmuME_2005.vcproj b/src/windows/DeSmuME_2005.vcproj index 674e3a5c2..ffedbf405 100644 --- a/src/windows/DeSmuME_2005.vcproj +++ b/src/windows/DeSmuME_2005.vcproj @@ -53,6 +53,7 @@ AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;DEBUG;WANTPROGINFO;EXPERIMENTAL_WIFI" ExceptionHandling="1" + BasicRuntimeChecks="0" BufferSecurityCheck="false" EnableEnhancedInstructionSet="0" FloatingPointModel="2" diff --git a/src/windows/DeSmuME_2008.vcproj b/src/windows/DeSmuME_2008.vcproj index 5d6b88010..4bb0b174f 100644 --- a/src/windows/DeSmuME_2008.vcproj +++ b/src/windows/DeSmuME_2008.vcproj @@ -54,7 +54,8 @@ AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;NOMINMAX;EXPERIMENTAL_WIFI;HAVE_LIBZZIP;HAVE_LIBZ" ExceptionHandling="1" - BufferSecurityCheck="false" + BasicRuntimeChecks="3" + BufferSecurityCheck="true" EnableEnhancedInstructionSet="0" FloatingPointModel="2" DebugInformationFormat="4" diff --git a/src/windows/ginfo.cpp b/src/windows/ginfo.cpp index 717dc8edc..052f64970 100644 --- a/src/windows/ginfo.cpp +++ b/src/windows/ginfo.cpp @@ -87,35 +87,35 @@ LRESULT GInfo_Paint(HWND hDlg, WPARAM wParam, LPARAM lParam) hdc = BeginPaint(hDlg, &ps); - icontitleOffset = T1ReadLong(MMU.CART_ROM, 0x68); + icontitleOffset = T1ReadLong(MMU_static.CART_ROM, 0x68); if(icontitleOffset >= 0x8000) { - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x240 + (0x100 * win_fw_config.language)); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x240 + (0x100 * win_fw_config.language)); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLE), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x240); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x240); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLEJP), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x340); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x340); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLEEN), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x440); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x440); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLEFR), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x540); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x540); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLEGE), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x640); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x640); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLEIT), text); - utf16text = (wchar_t*)(MMU.CART_ROM + icontitleOffset + 0x740); + utf16text = (wchar_t*)(MMU_static.CART_ROM + icontitleOffset + 0x740); sprintf(text, "%ws", utf16text); SetWindowText(GetDlgItem(hDlg, IDC_GI_TITLESP), text); } @@ -132,69 +132,69 @@ LRESULT GInfo_Paint(HWND hDlg, WPARAM wParam, LPARAM lParam) } - memcpy(text, MMU.CART_ROM, 12); + memcpy(text, MMU_static.CART_ROM, 12); text[12] = '\0'; SetWindowText(GetDlgItem(hDlg, IDC_GI_GAMETITLE), text); - memcpy(text, (MMU.CART_ROM+0xC), 4); + memcpy(text, (MMU_static.CART_ROM+0xC), 4); text[4] = '\0'; SetWindowText(GetDlgItem(hDlg, IDC_GI_GAMECODE), text); - memcpy(text, (MMU.CART_ROM+0x10), 2); + memcpy(text, (MMU_static.CART_ROM+0x10), 2); text[2] = '\0'; SetWindowText(GetDlgItem(hDlg, IDC_GI_MAKERCODE), text); - val = T1ReadByte(MMU.CART_ROM, 0x14); + val = T1ReadByte(MMU_static.CART_ROM, 0x14); sprintf(text, "%i kilobytes", (0x80 << val)); SetWindowText(GetDlgItem(hDlg, IDC_GI_CHIPSIZE), text); - val = T1ReadLong(MMU.CART_ROM, 0x20); + val = T1ReadLong(MMU_static.CART_ROM, 0x20); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM9ROM), text); - val = T1ReadLong(MMU.CART_ROM, 0x24); + val = T1ReadLong(MMU_static.CART_ROM, 0x24); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM9ENTRY), text); - val = T1ReadLong(MMU.CART_ROM, 0x28); + val = T1ReadLong(MMU_static.CART_ROM, 0x28); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM9START), text); - val = T1ReadLong(MMU.CART_ROM, 0x2C); + val = T1ReadLong(MMU_static.CART_ROM, 0x2C); sprintf(text, "%i bytes", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM9SIZE), text); - val = T1ReadLong(MMU.CART_ROM, 0x30); + val = T1ReadLong(MMU_static.CART_ROM, 0x30); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM7ROM), text); - val = T1ReadLong(MMU.CART_ROM, 0x34); + val = T1ReadLong(MMU_static.CART_ROM, 0x34); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM7ENTRY), text); - val = T1ReadLong(MMU.CART_ROM, 0x38); + val = T1ReadLong(MMU_static.CART_ROM, 0x38); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM7START), text); - val = T1ReadLong(MMU.CART_ROM, 0x3C); + val = T1ReadLong(MMU_static.CART_ROM, 0x3C); sprintf(text, "%i bytes", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_ARM7SIZE), text); - val = T1ReadLong(MMU.CART_ROM, 0x40); + val = T1ReadLong(MMU_static.CART_ROM, 0x40); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_FNTOFS), text); - val = T1ReadLong(MMU.CART_ROM, 0x44); + val = T1ReadLong(MMU_static.CART_ROM, 0x44); sprintf(text, "%i bytes", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_FNTSIZE), text); - val = T1ReadLong(MMU.CART_ROM, 0x48); + val = T1ReadLong(MMU_static.CART_ROM, 0x48); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_FATOFS), text); - val = T1ReadLong(MMU.CART_ROM, 0x4C); + val = T1ReadLong(MMU_static.CART_ROM, 0x4C); sprintf(text, "%i bytes", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_FATSIZE), text); @@ -202,7 +202,7 @@ LRESULT GInfo_Paint(HWND hDlg, WPARAM wParam, LPARAM lParam) sprintf(text, "0x%08X", icontitleOffset); SetWindowText(GetDlgItem(hDlg, IDC_GI_ICONTITLEOFS), text); - val = T1ReadLong(MMU.CART_ROM, 0x80); + val = T1ReadLong(MMU_static.CART_ROM, 0x80); sprintf(text, "0x%08X", val); SetWindowText(GetDlgItem(hDlg, IDC_GI_USEDROMSIZE), text); @@ -279,7 +279,7 @@ LRESULT GInfo_IconBoxPaint(HWND hCtl, WPARAM wParam, LPARAM lParam) bmph.bV4Width = 32; bmph.bV4Height = -32; - icontitleOffset = T1ReadLong(MMU.CART_ROM, 0x68); + icontitleOffset = T1ReadLong(MMU_static.CART_ROM, 0x68); if(icontitleOffset >= 0x8000) { @@ -292,14 +292,14 @@ LRESULT GInfo_IconBoxPaint(HWND hCtl, WPARAM wParam, LPARAM lParam) int tiley = (y % 8); int mapoffset = ((tilenum * 64) + (tiley * 8) + tilex); - u8 val = T1ReadByte(MMU.CART_ROM, (icontitleOffset + 0x20 + (mapoffset>>1))); + u8 val = T1ReadByte(MMU_static.CART_ROM, (icontitleOffset + 0x20 + (mapoffset>>1))); if(mapoffset & 1) val = ((val >> 4) & 0xF); else val = (val & 0xF); - icon[(y * 32) + x] = T1ReadWord(MMU.CART_ROM, (icontitleOffset + 0x220 + (val<<1))); + icon[(y * 32) + x] = T1ReadWord(MMU_static.CART_ROM, (icontitleOffset + 0x220 + (val<<1))); } } diff --git a/src/windows/ram_search.cpp b/src/windows/ram_search.cpp index ad40237c6..ee63b707a 100644 --- a/src/windows/ram_search.cpp +++ b/src/windows/ram_search.cpp @@ -31,6 +31,7 @@ #include "ramwatch.h" #include "ram_search.h" +#include "main.h" #include #include #include "ramwatch.h" diff --git a/src/windows/ramwatch.cpp b/src/windows/ramwatch.cpp index c2f9a2bed..5136609fc 100644 --- a/src/windows/ramwatch.cpp +++ b/src/windows/ramwatch.cpp @@ -4,6 +4,7 @@ #include "NDSSystem.h" #include "ramwatch.h" #include "ram_search.h" +#include "main.h" #include #include #include