u64 FifoDataFile::WriteMemoryUpdates(const std::vector<MemoryUpdate>& memUpdates, File::IOFile& file) { // Add space for memory update list u64 updateListOffset = file.Tell(); PadFile(memUpdates.size() * sizeof(FileMemoryUpdate), file); for (unsigned int i = 0; i < memUpdates.size(); ++i) { const MemoryUpdate& srcUpdate = memUpdates[i]; // Write memory file.Seek(0, SEEK_END); u64 dataOffset = file.Tell(); file.WriteBytes(srcUpdate.data.data(), srcUpdate.data.size()); FileMemoryUpdate dstUpdate; dstUpdate.address = srcUpdate.address; dstUpdate.dataOffset = dataOffset; dstUpdate.dataSize = static_cast<u32>(srcUpdate.data.size()); dstUpdate.fifoPosition = srcUpdate.fifoPosition; dstUpdate.type = srcUpdate.type; u64 updateOffset = updateListOffset + (i * sizeof(FileMemoryUpdate)); file.Seek(updateOffset, SEEK_SET); file.WriteBytes(&dstUpdate, sizeof(FileMemoryUpdate)); } return updateListOffset; }
void UpdateStateFlags(std::function<void(StateFlags*)> update_function) { const std::string file_path = Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + WII_STATE; File::IOFile file; StateFlags state; if (File::Exists(file_path)) { file.Open(file_path, "r+b"); file.ReadBytes(&state, sizeof(state)); } else { File::CreateFullPath(file_path); file.Open(file_path, "a+b"); memset(&state, 0, sizeof(state)); } update_function(&state); state.UpdateChecksum(); file.Seek(0, SEEK_SET); file.WriteBytes(&state, sizeof(state)); }
bool FifoDataFile::Save(const std::string& filename) { File::IOFile file; if (!file.Open(filename, "wb")) return false; // Add space for header PadFile(sizeof(FileHeader), file); // Add space for frame list u64 frameListOffset = file.Tell(); PadFile(m_Frames.size() * sizeof(FileFrameInfo), file); u64 bpMemOffset = file.Tell(); file.WriteArray(m_BPMem, BP_MEM_SIZE); u64 cpMemOffset = file.Tell(); file.WriteArray(m_CPMem, CP_MEM_SIZE); u64 xfMemOffset = file.Tell(); file.WriteArray(m_XFMem, XF_MEM_SIZE); u64 xfRegsOffset = file.Tell(); file.WriteArray(m_XFRegs, XF_REGS_SIZE); u64 texMemOffset = file.Tell(); file.WriteArray(m_TexMem, TEX_MEM_SIZE); // Write header FileHeader header; header.fileId = FILE_ID; header.file_version = VERSION_NUMBER; header.min_loader_version = MIN_LOADER_VERSION; header.bpMemOffset = bpMemOffset; header.bpMemSize = BP_MEM_SIZE; header.cpMemOffset = cpMemOffset; header.cpMemSize = CP_MEM_SIZE; header.xfMemOffset = xfMemOffset; header.xfMemSize = XF_MEM_SIZE; header.xfRegsOffset = xfRegsOffset; header.xfRegsSize = XF_REGS_SIZE; header.texMemOffset = texMemOffset; header.texMemSize = TEX_MEM_SIZE; header.frameListOffset = frameListOffset; header.frameCount = (u32)m_Frames.size(); header.flags = m_Flags; file.Seek(0, SEEK_SET); file.WriteBytes(&header, sizeof(FileHeader)); // Write frames list for (unsigned int i = 0; i < m_Frames.size(); ++i) { const FifoFrameInfo& srcFrame = m_Frames[i]; // Write FIFO data file.Seek(0, SEEK_END); u64 dataOffset = file.Tell(); file.WriteBytes(srcFrame.fifoData.data(), srcFrame.fifoData.size()); u64 memoryUpdatesOffset = WriteMemoryUpdates(srcFrame.memoryUpdates, file); FileFrameInfo dstFrame; dstFrame.fifoDataSize = static_cast<u32>(srcFrame.fifoData.size()); dstFrame.fifoDataOffset = dataOffset; dstFrame.fifoStart = srcFrame.fifoStart; dstFrame.fifoEnd = srcFrame.fifoEnd; dstFrame.memoryUpdatesOffset = memoryUpdatesOffset; dstFrame.numMemoryUpdates = static_cast<u32>(srcFrame.memoryUpdates.size()); // Write frame info u64 frameOffset = frameListOffset + (i * sizeof(FileFrameInfo)); file.Seek(frameOffset, SEEK_SET); file.WriteBytes(&dstFrame, sizeof(FileFrameInfo)); } if (!file.Close()) return false; return true; }
int SyncTrace() { if (bWriteTrace) { tracefile.WriteBytes(&PowerPC::ppcState, stateSize); tracefile.Flush(); return 1; } if (bReadTrace) { PowerPC::PowerPCState state; if (!tracefile.ReadBytes(&state, stateSize)) return 1; bool difference = false; for (int i=0; i<32; i++) { if (PowerPC::ppcState.gpr[i] != state.gpr[i]) { DEBUG_LOG(POWERPC, "DIFFERENCE - r%i (local %08x, remote %08x)", i, PowerPC::ppcState.gpr[i], state.gpr[i]); difference = true; } } /* for (int i=0; i<32; i++) { for (int j=0; j<2; j++) { if (PowerPC::ppcState.ps[i][j] != state.ps[i][j]) { LOG(GEKKO, "DIFFERENCE - ps%i_%i (local %f, remote %f)", i, j, PowerPC::ppcState.ps[i][j], state.ps[i][j]); difference = true; } } }*/ /* if (GetCR() != state.cr) { LOG(GEKKO, "DIFFERENCE - CR (local %08x, remote %08x)", PowerPC::ppcState.cr, state.cr); difference = true; } if (PowerPC::ppcState.pc != state.pc) { LOG(GEKKO, "DIFFERENCE - PC (local %08x, remote %08x)", PowerPC::ppcState.pc, state.pc); difference = true; } if (PowerPC::ppcState.npc != state.npc) { LOG(GEKKO, "DIFFERENCE - NPC (local %08x, remote %08x)", PowerPC::ppcState.npc, state.npc); difference = true; } if (PowerPC::ppcState.msr != state.msr) { LOG(GEKKO, "DIFFERENCE - MSR (local %08x, remote %08x)", PowerPC::ppcState.msr, state.msr); difference = true; } if (PowerPC::ppcState.fpscr != state.fpscr) { LOG(GEKKO, "DIFFERENCE - FPSCR (local %08x, remote %08x)", PowerPC::ppcState.fpscr, state.fpscr); difference = true; } */ if (difference) { Host_UpdateLogDisplay(); //Also show drec compare window here //CDynaViewDlg::Show(true); //CDynaViewDlg::ViewAddr(m_BlockStart); //CDynaViewDlg::Show(true); //PanicAlert("Hang on"); //Sleep(INFINITE); return 0; } else { return 1; //LOG(GEKKO, "No difference!"); } } return 1; }