diff options
Diffstat (limited to 'Source/Core/VideoCommon/CPMemory.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/CPMemory.cpp | 169 |
1 files changed, 168 insertions, 1 deletions
diff --git a/Source/Core/VideoCommon/CPMemory.cpp b/Source/Core/VideoCommon/CPMemory.cpp index afa354b4e4..4781595e8c 100644 --- a/Source/Core/VideoCommon/CPMemory.cpp +++ b/Source/Core/VideoCommon/CPMemory.cpp @@ -2,7 +2,13 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "VideoCommon/CPMemory.h" + +#include <cstring> + #include "Common/ChunkFile.h" +#include "Common/Logging/Log.h" +#include "Core/DolphinAnalytics.h" +#include "VideoCommon/CommandProcessor.h" // CP state CPState g_main_cp_state; @@ -28,7 +34,7 @@ void DoCPState(PointerWrap& p) void CopyPreprocessCPStateFromMain() { - memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState)); + std::memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState)); } std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value) @@ -73,3 +79,164 @@ std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value) return std::make_pair(fmt::format("Invalid CP register {:02x} = {:08x}", cmd, value), ""); } } + +CPState::CPState(const u32* memory) : CPState() +{ + matrix_index_a.Hex = memory[MATINDEX_A]; + matrix_index_b.Hex = memory[MATINDEX_B]; + vtx_desc.low.Hex = memory[VCD_LO]; + vtx_desc.high.Hex = memory[VCD_HI]; + + for (u32 i = 0; i < CP_NUM_VAT_REG; i++) + { + vtx_attr[i].g0.Hex = memory[CP_VAT_REG_A + i]; + vtx_attr[i].g1.Hex = memory[CP_VAT_REG_B + i]; + vtx_attr[i].g2.Hex = memory[CP_VAT_REG_C + i]; + } + + for (u32 i = 0; i < CP_NUM_ARRAYS; i++) + { + array_bases[static_cast<CPArray>(i)] = memory[ARRAY_BASE + i]; + array_strides[static_cast<CPArray>(i)] = memory[ARRAY_STRIDE + i]; + } +} + +void CPState::LoadCPReg(u8 sub_cmd, u32 value) +{ + switch (sub_cmd & CP_COMMAND_MASK) + { + case UNKNOWN_00: + case UNKNOWN_10: + case UNKNOWN_20: + if (!(sub_cmd == UNKNOWN_20 && value == 0)) + { + // All titles using libogc or the official SDK issue 0x20 with value=0 on startup + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_CP_PERF_COMMAND); + DEBUG_LOG_FMT(VIDEO, "Unknown CP command possibly relating to perf queries used: {:02x}", + sub_cmd); + } + break; + + case MATINDEX_A: + if (sub_cmd != MATINDEX_A) + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, + "CP MATINDEX_A: an exact value of {:02x} was expected " + "but instead a value of {:02x} was seen", + MATINDEX_A, sub_cmd); + } + + matrix_index_a.Hex = value; + break; + + case MATINDEX_B: + if (sub_cmd != MATINDEX_B) + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, + "CP MATINDEX_B: an exact value of {:02x} was expected " + "but instead a value of {:02x} was seen", + MATINDEX_B, sub_cmd); + } + + matrix_index_b.Hex = value; + break; + + case VCD_LO: + if (sub_cmd != VCD_LO) // Stricter than YAGCD + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, + "CP VCD_LO: an exact value of {:02x} was expected " + "but instead a value of {:02x} was seen", + VCD_LO, sub_cmd); + } + + vtx_desc.low.Hex = value; + attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); + bases_dirty = true; + break; + + case VCD_HI: + if (sub_cmd != VCD_HI) // Stricter than YAGCD + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, + "CP VCD_HI: an exact value of {:02x} was expected " + "but instead a value of {:02x} was seen", + VCD_HI, sub_cmd); + } + + vtx_desc.high.Hex = value; + attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); + bases_dirty = true; + break; + + case CP_VAT_REG_A: + if ((sub_cmd - CP_VAT_REG_A) >= CP_NUM_VAT_REG) + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_A: Invalid VAT {}", sub_cmd - CP_VAT_REG_A); + } + vtx_attr[sub_cmd & CP_VAT_MASK].g0.Hex = value; + attr_dirty[sub_cmd & CP_VAT_MASK] = true; + break; + + case CP_VAT_REG_B: + if ((sub_cmd - CP_VAT_REG_B) >= CP_NUM_VAT_REG) + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_B: Invalid VAT {}", sub_cmd - CP_VAT_REG_B); + } + vtx_attr[sub_cmd & CP_VAT_MASK].g1.Hex = value; + attr_dirty[sub_cmd & CP_VAT_MASK] = true; + break; + + case CP_VAT_REG_C: + if ((sub_cmd - CP_VAT_REG_C) >= CP_NUM_VAT_REG) + { + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND); + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_C: Invalid VAT {}", sub_cmd - CP_VAT_REG_C); + } + vtx_attr[sub_cmd & CP_VAT_MASK].g2.Hex = value; + attr_dirty[sub_cmd & CP_VAT_MASK] = true; + break; + + // Pointers to vertex arrays in GC RAM + case ARRAY_BASE: + array_bases[static_cast<CPArray>(sub_cmd & CP_ARRAY_MASK)] = + value & CommandProcessor::GetPhysicalAddressMask(); + bases_dirty = true; + break; + + case ARRAY_STRIDE: + array_strides[static_cast<CPArray>(sub_cmd & CP_ARRAY_MASK)] = value & 0xFF; + break; + + default: + DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_UNKNOWN_CP_COMMAND); + WARN_LOG_FMT(VIDEO, "Unknown CP register {:02x} set to {:08x}", sub_cmd, value); + } +} + +void CPState::FillCPMemoryArray(u32* memory) const +{ + memory[MATINDEX_A] = matrix_index_a.Hex; + memory[MATINDEX_B] = matrix_index_b.Hex; + memory[VCD_LO] = vtx_desc.low.Hex; + memory[VCD_HI] = vtx_desc.high.Hex; + + for (int i = 0; i < CP_NUM_VAT_REG; ++i) + { + memory[CP_VAT_REG_A + i] = vtx_attr[i].g0.Hex; + memory[CP_VAT_REG_B + i] = vtx_attr[i].g1.Hex; + memory[CP_VAT_REG_C + i] = vtx_attr[i].g2.Hex; + } + + for (int i = 0; i < CP_NUM_ARRAYS; ++i) + { + memory[ARRAY_BASE + i] = array_bases[static_cast<CPArray>(i)]; + memory[ARRAY_STRIDE + i] = array_strides[static_cast<CPArray>(i)]; + } +} |
