📄 memmap.cpp
字号:
EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_ENABLED); else EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_GRAYED); #endif#endif Settings.ForceHeader = Settings.ForceHiROM = Settings.ForceLoROM = Settings.ForceInterleaved = Settings.ForceNoHeader = Settings.ForceNotInterleaved = Settings.ForceInterleaved2=false;}bool8 CMemory::LoadSRAM (const char *filename){ int size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; memset (SRAM, SNESGameFixes.SRAMInitialValue, 0x20000); if (size > 0x20000) size = 0x20000; if (size) { FILE *file; if ((file = fopen (filename, "rb"))) { int len = fread ((char*) ::SRAM, 1, 0x20000, file); fclose (file); if (len - size == 512) { // S-RAM file has a header - remove it memmove (::SRAM, ::SRAM + 512, size); } if (len == size + SRTC_SRAM_PAD) { S9xSRTCPostLoadState (); S9xResetSRTC (); rtc.index = -1; rtc.mode = MODE_READ; } else S9xHardResetSRTC (); if(Settings.SPC7110RTC) { S9xLoadSPC7110RTC (&rtc_f9); } return (TRUE); } S9xHardResetSRTC (); return (FALSE); } if (Settings.SDD1) S9xSDD1LoadLoggedData (); return (TRUE);}bool8 CMemory::SaveSRAM (const char *filename){ if(Settings.SuperFX && Memory.ROMType < 0x15) return TRUE; if(Settings.SA1 && Memory.ROMType == 0x34) return TRUE; int size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; if (Settings.SRTC) { size += SRTC_SRAM_PAD; S9xSRTCPreSaveState (); } if (Settings.SDD1) S9xSDD1SaveLoggedData (); if (size > 0x20000) size = 0x20000; if (size && *Memory.ROMFilename) { FILE *file; if ((file = fopen (filename, "wb"))) { fwrite ((char *) ::SRAM, size, 1, file); fclose (file);#if defined(__linux) chown (filename, getuid (), getgid ());#endif if(Settings.SPC7110RTC) { S9xSaveSPC7110RTC (&rtc_f9); } return (TRUE); } } return (FALSE);}void CMemory::FixROMSpeed (){ int c; if(CPU.FastROMSpeed==0) CPU.FastROMSpeed=SLOW_ONE_CYCLE; for (c = 0x800; c < 0x1000; c++) { if (c&0x8 || c&0x400) MemorySpeed [c] = (uint8) CPU.FastROMSpeed; }}void CMemory::ResetSpeedMap(){ int i; memset(MemorySpeed, SLOW_ONE_CYCLE, 0x1000); for(i=0;i<0x400;i+=0x10) { MemorySpeed[i+2]=MemorySpeed[0x800+i+2]= ONE_CYCLE; MemorySpeed[i+3]=MemorySpeed[0x800+i+3]= ONE_CYCLE; MemorySpeed[i+4]=MemorySpeed[0x800+i+4]= ONE_CYCLE; MemorySpeed[i+5]=MemorySpeed[0x800+i+5]= ONE_CYCLE; } CMemory::FixROMSpeed ();}void CMemory::WriteProtectROM (){ memmove ((void *) WriteMap, (void *) Map, sizeof (Map)); for (int c = 0; c < 0x1000; c++) { if (BlockIsROM [c]) WriteMap [c] = (uint8 *) MAP_NONE; }}void CMemory::MapRAM (){ int c; if(Memory.LoROM&&!Settings.SDD1) { // Banks 70->77, S-RAM for (c = 0; c < 0x0f; c++) { for(int i=0;i<8;i++) { Map [(c<<4) + 0xF00+i]=Map [(c<<4) + 0x700+i] = (uint8 *) MAP_LOROM_SRAM; BlockIsRAM [(c<<4) + 0xF00+i] =BlockIsRAM [(c<<4) + 0x700+i] = TRUE; BlockIsROM [(c<<4) + 0xF00+i] =BlockIsROM [(c<<4) + 0x700+i] = FALSE; } } } else if(Memory.LoROM&&Settings.SDD1) { // Banks 70->77, S-RAM for (c = 0; c < 0x0f; c++) { for(int i=0;i<8;i++) { Map [(c<<4) + 0x700+i] = (uint8 *) MAP_LOROM_SRAM; BlockIsRAM [(c<<4) + 0x700+i] = TRUE; BlockIsROM [(c<<4) + 0x700+i] = FALSE; } } } // Banks 7e->7f, RAM for (c = 0; c < 16; c++) { Map [c + 0x7e0] = RAM; Map [c + 0x7f0] = RAM + 0x10000; BlockIsRAM [c + 0x7e0] = TRUE; BlockIsRAM [c + 0x7f0] = TRUE; BlockIsROM [c + 0x7e0] = FALSE; BlockIsROM [c + 0x7f0] = FALSE; } WriteProtectROM ();}void CMemory::MapExtraRAM (){ int c; // Banks 7e->7f, RAM for (c = 0; c < 16; c++) { Map [c + 0x7e0] = RAM; Map [c + 0x7f0] = RAM + 0x10000; BlockIsRAM [c + 0x7e0] = TRUE; BlockIsRAM [c + 0x7f0] = TRUE; BlockIsROM [c + 0x7e0] = FALSE; BlockIsROM [c + 0x7f0] = FALSE; } // Banks 70->73, S-RAM for (c = 0; c < 16; c++) { Map [c + 0x700] = ::SRAM; Map [c + 0x710] = ::SRAM + 0x8000; Map [c + 0x720] = ::SRAM + 0x10000; Map [c + 0x730] = ::SRAM + 0x18000; BlockIsRAM [c + 0x700] = TRUE; BlockIsROM [c + 0x700] = FALSE; BlockIsRAM [c + 0x710] = TRUE; BlockIsROM [c + 0x710] = FALSE; BlockIsRAM [c + 0x720] = TRUE; BlockIsROM [c + 0x720] = FALSE; BlockIsRAM [c + 0x730] = TRUE; BlockIsROM [c + 0x730] = FALSE; }}void CMemory::LoROMMap (){ int c; int i; int j; int mask[4]; for (j=0; j<4; j++) mask[j]=0x00ff; mask[0]=(CalculatedSize/0x8000)-1; int x; bool foundZeros; bool pastZeros; for(j=0;j<3;j++) { x=1; foundZeros=false; pastZeros=false; mask[j+1]=mask[j]; while (x>0x100&&!pastZeros) { if(mask[j]&x) { x<<=1; if(foundZeros) pastZeros=true; } else { foundZeros=true; pastZeros=false; mask[j+1]|=x; x<<=1; } } } // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) { Map [c + 0] = Map [c + 0x800] = RAM; Map [c + 1] = Map [c + 0x801] = RAM; BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; if(Settings.SETA==ST_018) Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_SETA_RISC; else Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; if (Settings.DSP1Master) { Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_DSP; Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_DSP; } else if (Settings.C4) { Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_C4; Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_C4; } else if(Settings.OBC1) { Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_OBC_RAM; Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_OBC_RAM; } else { Map [c + 6] = Map [c + 0x806] = (uint8 *) bytes0x2000 - 0x6000; Map [c + 7] = Map [c + 0x807] = (uint8 *) bytes0x2000 - 0x6000; } for (i = c + 8; i < c + 16; i++) { int e=3; int d=c>>4; while(d>mask[0]) { d&=mask[e]; e--; } Map [i] = Map [i + 0x800] = ROM + (((d)-1)*0x8000); BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; } } if (Settings.DSP1Master) { // Banks 30->3f and b0->bf for (c = 0x300; c < 0x400; c += 16) { for (i = c + 8; i < c + 16; i++) { Map [i] = Map [i + 0x800] = (uint8 *) MAP_DSP; BlockIsROM [i] = BlockIsROM [i + 0x800] = FALSE; } } } // Banks 40->7f and c0->ff for (c = 0; c < 0x400; c += 16) { for (i = c; i < c + 8; i++) Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) % CalculatedSize]; for (i = c + 8; i < c + 16; i++) { int e=3; int d=(c+0x400)>>4; while(d>mask[0]) { d&=mask[e]; e--; } Map [i + 0x400] = Map [i + 0xc00] = ROM + (((d)-1)*0x8000); } for (i = c; i < c + 16; i++) { BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; } } if (Settings.DSP1Master) { for (c = 0; c < 0x100; c++) { Map [c + 0xe00] = (uint8 *) MAP_DSP; BlockIsROM [c + 0xe00] = FALSE; } } int sum=0, k,l, bankcount; bankcount=1<<(ROMSize-7);//Mbits //safety for corrupt headers if(bankcount > 128) bankcount = (CalculatedSize/0x8000)/4; bankcount*=4;//to banks bankcount<<=4;//Map banks bankcount+=0x800;//normalize for(k=0x800;k<(bankcount);k+=16) { uint8* bank=0x8000+Map[k+8]; for(l=0;l<0x8000;l++) sum+=bank[l]; } CalculatedChecksum=sum&0xFFFF; MapRAM (); WriteProtectROM ();}void CMemory::SetaDSPMap (){ int c; int i; int j; int mask[4]; for (j=0; j<4; j++) mask[j]=0x00ff; mask[0]=(CalculatedSize/0x8000)-1; int x; bool foundZeros; bool pastZeros; for(j=0;j<3;j++) { x=1; foundZeros=false; pastZeros=false; mask[j+1]=mask[j]; while (x>0x100&&!pastZeros) { if(mask[j]&x) { x<<=1; if(foundZeros) pastZeros=true; } else { foundZeros=true; pastZeros=false; mask[j+1]|=x; x<<=1; } } } // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) { Map [c + 0] = Map [c + 0x800] = RAM; Map [c + 1] = Map [c + 0x801] = RAM; BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; Map [c + 6] = Map [c + 0x806] = (uint8 *) bytes0x2000 - 0x6000; Map [c + 7] = Map [c + 0x807] = (uint8 *) bytes0x2000 - 0x6000; for (i = c + 8; i < c + 16; i++) { int e=3; int d=c>>4; while(d>mask[0]) { d&=mask[e]; e--; } Map [i] = Map [i + 0x800] = ROM + (((d)-1)*0x8000); BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; } } // Banks 40->7f and c0->ff for (c = 0; c < 0x400; c += 16) { for (i = c + 8; i < c + 16; i++) { int e=3; int d=(c+0x400)>>4; while(d>mask[0]) { d&=mask[e]; e--; } Map [i + 0x400] = Map [i + 0xc00] = ROM + (((d)-1)*0x8000); } //only upper half is ROM for (i = c+8; i < c + 16; i++) { BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; } } memset(SRAM, 0, 0x1000); for (c=0x600;c<0x680;c+=0x10) { for(i=0;i<0x08;i++) { //where does the SETA chip access, anyway? //please confirm this? Map[c+0x80+i]=(uint8*)MAP_SETA_DSP; BlockIsROM [c+0x80+i] = FALSE; BlockIsRAM [c+0x80+i] = TRUE; } for(i=0;i<0x04;i++) { //and this! Map[c+i]=(uint8*)MAP_SETA_DSP; BlockIsROM [c+i] = FALSE; } } int sum=0, k,l, bankcount; bankcount=1<<(ROMSize-7);//Mbits //safety for corrupt headers if(bankcount > 128) bankcount = (CalculatedSize/0x8000)/4; bankcount*=4;//to banks bankcount<<=4;//Map banks bankcount+=0x800;//normalize for(k=0x800;k<(bankcount);k+=16) { uint8* bank=0x8000+Map[k+8]; for(l=0;l<0x8000;l++) sum+=bank[l]; } CalculatedChecksum=sum&0xFFFF; MapRAM (); WriteProtectROM ();}void CMemory::BSLoROMMap (){ int c; int i; if(Settings.BS) SRAMSize=5; // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) { Map [c + 0] = Map [c + 0x800] = RAM; Map [c + 1] = Map [c + 0x801] = RAM; BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; Map [c + 5] = Map [c + 0x805] = (uint8 *) RAM;// Map [c + 5] = Map [c + 0x805] = (uint8 *) SRAM;BlockIsRAM [c + 5] = BlockIsRAM [c + 0x805] = TRUE; // Map [c + 6] = Map [c + 0x806] = (uint8 *)MAP_NONE;// Map [c + 7] = Map [c + 0x807] = (uint8 *)MAP_NONE; Map [c + 6] = Map [c + 0x806] = (uint8 *) RAM;// Map [c + 5] = Map [c + 0x805] = (uint8 *) SRAM;BlockIsRAM [c + 6] = BlockIsRAM [c + 0x806] = TRUE; Map [c + 7] = Map [c + 0x807] = (uint8 *) RAM;// Map [c + 5] = Map [c + 0x805] = (uint8 *) SRAM;BlockIsRAM [c + 7] = BlockIsRAM [c + 0x807] = TRUE; for (i = c + 8; i < c + 16; i++) { Map [i] = Map [i + 0x800] = &ROM [(c << 11) % CalculatedSize] - 0x8000;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -