Convert BPMEM_LOADTLUT1 to a struct

This commit is contained in:
Pokechu22 2023-10-29 19:24:40 -07:00
parent 2a1d445b30
commit ea41d0e384
2 changed files with 21 additions and 6 deletions

View File

@ -2240,6 +2240,13 @@ struct fmt::formatter<BPU_PreloadTileInfo>
} }
}; };
union BPU_LoadTlutInfo
{
BitField<0, 10, u32> tmem_addr;
BitField<10, 11, u32> tmem_line_count;
u32 hex;
};
struct BPS_TmemConfig struct BPS_TmemConfig
{ {
u32 preload_addr; u32 preload_addr;
@ -2247,7 +2254,7 @@ struct BPS_TmemConfig
u32 preload_tmem_odd; u32 preload_tmem_odd;
BPU_PreloadTileInfo preload_tile_info; BPU_PreloadTileInfo preload_tile_info;
u32 tlut_src; u32 tlut_src;
u32 tlut_dest; BPU_LoadTlutInfo tlut_dest;
u32 texinvalidate; u32 texinvalidate;
}; };

View File

@ -380,24 +380,32 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager,
return; return;
} }
case BPMEM_LOADTLUT0: // This one updates bpmem.tlutXferSrc, no need to do anything here. case BPMEM_LOADTLUT0: // This updates bpmem.tmem_config.tlut_src, no need to do anything here.
return; return;
case BPMEM_LOADTLUT1: // Load a Texture Look Up Table case BPMEM_LOADTLUT1: // Load a Texture Look Up Table
{ {
u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9; u32 tmem_addr = bpmem.tmem_config.tlut_dest.tmem_addr << 9;
u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5; u32 tmem_transfer_count = bpmem.tmem_config.tlut_dest.tmem_line_count * TMEM_LINE_SIZE;
u32 addr = bpmem.tmem_config.tlut_src << 5; u32 addr = bpmem.tmem_config.tlut_src << 5;
// The GameCube ignores the upper bits of this address. Some games (WW, MKDD) set them. // The GameCube ignores the upper bits of this address. Some games (WW, MKDD) set them.
if (!SConfig::GetInstance().bWii) if (!SConfig::GetInstance().bWii)
addr = addr & 0x01FFFFFF; addr = addr & 0x01FFFFFF;
// The copy below will always be in bounds as tmem is bigger than the maximum address a TLUT can
// be loaded to.
static constexpr u32 MAX_LOADABLE_TMEM_ADDR =
(1 << bpmem.tmem_config.tlut_dest.tmem_addr.NumBits()) << 9;
static constexpr u32 MAX_TMEM_LINE_COUNT =
(1 << bpmem.tmem_config.tlut_dest.tmem_line_count.NumBits()) * TMEM_LINE_SIZE;
static_assert(MAX_LOADABLE_TMEM_ADDR + MAX_TMEM_LINE_COUNT < TMEM_SIZE);
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.CopyFromEmu(texMem + tlutTMemAddr, addr, tlutXferCount); memory.CopyFromEmu(texMem + tmem_addr, addr, tmem_transfer_count);
if (OpcodeDecoder::g_record_fifo_data) if (OpcodeDecoder::g_record_fifo_data)
FifoRecorder::GetInstance().UseMemory(addr, tlutXferCount, MemoryUpdate::Type::TMEM); FifoRecorder::GetInstance().UseMemory(addr, tmem_transfer_count, MemoryUpdate::Type::TMEM);
TMEM::InvalidateAll(); TMEM::InvalidateAll();