MMU .c/.h - Added a Clear Memory function

NDSSystem.c - Call Clear Memory every time you run a rom to make sure all the the
 memory is blank like it should be
mc.c - Added basic saving backup ram to file (it slows saving down ALOT though)
This commit is contained in:
normmatt234 2006-11-14 04:35:54 +00:00
parent 52f564a0fe
commit f19bb9cfce
4 changed files with 54 additions and 10 deletions

View File

@ -287,6 +287,28 @@ 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_ABG, 0, 0x80000);
memset(ARM9Mem.ARM9_AOBJ, 0, 0x40000);
memset(ARM9Mem.ARM9_BBG, 0, 0x20000);
memset(ARM9Mem.ARM9_BOBJ, 0, 0x20000);
memset(ARM9Mem.ARM9_DTCM, 0, 0x4000);
memset(ARM9Mem.ARM9_ITCM, 0, 0x8000);
memset(ARM9Mem.ARM9_LCD, 0, 0xA4000);
memset(ARM9Mem.ARM9_OAM, 0, 0x800);
memset(ARM9Mem.ARM9_REG, 0, 0x1000000);
memset(ARM9Mem.ARM9_VMEM, 0, 0x800);
memset(ARM9Mem.ARM9_WRAM, 0, 0x1000000);
memset(ARM9Mem.MAIN_MEM, 0, 0x400000);
//memset(&ARM9, 0, sizeof(ARM9_struct));
memset(MMU.ARM7_ERAM, 0, 0x10000);
memset(MMU.ARM7_REG, 0, 0x10000);
MainScreen.offset = 192;
SubScreen.offset = 0;
}
void MMU_setRom(u8 * rom, u32 mask)
{
@ -1068,42 +1090,42 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val)
GPU_setYH(SubScreen.gpu, 3, val);
return;
case BG0_CR :
GPULOG("MAIN BG0 SETPROP 16B %08X\r\n", val);
//GPULOG("MAIN BG0 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(MainScreen.gpu, 0, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x8, val);
return;
case BG1_CR :
GPULOG("MAIN BG1 SETPROP 16B %08X\r\n", val);
//GPULOG("MAIN BG1 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(MainScreen.gpu, 1, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xA, val);
return;
case BG2_CR :
GPULOG("MAIN BG2 SETPROP 16B %08X\r\n", val);
//GPULOG("MAIN BG2 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(MainScreen.gpu, 2, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xC, val);
return;
case BG3_CR :
GPULOG("MAIN BG3 SETPROP 16B %08X\r\n", val);
//GPULOG("MAIN BG3 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(MainScreen.gpu, 3, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xE, val);
return;
case SUB_BG0_CR :
GPULOG("SUB BG0 SETPROP 16B %08X\r\n", val);
//GPULOG("SUB BG0 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(SubScreen.gpu, 0, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x1008, val);
return;
case SUB_BG1_CR :
GPULOG("SUB BG1 SETPROP 16B %08X\r\n", val);
//GPULOG("SUB BG1 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(SubScreen.gpu, 1, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x100A, val);
return;
case SUB_BG2_CR :
GPULOG("SUB BG2 SETPROP 16B %08X\r\n", val);
//GPULOG("SUB BG2 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(SubScreen.gpu, 2, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x100C, val);
return;
case SUB_BG3_CR :
GPULOG("SUB BG3 SETPROP 16B %08X\r\n", val);
//GPULOG("SUB BG3 SETPROP 16B %08X\r\n", val);
GPU_setBGProp(SubScreen.gpu, 3, val);
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x100E, val);
return;
@ -1595,13 +1617,13 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val)
case 0x04000000 :
GPU_setVideoProp(MainScreen.gpu, val);
GPULOG("MAIN INIT 32B %08X\r\n", val);
//GPULOG("MAIN INIT 32B %08X\r\n", val);
T1WriteLong(MMU.MMU_MEM[proc][0x40], 0, val);
return;
case 0x04001000 :
GPU_setVideoProp(SubScreen.gpu, val);
GPULOG("SUB INIT 32B %08X\r\n", val);
//GPULOG("SUB INIT 32B %08X\r\n", val);
T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x1000, val);
return;

View File

@ -100,6 +100,8 @@ extern MMU_struct MMU;
void MMUInit(void);
void MMUDeInit(void);
void MMU_clearMem();
void MMU_setRom(u8 * rom, u32 mask);
void MMU_unsetRom();

View File

@ -86,6 +86,8 @@ void NDS_DeInit(void) {
BOOL NDS_SetROM(u8 * rom, u32 mask)
{
u32 i;
MMU_clearMem();
MMU_setRom(rom, mask);

View File

@ -83,6 +83,22 @@ void mc_reset_com(memory_chip_t *mc)
mc->com = 0;
}
void mc_read_file(memory_chip_t *mc, char* filename)
{
FILE* file = fopen(filename, "rb");
if(file == NULL) return;
fread (mc->data, mc->size, 1, file);
fclose (file);
}
void mc_write_file(memory_chip_t *mc, char* filename)
{
FILE* file = fopen(filename, "wb");
if(file == NULL) return;
fwrite (mc->data, mc->size, 1, file);
fclose (file);
}
u8 fw_transfer(memory_chip_t *mc, u8 data)
{
if(mc->com == FW_CMD_READ || mc->com == FW_CMD_PAGEWRITE) /* check if we are in a command that needs 3 bytes address */
@ -164,6 +180,7 @@ u8 fw_transfer(memory_chip_t *mc, u8 data)
u8 bm_transfer(memory_chip_t *mc, u8 data)
{
mc_read_file(mc,"test.sav");
if(mc->com == BM_CMD_READLOW || mc->com == BM_CMD_READHIGH ||
mc->com == BM_CMD_WRITELOW || mc->com == BM_CMD_WRITEHIGH) /* check if we are in a command that needs multiple byte address */
{
@ -258,6 +275,7 @@ u8 bm_transfer(memory_chip_t *mc, u8 data)
}
}
mc_write_file(mc,"test.sav");
return data;
}