From fdbfec783b1c004dcb8b4f1a7cedbd8a129ce696 Mon Sep 17 00:00:00 2001 From: neobrain Date: Sun, 22 Sep 2013 00:34:32 +0200 Subject: [PATCH] Restore dffv1 compatibility. --- source/FifoDataFile.cpp | 45 ++++++++++++++++----------- source/FifoDataFile.h | 4 ++- source/main.cpp | 67 +++++++++++++++++------------------------ 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/source/FifoDataFile.cpp b/source/FifoDataFile.cpp index 5c5da75..746d140 100644 --- a/source/FifoDataFile.cpp +++ b/source/FifoDataFile.cpp @@ -12,15 +12,15 @@ void LoadDffData(const char* filename, FifoData& out) size_t numread = fread(&header, sizeof(DffFileHeader), 1, out.file); header.FixEndianness(); - // TODO: Version is not being checked for.. - - if (header.fileId != 0x0d01f1f0 || header.min_loader_version > 1) + if (header.fileId != 0x0d01f1f0 || header.min_loader_version > 2) { printf ("file ID or version don't match!\n"); } + out.version = header.file_version; + printf ("Got %d frame%s\n", header.frameCount, (header.frameCount == 1) ? "" : "s"); - for (unsigned int i = 0;i < header.frameCount; ++i) + for (unsigned int i = 0; i < header.frameCount; ++i) { u64 frameOffset = header.frameListOffset + (i * sizeof(DffFrameInfo)); DffFrameInfo srcFrame; @@ -32,9 +32,14 @@ void LoadDffData(const char* filename, FifoData& out) out.frames.push_back(FifoFrameData()); FifoFrameData& dstFrame = out.frames[i]; - dstFrame.fifoData.resize(srcFrame.fifoDataSize); + // Version 1 did not support XFB copies. + // To get it working at all the last 5 bytes are assumed + // to be a EFB->XFB copy and replaced with manual XFB handling. + // Thus they're not loaded into the actual fifo data. + u32 used_fifo_data_size = (header.file_version < 2) ? (srcFrame.fifoDataSize-5) : srcFrame.fifoDataSize; + dstFrame.fifoData.resize(used_fifo_data_size); fseek(out.file, srcFrame.fifoDataOffset, SEEK_SET); - fread(&dstFrame.fifoData[0], srcFrame.fifoDataSize, 1, out.file); + fread(&dstFrame.fifoData[0], used_fifo_data_size, 1, out.file); dstFrame.memoryUpdates.resize(srcFrame.numMemoryUpdates); for (unsigned int i = 0; i < srcFrame.numMemoryUpdates; ++i) @@ -46,14 +51,17 @@ void LoadDffData(const char* filename, FifoData& out) srcUpdate.FixEndianness(); } - dstFrame.asyncEvents.resize(srcFrame.numAsyncEvents); - for (unsigned int i = 0; i < srcFrame.numAsyncEvents; ++i) + if (header.file_version >= 2) { - u64 eventOffset = srcFrame.asyncEventsOffset + (i * sizeof(DffAsyncEvent)); - DffAsyncEvent& srcEvent = dstFrame.asyncEvents[i]; - fseek(out.file, eventOffset, SEEK_SET); - fread(&srcEvent, sizeof(DffAsyncEvent), 1, out.file); - srcEvent.FixEndianness(); + dstFrame.asyncEvents.resize(srcFrame.numAsyncEvents); + for (unsigned int i = 0; i < srcFrame.numAsyncEvents; ++i) + { + u64 eventOffset = srcFrame.asyncEventsOffset + (i * sizeof(DffAsyncEvent)); + DffAsyncEvent& srcEvent = dstFrame.asyncEvents[i]; + fseek(out.file, eventOffset, SEEK_SET); + fread(&srcEvent, sizeof(DffAsyncEvent), 1, out.file); + srcEvent.FixEndianness(); + } } } @@ -78,8 +86,11 @@ void LoadDffData(const char* filename, FifoData& out) fseek(out.file, header.xfRegsOffset, SEEK_SET); fread(&out.xfregs[0], xf_regs_size*4, 1, out.file); - u32 vi_size = header.viMemSize; - out.vimem.resize(vi_size); - fseek(out.file, header.viMemOffset, SEEK_SET); - fread(&out.vimem[0], vi_size*2, 1, out.file); + if (header.file_version >= 2) + { + u32 vi_size = header.viMemSize; + out.vimem.resize(vi_size); + fseek(out.file, header.viMemOffset, SEEK_SET); + fread(&out.vimem[0], vi_size*2, 1, out.file); + } } diff --git a/source/FifoDataFile.h b/source/FifoDataFile.h index 18fca6b..2831284 100644 --- a/source/FifoDataFile.h +++ b/source/FifoDataFile.h @@ -12,10 +12,11 @@ struct FifoFrameData { - std::vector fifoData; u32 fifoStart; u32 fifoEnd; + std::vector fifoData; + // Sorted by position - TODO: Make this a map instead? std::vector memoryUpdates; std::vector asyncEvents; @@ -24,6 +25,7 @@ struct FifoFrameData struct FifoData { FILE* file; + u32 version; std::vector frames; diff --git a/source/main.cpp b/source/main.cpp index fe2c0d4..67239f9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -324,9 +324,9 @@ void Init() rmode = VIDEO_GetPreferredMode(NULL); first_frame = 1; fb = 0; +#if ENABLE_CONSOLE!=1 frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // TODO: Shouldn't require manual framebuffer management! frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); -#if ENABLE_CONSOLE!=1 VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); @@ -334,14 +334,6 @@ void Init() VIDEO_WaitVSync(); if(rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); -#else - //TODO Remove? - VIDEO_Configure(rmode); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if(rmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); #endif fb ^= 1; @@ -757,7 +749,9 @@ int main() { u32 tempval = /*be32toh*/(*(u32*)&cmd_data[1]); UPE_Copy* copy = (UPE_Copy*)&tempval; -// if (!copy->copy_to_xfb) + + // Version 1 did not support EFB->XFB copies + if (fifo_data.version >= 2 || !copy->copy_to_xfb) { bool update_textures = PrepareMemoryLoad(efbcopy_target, 640*480*4); // TODO: Size!! u32 new_addr = MEM_VIRTUAL_TO_PHYSICAL(GetPointer(efbcopy_target)); @@ -785,11 +779,13 @@ int main() } } } +#if ENABLE_CONSOLE!=1 wgPipe->U8 = 0x61; wgPipe->U8 = cmd_data[1]; wgPipe->U8 = cmd_data[2]; wgPipe->U8 = cmd_data[3]; wgPipe->U8 = cmd_data[4]; +#endif } else { @@ -878,28 +874,30 @@ int main() // TODO: Flush WGPipe #if ENABLE_CONSOLE!=1 -#if 0 - // finish frame - // Note that GX_CopyDisp(frameBuffer[fb],GX_TRUE) uses an internal state - // which is out of sync with the dff_data, so we're manually writing - // to the EFB copy registers instead. - wgPipe->U8 = GX_LOAD_BP_REG; - wgPipe->U32 = (BPMEM_EFB_ADDR << 24) | ((MEM_VIRTUAL_TO_PHYSICAL(frameBuffer[fb]) >> 5) & 0xFFFFFF); - - UPE_Copy copy; - copy.Hex = 0; - copy.clear = 1; - copy.copy_to_xfb = 1; - wgPipe->U8 = GX_LOAD_BP_REG; - wgPipe->U32 = (BPMEM_TRIGGER_EFB_COPY << 24) | copy.Hex; - - VIDEO_SetNextFramebuffer(frameBuffer[fb]); - if (first_frame) + if (fifo_data.version < 2) { - VIDEO_SetBlack(FALSE); - first_frame = 0; + // finish frame for legacy dff files + // + // Note that GX_CopyDisp(frameBuffer[fb],GX_TRUE) uses an internal state + // which is out of sync with the dff_data, so we're manually writing + // to the EFB copy registers instead. + wgPipe->U8 = GX_LOAD_BP_REG; + wgPipe->U32 = (BPMEM_EFB_ADDR << 24) | ((MEM_VIRTUAL_TO_PHYSICAL(frameBuffer[fb]) >> 5) & 0xFFFFFF); + + UPE_Copy copy; + copy.Hex = 0; + copy.clear = 1; + copy.copy_to_xfb = 1; + wgPipe->U8 = GX_LOAD_BP_REG; + wgPipe->U32 = (BPMEM_TRIGGER_EFB_COPY << 24) | copy.Hex; + + VIDEO_SetNextFramebuffer(frameBuffer[fb]); + if (first_frame) + { + VIDEO_SetBlack(FALSE); + first_frame = 0; + } } -#endif #endif VIDEO_Flush(); VIDEO_WaitVSync(); @@ -924,15 +922,6 @@ int main() if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) { printf("\n"); -/* for (unsigned int i = 0; i < fifo_data.frames[0].fifoData.size(); ++i) - { - printf("%02x", fifo_data.frames[0].fifoData[i]); - if (i == fifo_data.frames[0].fifoData.size()-5) printf("_"); -// if ((i % 4) == 3) printf(" "); -// if ((i % 16) == 15) printf("\n"); - if ((i % 4) == 3) printf(" "); - if ((i % 24) == 23) printf("\n"); - }*/ fclose(fifo_data.file); exit(0); }